Skip to content

Commit

Permalink
add error text tests, flash test, leyout content_for, and revert side…
Browse files Browse the repository at this point in the history
…bar vertical-align:top
  • Loading branch information
noel committed Feb 4, 2012
1 parent cc0c124 commit c76fa9b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/layout.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ td.main {
td.sidebar {
width: 30%;
padding: 1em;
vertical-align: middle;
vertical-align: top;
background: #ffc;
}

Expand Down
6 changes: 4 additions & 2 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +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 = "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
end
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<section class="round">
<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>
<%= content_tag(:div, value, class: "flash #{key}") %>
<% end %>
<%= yield %>
</section>

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 @@ -4,7 +4,7 @@
<tr>
<td class="main">
<h1>
<%= gravatar_for @user %>
<%= gravatar_for @user, size:50 %>
<%= @user.name %>
</h1>
</td>
Expand Down
17 changes: 17 additions & 0 deletions spec/requests/user_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@
it "should create a user" do
expect { click_button "Sign up" }.to change(User, :count).by(1)
end

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

it { should have_selector('title', text: user.name) }
it { should have_selector('div.flash.success', text: 'Welcome') }
end
end

describe "error messages" do
before { click_button "Sign up" }

let(:error_text) { 'errors prohibited this user from being saved' }

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

Expand Down

0 comments on commit c76fa9b

Please sign in to comment.