require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "selects_date" do before do @session = Webrat::TestSession.new end it "should send the values for each individual date component" do @session.response_body = <<-EOS

EOS @session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @session.selects_date "December 25, 2003", :from => "Date" @session.click_button end it "should select the date components with the suffix convention provided" do @session.response_body = <<-EOS

EOS @session.should_receive(:post).with("/appointments", "appointment" => {"year" => '2003', "month" => "12", "day" => "25"}) @session.selects_date "December 25, 2003 9:30", :from => "Date", :suffix_convention => :full_words @session.click_button end it "should select the date components with the suffixes provided" do @session.response_body = <<-EOS

EOS @session.should_receive(:post).with("/appointments", "appointment" => {"y" => '2003', "mo" => "12", "d" => "25"}) @session.selects_date "December 25, 2003 9:30", :from => "Date", :suffixes => {:year => 'y', :month => 'mo', :day => 'd'} @session.click_button end it "should accept a date object" do @session.response_body = <<-EOS

EOS @session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @session.selects_date Date.parse("December 25, 2003"), :from => "date" @session.click_button end it "should work when no label is specified" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @session.selects_date "December 25, 2003" @session.click_button end it "should fail if the specified label is not found" do @session.response_body = <<-EOS
EOS lambda { @session.selects_date "December 25, 2003", :from => "date" }.should raise_error end end