Skip to content

Commit

Permalink
Chapter 7 exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
aplarson committed Aug 28, 2014
1 parent 8de6a48 commit 5e2eff5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module UsersHelper

def gravatar_for(user)
def gravatar_for(user, options = { size: 50 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
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
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
15 changes: 15 additions & 0 deletions spec/requests/user_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
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_title('Sign up') }
it { should have_content('error') }
end
end

describe "with valid information" do
Expand All @@ -30,6 +37,14 @@
fill_in "Confirmation", with: "foobar"
end

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

it { should have_title(user.name) }
it {should have_selector('div.alert.alert-success', text: 'Welcome')}
end

it "should create a user" do
expect { click_button submit }.to change(User, :count)
end
Expand Down

0 comments on commit 5e2eff5

Please sign in to comment.