spec/calendar_spec.rb in simple_calendar-2.1.0 vs spec/calendar_spec.rb in simple_calendar-2.1.1
- old
+ new
@@ -1,6 +1,7 @@
require 'spec_helper'
+require 'action_controller'
require 'simple_calendar/calendar'
class ViewContext
attr_accessor :start_date
@@ -8,19 +9,19 @@
@start_date = start_date
end
def params
if @start_date.present?
- {start_date: @start_date}
+ ActionController::Parameters.new({start_date: @start_date})
else
- {}
+ ActionController::Parameters.new
end
end
end
describe SimpleCalendar::Calendar do
- let(:calendar) { SimpleCalendar::Calendar.new(nil) }
+ let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
it 'renders a partial with the same name as the class' do
expect(calendar.send(:partial_name)).to eq("simple_calendar/calendar")
end
@@ -28,11 +29,11 @@
it 'has start_time as the default attribute' do
expect(calendar.send(:attribute)).to eq(:start_time)
end
it 'allows you to override the default attribute' do
- expect(SimpleCalendar::Calendar.new(nil, attribute: :starts_at).send(:attribute)).to eq(:starts_at)
+ expect(SimpleCalendar::Calendar.new(ViewContext.new, 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' do
@@ -41,20 +42,20 @@
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)
+ 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([event3])
end
it 'handles events without a start time' do
event = double(start_time: nil)
- calendar = SimpleCalendar::Calendar.new(nil, events: [event])
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])
expect{calendar.send(:sorted_events)}.not_to raise_error
end
end