diff options
author | George Andrinopoulos <geoandri@gmail.com> | 2017-11-06 20:51:24 +0300 |
---|---|---|
committer | George Andrinopoulos <geoandri@gmail.com> | 2017-11-07 07:37:46 +0300 |
commit | f4ed780ef5fc76b7704742d4886ac435c3e5ab98 (patch) | |
tree | 7536ed460f72156638203606ce20dadff5305468 /spec/lib/milestone_array_spec.rb | |
parent | bba020a56cbedd6403b637ec7f9eaee258eb7c67 (diff) |
Add Group Milestone sorting
Diffstat (limited to 'spec/lib/milestone_array_spec.rb')
-rw-r--r-- | spec/lib/milestone_array_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/lib/milestone_array_spec.rb b/spec/lib/milestone_array_spec.rb new file mode 100644 index 00000000000..df91677b925 --- /dev/null +++ b/spec/lib/milestone_array_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe MilestoneArray do + let(:object1) { instance_double("BirdMilestone", due_date: Time.now, start_date: Time.now - 15.days, title: 'v2.0') } + let(:object2) { instance_double("CatMilestone", due_date: Time.now - 1.day, start_date: nil, title: 'v1.0') } + let(:object3) { instance_double("DogMilestone", due_date: nil, start_date: Time.now - 30.days, title: 'v3.0') } + let(:array) { [object1, object3, object2] } + + describe '#sort' do + it 'reorders array with due date in ascending order with nulls last' do + expect(described_class.sort(array, 'due_date_asc')).to eq([object2, object1, object3]) + end + + it 'reorders array with due date in desc order with nulls last' do + expect(described_class.sort(array, 'due_date_desc')).to eq([object1, object2, object3]) + end + + it 'reorders array with start date in ascending order with nulls last' do + expect(described_class.sort(array, 'start_date_asc')).to eq([object3, object1, object2]) + end + + it 'reorders array with start date in descending order with nulls last' do + expect(described_class.sort(array, 'start_date_desc')).to eq([object1, object3, object2]) + end + + it 'reorders array with title in ascending order' do + expect(described_class.sort(array, 'name_asc')).to eq([object2, object1, object3]) + end + + it 'reorders array with title in descending order' do + expect(described_class.sort(array, 'name_desc')).to eq([object3, object1, object2]) + end + end +end |