-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7.2.4 An Authentication method | ||
8.4.1 integration tests with style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
class UsersController < ApplicationController | ||
|
||
def new | ||
@user = User.new | ||
@title = "Sign up" | ||
end | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
@title = @user.name | ||
end | ||
|
||
def create | ||
@user = User.new(params[:user]) | ||
if @user.save | ||
flash[:success] = "Welcome to the Sample App!" | ||
redirect_to @user | ||
else | ||
@title = "Sign up" | ||
render 'new' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<% if @user.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@user.errors.count, "error") %> | ||
prohibited this user from being saved:</h2> | ||
<p>There were problems with the following fields:</p> | ||
<ul> | ||
<% @user.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
<h1>Users#new</h1> | ||
<p>Find me in app/views/users/new.html.erb</p> | ||
<h1>Sign up</h1> | ||
|
||
<%= form_for(@user) do |f| %> | ||
<%= render 'shared/error_messages' %> | ||
<div class="field"> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :email %><br /> | ||
<%= f.text_field :email %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :password %><br /> | ||
<%= f.password_field :password %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :password_confirmation, "Confirmation" %><br /> | ||
<%= f.password_field :password_confirmation %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit "Sign up" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,55 @@ | |
response.should have_selector("title", :content => "Sign up") | ||
end | ||
end | ||
|
||
|
||
describe "POST 'create'" do | ||
|
||
describe "failure" do | ||
|
||
before(:each) do | ||
@attr = { :name => "", :email => "", :password => "", | ||
:password_confirmation => "" } | ||
end | ||
|
||
it "should not create a user" do | ||
lambda do | ||
post :create, :user => @attr | ||
end.should_not change(User, :count) | ||
end | ||
|
||
it "should have the right title" do | ||
post :create, :user => @attr | ||
response.should have_selector("title", :content => "Sign up") | ||
end | ||
|
||
it "should render the 'new' page" do | ||
post :create, :user => @attr | ||
response.should render_template('new') | ||
end | ||
end | ||
|
||
describe "success" do | ||
before(:each) do | ||
@attr = { :name => "New User", :email => "[email protected]", | ||
:password => "foobar", :password_confirmation => "foobar" } | ||
end | ||
|
||
it "should create a user" do | ||
lambda do | ||
post :create, :user => @attr | ||
end.should change(User, :count).by(1) | ||
end | ||
|
||
it "should redirect to the user show page" do | ||
post :create, :user => @attr | ||
response.should redirect_to(user_path(assigns(:user))) | ||
end | ||
|
||
it "should have a welcome message" do | ||
post :create, :user => @attr | ||
flash[:success].should =~ /welcome to the sample app/i | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'spec_helper' | ||
|
||
describe "Users" do | ||
|
||
describe "signup" do | ||
|
||
describe "failure" do | ||
|
||
it "should not make a new user" do | ||
lambda do | ||
visit signup_path | ||
fill_in "Name", :with => "" | ||
fill_in "Email", :with => "" | ||
fill_in "Password", :with => "" | ||
fill_in "Confirmation", :with => "" | ||
click_button | ||
response.should render_template('users/new') | ||
response.should have_selector("div#error_explanation") | ||
end.should_not change(User, :count) | ||
end | ||
end | ||
|
||
describe "success" do | ||
|
||
it "should make a new user" do | ||
lambda do | ||
visit signup_path | ||
fill_in "Name", :with => "Example User101" | ||
fill_in "Email", :with => "[email protected]" | ||
fill_in "Password", :with => "foobar" | ||
fill_in "Confirmation", :with => "foobar" | ||
click_button | ||
response.should have_selector("div.flash.success", | ||
:content => "Welcome") | ||
response.should render_template('users/show') | ||
end.should change(User, :count).by(1) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Logfile created on 2011-07-17 21:47:19 +0100 by logger.rb/25413 | ||
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"=>"[email protected]", "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 /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 User101", "email"=>"[email protected]", "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 /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 User101", "email"=>"[email protected]", "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"} |