Permalink
Browse files

User signup complete

  • Loading branch information...
1 parent 8554180 commit 03376b8bcce5f22913c14db11df0a51dd43cb6e6 @footmark committed Dec 6, 2011
@@ -130,4 +130,49 @@ td.sidebar {
.profile img.gravatar {
border: 1px solid #999;
margin-bottom: -15px;
+}
+
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+.field_with_errors {
+ margin-top: 10px;
+ padding: 2px;
+ background-color:red;
+ display: table;
+}
+
+.field_with_errors label {
+ color:#fff;
+}
+
+#error_explanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ 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;
+ background-color:#c00;
+ color:#fff;
+}
+
+#error_explanation p {
+ color:#333;
+ margin-bottom: 0;
+ padding: 5px;
+}
+
+#error_explanation ul li {
+ font-size: 12px;
+ list-style: square;
}
@@ -5,6 +5,18 @@ def show
end
def new
+ @user = User.new
@title = 'Sign up'
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
@@ -11,6 +11,11 @@
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
+ <section class="round">
+ <% flash.each do |key, value| %>
+ <div class="flash <%= key %>"><%= value %></div>
+ <% end %>
+ </section>
<%= yield %>
</section>
<%= render 'layouts/footer' %>
@@ -0,0 +1,14 @@
+<% 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 %>
@@ -1,2 +1,23 @@
-<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 -%>
View
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>currentDocument</key>
- <string>spec/models/user_spec.rb</string>
+ <string>app/assets/stylesheets/custom.css</string>
<key>documents</key>
<array>
<dict>
@@ -21,28 +21,56 @@
<integer>200</integer>
<key>metaData</key>
<dict>
+ <key>app/assets/stylesheets/custom.css</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>1</integer>
+ <key>line</key>
+ <integer>132</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>107</integer>
+ </dict>
<key>app/controllers/users_controller.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
- <integer>5</integer>
+ <integer>19</integer>
<key>line</key>
- <integer>3</integer>
+ <integer>2</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
- <key>app/models/user.rb</key>
+ <key>app/helpers/users_helper.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
- <integer>57</integer>
+ <integer>64</integer>
<key>line</key>
- <integer>19</integer>
+ <integer>4</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>0</integer>
+ </dict>
+ <key>app/views/users/show.html.erb</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>59</integer>
+ <key>line</key>
+ <integer>10</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
@@ -77,32 +105,47 @@
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
- <key>spec/models/user_spec.rb</key>
+ <key>spec/controllers/users_controller_spec.rb</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
- <integer>25</integer>
+ <integer>7</integer>
<key>line</key>
- <integer>88</integer>
+ <integer>18</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
- <integer>67</integer>
+ <integer>10</integer>
+ </dict>
+ <key>spec/factories.rb</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>26</integer>
+ <key>line</key>
+ <integer>1</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>0</integer>
</dict>
</dict>
<key>openDocuments</key>
<array>
- <string>app/models/user.rb</string>
- <string>db/migrate/20111204102932_add_email_uniqueness_index.rb</string>
<string>app/controllers/users_controller.rb</string>
- <string>config/routes.rb</string>
- <string>spec/models/user_spec.rb</string>
+ <string>app/views/users/show.html.erb</string>
+ <string>app/assets/stylesheets/custom.css</string>
+ <string>app/helpers/users_helper.rb</string>
+ <string>spec/controllers/users_controller_spec.rb</string>
+ <string>spec/factories.rb</string>
</array>
<key>showFileHierarchyDrawer</key>
<false/>
<key>windowFrame</key>
- <string>{{701, 280}, {739, 594}}</string>
+ <string>{{697, 282}, {739, 594}}</string>
</dict>
</plist>
@@ -46,4 +46,51 @@
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 => "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
@@ -0,0 +1,35 @@
+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 => "Welcom")
+ response.should render_template('users/show')
+ end.should change(User, :count).by(1)
+ end
+ end
+ end
+end
View
@@ -95,3 +95,56 @@ 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 / 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 / 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 / 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 / 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 / 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: GET /signup with {} and HTTP headers {}
+REQUESTING PAGE: GET /signup with {} and HTTP headers {}
+REQUESTING PAGE: POST /users with {"utf8"=>"✓", "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"=>"✓", "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 /signup with {} and HTTP headers {}
+REQUESTING PAGE: POST /users with {"utf8"=>"✓", "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"=>"✓", "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"=>"✓", "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"=>"✓", "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 03376b8

Please sign in to comment.