require "spec_helper"
describe "Enhanced DateSelect" do
include ActionView::Helpers::FormOptionsHelper
let(:student) {Object.new}
let(:form_builder){ ActionView::Helpers::FormBuilder.new(:birthday, student, self, {}, nil)}
let(:instance_tag) { ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )}
let(:datetime){{:year => 2001, :month => 2, :day => 3}}
let(:html_options){{}}
let(:options) {{ :discard_day =>true,
:value => {:year => 2001, :month => 2, :day => 3},
:order => [:day, :month, :year],
:start_year => Time.now.year,
:end_year => 1940 }}
let(:expected_result) {"\n\n\n"}
before(:each) do
@instance_tag =ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )
@enhanced_datetime_selector = ActionView::Helpers::EnhancedDateTimeSelector.new(datetime, options, {})
end
describe ".enhanced_date_select" do
it "constructs 3 selectboxes" do
form_builder.enhanced_date_select(:birthday,{ :prompt => {
:day => "please select one",
:month => "please select one",
:year => "please select one" },
:value => {:year => 2001, :month => 2, :day => 3},
:order => [:day, :month, :year],
:start_year => Time.now.year,
:end_year => 1940 } ).should == "\n\n\n"
end
it "construct withoud the day dropdown" do
form_builder.enhanced_date_select(:birthday,{ :discard_day =>true,
:value => {:year => 2001, :month => 2, :day => 3},
:order => [:day, :month, :year],
:start_year => Time.now.year,
:end_year => 1940 } ).should =="\n\n\n"
end
end
describe ActionView::Helpers::FormOptionsHelper do
before(:each) do
ActionView::Helpers::InstanceTag.stub(:new).and_return(@instance_tag)
end
it "should call the instance tag with argument" do
ActionView::Helpers::InstanceTag.should_receive(:new).with(student, 'birthday', self, options.delete(:object)).and_return(@instance_tag)
enhanced_date_select(student,'birthday',options )
end
it "should call the tp date_select_tag method" do
@instance_tag.should_receive(:to_enhanced_date_select_tag).with(options, {})
enhanced_date_select(student,'birthday',options )
end
end
describe ActionView::Helpers::InstanceTag do
before(:each) do
@instance_tag.stub(:enhanced_datetime_selector).and_return(@enhanced_datetime_selector)
end
it "should call the datetimeselector" do
@instance_tag.should_receive(:enhanced_datetime_selector).with(options, html_options).and_return(@enhanced_datetime_selector)
@instance_tag.to_enhanced_date_select_tag(options, html_options)
end
it "should call the datetimeselector" do
@enhanced_datetime_selector.should_receive(:enhanced_select_date).and_return(expected_result)
@instance_tag.to_enhanced_date_select_tag(options, html_options)
end
end
end