Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

exercises from chap 8

  • Loading branch information...
commit ef22073aea17b053dc7e0fcd4e85e7024ebfbdfb 1 parent 5f86918
@jimbomt authored
View
2  app/controllers/users_controller.rb
@@ -16,6 +16,8 @@ def create
redirect_to @user
else
@title = "Sign up"
+ @user.password = ""
+ @user.password_confirmation = ""
render 'new'
end
end
View
3  app/views/layouts/application.html.erb
@@ -11,7 +11,8 @@
<%= render 'layouts/header' %>
<section class="round">
<% flash.each do |key, value| %>
- <div class="flash <%= key %>"><%= value %></div>
+ <!-- <div class="flash <%= key %>"><%= value %></div> -->
+ <%= content_tag(:div, value, :class => "flash #{key}") %>
<% end%>
<%= yield %>
</section>
View
33 spec/controllers/users_controller_spec.rb
@@ -45,13 +45,34 @@
get 'new'
response.should have_selector("title", :content => "Sign up")
end
+
+ it "should have a name field" do
+ get :new
+ response.should have_selector("input[name='user[name]'][type='text']")
+ end
+
+ it "should have an email field" do
+ get :new
+ response.should have_selector("input[name='user[email]'][type='text']")
+ end
+
+ it "should have a password field" do
+ get :new
+ response.should have_selector("input[name='user[password]'][type='password']")
+ end
+
+ it "should have a password confirmation field" do
+ get :new
+ response.should have_selector("input[name='user[password_confirmation]'][type='password']")
+ end
+
end
describe "POST 'create'" do
describe "failure" do
before(:each) do
- @attr = { :name => "", :email => "", :password => "", :password_confirmation => "" }
+ @attr = { :name => "", :email => "", :password => "bad", :password_confirmation => "bad" }
end
it "should not create a user" do
@@ -65,6 +86,16 @@
response.should have_selector("title", :content => "Sign up")
end
+ it "should reset the password field" do
+ post :create, :user => @attr
+ response.should have_selector("input[name='user[password]'][type='password'][value='']")
+ end
+
+ it "should reset the password confirmation field" do
+ post :create, :user => @attr
+ response.should have_selector("input[name='user[password_confirmation]'][type='password'][value='']")
+ end
+
it "should render the 'new' page" do
post :create, :user => @attr
response.should render_template('new')
View
11 webrat.log
@@ -188,3 +188,14 @@ REQUESTING PAGE: POST /users with {"utf8"=>"\xE2\x9C\x93", "user"=>{"name"=>"",
REQUESTING PAGE: GET /signup with {} and HTTP headers {}
REQUESTING PAGE: POST /users with {"utf8"=>"\xE2\x9C\x93", "user"=>{"name"=>"Example User", "email"=>"user@example.com", "password"=>"foobar", "password_confirmation"=>"foobar"}, "commit"=>"Sign Up"} and HTTP headers {"HTTP_REFERER"=>"/signup"}
REQUESTING PAGE: GET http://www.example.com/users/1 with {} and HTTP headers {"HTTP_REFERER"=>"/users"}
+REQUESTING PAGE: GET / with {} and HTTP headers {}
+REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"}
+REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"}
+REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"}
+REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"}
+REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"}
+REQUESTING PAGE: GET /signup with {} and HTTP headers {}
+REQUESTING PAGE: POST /users with {"utf8"=>"\xE2\x9C\x93", "user"=>{"name"=>"", "email"=>"", "password"=>"", "password_confirmation"=>""}, "commit"=>"Sign Up"} and HTTP headers {"HTTP_REFERER"=>"/signup"}
+REQUESTING PAGE: GET /signup with {} and HTTP headers {}
+REQUESTING PAGE: POST /users with {"utf8"=>"\xE2\x9C\x93", "user"=>{"name"=>"Example User", "email"=>"user@example.com", "password"=>"foobar", "password_confirmation"=>"foobar"}, "commit"=>"Sign Up"} and HTTP headers {"HTTP_REFERER"=>"/signup"}
+REQUESTING PAGE: GET http://www.example.com/users/1 with {} and HTTP headers {"HTTP_REFERER"=>"/users"}
Please sign in to comment.
Something went wrong with that request. Please try again.