Skip to content
Browse files

User signup complete

  • Loading branch information...
1 parent 6b3f438 commit 32c7ec0c05a199d80c77d66b840a37ddebf00ff6 @ryanatwork committed
View
4 Gemfile
@@ -33,12 +33,12 @@ gem 'gravatar_image_tag', '1.0.0.pre2'
group :development do
- gem 'rspec-rails', '2.5.0'
+ gem 'rspec-rails'
gem 'annotate-models', '1.0.4'
end
group :test do
- gem 'rspec', '2.5.0'
+ gem 'rspec'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
end
View
28 Gemfile.lock
@@ -29,7 +29,7 @@ GEM
activesupport (= 3.0.7)
activesupport (3.0.7)
annotate-models (1.0.4)
- arel (2.0.9)
+ arel (2.0.10)
builder (2.1.2)
diff-lcs (1.1.2)
erubis (2.6.6)
@@ -48,7 +48,7 @@ GEM
mime-types (1.16)
nokogiri (1.4.4)
polyglot (0.3.1)
- rack (1.2.2)
+ rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
@@ -66,20 +66,20 @@ GEM
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
- rake (0.8.7)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.2)
- rspec-expectations (2.5.0)
+ rake (0.9.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.3)
+ rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
- rspec-rails (2.5.0)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.0)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
- rspec (~> 2.5.0)
+ rspec (~> 2.6.0)
sqlite3-ruby (1.3.2)
thor (0.14.6)
treetop (1.4.9)
@@ -98,7 +98,7 @@ DEPENDENCIES
factory_girl_rails (= 1.0)
gravatar_image_tag (= 1.0.0.pre2)
rails (= 3.0.7)
- rspec (= 2.5.0)
- rspec-rails (= 2.5.0)
+ rspec
+ rspec-rails
sqlite3-ruby (= 1.3.2)
webrat (= 0.7.1)
View
15 app/controllers/users_controller.rb
@@ -10,13 +10,14 @@ def show
end
def create
- @user = User.new(params[:user])
- if @user.save
- #Handle a successful save
- else
- @title = "Sign up"
- @render = 'new'
+ @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
end
View
2 app/models/user.rb
@@ -10,6 +10,8 @@
# updated_at :datetime
#
+require 'digest'
+
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
View
3 app/views/layouts/application.html.erb
@@ -9,6 +9,9 @@
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
+ <% flash.each do |key, value| %>
+ <div class="flash <%= key %>"><%= value %></div>
+ <% end %>
<%= yield %>
</section>
<%= render 'layouts/footer' %>
View
0 app/views/users/create.html.erb
No changes.
View
56 public/stylesheets/scaffold.css
@@ -0,0 +1,56 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#error_explanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#error_explanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
View
44 spec/controllers/users_controller_spec.rb
@@ -37,17 +37,17 @@
end
describe "GET 'new'" do
-
- it "should be successful" do
- get 'new'
- response.should be_success
- end
- it "should have the right title" do
- get 'new'
- response.should have_selector("title", :content => "Sign up")
+ it "should be successful" do
+ get :new
+ response.should be_success
+ end
+
+ it "should have the right title" do
+ get :new
+ response.should have_selector("title", :content => "Sign up")
+ end
end
- end
describe "POST 'create'" do
@@ -74,6 +74,30 @@
response.should render_template('new')
end
end
- end
+
+ describe "success" do
+
+ before(:each) do
+ @attr = { :name => "New User", :email => "user@example.com",
+ :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
View
40 spec/requests/users_spec.rb
@@ -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 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
View
8 webrat.log
@@ -0,0 +1,8 @@
+# Logfile created on 2011-05-25 16:25:35 -0700 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"=>"", "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"}

0 comments on commit 32c7ec0

Please sign in to comment.
Something went wrong with that request. Please try again.