Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add session based identity

  • Loading branch information...
commit 564bcd0687a542a9aec4a84fe77b906aea92fd45 1 parent acf7a9c
@stevehodgkiss authored
View
18 app.rb
@@ -3,7 +3,25 @@
class App < Sinatra::Base
set :public, File.dirname(__FILE__) + '/public'
+ enable :sessions
+
+ helpers do
+ def current_user
+ session[:name]
+ end
+ end
+
get "/" do
slim :homepage
end
+
+ post "/sign_in" do
+ session[:name] = params[:name]
+ redirect "/"
+ end
+
+ get "/sign_out" do
+ session[:name] = nil
+ redirect "/"
+ end
end
View
6 config/cucumber.yml
@@ -0,0 +1,6 @@
+<%
+requires = "--require features/support --require features/step_definitions"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip #{requires}"
+%>
+default: <%= std_opts %> features
+wip: --tags @wip:3 --wip <%= requires %> features
View
19 features/identity.feature
@@ -0,0 +1,19 @@
+Feature: Identity
+ In order to chat
+ As a User
+ I want to assign a username to identify myself with
+
+ Background:
+ Given I am on the homepage
+
+ Scenario: Sign in
+ Given I fill in "Name" with "Steve"
+ And I press "Go"
+ Then I should see "Hi Steve"
+ And I should see "Sign out"
+
+ Scenario: Sign out
+ Given I have signed in as "Steve"
+ When I follow "Sign out"
+ Then I should see "Sign in"
+ And I should not see "Steve"
View
4 features/step_definitions/identity_steps.rb
@@ -0,0 +1,4 @@
+Given /^I have signed in as "([^"]*)"$/ do |name|
+ fill_in "Name", :with => name
+ click_button "Go"
+end
View
14 views/homepage.slim
@@ -0,0 +1,14 @@
+- if current_user
+ p
+ | Hi
+ = current_user
+ p
+ a href="/sign_out" Sign out
+- else
+ h1 Sign in
+ form action="/sign_in" method="post"
+ p
+ label for="name" Name
+ input type="text" id="name" name="name"
+ p
+ input type="submit" value="Go"
Please sign in to comment.
Something went wrong with that request. Please try again.