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
Aditya Sanghi
committed
Aug 31, 2010
1 parent
bd2df62
commit 683e72b
Showing
8 changed files
with
221 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,10 +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
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,37 @@ | ||
require 'spec_helper' | ||
|
||
describe "Users" do | ||
|
||
describe "signup" do | ||
|
||
describe "failure" do | ||
|
||
it "should not make a new user" 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 | ||
end | ||
describe "success" do | ||
|
||
it "should make a new user" do | ||
lambda do | ||
visit signup_path | ||
fill_in "Name", :with => "Example User" | ||
fill_in "Email", :with => "user@example.com" | ||
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