Permalink
Browse files

Finish user signup

  • Loading branch information...
1 parent 54686e2 commit bec5aebbd8aa748c2f2b5570dd46d861ad73bae1 Jason Kim committed Mar 13, 2012
View
@@ -23,6 +23,7 @@ gem 'jquery-rails', '2.0.0'
group :test do
gem 'capybara', '1.1.2'
+ gem 'factory_girl_rails', '1.4.0'
end
group :production do
View
@@ -53,6 +53,11 @@ GEM
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ factory_girl (2.3.2)
+ activesupport
+ factory_girl_rails (1.4.0)
+ factory_girl (~> 2.3.0)
+ railties (>= 3.0.0)
ffi (1.0.11)
hike (1.2.1)
i18n (0.6.0)
@@ -145,6 +150,7 @@ DEPENDENCIES
bootstrap-sass (= 2.0.0)
capybara (= 1.1.2)
coffee-rails (= 3.2.2)
+ factory_girl_rails (= 1.4.0)
jquery-rails (= 2.0.0)
pg (= 0.12.2)
rails (= 3.2.2)
@@ -4,6 +4,12 @@
$grayMediumLight: #eaeaea;
+@mixin box_sizing {
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
/* universal */
html {
@@ -100,3 +106,66 @@ footer {
}
}
}
+
+/* miscellaneous */
+
+.debug_dump {
+ clear: both;
+ float: left;
+ width: 100%;
+ margin-top: 45px;
+ @include box_sizing;
+}
+
+/* sidebar */
+
+aside {
+ section {
+ padding: 10px 0;
+ border-top: 1px solid $grayLighter;
+ &:first-child {
+ border: 0;
+ padding-top: 0;
+ }
+ span {
+ display: block;
+ margin-bottom: 3px;
+ line-height: 1;
+ }
+ h1 {
+ font-size: 1.6em;
+ text-align: left;
+ letter-spacing: -1px;
+ margin-bottom: 3px;
+ }
+ }
+}
+
+.gravatar {
+ float: left;
+ margin-right: 10px;
+}
+
+/* forms */
+
+input, textarea, select, .uneditable-input {
+ border: 1px solid #bbb;
+ width: 100%;
+ padding: 10px;
+ height: auto;
+ margin-bottom: 15px;
+ @include box_sizing;
+}
+
+#error_explanation {
+ color:#f00;
+ ul {
+ list-style: none;
+ margin: 0 0 18px 0;
+ }
+}
+
+.field_with_errors {
+ @extend .control-group;
+ @extend .error;
+ }
@@ -1,4 +1,19 @@
class UsersController < ApplicationController
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ flash[:success] = "Welcome to the Sample App!"
+ redirect_to @user
+ else
+ render 'new'
+ end
+ end
+
+ def show
+ @user = User.find(params[:id])
+ end
+
def new
+ @user = User.new
end
end
@@ -1,2 +1,11 @@
module UsersHelper
+
+ # Returns the Gravatar (http://gravatar.com/) for the given user.
+ def gravatar_for(user)
+ gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
+ gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}"
+ image_tag(gravatar_url, alt: user.name, class: "gravatar")
+ end
end
+
+
@@ -10,8 +10,12 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
+ <% flash.each do |key, value| %>
+ <div class="alert alert-<%= key %>"><%= value %></div>
+ <% end %>
<%= yield %>
<%= render 'layouts/footer' %>
+ <%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
@@ -0,0 +1,12 @@
+<% if @user.errors.any? %>
+ <div id="error_explanation">
+ <div class="alert alert-error">
+ The form contains <%= pluralize(@user.errors.count, "error") %>.
+ </div>
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li>* <%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
@@ -1,3 +1,24 @@
-<% provide(:title, 'Sign up') %>
+<%= provide(:title, 'Sign up') %>
<h1>Sign up</h1>
-<p>Find me in app/views/users/new.html.erb</p>
+
+<div class="row">
+ <div class="span6 offset3">
+ <%= form_for(@user) do |f| %>
+ <%= render 'shared/error_messages' %>
+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+
+ <%= f.label :password_confirmation, "Confirmation" %>
+ <%= f.password_field :password_confirmation %>
+
+ <%= f.submit "Create my account", :class => "btn btn-large btn-primary" %>
+ <% end %>
+ </div>
+</div>
@@ -0,0 +1,11 @@
+<% provide(:title, @user.name) %>
+<div class="row">
+ <aside class="span4">
+ <section>
+ <h1>
+ <%= gravatar_for @user %>
+ <%= @user.name %>
+ </h1>
+ </section>
+ </aside>
+</div>
@@ -34,4 +34,10 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+
+ # Speed up tests by lowering BCrypt's cost function.
+ require 'bcrypt'
+ silence_warnings do
+ BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
+ end
end
View
@@ -1,5 +1,5 @@
SampleApp::Application.routes.draw do
- get "users/new"
+ resources :users
root to: 'static_pages#home'
# match '/', to: 'static_pages#home'
View
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :user do
+ name "Michael Hartl"
+ email "michael@example.com"
+ password "foobar"
+ password_confirmation "foobar"
+ end
+end
@@ -1,12 +1,47 @@
require 'spec_helper'
describe "User pages" do
+
subject { page }
+
+ describe "profile page" do
+ let(:user) { FactoryGirl.create(:user) }
+ before { visit user_path(user) }
+
+ it { should have_selector('h1', text: user.name) }
+ it { should have_selector('title', text: user.name) }
+ end
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
-end
+
+ describe "signup" do
+
+ before { visit signup_path }
+
+ describe "with invalid information" do
+ it "should not create a user" do
+ expect { click_button "Create my account" }.not_to change(User, :count)
+ end
+ end
+
+ describe "with valid information" do
+ before do
+ fill_in "Name", with: "Example User"
+ fill_in "Email", with: "user@example.com"
+ fill_in "Password", with: "foobar"
+ fill_in "Confirmation", with: "foobar"
+ end
+
+ it "should create a user" do
+ expect do
+ click_button "Create my account"
+ end.to change(User, :count).by(1)
+ end
+ end
+ end
+end

0 comments on commit bec5aeb

Please sign in to comment.