Skip to content

Commit

Permalink
Chapter 7 Exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjortega committed Mar 24, 2012
1 parent 30ff976 commit 8125d5d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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 = "http://gravatar.com/avatar/#{gravatar_id}.png"
size = options[:size]
gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end

Expand Down
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
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"
16 changes: 16 additions & 0 deletions spec/requests/user_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
it "should not create a user" do
expect { click_button "Create my account" }.not_to change(User, :count)
end

describe "error messages" do
before { click_button "Create my account" }

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

describe "with valid information" do
Expand All @@ -43,6 +50,15 @@
click_button "Create my account"
end.to change(User, :count).by(1)
end

describe "after saving the user" do
before { click_button "Create my account" }
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') }
end

end
end
end

0 comments on commit 8125d5d

Please sign in to comment.