Skip to content

Commit c0855a8

Browse files
author
Ryan Bigg
committed
Section 6.3: Add sign in and sign out
1 parent 96e08cd commit c0855a8

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

ticketee/app/views/layouts/application.html.erb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@
2424
<li class='<%= 'active' if current_page?('/') %>'>
2525
<%= link_to "Home", root_path %>
2626
</li>
27-
<li class='<%= 'active' if current_page?('/users/sign_up') %>'>
28-
<%= link_to "Sign up", new_user_registration_path %>
29-
</li>
27+
<% unless user_signed_in? %>
28+
<li class='<%= 'active' if current_page?('/users/sign_up') %>'>
29+
<%= link_to "Sign up", new_user_registration_path %>
30+
</li>
31+
<li class='<%= 'active' if current_page?('/users/sign_in') %>'>
32+
<%= link_to "Sign in", new_user_session_path %>
33+
</li>
34+
<% end %>
3035
</ul>
36+
37+
<% if user_signed_in? %>
38+
<div class="collapse navbar-collapse">
39+
<div class="navbar-text navbar-right">
40+
Signed in as <%= current_user.email %> &middot;
41+
<%= link_to "Sign out", destroy_user_session_path, method: :delete %>
42+
</div>
43+
</div>
44+
<% end %>
3145
</div>
3246
</nav>
3347

@@ -42,6 +56,5 @@
4256
<%= yield %>
4357
</div>
4458
</div>
45-
4659
</body>
4760
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FactoryGirl.define do
2+
factory :user do
3+
sequence(:email) { |n| "test#{n}@example.com" }
4+
password "password"
5+
end
6+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "rails_helper"
2+
3+
feature "Sign in" do
4+
let!(:user) { FactoryGirl.create(:user) }
5+
6+
it "a user can sign in" do
7+
visit "/"
8+
click_link "Sign in"
9+
fill_in "Email", with: user.email
10+
fill_in "Password", with: "password"
11+
click_button "Log in"
12+
expect(page).to have_content("Signed in successfully.")
13+
expect(page).to have_content("Signed in as #{user.email}")
14+
end
15+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "rails_helper"
2+
3+
feature "Sign in" do
4+
let!(:user) { FactoryGirl.create(:user) }
5+
6+
before do
7+
login_as(user)
8+
end
9+
10+
it "a user can sign in" do
11+
visit "/"
12+
click_link "Sign out"
13+
expect(page).to have_content("Signed out successfully.")
14+
end
15+
end

ticketee/spec/rails_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@
4747
# The different available types are documented in the features, such as in
4848
# https://relishapp.com/rspec/rspec-rails/docs
4949
config.infer_spec_type_from_file_location!
50+
51+
config.include Warden::Test::Helpers, type: :feature
52+
config.after(type: :feature) { Warden.test_reset! }
5053
end

0 commit comments

Comments
 (0)