Skip to content
This repository has been archived by the owner on Oct 4, 2018. It is now read-only.

Commit

Permalink
Added cucumber/capybara features for user authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Barrett Griffith committed Sep 12, 2012
1 parent d480030 commit 37fe099
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ end
gem 'rspec-rails', :group => [:test, :development]

group :test do
gem 'pry'
gem 'rake'
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'cucumber-rails'
end
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ GEM
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.5)
ffi (~> 1.0, >= 1.0.6)
coderay (1.0.7)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand All @@ -45,6 +56,15 @@ GEM
execjs
coffee-script-source (1.3.3)
commonjs (0.2.6)
cucumber (1.2.1)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.11.0)
json (>= 1.4.6)
cucumber-rails (1.3.0)
capybara (>= 1.1.2)
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
Expand All @@ -60,6 +80,9 @@ GEM
factory_girl_rails (4.0.0)
factory_girl (~> 4.0.0)
railties (>= 3.0.0)
ffi (1.1.5)
gherkin (2.11.2)
json (>= 1.4.6)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
Expand All @@ -73,15 +96,23 @@ GEM
actionpack (>= 3.1)
less (~> 2.2.0)
libv8 (3.3.10.4)
libwebsocket (0.1.5)
addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8)
mime-types (1.19)
multi_json (1.3.6)
nokogiri (1.5.5)
orm_adapter (0.4.0)
pg (0.14.0)
polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
Expand Down Expand Up @@ -120,11 +151,18 @@ GEM
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.11.0)
rubyzip (0.9.9)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.25.0)
childprocess (>= 0.2.5)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
slop (3.3.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
Expand All @@ -147,12 +185,15 @@ GEM
multi_json (~> 1.3)
warden (1.2.1)
rack (>= 1.0)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 3.2.1)
cucumber-rails
database_cleaner
devise (= 2.1.2)
dpla_search_api_v1!
Expand All @@ -161,6 +202,7 @@ DEPENDENCIES
json
less
pg
pry
rails (= 3.2.8)
rake
rspec-rails
Expand Down
32 changes: 15 additions & 17 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@
<a class="brand" href="#">DP.LA</a>
<div class="container nav-collapse">
<ul class="nav">
<li><%= link_to "Sign Up", new_user_registration_path %></li>
<li><%= link_to "Log In", new_user_session_path %></li>
</ul>
<% unless signed_in? :user %>
<li><%= link_to "Sign Up", new_user_registration_path %></li>
<li><%= link_to "Log In", new_user_session_path %></li>
<% else %>
<li><%= link_to "Sign Out", destroy_user_session_path, :method => :delete %></li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
Expand All @@ -58,22 +62,16 @@
<div class="container">
<div class="content">
<div class="row">
<div class="span9">
<p class="notice" style="display:none"><%= notice %></p>
<p class="alert" style="display:none"><%= alert %></p>
<div class="span12">

<% if flash[:notice] %>
<p class=notice"><%= notice %></p>
<% end %>
<% if flash[:alert] %>
<p class="alert"><%= alert %></p>
<% end %>
<%= yield %>
</div>
<div class="span3">
<div class="well sidebar-nav">
<h3>Sidebar</h3>
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<li><%= link_to "Link1", "/path1" %></li>
<li><%= link_to "Link2", "/path2" %></li>
<li><%= link_to "Link3", "/path3" %></li>
</ul>
</div><!--/.well -->
</div><!--/span-->
</div><!--/row-->
</div><!--/content-->

Expand Down
8 changes: 8 additions & 0 deletions config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
23 changes: 23 additions & 0 deletions features/new_user.feature.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: New user Feature
In order to connect with DPLA
As a user who wants to connect to DPLA

Scenario: user does NOT have an account
Given a visitor to the home page
When they choose the log in
Then the reponse should be "200"
When they try and sign in with user "mrtestuser@somedomain.com" and with password "testpass"
Then they should not see "Log Out"
Scenario: user signes up
Given a visitor to the home page
When they choose to sign up
Then the response should be "200"
When they sign up with user "mrtestuser@somedomain.com" and with password "testpass" and password confirmation "testpass"
Then they should see "Log Out"

Scenario: user does have an accoiunt
Given a visitor to the home page
When they choose the log in
Then the reponse should be "200"
When they try and sign in with user "mrtestuser@somedomain.com" and with password "testpass"
Then they should see "Log Out"
56 changes: 56 additions & 0 deletions features/step_definitions/user_authentication_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
When /^I go to the homepage$/ do
visit("/")
end

Then /^I should see "(.*?)"$/ do |arg1|
page.should have_content("DP.LA")
end

Then /^I should not see "(.*?)"$/ do |arg1|
page.should_not have_content(arg1)
end


When /^I follow "(.*?)"$/ do |arg1|
click_link arg1
page.should have_content "Email"
end



When /^I fill in the following:$/ do |table|
fill_in "Email", :with => "mrtestuser@somedomain.com"
fill_in "Password", :with => "testpass"
end

When /^I press "(.*?)"$/ do |arg1|

click_on "Sign in"
page.should_not have_content "Sign Out"

end


Given /^the following user exists:$/ do |table|
table.hashes.each do |attributes|
lambda{ User.create!(attributes)}.should change(User, :count).by(1)
end
end

When /^I log in with the following:$/ do |table|
visit "/"
click_link "Log In"
table.hashes.each do |hash|
fill_in "Email", :with => hash["Email"]
fill_in "Password", :with => hash["Password"]
end
click_button "Sign in"
end

Then /^I should see "(.*?)" link$/ do |arg1|
page.should have_content arg1
end

Then /^I should not see "(.*?)" link$/ do |arg1|
page.should_not have_content arg1
end
5 changes: 5 additions & 0 deletions features/step_definitions/user_signup_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
When /I sign in/ do
visit('/')
page.should have_content("DP.LA")
click_link 'Sign Up'
end
59 changes: 59 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.

require 'cucumber/rails'

# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
# steps to use the XPath syntax.
Capybara.default_selector = :css

# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with @allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
ActionController::Base.allow_rescue = false

# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# # { :except => [:widgets] } may not do what you expect here
# # as tCucumber::Rails::Database.javascript_strategy overrides
# # this setting.
# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#

# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation

40 changes: 40 additions & 0 deletions features/user_authentication.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Feature: User Authentication

Scenario: un-successful DPLA authentication
When I go to the homepage
Then I should see "Log In"
But I should not see "Sign Out"
When I follow "Log In"
And I fill in the following:
| Email | mrtestuser@somedomain.com |
| Password | test |
And I press "Sign in"
Then I should see "Sign In"
But I should not see "Sign Out"

Scenario: successful DPLA sign up
When I go to the homepage
Then I should see "Sign Up"
But I should not see "Sign Out"
When I follow "Sign Up"
And I fill in the following:
| Email | mrtestuser@somedomain.com |
| Password | testpass |
| Password confirmation | testpass |
And I press "Sign up"
Then I should see "Sign Out"
But I should not see "Sign In"

Scenario: successful DPLA authentication
Given the following user exists:
| email | password | password_confirmation |
| mrtestuser@somedomain.com | testpass | testpass |
When I go to the homepage
Then I should see "Log In"
But I should not see "Sign Out"
When I follow "Log In"
And I log in with the following:
| Email | Password |
| mrtestuser@somedomain.com | testpass |
Then I should see "Sign Out" link
But I should not see "Sign In" link
Loading

0 comments on commit 37fe099

Please sign in to comment.