webrat/spec/api/checks_spec.rb

117 lines
3.4 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2008-03-02 20:14:52 +00:00
2008-04-23 14:54:07 +00:00
describe "checks" do
before do
@session = Webrat::TestSession.new
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should fail if no checkbox found" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
</form>
EOS
2008-04-07 04:52:49 +00:00
2008-04-23 14:54:07 +00:00
lambda { @session.checks "remember_me" }.should raise_error
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should fail if input is not a checkbox" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
EOS
2008-04-07 04:52:49 +00:00
2008-04-23 14:54:07 +00:00
lambda { @session.checks "remember_me" }.should raise_error
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should check rails style checkboxes" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
EOS
2008-07-25 23:11:56 +00:00
@session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
2008-03-02 20:14:52 +00:00
@session.checks "TOS"
@session.clicks_button
end
2008-04-27 16:45:01 +00:00
it "should result in the value on being posted if not specified" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
<input type="checkbox" name="remember_me" />
<input type="submit" />
</form>
EOS
2008-07-25 23:11:56 +00:00
@session.should_receive(:post).with("/login", "remember_me" => "on")
2008-03-02 20:14:52 +00:00
@session.checks "remember_me"
@session.clicks_button
end
2008-04-27 16:45:01 +00:00
it "should result in a custom value being posted" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" />
<input type="submit" />
</form>
EOS
2008-07-25 23:11:56 +00:00
@session.should_receive(:post).with("/login", "remember_me" => "yes")
2008-03-02 20:14:52 +00:00
@session.checks "remember_me"
@session.clicks_button
end
end
2008-04-23 14:54:07 +00:00
describe "unchecks" do
before do
@session = Webrat::TestSession.new
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should fail if no checkbox found" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
</form>
EOS
2008-04-07 04:52:49 +00:00
2008-04-23 14:54:07 +00:00
lambda { @session.unchecks "remember_me" }.should raise_error
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should fail if input is not a checkbox" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
EOS
2008-04-07 04:52:49 +00:00
2008-04-23 14:54:07 +00:00
lambda { @session.unchecks "remember_me" }.should raise_error
2008-03-02 20:14:52 +00:00
end
2008-04-27 16:45:01 +00:00
it "should uncheck rails style checkboxes" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
EOS
2008-07-25 23:11:56 +00:00
@session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
2008-04-07 04:52:49 +00:00
@session.checks "TOS"
2008-03-02 20:14:52 +00:00
@session.unchecks "TOS"
@session.clicks_button
end
2008-04-27 16:45:01 +00:00
it "should result in value not being posted" do
@session.response_body = <<-EOS
2008-03-02 20:14:52 +00:00
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
<input type="submit" />
</form>
EOS
2008-07-25 23:11:56 +00:00
@session.should_receive(:post).with("/login", {})
2008-03-02 20:14:52 +00:00
@session.unchecks "remember_me"
@session.clicks_button
end
2008-04-27 16:45:01 +00:00
end