spec/calendar_spec.rb in simple_calendar-2.2.4 vs spec/calendar_spec.rb in simple_calendar-2.2.5

- old
+ new

@@ -1,19 +1,20 @@ require 'spec_helper' require 'action_controller' require 'simple_calendar/calendar' class ViewContext - attr_accessor :start_date + attr_accessor :start_date, :start_date_param - def initialize(start_date=nil) + def initialize(start_date=nil, options={}) @start_date = start_date + @start_date_param = options.fetch(:start_date_param, :start_date) end def params if @start_date.present? - ActionController::Parameters.new({start_date: @start_date}) + ActionController::Parameters.new({start_date_param => @start_date}) else ActionController::Parameters.new end end end @@ -101,9 +102,15 @@ it "uses the optional argument's start_date to override view_context's start_date" do view_context = ViewContext.new(Date.yesterday) calendar = SimpleCalendar::Calendar.new(view_context, start_date: Date.tomorrow) expect(calendar.send(:start_date)).to eq(Date.tomorrow) + end + + it "takes an option to override the start_date parameter" do + view_context = ViewContext.new(Date.yesterday, start_date_param: :date) + calendar = SimpleCalendar::Calendar.new(view_context, start_date_param: :date) + expect(calendar.send(:start_date)).to eq(Date.yesterday) end end it 'has a param that determines the start date of the calendar' it 'generates a default date if no start date is present'