Skip to content

Commit

Permalink
added the sign out tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drapergeek committed Mar 26, 2012
1 parent a6645df commit c2e7537
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
5 changes: 5 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ def create
session[:current_user] = params[:user][:email]
redirect_to root_path
end

def destroy
session[:current_user] = nil
redirect_to root_path
end
end
27 changes: 15 additions & 12 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>IntroTodos</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div data-role="user-identification">
<%= session[:current_user] %>
</div>
<head>
<title>IntroTodos</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<% if session[:current_user] %>
<div data-role="user-identification">
<%= session[:current_user] %>
</div>
<%= link_to "Sign Out", sessions_path, method: :delete %>
<% end %>
<%= yield %>
<%= yield %>

</body>
</body>
</html>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IntroTodos::Application.routes.draw do
resources :sessions, :only=>[:new, :create]
resource :sessions, :only=>[:new, :create, :destroy]
match "/sign_up", to: "sessions#new"

root to: "high_voltage/pages#show", id: "homepage"
Expand Down
10 changes: 10 additions & 0 deletions features/sign_out.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Sign out of the application
In order to prevent unauthorized access to my todos
As a user
I should to be able to sign out

Scenario:
Given I am logged in as "person@example.com"
When I sign out
Then I should be signed out

2 changes: 1 addition & 1 deletion features/sign_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Sign up for an account

Scenario: Create an account from the homepage
Given I am on the homepage
When I registrater for an account with the email "person@example.com"
When I register for an account with the email "person@example.com"
Then I should be signed in as "person@example.com"


15 changes: 15 additions & 0 deletions features/step_definitions/session_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Given /^I am logged in as "([^"]*)"$/ do |email_address|
steps %{
Given I am on the homepage
When I register for an account with the email "#{email_address}"
}
end

When /^I sign out$/ do
click_link "Sign Out"
end

Then /^I should be signed out$/ do
page.should_not have_css("[data-role='user-identification']")
page.should_not have_link("Sign out")
end
2 changes: 1 addition & 1 deletion features/step_definitions/signup_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

When /^I registrater for an account with the email "([^"]*)"$/ do |email_address|
When /^I register for an account with the email "([^"]*)"$/ do |email_address|
click_link "Sign up for an account"
fill_in "Email", with: email_address
click_button "Create my account"
Expand Down

0 comments on commit c2e7537

Please sign in to comment.