spec/calendar_spec.rb in simple_calendar-2.4.1 vs spec/calendar_spec.rb in simple_calendar-2.4.2
- old
+ new
@@ -1,40 +1,40 @@
-require 'spec_helper'
-require 'action_controller'
-require 'simple_calendar/calendar'
-require_relative 'support/fake_event'
-require_relative 'support/view_context'
+require "spec_helper"
+require "action_controller"
+require "simple_calendar/calendar"
+require_relative "support/fake_event"
+require_relative "support/view_context"
describe SimpleCalendar::Calendar do
let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
- it 'renders a partial with the same name as the class' do
+ it "renders a partial with the same name as the class" do
expect(calendar.send(:partial_name)).to eq("simple_calendar/calendar")
end
- context 'event sorting attribute' do
- it 'has start_time as the default attribute' do
+ context "event sorting attribute" do
+ 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
+ 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')
+ 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')
+ 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
+ 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)
@@ -46,11 +46,11 @@
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
+ 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)
@@ -62,21 +62,21 @@
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
+ it "handles events without a start time" do
event = double(start_time: nil)
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])
- expect{calendar.send(:sorted_events)}.not_to raise_error
+ 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()
+ view_context = ViewContext.new
calendar = SimpleCalendar::Calendar.new(view_context)
expect(calendar.send(:start_date)).to eq(Date.today)
end
it "uses the view context's params start_date to override" do
@@ -96,70 +96,70 @@
calendar = SimpleCalendar::Calendar.new(view_context, start_date_param: :date)
expect(calendar.send(:start_date)).to eq(Date.yesterday)
end
end
- describe 'current week class' do
- it 'should have the current week' do
+ describe "current week class" do
+ it "should have the current week" do
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
week = calendar.date_range.each_slice(7).to_a[0]
- expect(calendar.send(:tr_classes_for, week)).to include('current-week')
+ expect(calendar.send(:tr_classes_for, week)).to include("current-week")
end
- it 'should not have the current week if it does not contain today' do
+ it "should not have the current week if it does not contain today" do
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new(6.months.ago))
week = calendar.date_range.each_slice(7).to_a[0]
- expect(calendar.send(:tr_classes_for, week)).to_not include('current-week')
+ expect(calendar.send(:tr_classes_for, week)).to_not include("current-week")
end
end
- it 'has a param that determines the start date of the calendar' do
+ it "has a param that determines the start date of the calendar" do
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
rendering_variables = calendar.render[:locals]
expect(rendering_variables[:start_date]).not_to be_nil
end
- it 'generates a default date if no start date is present' do
+ it "generates a default date if no start date is present" do
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
calendar_start_date = calendar.render[:locals][:start_date]
expect(calendar_start_date).not_to be_nil
expect(calendar_start_date).to be_a(Date)
end
- it 'has a range of dates' do
+ it "has a range of dates" do
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
calendar_date_range = calendar.date_range
expect(calendar_date_range).to be_an(Array)
expect(calendar_date_range).to all(be_an(Date))
end
- it 'can split the range of dates into weeks'
- it 'has a title'
- it 'has a next view link'
- it 'has a previous view link'
+ it "can split the range of dates into weeks"
+ it "has a title"
+ it "has a next view link"
+ it "has a previous view link"
- it 'accepts an array of events' do
- first_event = FakeEvent.new('event1', Date.today)
- second_event = FakeEvent.new('event2', Date.today + 1.day)
+ it "accepts an array of events" do
+ first_event = FakeEvent.new("event1", Date.today)
+ second_event = FakeEvent.new("event2", Date.today + 1.day)
events = [first_event, second_event]
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
calendar_sorted_events = calendar.render[:locals][:sorted_events]
expect(calendar_sorted_events.length).to eq(2)
end
- it 'sorts the events' do
- first_event = FakeEvent.new('event1', Date.today + 2.days)
- second_event = FakeEvent.new('event2', Date.today + 1.day)
- third_event = FakeEvent.new('event3', Date.today)
+ it "sorts the events" do
+ first_event = FakeEvent.new("event1", Date.today + 2.days)
+ second_event = FakeEvent.new("event2", Date.today + 1.day)
+ third_event = FakeEvent.new("event3", Date.today)
events = [first_event, third_event, second_event]
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
calendar_sorted_events = calendar.render[:locals][:sorted_events]
first_key = calendar_sorted_events.keys[0]
@@ -169,8 +169,8 @@
expect(calendar_sorted_events[first_key][0]).to eq(third_event)
expect(calendar_sorted_events[second_key][0]).to eq(second_event)
expect(calendar_sorted_events[third_key][0]).to eq(first_event)
end
- it 'yields the events for each day'
+ it "yields the events for each day"
it "doesn't crash when an event has a nil start_time"
end