2008-05-12 03:58:20 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2008-03-02 20:14:52 +00:00
|
|
|
|
2008-11-05 23:15:12 +00:00
|
|
|
describe "fill_in" do
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with textareas" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-03-02 20:14:52 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_text">User Text</label>
|
|
|
|
<textarea id="user_text" name="user[text]"></textarea>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "User Text", :with => "filling text area"
|
|
|
|
click_button
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|
2009-09-19 21:34:09 +00:00
|
|
|
|
2009-09-07 18:04:32 +00:00
|
|
|
it "should support multiline values" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_text">User Text</label>
|
|
|
|
<textarea id="user_text" name="user[text]"></textarea>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"text" => "One\nTwo"})
|
|
|
|
fill_in "User Text", :with => "One\nTwo"
|
|
|
|
click_button
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with password fields" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input id="user_text" name="user[text]" type="password" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"text" => "pass"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "user_text", :with => "pass"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if input not found" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="get" action="/login">
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::NotFoundError)
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-02 00:22:23 +00:00
|
|
|
it "should fail if input is disabled" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-02 00:22:23 +00:00
|
|
|
<form method="get" action="/login">
|
|
|
|
<label for="user_email">Email</label>
|
|
|
|
<input id="user_email" name="user[email]" type="text" disabled="disabled" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::DisabledFieldError)
|
2008-10-02 00:22:23 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should allow overriding default form values" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_email">Email</label>
|
|
|
|
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "user[email]", :with => "foo@example.com"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should choose the shortest label match" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_mail1">Some other mail</label>
|
|
|
|
<input id="user_mail1" name="user[mail1]" type="text" />
|
|
|
|
<label for="user_mail2">Some mail</label>
|
|
|
|
<input id="user_mail2" name="user[mail2]" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "Some", :with => "value"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should choose the first label match if closest is a tie" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_mail1">Some mail one</label>
|
|
|
|
<input id="user_mail1" name="user[mail1]" type="text" />
|
|
|
|
<label for="user_mail2">Some mail two</label>
|
|
|
|
<input id="user_mail2" name="user[mail2]" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "Some mail", :with => "value"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should anchor label matches to start of label" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_email">Some mail</label>
|
|
|
|
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 19:08:34 +00:00
|
|
|
lambda { fill_in "mail", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should anchor label matches to word boundaries" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_email">Emailtastic</label>
|
|
|
|
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 19:08:34 +00:00
|
|
|
lambda { fill_in "Email", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with inputs nested in labels" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label>
|
|
|
|
Email
|
2008-04-05 16:49:18 +00:00
|
|
|
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
2008-04-07 23:19:30 +00:00
|
|
|
</label>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "Email", :with => "foo@example.com"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with full input names" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input id="user_email" name="user[email]" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "user[email]", :with => "foo@example.com"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2008-04-16 09:54:37 +00:00
|
|
|
|
2008-10-22 03:19:09 +00:00
|
|
|
it "should work if the input type is not set" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-16 09:54:37 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input id="user_email" name="user[email]" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in "user[email]", :with => "foo@example.com"
|
|
|
|
click_button
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with symbols" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-04-07 23:19:30 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="user_email">Email</label>
|
|
|
|
<input id="user_email" name="user[email]" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in :email, :with => "foo@example.com"
|
|
|
|
click_button
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-10-21 16:13:42 +00:00
|
|
|
it "should escape field values" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-21 16:13:42 +00:00
|
|
|
<form method="post" action="/users">
|
|
|
|
<label for="user_phone">Phone</label>
|
|
|
|
<input id="user_phone" name="user[phone]" type="text" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"})
|
2008-11-23 05:22:49 +00:00
|
|
|
fill_in 'Phone', :with => "+1 22 33"
|
|
|
|
click_button
|
2008-10-21 16:13:42 +00:00
|
|
|
end
|
2008-04-07 23:19:30 +00:00
|
|
|
end
|