Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Features running and some passing

  • Loading branch information...
commit 0480461e6660f9fd4ca87059aa65aa013c75f5de 1 parent 74169ed
@mike-burns mike-burns authored
Showing with 9,251 additions and 56 deletions.
  1. +1 −0  generators/clearance_twitter/USAGE
  2. +22 −0 generators/clearance_twitter/clearance_twitter_generator.rb
  3. +34 −0 generators/clearance_twitter/lib/insert_commands.rb
  4. +16 −0 generators/clearance_twitter/templates/README
  5. +15 −0 generators/clearance_twitter/templates/migration.rb
  6. +1 −0  generators/clearance_twitter_features/USAGE
  7. +15 −0 generators/clearance_twitter_features/clearance_twitter_features_generator.rb
  8. BIN  generators/clearance_twitter_features/templates/features/step_definitions/.clearance_twitter_steps.rb.swp
  9. +53 −0 generators/clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
  10. +36 −0 generators/clearance_twitter_features/templates/features/twitter_sign_in.feature
  11. +25 −0 generators/clearance_twitter_features/templates/features/twitter_sign_up.feature
  12. BIN  test/rails_root/features/support/.swp → lib/clearance_twitter/.fake_twitter.rb.swp
  13. BIN  lib/clearance_twitter/.routes.rb.swp
  14. +18 −0 lib/clearance_twitter/fake_twitter.rb
  15. +8 −0 lib/clearance_twitter/routes.rb
  16. +1 −0  test/rails_root/app/controllers/application_controller.rb
  17. +3 −0  test/rails_root/app/models/user.rb
  18. +15 −0 test/rails_root/app/views/layouts/application.html.erb
  19. +21 −0 test/rails_root/app/views/sessions/new.html.erb
  20. +14 −0 test/rails_root/app/views/users/new.html.erb
  21. BIN  test/rails_root/config/.environment.rb.swp
  22. +4 −1 test/rails_root/config/environment.rb
  23. +2 −0  test/rails_root/config/environments/cucumber.rb
  24. +2 −1  test/rails_root/config/environments/development.rb
  25. +2 −1  test/rails_root/config/environments/test.rb
  26. +3 −0  test/rails_root/config/initializers/clearance.rb
  27. +3 −40 test/rails_root/config/routes.rb
  28. BIN  test/rails_root/db/development.sqlite3
  29. +12 −0 test/rails_root/db/migrate/20100312194919_create_users.rb
  30. +22 −0 test/rails_root/db/migrate/20100312195052_clearance_update_users_to_0_8_8.rb
  31. +15 −0 test/rails_root/db/migrate/20100312212628_add_clearance_twitter_fields_to_users.rb
  32. +20 −1 test/rails_root/db/schema.rb
  33. BIN  test/rails_root/db/test.sqlite3
  34. +33 −0 test/rails_root/features/password_reset.feature
  35. +35 −0 test/rails_root/features/sign_in.feature
  36. +15 −0 test/rails_root/features/sign_out.feature
  37. +45 −0 test/rails_root/features/sign_up.feature
  38. +122 −0 test/rails_root/features/step_definitions/clearance_steps.rb
  39. +53 −0 test/rails_root/features/step_definitions/clearance_twitter_steps.rb
  40. +1 −0  test/rails_root/features/step_definitions/factory_girl_steps.rb
  41. +7 −11 test/rails_root/features/support/paths.rb
  42. +36 −0 test/rails_root/features/twitter_sign_in.feature
  43. +25 −0 test/rails_root/features/twitter_sign_up.feature
  44. +6,838 −1 test/rails_root/log/cucumber.log
  45. +1,644 −0 test/rails_root/log/development.log
  46. +13 −0 test/rails_root/test/factories/clearance.rb
  47. +1 −0  test/rails_root/vendor/plugins/clearance_twitter
View
1  generators/clearance_twitter/USAGE
@@ -0,0 +1 @@
+script/generate clearance_facebook
View
22 generators/clearance_twitter/clearance_twitter_generator.rb
@@ -0,0 +1,22 @@
+require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
+
+class ClearanceTwitterGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ if defined?(ActiveRecord)
+ m.migration_template "migration.rb",
+ 'db/migrate',
+ :migration_file_name => "add_clearance_twitter_fields_to_users"
+ end
+# m.insert_into 'app/controllers/application_controller.rb',
+# 'helper :clearance_twitter'
+# m.insert_into 'app/controllers/application_controller.rb',
+# 'include ClearanceTwitter::Authentication',
+# :after => 'include Clearance::Authentication'
+ m.insert_into 'config/routes.rb', 'ClearanceTwitter::Routes.draw(map)'
+# m.insert_into 'app/models/user.rb', "include ClearanceTwitter::LinkedUser",
+# :after => /include Clearance::User\s*$/
+# m.readme "README"
+ end
+ end
+end
View
34 generators/clearance_twitter/lib/insert_commands.rb
@@ -0,0 +1,34 @@
+# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
+
+Rails::Generator::Commands::Base.class_eval do
+ def file_contains?(relative_destination, line)
+ File.read(destination_path(relative_destination)).include?(line)
+ end
+end
+
+Rails::Generator::Commands::Create.class_eval do
+ def insert_into(file, line, opts = {})
+ logger.insert "#{line} into #{file}"
+ after = opts[:after] || /^(class|module|.*ActionController::Routing::Routes\.draw).*$/
+ unless options[:pretend] || file_contains?(file, line)
+ gsub_file file, after do |match|
+ "#{match}\n #{line}"
+ end
+ end
+ end
+end
+
+Rails::Generator::Commands::Destroy.class_eval do
+ def insert_into(file, line)
+ logger.remove "#{line} from #{file}"
+ unless options[:pretend]
+ gsub_file file, "\n #{line}", ''
+ end
+ end
+end
+
+Rails::Generator::Commands::List.class_eval do
+ def insert_into(file, line)
+ logger.insert "#{line} into #{file}"
+ end
+end
View
16 generators/clearance_twitter/templates/README
@@ -0,0 +1,16 @@
+
+*******************************************************************************
+
+Next:
+
+1. Install and configure the facebooker plugin:
+
+ script/plugin install git://github.com/mmangino/facebooker.git
+
+2. Migrate:
+
+ rake db:migrate
+
+3. Add calls to fb_connect_and_sign_up_button in your sign in and sign up forms.
+
+*******************************************************************************
View
15 generators/clearance_twitter/templates/migration.rb
@@ -0,0 +1,15 @@
+class AddClearanceTwitterFieldsToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :twitter_username, :string
+ add_column :users, :twitter_id, :string
+ add_column :users, :access_token, :string
+ add_column :users, :access_secret, :string
+ end
+
+ def self.down
+ remove_column :users, :access_token
+ remove_column :users, :access_secret
+ remove_column :users, :twitter_id
+ remove_column :users, :twitter_username
+ end
+end
View
1  generators/clearance_twitter_features/USAGE
@@ -0,0 +1 @@
+script/generate clearance_facebook_features
View
15 generators/clearance_twitter_features/clearance_twitter_features_generator.rb
@@ -0,0 +1,15 @@
+class ClearanceTwitterFeaturesGenerator < Rails::Generator::Base
+
+ def manifest
+ record do |m|
+ m.directory File.join("features", "step_definitions")
+
+ ["features/step_definitions/clearance_twitter_steps.rb",
+ "features/twitter_sign_in.feature",
+ "features/twitter_sign_up.feature"].each do |file|
+ m.file file, file
+ end
+ end
+ end
+
+end
View
BIN  generators/clearance_twitter_features/templates/features/step_definitions/.clearance_twitter_steps.rb.swp
Binary file not shown
View
53 generators/clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
@@ -0,0 +1,53 @@
+require 'clearance_twitter/fake_twitter'
+
+Before do
+ FakeTwitterUser.clear_remote_profiles
+ FakeTwitterSession.logout
+end
+
+Given /^there are no users$/ do
+ User.delete_all
+end
+
+Given /^remote Twitter user exists with an username of "([^"]+)"$/ do |twitter_username|
+ FakeTwitterUser.add_remote_profile({:username => twitter_username})
+end
+
+Given 'remote Twitter user exists with an username of "$username" and a name of "$name" and an email of "$email"' do |twitter_username, twitter_user_name, twitter_user_email|
+ FakeTwitterUser.add_remote_profile({:id => twitter_username, :name => twitter_user_name, :email => twitter_user_email})
+end
+
+Given 'I am signed into Twitter account "$username"' do |twitter_username|
+ twitter_user = FakeTwitterUser.get_remote_profile(twitter_username)
+ FakeTwitterSession.login(twitter_user)
+end
+
+When 'I click the Twitter button' do
+ click_link 'Sign in using Twitter'
+end
+
+Then /^there should be (\d+) users? in the system$/ do |count|
+ assert_equal count.to_i, User.count, User.all.inspect
+end
+
+Given 'an user exists that is connected to Twitter account "$username"' do |twitter_username|
+ Factory(:user, :twitter_username => twitter_username)
+end
+
+Then 'I should be signed in as Twitter user "$username"' do |twitter_username|
+ assert user = User.find_by_twitter_username(twitter_username), "No user exists for Twitter username #{twitter_username.inspect}"
+ assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
+end
+
+And /^I sign out of Twitter$/ do
+ FakeTwitterSession.logout
+ visit url_for(
+ :controller => 'clearance/sessions',
+ :action => 'destroy',
+ :method => :delete
+ ), :delete
+end
+
+Then /^I should be signed out of Twitter$/ do
+ assert !@controller.local_twitter_session?
+end
View
36 generators/clearance_twitter_features/templates/features/twitter_sign_in.feature
@@ -0,0 +1,36 @@
+Feature: Sign in with Twitter OAuth
+ In order to use their Twitter credentials for authentication.
+ An existing user
+ Should be able to sign in with Twitter OAuth
+
+ @wip
+ Scenario: User has already signed up with Twitter OAuth
+ Given remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ @wip
+ Scenario: User has already signed up, but their account is not linked to Twitter
+ Given remote Twitter user exists with an username of "jerkcity" and a name of "Alice Appleton" and an email of "user@example.com"
+ And an email confirmed user exists with an email of "user@example.com"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ Scenario: A user with a Twitter account signs out
+ Given remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ When I go to the homepage
+ And I sign out of Twitter
+ Then I should be signed out
+ And I should be signed out of Twitter
View
25 generators/clearance_twitter_features/templates/features/twitter_sign_up.feature
@@ -0,0 +1,25 @@
+Feature: Sign up with Twitter OAuth
+ In order to use their Twitter credentials for authentication,
+ A visitor to the site
+ Should be able to sign up with Twitter OAuth
+
+ @wip
+ Scenario: User signs up with Twitter OAuth
+ Given there are no users
+ And remote Twitter user exists with an username of "jerkcity"
+ When I am signed into Twitter account "jerkcity"
+ And I go to the sign up page
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ @wip
+ Scenario: User has already signed up with Twitter OAuth
+ Given there are no users
+ And remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign up page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
View
BIN  test/rails_root/features/support/.swp → lib/clearance_twitter/.fake_twitter.rb.swp
Binary file not shown
View
BIN  lib/clearance_twitter/.routes.rb.swp
Binary file not shown
View
18 lib/clearance_twitter/fake_twitter.rb
@@ -0,0 +1,18 @@
+class FakeTwitterUser
+ def self.clear_remote_profiles
+ end
+
+ def self.add_remote_profile(profile_hash)
+ end
+
+ def self.get_remote_profile(username)
+ end
+end
+
+class FakeTwitterSession
+ def self.logout
+ end
+
+ def self.login(twitter_user)
+ end
+end
View
8 lib/clearance_twitter/routes.rb
@@ -0,0 +1,8 @@
+module ClearanceTwitter
+ module Routes
+ def self.draw(map)
+ map.resources :twitter_users, :controller => 'clearance_twitter/twitter_users',
+ :only => [:new, :create]
+ end
+ end
+end
View
1  test/rails_root/app/controllers/application_controller.rb
@@ -2,6 +2,7 @@
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
+ include Clearance::Authentication
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
View
3  test/rails_root/app/models/user.rb
@@ -0,0 +1,3 @@
+class User < ActiveRecord::Base
+ include Clearance::User
+end
View
15 test/rails_root/app/views/layouts/application.html.erb
@@ -0,0 +1,15 @@
+<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Some page</title>
+ </head>
+ <body>
+ <div id="flash">
+ <% flash.each do |key, value| -%>
+ <div id="flash_<%= key %>"><%=h value %></div>
+ <% end -%>
+ </div>
+
+ <%= yield %>
+
+ </body>
+</html>
View
21 test/rails_root/app/views/sessions/new.html.erb
@@ -0,0 +1,21 @@
+<h2>Sign in</h2>
+
+<% semantic_form_for :session, :url => session_path do |form| %>
+ <%= link_to 'Sign in using Twitter', new_twitter_user_path %>
+ <% form.inputs do %>
+ <%= form.input :email %>
+ <%= form.input :password, :as => :password %>
+ <% end %>
+ <% form.buttons do %>
+ <%= form.commit_button "Sign in" %>
+ <% end %>
+<% end %>
+
+<ul>
+ <li>
+ <%= link_to "Sign up", sign_up_path %>
+ </li>
+ <li>
+ <%= link_to "Forgot password?", new_password_path %>
+ </li>
+</ul>
View
14 test/rails_root/app/views/users/new.html.erb
@@ -0,0 +1,14 @@
+<h2>Sign up</h2>
+
+<% semantic_form_for @user do |form| %>
+ <%= link_to 'Sign in using Twitter', new_twitter_user_path %>
+ <%= form.error_messages %>
+ <% form.inputs do %>
+ <%= form.input :email %>
+ <%= form.input :password %>
+ <%= form.input :password_confirmation, :label => "Confirm password" %>
+ <% end %>
+ <% form.buttons do %>
+ <%= form.commit_button "Sign up" %>
+ <% end %>
+<% end %>
View
BIN  test/rails_root/config/.environment.rb.swp
Binary file not shown
View
5 test/rails_root/config/environment.rb
@@ -35,7 +35,10 @@
# Run "rake -D time" for a list of tasks for finding time zone names.
config.time_zone = 'UTC'
+ config.gem 'clearance'
+ config.gem 'formtastic'
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
# config.i18n.default_locale = :de
-end
+end
View
2  test/rails_root/config/environments/cucumber.rb
@@ -20,7 +20,9 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
+config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.gem 'cucumber-rails', :lib => false, :version => '>=0.2.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails'))
config.gem 'database_cleaner', :lib => false, :version => '>=0.4.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
config.gem 'webrat', :lib => false, :version => '>=0.6.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
+config.gem 'factory_girl'
View
3  test/rails_root/config/environments/development.rb
@@ -14,4 +14,5 @@
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
-config.action_mailer.raise_delivery_errors = false
+config.action_mailer.raise_delivery_errors = false
+config.action_mailer.default_url_options = { :host => 'localhost:3000' }
View
3  test/rails_root/config/environments/test.rb
@@ -21,8 +21,9 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
+config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
-# config.active_record.schema_format = :sql
+# config.active_record.schema_format = :sql
View
3  test/rails_root/config/initializers/clearance.rb
@@ -0,0 +1,3 @@
+Clearance.configure do |config|
+ config.mailer_sender = 'donotreply@example.com'
+end
View
43 test/rails_root/config/routes.rb
@@ -1,43 +1,6 @@
ActionController::Routing::Routes.draw do |map|
- # The priority is based upon order of creation: first created -> highest priority.
+ ClearanceTwitter::Routes.draw(map)
+ map.root :controller => 'clearance/sessions', :action => 'new'
- # Sample of regular route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # map.resources :products
-
- # Sample resource route with options:
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
-
- # Sample resource route with sub-resources:
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
-
- # Sample resource route with more complex sub-resources
- # map.resources :products do |products|
- # products.resources :comments
- # products.resources :sales, :collection => { :recent => :get }
- # end
-
- # Sample resource route within a namespace:
- # map.namespace :admin do |admin|
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
- # admin.resources :products
- # end
-
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
- # map.root :controller => "welcome"
-
- # See how all your routes lay out with "rake routes"
-
- # Install the default routes as the lowest priority.
- # Note: These default routes make all actions in every controller accessible via GET requests. You should
- # consider removing or commenting them out if you're using named routes and resources.
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
+ Clearance::Routes.draw(map)
end
View
BIN  test/rails_root/db/development.sqlite3
Binary file not shown
View
12 test/rails_root/db/migrate/20100312194919_create_users.rb
@@ -0,0 +1,12 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
22 test/rails_root/db/migrate/20100312195052_clearance_update_users_to_0_8_8.rb
@@ -0,0 +1,22 @@
+class ClearanceUpdateUsersTo088 < ActiveRecord::Migration
+ def self.up
+ change_table(:users) do |t|
+ t.string :email
+ t.string :encrypted_password, :limit => 128
+ t.string :salt, :limit => 128
+ t.string :confirmation_token, :limit => 128
+ t.string :remember_token, :limit => 128
+ t.boolean :email_confirmed, :default => false, :null => false
+ end
+
+ add_index :users, [:id, :confirmation_token]
+ add_index :users, :email
+ add_index :users, :remember_token
+ end
+
+ def self.down
+ change_table(:users) do |t|
+ t.remove :email,:encrypted_password,:salt,:confirmation_token,:remember_token,:email_confirmed
+ end
+ end
+end
View
15 test/rails_root/db/migrate/20100312212628_add_clearance_twitter_fields_to_users.rb
@@ -0,0 +1,15 @@
+class AddClearanceTwitterFieldsToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :twitter_username, :string
+ add_column :users, :twitter_id, :string
+ add_column :users, :access_token, :string
+ add_column :users, :access_secret, :string
+ end
+
+ def self.down
+ remove_column :users, :access_token
+ remove_column :users, :access_secret
+ remove_column :users, :twitter_id
+ remove_column :users, :twitter_username
+ end
+end
View
21 test/rails_root/db/schema.rb
@@ -9,6 +9,25 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20100312212628) do
+
+ create_table "users", :force => true do |t|
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "email"
+ t.string "encrypted_password", :limit => 128
+ t.string "salt", :limit => 128
+ t.string "confirmation_token", :limit => 128
+ t.string "remember_token", :limit => 128
+ t.boolean "email_confirmed", :default => false, :null => false
+ t.string "twitter_username"
+ t.string "twitter_id"
+ t.string "access_token"
+ t.string "access_secret"
+ end
+
+ add_index "users", ["email"], :name => "index_users_on_email"
+ add_index "users", ["id", "confirmation_token"], :name => "index_users_on_id_and_confirmation_token"
+ add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
end
View
BIN  test/rails_root/db/test.sqlite3
Binary file not shown
View
33 test/rails_root/features/password_reset.feature
@@ -0,0 +1,33 @@
+Feature: Password reset
+ In order to sign in even if user forgot their password
+ A user
+ Should be able to reset it
+
+ Scenario: User is not signed up
+ Given no user exists with an email of "email@person.com"
+ When I request password reset link to be sent to "email@person.com"
+ Then I should see "Unknown email"
+
+ Scenario: User is signed up and requests password reset
+ Given I signed up with "email@person.com/password"
+ When I request password reset link to be sent to "email@person.com"
+ Then I should see "instructions for changing your password"
+ And a password reset message should be sent to "email@person.com"
+
+ Scenario: User is signed up updated his password and types wrong confirmation
+ Given I signed up with "email@person.com/password"
+ When I follow the password reset link sent to "email@person.com"
+ And I update my password with "newpassword/wrongconfirmation"
+ Then I should see error messages
+ And I should be signed out
+
+ Scenario: User is signed up and updates his password
+ Given I signed up with "email@person.com/password"
+ When I follow the password reset link sent to "email@person.com"
+ And I update my password with "newpassword/newpassword"
+ Then I should be signed in
+ When I sign out
+ Then I should be signed out
+ And I sign in as "email@person.com/newpassword"
+ Then I should be signed in
+
View
35 test/rails_root/features/sign_in.feature
@@ -0,0 +1,35 @@
+Feature: Sign in
+ In order to get access to protected sections of the site
+ A user
+ Should be able to sign in
+
+ Scenario: User is not signed up
+ Given no user exists with an email of "email@person.com"
+ When I go to the sign in page
+ And I sign in as "email@person.com/password"
+ Then I should see "Bad email or password"
+ And I should be signed out
+
+ Scenario: User is not confirmed
+ Given I signed up with "email@person.com/password"
+ When I go to the sign in page
+ And I sign in as "email@person.com/password"
+ Then I should see "User has not confirmed email"
+ And I should be signed out
+
+ Scenario: User enters wrong password
+ Given I am signed up and confirmed as "email@person.com/password"
+ When I go to the sign in page
+ And I sign in as "email@person.com/wrongpassword"
+ Then I should see "Bad email or password"
+ And I should be signed out
+
+ Scenario: User signs in successfully
+ Given I am signed up and confirmed as "email@person.com/password"
+ When I go to the sign in page
+ And I sign in as "email@person.com/password"
+ Then I should see "Signed in"
+ And I should be signed in
+ When I return next time
+ Then I should be signed in
+
View
15 test/rails_root/features/sign_out.feature
@@ -0,0 +1,15 @@
+Feature: Sign out
+ To protect my account from unauthorized access
+ A signed in user
+ Should be able to sign out
+
+ Scenario: User signs out
+ Given I am signed up and confirmed as "email@person.com/password"
+ When I sign in as "email@person.com/password"
+ Then I should be signed in
+ And I sign out
+ Then I should see "Signed out"
+ And I should be signed out
+ When I return next time
+ Then I should be signed out
+
View
45 test/rails_root/features/sign_up.feature
@@ -0,0 +1,45 @@
+Feature: Sign up
+ In order to get access to protected sections of the site
+ A user
+ Should be able to sign up
+
+ Scenario: User signs up with invalid data
+ When I go to the sign up page
+ And I fill in "Email" with "invalidemail"
+ And I fill in "Password" with "password"
+ And I fill in "Confirm password" with ""
+ And I press "Sign up"
+ Then I should see error messages
+
+ Scenario: User signs up with valid data
+ When I go to the sign up page
+ And I fill in "Email" with "email@person.com"
+ And I fill in "Password" with "password"
+ And I fill in "Confirm password" with "password"
+ And I press "Sign up"
+ Then I should see "instructions for confirming"
+ And a confirmation message should be sent to "email@person.com"
+
+ Scenario: User confirms his account
+ Given I signed up with "email@person.com/password"
+ When I follow the confirmation link sent to "email@person.com"
+ Then I should see "Confirmed email and signed in"
+ And I should be signed in
+
+ Scenario: Signed in user clicks confirmation link again
+ Given I signed up with "email@person.com/password"
+ When I follow the confirmation link sent to "email@person.com"
+ Then I should be signed in
+ When I follow the confirmation link sent to "email@person.com"
+ Then I should see "Confirmed email and signed in"
+ And I should be signed in
+
+ Scenario: Signed out user clicks confirmation link again
+ Given I signed up with "email@person.com/password"
+ When I follow the confirmation link sent to "email@person.com"
+ Then I should be signed in
+ When I sign out
+ And I follow the confirmation link sent to "email@person.com"
+ Then I should see "Already confirmed email. Please sign in."
+ And I should be signed out
+
View
122 test/rails_root/features/step_definitions/clearance_steps.rb
@@ -0,0 +1,122 @@
+# General
+
+Then /^I should see error messages$/ do
+ assert_match /error(s)? prohibited/m, response.body
+end
+
+# Database
+
+Given /^no user exists with an email of "(.*)"$/ do |email|
+ assert_nil User.find_by_email(email)
+end
+
+Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
+ user = Factory :user,
+ :email => email,
+ :password => password,
+ :password_confirmation => password
+end
+
+Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
+ user = Factory :email_confirmed_user,
+ :email => email,
+ :password => password,
+ :password_confirmation => password
+end
+
+# Session
+
+Then /^I should be signed in$/ do
+ assert controller.signed_in?
+end
+
+Then /^I should be signed out$/ do
+ assert ! controller.signed_in?
+end
+
+When /^session is cleared$/ do
+ request.reset_session
+ controller.instance_variable_set(:@_current_user, nil)
+end
+
+Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
+ Given %{I am signed up and confirmed as "#{email}/#{password}"}
+ And %{I sign in as "#{email}/#{password}"}
+end
+
+# Emails
+
+Then /^a confirmation message should be sent to "(.*)"$/ do |email|
+ user = User.find_by_email(email)
+ assert !user.confirmation_token.blank?
+ assert !ActionMailer::Base.deliveries.empty?
+ result = ActionMailer::Base.deliveries.any? do |email|
+ email.to == [user.email] &&
+ email.subject =~ /confirm/i &&
+ email.body =~ /#{user.confirmation_token}/
+ end
+ assert result
+end
+
+When /^I follow the confirmation link sent to "(.*)"$/ do |email|
+ user = User.find_by_email(email)
+ visit new_user_confirmation_path(:user_id => user,
+ :token => user.confirmation_token)
+end
+
+Then /^a password reset message should be sent to "(.*)"$/ do |email|
+ user = User.find_by_email(email)
+ assert !user.confirmation_token.blank?
+ assert !ActionMailer::Base.deliveries.empty?
+ result = ActionMailer::Base.deliveries.any? do |email|
+ email.to == [user.email] &&
+ email.subject =~ /password/i &&
+ email.body =~ /#{user.confirmation_token}/
+ end
+ assert result
+end
+
+When /^I follow the password reset link sent to "(.*)"$/ do |email|
+ user = User.find_by_email(email)
+ visit edit_user_password_path(:user_id => user,
+ :token => user.confirmation_token)
+end
+
+When /^I try to change the password of "(.*)" without token$/ do |email|
+ user = User.find_by_email(email)
+ visit edit_user_password_path(:user_id => user)
+end
+
+Then /^I should be forbidden$/ do
+ assert_response :forbidden
+end
+
+# Actions
+
+When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
+ When %{I go to the sign in page}
+ And %{I fill in "Email" with "#{email}"}
+ And %{I fill in "Password" with "#{password}"}
+ And %{I press "Sign in"}
+end
+
+When /^I sign out$/ do
+ visit '/sign_out'
+end
+
+When /^I request password reset link to be sent to "(.*)"$/ do |email|
+ When %{I go to the password reset request page}
+ And %{I fill in "Email address" with "#{email}"}
+ And %{I press "Reset password"}
+end
+
+When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
+ And %{I fill in "Choose password" with "#{password}"}
+ And %{I fill in "Confirm password" with "#{confirmation}"}
+ And %{I press "Save this password"}
+end
+
+When /^I return next time$/ do
+ When %{session is cleared}
+ And %{I go to the homepage}
+end
View
53 test/rails_root/features/step_definitions/clearance_twitter_steps.rb
@@ -0,0 +1,53 @@
+require 'clearance_twitter/fake_twitter'
+
+Before do
+ FakeTwitterUser.clear_remote_profiles
+ FakeTwitterSession.logout
+end
+
+Given /^there are no users$/ do
+ User.delete_all
+end
+
+Given /^remote Twitter user exists with an username of "([^"]+)"$/ do |twitter_username|
+ FakeTwitterUser.add_remote_profile({:username => twitter_username})
+end
+
+Given 'remote Twitter user exists with an username of "$username" and a name of "$name" and an email of "$email"' do |twitter_username, twitter_user_name, twitter_user_email|
+ FakeTwitterUser.add_remote_profile({:id => twitter_username, :name => twitter_user_name, :email => twitter_user_email})
+end
+
+Given 'I am signed into Twitter account "$username"' do |twitter_username|
+ twitter_user = FakeTwitterUser.get_remote_profile(twitter_username)
+ FakeTwitterSession.login(twitter_user)
+end
+
+When 'I click the Twitter button' do
+ click_link 'Sign in using Twitter'
+end
+
+Then /^there should be (\d+) users? in the system$/ do |count|
+ assert_equal count.to_i, User.count, User.all.inspect
+end
+
+Given 'an user exists that is connected to Twitter account "$username"' do |twitter_username|
+ Factory(:user, :twitter_username => twitter_username)
+end
+
+Then 'I should be signed in as Twitter user "$username"' do |twitter_username|
+ assert user = User.find_by_twitter_username(twitter_username), "No user exists for Twitter username #{twitter_username.inspect}"
+ assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
+end
+
+And /^I sign out of Twitter$/ do
+ FakeTwitterSession.logout
+ visit url_for(
+ :controller => 'clearance/sessions',
+ :action => 'destroy',
+ :method => :delete
+ ), :delete
+end
+
+Then /^I should be signed out of Twitter$/ do
+ assert !@controller.local_twitter_session?
+end
View
1  test/rails_root/features/step_definitions/factory_girl_steps.rb
@@ -0,0 +1 @@
+require 'factory_girl/step_definitions'
View
18 test/rails_root/features/support/paths.rb
@@ -1,21 +1,17 @@
module NavigationHelpers
- # Maps a name to a path. Used by the
- #
- # When /^I go to (.+)$/ do |page_name|
- #
- # step definition in web_steps.rb
- #
def path_to(page_name)
case page_name
when /the home\s?page/
'/'
+ when /the sign up page/i
+ sign_up_path
+ when /the sign in page/i
+ sign_in_path
+ when /the password reset request page/i
+ new_password_path
- # Add more mappings here.
- # Here is an example that pulls values out of the Regexp:
- #
- # when /^(.*)'s profile page$/i
- # user_profile_path(User.find_by_login($1))
+ # Add more page name => path mappings here
else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
View
36 test/rails_root/features/twitter_sign_in.feature
@@ -0,0 +1,36 @@
+Feature: Sign in with Twitter OAuth
+ In order to use their Twitter credentials for authentication.
+ An existing user
+ Should be able to sign in with Twitter OAuth
+
+ @wip
+ Scenario: User has already signed up with Twitter OAuth
+ Given remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ @wip
+ Scenario: User has already signed up, but their account is not linked to Twitter
+ Given remote Twitter user exists with an username of "jerkcity" and a name of "Alice Appleton" and an email of "user@example.com"
+ And an email confirmed user exists with an email of "user@example.com"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ Scenario: A user with a Twitter account signs out
+ Given remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign in page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ When I go to the homepage
+ And I sign out of Twitter
+ Then I should be signed out
+ And I should be signed out of Twitter
View
25 test/rails_root/features/twitter_sign_up.feature
@@ -0,0 +1,25 @@
+Feature: Sign up with Twitter OAuth
+ In order to use their Twitter credentials for authentication,
+ A visitor to the site
+ Should be able to sign up with Twitter OAuth
+
+ @wip
+ Scenario: User signs up with Twitter OAuth
+ Given there are no users
+ And remote Twitter user exists with an username of "jerkcity"
+ When I am signed into Twitter account "jerkcity"
+ And I go to the sign up page
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
+
+ @wip
+ Scenario: User has already signed up with Twitter OAuth
+ Given there are no users
+ And remote Twitter user exists with an username of "jerkcity"
+ And an user exists that is connected to Twitter account "jerkcity"
+ When I go to the sign up page
+ And I am signed into Twitter account "jerkcity"
+ And I click the Twitter button
+ Then I should be signed in as Twitter user "jerkcity"
+ And there should be 1 user in the system
View
6,839 test/rails_root/log/cucumber.log
6,838 additions, 1 deletion not shown
View
1,644 test/rails_root/log/development.log
1,644 additions, 0 deletions not shown
View
13 test/rails_root/test/factories/clearance.rb
@@ -0,0 +1,13 @@
+Factory.sequence :email do |n|
+ "user#{n}@example.com"
+end
+
+Factory.define :user do |user|
+ user.email { Factory.next :email }
+ user.password { "password" }
+ user.password_confirmation { "password" }
+end
+
+Factory.define :email_confirmed_user, :parent => :user do |user|
+ user.email_confirmed { true }
+end
View
1  test/rails_root/vendor/plugins/clearance_twitter
Please sign in to comment.
Something went wrong with that request. Please try again.