Skip to content

Commit

Permalink
Finishi Exercise 7
Browse files Browse the repository at this point in the history
  • Loading branch information
utwang committed Jun 6, 2012
1 parent 123456d commit 2e090a8
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'

gem 'pg', '0.12.2'

Expand Down Expand Up @@ -39,6 +42,8 @@ group :test do
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'factory_girl_rails', '1.4.0'
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end

#group :production do
Expand Down
22 changes: 22 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ GEM
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.0)
bootstrap-will_paginate (0.0.6)
will_paginate
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
Expand All @@ -50,6 +52,16 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.2)
cucumber (1.2.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.10.0)
json (>= 1.4.6)
cucumber-rails (1.2.1)
capybara (>= 1.1.2)
cucumber (>= 1.1.3)
nokogiri (>= 1.5.0)
database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.2)
Expand All @@ -59,7 +71,11 @@ GEM
factory_girl_rails (1.4.0)
factory_girl (~> 2.3.0)
railties (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
ffi (1.0.11)
gherkin (2.10.0)
json (>= 1.4.6)
guard (1.0.3)
ffi (>= 0.5.0)
thor (>= 0.14.6)
Expand Down Expand Up @@ -153,6 +169,7 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
will_paginate (3.0.3)
xpath (0.1.4)
nokogiri (~> 1.3)

Expand All @@ -163,9 +180,13 @@ DEPENDENCIES
annotate (~> 2.4.1.beta)
bcrypt-ruby (= 3.0.1)
bootstrap-sass (= 2.0.0)
bootstrap-will_paginate (= 0.0.6)
capybara (= 1.1.2)
coffee-rails (= 3.2.2)
cucumber-rails (= 1.2.1)
database_cleaner (= 0.7.0)
factory_girl_rails (= 1.4.0)
faker (= 1.0.1)
guard-rspec (= 0.5.5)
guard-spork (= 0.3.2)
jquery-rails (= 2.0.0)
Expand All @@ -177,3 +198,4 @@ DEPENDENCIES
sass-rails (= 3.2.4)
spork (= 0.9.0)
uglifier (= 1.2.3)
will_paginate (= 3.0.3)
5 changes: 3 additions & 2 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module UsersHelper

# Returns the Gravatar (http://gravatar.com/) for the given user.
def gravatar_for(user)
def gravatar_for(user, options = { size: 50 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class User < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 }
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The form contains <%= pluralize(@user.errors.count, "error") %>
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<% @user.errors.full_messages.sort.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<aside class="span4">
<section>
<h1>
<%= gravatar_for @user %>
<%= gravatar_for @user, size: 40 %>
<%= @user.name %>
</h1>
</section>
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
hello: "Hello world"
activerecord:
attributes:
user:
password_digest: "Password"
33 changes: 32 additions & 1 deletion spec/requests/user_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end

describe "after submission" do
before { click_button submit }

it { should have_selector('title', text: 'Sign up') }
it { should have_content('errors') }
end

describe "after submission" do
before do
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
click_button submit
end

it { should have_selector('title', text: 'Sign up') }
it { should have_selector('li', text: "Name can't be blank") }
it { should have_content('error') }
it { should_not have_content('errors') }
end
end

describe "with valid information" do
Expand All @@ -25,11 +46,21 @@
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end

describe "after submission and saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('user@example.com') }

it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome')}
it { should_not have_content('error') }
it { should_not have_content('errors') }
end
end

it { should have_selector('h1', text: 'Sign up') }
#it { should have_selector('title', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }

end

describe "profile page" do
Expand Down

0 comments on commit 2e090a8

Please sign in to comment.