benaldred-clearance 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/CHANGELOG.md +274 -0
  2. data/LICENSE +21 -0
  3. data/README.md +129 -0
  4. data/Rakefile +87 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/clearance/confirmations_controller.rb +76 -0
  7. data/app/controllers/clearance/passwords_controller.rb +85 -0
  8. data/app/controllers/clearance/sessions_controller.rb +67 -0
  9. data/app/controllers/clearance/users_controller.rb +35 -0
  10. data/app/models/clearance_mailer.rb +21 -0
  11. data/app/views/clearance_mailer/change_password.html.erb +9 -0
  12. data/app/views/clearance_mailer/confirmation.html.erb +5 -0
  13. data/app/views/passwords/edit.html.erb +23 -0
  14. data/app/views/passwords/new.html.erb +15 -0
  15. data/app/views/sessions/new.html.erb +24 -0
  16. data/app/views/users/_form.html.erb +13 -0
  17. data/app/views/users/new.html.erb +6 -0
  18. data/generators/clearance/USAGE +1 -0
  19. data/generators/clearance/clearance_generator.rb +68 -0
  20. data/generators/clearance/lib/insert_commands.rb +33 -0
  21. data/generators/clearance/lib/rake_commands.rb +22 -0
  22. data/generators/clearance/templates/README +24 -0
  23. data/generators/clearance/templates/clearance.rb +3 -0
  24. data/generators/clearance/templates/factories.rb +13 -0
  25. data/generators/clearance/templates/migrations/create_users.rb +21 -0
  26. data/generators/clearance/templates/migrations/update_users.rb +41 -0
  27. data/generators/clearance/templates/user.rb +3 -0
  28. data/generators/clearance_features/USAGE +1 -0
  29. data/generators/clearance_features/clearance_features_generator.rb +19 -0
  30. data/generators/clearance_features/templates/features/password_reset.feature +33 -0
  31. data/generators/clearance_features/templates/features/sign_in.feature +35 -0
  32. data/generators/clearance_features/templates/features/sign_out.feature +15 -0
  33. data/generators/clearance_features/templates/features/sign_up.feature +45 -0
  34. data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +122 -0
  35. data/generators/clearance_features/templates/features/support/paths.rb +23 -0
  36. data/generators/clearance_views/USAGE +0 -0
  37. data/generators/clearance_views/clearance_views_generator.rb +27 -0
  38. data/generators/clearance_views/templates/formtastic/passwords/edit.html.erb +21 -0
  39. data/generators/clearance_views/templates/formtastic/passwords/new.html.erb +15 -0
  40. data/generators/clearance_views/templates/formtastic/sessions/new.html.erb +21 -0
  41. data/generators/clearance_views/templates/formtastic/users/_inputs.html.erb +6 -0
  42. data/generators/clearance_views/templates/formtastic/users/new.html.erb +10 -0
  43. data/lib/clearance.rb +7 -0
  44. data/lib/clearance/authentication.rb +131 -0
  45. data/lib/clearance/configuration.rb +26 -0
  46. data/lib/clearance/extensions/errors.rb +6 -0
  47. data/lib/clearance/extensions/rescue.rb +5 -0
  48. data/lib/clearance/routes.rb +49 -0
  49. data/lib/clearance/user.rb +215 -0
  50. data/rails/init.rb +1 -0
  51. data/shoulda_macros/clearance.rb +266 -0
  52. data/test/controllers/confirmations_controller_test.rb +104 -0
  53. data/test/controllers/passwords_controller_test.rb +183 -0
  54. data/test/controllers/sessions_controller_test.rb +146 -0
  55. data/test/controllers/users_controller_test.rb +65 -0
  56. data/test/models/clearance_mailer_test.rb +55 -0
  57. data/test/models/user_test.rb +255 -0
  58. data/test/rails_root/app/controllers/accounts_controller.rb +10 -0
  59. data/test/rails_root/app/controllers/application_controller.rb +6 -0
  60. data/test/rails_root/app/helpers/application_helper.rb +5 -0
  61. data/test/rails_root/app/helpers/confirmations_helper.rb +2 -0
  62. data/test/rails_root/app/helpers/passwords_helper.rb +2 -0
  63. data/test/rails_root/app/models/user.rb +3 -0
  64. data/test/rails_root/config/boot.rb +110 -0
  65. data/test/rails_root/config/environment.rb +17 -0
  66. data/test/rails_root/config/environments/development.rb +19 -0
  67. data/test/rails_root/config/environments/production.rb +1 -0
  68. data/test/rails_root/config/environments/test.rb +36 -0
  69. data/test/rails_root/config/initializers/clearance.rb +3 -0
  70. data/test/rails_root/config/initializers/inflections.rb +10 -0
  71. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  72. data/test/rails_root/config/initializers/requires.rb +13 -0
  73. data/test/rails_root/config/initializers/time_formats.rb +4 -0
  74. data/test/rails_root/config/routes.rb +6 -0
  75. data/test/rails_root/features/step_definitions/clearance_steps.rb +122 -0
  76. data/test/rails_root/features/step_definitions/web_steps.rb +259 -0
  77. data/test/rails_root/features/support/env.rb +47 -0
  78. data/test/rails_root/features/support/paths.rb +23 -0
  79. data/test/rails_root/public/dispatch.rb +10 -0
  80. data/test/rails_root/script/create_project.rb +52 -0
  81. data/test/rails_root/test/factories/clearance.rb +13 -0
  82. data/test/rails_root/test/functional/accounts_controller_test.rb +23 -0
  83. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
  84. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +1236 -0
  85. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +10 -0
  86. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +3 -0
  87. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +2900 -0
  88. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +14 -0
  89. data/test/test_helper.rb +19 -0
  90. metadata +160 -0
@@ -0,0 +1,10 @@
1
+ class AccountsController < ApplicationController
2
+ before_filter :authenticate
3
+
4
+ def edit
5
+ end
6
+
7
+ def create
8
+ redirect_to edit_account_path
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class ApplicationController < ActionController::Base
2
+ helper :all
3
+ protect_from_forgery
4
+ include Clearance::Authentication
5
+ before_filter :authenticate
6
+ end
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def body_class
3
+ "#{controller.controller_name} #{controller.controller_name}-#{controller.action_name}"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module ConfirmationsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PasswordsHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include Clearance::User
3
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ require 'rubygems'
86
+ min_version = '1.3.1'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), 'boot')
2
+ require 'digest/md5'
3
+
4
+ Rails::Initializer.run do |config|
5
+ config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
6
+ config.time_zone = 'Eastern Time (US & Canada)'
7
+ config.action_controller.session = {
8
+ :session_key => "_clearance_session",
9
+ :secret => ['clearance', 'random', 'words', 'here'].map {|k| Digest::MD5.hexdigest(k) }.join
10
+ }
11
+
12
+ config.gem "justinfrench-formtastic",
13
+ :lib => 'formtastic',
14
+ :source => 'http://gems.github.com'
15
+
16
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
17
+ end
@@ -0,0 +1,19 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_controller.perform_caching = false
14
+ config.action_view.debug_rjs = true
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ HOST = "localhost"
@@ -0,0 +1 @@
1
+ HOST = "http://example.com"
@@ -0,0 +1,36 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Disable request forgery protection in test environment
17
+ config.action_controller.allow_forgery_protection = false
18
+
19
+ # Tell ActionMailer not to deliver emails to the real world.
20
+ # The :test delivery method accumulates sent emails in the
21
+ # ActionMailer::Base.deliveries array.
22
+ config.action_mailer.delivery_method = :test
23
+
24
+ config.gem 'shoulda',
25
+ :source => "http://gemcutter.org",
26
+ :version => '>= 2.9.1'
27
+ config.gem 'factory_girl',
28
+ :source => "http://gemcutter.org",
29
+ :version => '>= 1.2.3'
30
+
31
+ config.gem 'cucumber-rails',
32
+ :lib => false,
33
+ :version => '>= 0.2.2'
34
+ config.gem 'webrat',
35
+ :lib => false,
36
+ :version => '>= 0.6.0'
@@ -0,0 +1,3 @@
1
+ Clearance.configure do |config|
2
+ config.mailer_sender = 'donotreply@example.com'
3
+ end
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,13 @@
1
+ Dir[File.join(RAILS_ROOT, 'lib', 'extensions', '*.rb')].each do |f|
2
+ require f
3
+ end
4
+
5
+ Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
6
+ require f
7
+ end
8
+
9
+ # Rails 2 doesn't like mocks
10
+
11
+ Dir[File.join(RAILS_ROOT, 'test', 'mocks', RAILS_ENV, '*.rb')].each do |f|
12
+ require f
13
+ end
@@ -0,0 +1,4 @@
1
+ # Example time formats
2
+ { :short_date => "%x", :long_date => "%a, %b %d, %Y" }.each do |k, v|
3
+ ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v)
4
+ end
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.resource :account
3
+ map.root :controller => 'accounts', :action => 'edit'
4
+
5
+ Clearance::Routes.draw(map)
6
+ end
@@ -0,0 +1,122 @@
1
+ # General
2
+
3
+ Then /^I should see error messages$/ do
4
+ assert_match /error(s)? prohibited/m, response.body
5
+ end
6
+
7
+ # Database
8
+
9
+ Given /^no user exists with an email of "(.*)"$/ do |email|
10
+ assert_nil User.find_by_email(email)
11
+ end
12
+
13
+ Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
14
+ user = Factory :user,
15
+ :email => email,
16
+ :password => password,
17
+ :password_confirmation => password
18
+ end
19
+
20
+ Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
21
+ user = Factory :email_confirmed_user,
22
+ :email => email,
23
+ :password => password,
24
+ :password_confirmation => password
25
+ end
26
+
27
+ # Session
28
+
29
+ Then /^I should be signed in$/ do
30
+ assert controller.signed_in?
31
+ end
32
+
33
+ Then /^I should be signed out$/ do
34
+ assert ! controller.signed_in?
35
+ end
36
+
37
+ When /^session is cleared$/ do
38
+ request.reset_session
39
+ controller.instance_variable_set(:@_current_user, nil)
40
+ end
41
+
42
+ Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
43
+ Given %{I am signed up and confirmed as "#{email}/#{password}"}
44
+ And %{I sign in as "#{email}/#{password}"}
45
+ end
46
+
47
+ # Emails
48
+
49
+ Then /^a confirmation message should be sent to "(.*)"$/ do |email|
50
+ user = User.find_by_email(email)
51
+ assert !user.confirmation_token.blank?
52
+ assert !ActionMailer::Base.deliveries.empty?
53
+ result = ActionMailer::Base.deliveries.any? do |email|
54
+ email.to == [user.email] &&
55
+ email.subject =~ /confirm/i &&
56
+ email.body =~ /#{user.confirmation_token}/
57
+ end
58
+ assert result
59
+ end
60
+
61
+ When /^I follow the confirmation link sent to "(.*)"$/ do |email|
62
+ user = User.find_by_email(email)
63
+ visit new_user_confirmation_path(:user_id => user,
64
+ :token => user.confirmation_token)
65
+ end
66
+
67
+ Then /^a password reset message should be sent to "(.*)"$/ do |email|
68
+ user = User.find_by_email(email)
69
+ assert !user.confirmation_token.blank?
70
+ assert !ActionMailer::Base.deliveries.empty?
71
+ result = ActionMailer::Base.deliveries.any? do |email|
72
+ email.to == [user.email] &&
73
+ email.subject =~ /password/i &&
74
+ email.body =~ /#{user.confirmation_token}/
75
+ end
76
+ assert result
77
+ end
78
+
79
+ When /^I follow the password reset link sent to "(.*)"$/ do |email|
80
+ user = User.find_by_email(email)
81
+ visit edit_user_password_path(:user_id => user,
82
+ :token => user.confirmation_token)
83
+ end
84
+
85
+ When /^I try to change the password of "(.*)" without token$/ do |email|
86
+ user = User.find_by_email(email)
87
+ visit edit_user_password_path(:user_id => user)
88
+ end
89
+
90
+ Then /^I should be forbidden$/ do
91
+ assert_response :forbidden
92
+ end
93
+
94
+ # Actions
95
+
96
+ When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
97
+ When %{I go to the sign in page}
98
+ And %{I fill in "Email" with "#{email}"}
99
+ And %{I fill in "Password" with "#{password}"}
100
+ And %{I press "Sign in"}
101
+ end
102
+
103
+ When /^I sign out$/ do
104
+ visit '/sign_out'
105
+ end
106
+
107
+ When /^I request password reset link to be sent to "(.*)"$/ do |email|
108
+ When %{I go to the password reset request page}
109
+ And %{I fill in "Email address" with "#{email}"}
110
+ And %{I press "Reset password"}
111
+ end
112
+
113
+ When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
114
+ And %{I fill in "Choose password" with "#{password}"}
115
+ And %{I fill in "Confirm password" with "#{confirmation}"}
116
+ And %{I press "Save this password"}
117
+ end
118
+
119
+ When /^I return next time$/ do
120
+ When %{session is cleared}
121
+ And %{I go to the homepage}
122
+ end
@@ -0,0 +1,259 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
9
+
10
+ # Commonly used webrat steps
11
+ # http://github.com/brynary/webrat
12
+
13
+ Given /^(?:|I )am on (.+)$/ do |page_name|
14
+ visit path_to(page_name)
15
+ end
16
+
17
+ When /^(?:|I )go to (.+)$/ do |page_name|
18
+ visit path_to(page_name)
19
+ end
20
+
21
+ When /^(?:|I )press "([^\"]*)"$/ do |button|
22
+ click_button(button)
23
+ end
24
+
25
+ When /^(?:|I )follow "([^\"]*)"$/ do |link|
26
+ click_link(link)
27
+ end
28
+
29
+ When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
30
+ click_link_within(parent, link)
31
+ end
32
+
33
+ When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
34
+ fill_in(field, :with => value)
35
+ end
36
+
37
+ When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
38
+ fill_in(field, :with => value)
39
+ end
40
+
41
+ # Use this to fill in an entire form with data from a table. Example:
42
+ #
43
+ # When I fill in the following:
44
+ # | Account Number | 5002 |
45
+ # | Expiry date | 2009-11-01 |
46
+ # | Note | Nice guy |
47
+ # | Wants Email? | |
48
+ #
49
+ # TODO: Add support for checkbox, select og option
50
+ # based on naming conventions.
51
+ #
52
+ When /^(?:|I )fill in the following:$/ do |fields|
53
+ fields.rows_hash.each do |name, value|
54
+ When %{I fill in "#{name}" with "#{value}"}
55
+ end
56
+ end
57
+
58
+ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
59
+ select(value, :from => field)
60
+ end
61
+
62
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
63
+ # When I select "December 25, 2008 10:00" as the date and time
64
+ When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
65
+ select_datetime(time)
66
+ end
67
+
68
+ # Use this step when using multiple datetime_select helpers on a page or
69
+ # you want to specify which datetime to select. Given the following view:
70
+ # <%= f.label :preferred %><br />
71
+ # <%= f.datetime_select :preferred %>
72
+ # <%= f.label :alternative %><br />
73
+ # <%= f.datetime_select :alternative %>
74
+ # The following steps would fill out the form:
75
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
76
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
77
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
78
+ select_datetime(datetime, :from => datetime_label)
79
+ end
80
+
81
+ # Use this step in conjunction with Rail's time_select helper. For example:
82
+ # When I select "2:20PM" as the time
83
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
84
+ # will convert the 2:20PM to 14:20 and then select it.
85
+ When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
86
+ select_time(time)
87
+ end
88
+
89
+ # Use this step when using multiple time_select helpers on a page or you want to
90
+ # specify the name of the time on the form. For example:
91
+ # When I select "7:30AM" as the "Gym" time
92
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
93
+ select_time(time, :from => time_label)
94
+ end
95
+
96
+ # Use this step in conjunction with Rail's date_select helper. For example:
97
+ # When I select "February 20, 1981" as the date
98
+ When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
99
+ select_date(date)
100
+ end
101
+
102
+ # Use this step when using multiple date_select helpers on one page or
103
+ # you want to specify the name of the date on the form. For example:
104
+ # When I select "April 26, 1982" as the "Date of Birth" date
105
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
106
+ select_date(date, :from => date_label)
107
+ end
108
+
109
+ When /^(?:|I )check "([^\"]*)"$/ do |field|
110
+ check(field)
111
+ end
112
+
113
+ When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
114
+ uncheck(field)
115
+ end
116
+
117
+ When /^(?:|I )choose "([^\"]*)"$/ do |field|
118
+ choose(field)
119
+ end
120
+
121
+ # Adds support for validates_attachment_content_type. Without the mime-type getting
122
+ # passed to attach_file() you will get a "Photo file is not one of the allowed file types."
123
+ # error message
124
+ When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
125
+ type = path.split(".")[1]
126
+
127
+ case type
128
+ when "jpg"
129
+ type = "image/jpg"
130
+ when "jpeg"
131
+ type = "image/jpeg"
132
+ when "png"
133
+ type = "image/png"
134
+ when "gif"
135
+ type = "image/gif"
136
+ end
137
+
138
+ attach_file(field, path, type)
139
+ end
140
+
141
+ Then /^(?:|I )should see "([^\"]*)"$/ do |text|
142
+ if defined?(Spec::Rails::Matchers)
143
+ response.should contain(text)
144
+ else
145
+ assert_contain text
146
+ end
147
+ end
148
+
149
+ Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
150
+ within(selector) do |content|
151
+ if defined?(Spec::Rails::Matchers)
152
+ content.should contain(text)
153
+ else
154
+ assert content.include?(text)
155
+ end
156
+ end
157
+ end
158
+
159
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
160
+ regexp = Regexp.new(regexp)
161
+ if defined?(Spec::Rails::Matchers)
162
+ response.should contain(regexp)
163
+ else
164
+ assert_contain regexp
165
+ end
166
+ end
167
+
168
+ Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
169
+ within(selector) do |content|
170
+ regexp = Regexp.new(regexp)
171
+ if defined?(Spec::Rails::Matchers)
172
+ content.should contain(regexp)
173
+ else
174
+ assert content =~ regexp
175
+ end
176
+ end
177
+ end
178
+
179
+ Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
180
+ if defined?(Spec::Rails::Matchers)
181
+ response.should_not contain(text)
182
+ else
183
+ assert_not_contain text
184
+ end
185
+ end
186
+
187
+ Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
188
+ within(selector) do |content|
189
+ if defined?(Spec::Rails::Matchers)
190
+ content.should_not contain(text)
191
+ else
192
+ assert !content.include?(text)
193
+ end
194
+ end
195
+ end
196
+
197
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
198
+ regexp = Regexp.new(regexp)
199
+ if defined?(Spec::Rails::Matchers)
200
+ response.should_not contain(regexp)
201
+ else
202
+ assert_not_contain regexp
203
+ end
204
+ end
205
+
206
+ Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
207
+ within(selector) do |content|
208
+ regexp = Regexp.new(regexp)
209
+ if defined?(Spec::Rails::Matchers)
210
+ content.should_not contain(regexp)
211
+ else
212
+ assert content !~ regexp
213
+ end
214
+ end
215
+ end
216
+
217
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
218
+ if defined?(Spec::Rails::Matchers)
219
+ field_labeled(field).value.should =~ /#{value}/
220
+ else
221
+ assert_match(/#{value}/, field_labeled(field).value)
222
+ end
223
+ end
224
+
225
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
226
+ if defined?(Spec::Rails::Matchers)
227
+ field_labeled(field).value.should_not =~ /#{value}/
228
+ else
229
+ assert_no_match(/#{value}/, field_labeled(field).value)
230
+ end
231
+ end
232
+
233
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
234
+ if defined?(Spec::Rails::Matchers)
235
+ field_labeled(label).should be_checked
236
+ else
237
+ assert field_labeled(label).checked?
238
+ end
239
+ end
240
+
241
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
242
+ if defined?(Spec::Rails::Matchers)
243
+ field_labeled(label).should_not be_checked
244
+ else
245
+ assert !field_labeled(label).checked?
246
+ end
247
+ end
248
+
249
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
250
+ if defined?(Spec::Rails::Matchers)
251
+ URI.parse(current_url).path.should == path_to(page_name)
252
+ else
253
+ assert_equal path_to(page_name), URI.parse(current_url).path
254
+ end
255
+ end
256
+
257
+ Then /^show me the page$/ do
258
+ save_and_open_page
259
+ end