Skip to content

Commit

Permalink
Completed signin/out
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 27, 2010
1 parent 0704df5 commit 71e1e7a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def new
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
redirect_to @user, :flash => { :success => "Welcome to the Sample App!" }
else
@title = "Sign up"
Expand Down
9 changes: 8 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
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 %></li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</header>
5 changes: 5 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
post :create, :user => @attr
flash[:success].should =~ /welcome to the sample app/i
end

it "should sign the user in" do
post :create, :user => @attr
controller.should be_signed_in
end
end
end
end
31 changes: 31 additions & 0 deletions spec/requests/layout_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,35 @@
response.should have_selector('title', :content => "Sign up")
response.should have_selector('a[href="/"]>img')
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")
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: 27 additions & 1 deletion spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@
end
end

describe "signin" 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")
response.should render_template('sessions/new')
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

end

0 comments on commit 71e1e7a

Please sign in to comment.