Skip to content

Commit

Permalink
Customize headers in response to signed_in/signed_out state
Browse files Browse the repository at this point in the history
  • Loading branch information
David McMath committed Jan 10, 2012
1 parent 6fe5b96 commit 5c92d26
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/views/layouts/_header.html.erb
Expand Up @@ -3,8 +3,15 @@
<nav class='round'>
<ul>
<li><%= link_to 'Home', root_path %></li>
<% if signed_in? %>
<li><%= link_to 'Profile', current_user %></li>
<% end %>
<li><%= link_to 'Help', help_path %></li>
<li><%= link_to 'Sign In', '#' %></li>
<% if signed_in? %>
<li><%= link_to 'Sign out', signout_path, :method => :delete %></li>
<% else %>
<li><%= link_to 'Sign in', signin_path %></li>
<% end %>
</ul>
</nav>
</header>
32 changes: 32 additions & 0 deletions spec/requests/layout_links_spec.rb
Expand Up @@ -40,4 +40,36 @@
click_link 'Sign Up Now'
response.should have_selector('title', :content => 'Sign Up')
end

describe 'when not signed in' do
it 'should have a signin link' do
visit root_path
response.should have_selector( 'a', :href => signin_path,
:content => 'Sign in' )
end
end

describe 'when signed in' do
before(:each) do
@user = Factory(:user)
visit signin_path
fill_in :email, :with => @user.email
fill_in :password, :with => @user.password
click_button
end

it 'should have a signout link' do
visit root_path
response.should have_selector( 'a', :href => signout_path,
:content => 'Sign out')
response.should_not have_selector( 'a', :href => signin_path,
:content => 'Sign in')
end

it 'should have a profile link' do
visit root_path
response.should have_selector( 'a', :href => user_path(@user),
:content => 'Profile' )
end
end
end
28 changes: 25 additions & 3 deletions spec/requests/users_spec.rb
Expand Up @@ -27,9 +27,6 @@
click_button

response.should have_selector('input[id="user_password"][type="password"]', :value => '')
# do |input|
# input.
# end
response.should have_selector('input[id="user_password_confirmation"][type="password"]', :value => '')
end.should_not change(User, :count)
end
Expand All @@ -52,4 +49,29 @@
end
end
end

describe 'sign in/out' do
describe 'failure' do
it 'should not sign a user in' do
visit signin_path
fill_in :email, :with => ''
fill_in :password, :with => ''
click_button
response.should have_selector( 'div.flash.error', :content => 'Invalid' )
end
end

describe 'success' do
it 'should sign a user in and out' do
user = Factory(:user)
visit signin_path
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
controller.should be_signed_in
click_link 'Sign out'
controller.should_not be_signed_in
end
end
end
end

0 comments on commit 5c92d26

Please sign in to comment.