spec/calendar_spec.rb in simple_calendar-2.1.5 vs spec/calendar_spec.rb in simple_calendar-2.2.0

- old
+ new

@@ -31,10 +31,20 @@ end it 'allows you to override the default attribute' do expect(SimpleCalendar::Calendar.new(ViewContext.new, attribute: :starts_at).send(:attribute)).to eq(:starts_at) end + + it "set a default when `partial` option isn't present" do + expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/calendar') + expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/month_calendar') + expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/week_calendar') + end + + it 'allows to override the default partial' do + expect(SimpleCalendar::Calendar.new(ViewContext.new, partial: 'simple_calendar/custom_calendar').send(:partial_name)).to eq('simple_calendar/custom_calendar') + end end describe "#sorted_events" do it 'converts an array of events to a hash sorted by days' do today, tomorrow = Date.today, Date.tomorrow @@ -48,9 +58,25 @@ sorted_events = calendar.send(:sorted_events) expect(sorted_events[today]).to eq([event1, event2]) expect(sorted_events[tomorrow]).to eq([event3]) + end + + it 'converts an array of multi-day events to a hash sorted by days' do + today, tomorrow = Date.today, Date.tomorrow + + event1 = double(start_time: today.at_midnight, end_time: tomorrow.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(ViewContext.new, events: events) + + sorted_events = calendar.send(:sorted_events) + + expect(sorted_events[today]).to eq([event1, event2]) + expect(sorted_events[tomorrow]).to eq([event1, event3]) end it 'handles events without a start time' do event = double(start_time: nil) calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])