spec/calendar_spec.rb in simple_calendar-2.0.6 vs spec/calendar_spec.rb in simple_calendar-2.1.0
- old
+ new
@@ -33,10 +33,31 @@
expect(SimpleCalendar::Calendar.new(nil, attribute: :starts_at).send(:attribute)).to eq(:starts_at)
end
end
describe "#sorted_events" do
- it 'converts an array of events to a hash sorted by days'
+ it 'converts an array of events to a hash sorted by days' do
+ today, tomorrow = Date.today, Date.tomorrow
+
+ event1 = double(start_time: today.at_midnight)
+ event2 = double(start_time: today.at_noon)
+ event3 = double(start_time: tomorrow.at_noon)
+
+ events = [event1, event2, event3].shuffle
+ calendar = SimpleCalendar::Calendar.new(nil, events: events)
+
+ sorted_events = calendar.send(:sorted_events)
+
+ expect(sorted_events[today]).to eq([event1, event2])
+ expect(sorted_events[tomorrow]).to eq([event3])
+ end
+
+ it 'handles events without a start time' do
+ event = double(start_time: nil)
+ calendar = SimpleCalendar::Calendar.new(nil, events: [event])
+
+ expect{calendar.send(:sorted_events)}.not_to raise_error
+ end
end
describe "#start_date" do
it "defaults to today's date" do
view_context = ViewContext.new()