clearance 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

Files changed (133) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/README.md +15 -4
  3. data/VERSION +1 -1
  4. data/app/controllers/clearance/passwords_controller.rb +14 -6
  5. data/lib/clearance.rb +0 -3
  6. data/lib/clearance/shoulda_macros.rb +1 -176
  7. data/lib/rails/generators/clearance_features_templates/features/password_reset.feature +4 -3
  8. data/lib/rails/generators/clearance_features_templates/features/sign_in.feature +3 -2
  9. data/lib/rails/generators/clearance_features_templates/features/sign_out.feature +4 -3
  10. data/lib/rails/generators/clearance_features_templates/features/sign_up.feature +3 -2
  11. data/lib/rails/generators/clearance_features_templates/features/step_definitions/clearance_steps.rb +2 -10
  12. data/spec/rails_root/Gemfile.lock +143 -0
  13. data/spec/rails_root/app/views/passwords/edit.html.erb +21 -0
  14. data/spec/rails_root/app/views/passwords/new.html.erb +15 -0
  15. data/spec/rails_root/app/views/sessions/new.html.erb +21 -0
  16. data/spec/rails_root/app/views/users/_inputs.html.erb +6 -0
  17. data/spec/rails_root/app/views/users/new.html.erb +10 -0
  18. data/spec/rails_root/db/development.sqlite3 +0 -0
  19. data/spec/rails_root/db/migrate/20110209234521_clearance_create_users.rb +19 -0
  20. data/spec/rails_root/db/schema.rb +28 -0
  21. data/spec/rails_root/db/test.sqlite3 +0 -0
  22. data/spec/rails_root/features/password_reset.feature +40 -0
  23. data/spec/rails_root/features/sign_in.feature +28 -0
  24. data/spec/rails_root/features/sign_out.feature +16 -0
  25. data/spec/rails_root/features/sign_up.feature +21 -0
  26. data/spec/rails_root/features/step_definitions/clearance_steps.rb +109 -0
  27. data/spec/rails_root/log/development.log +536 -0
  28. data/spec/rails_root/log/test.log +7600 -0
  29. data/spec/rails_root/test/factories/clearance.rb +13 -0
  30. data/spec/rails_root/test/functional/accounts_controller_test.rb +22 -0
  31. data/spec/rails_root/test/performance/browsing_test.rb +9 -0
  32. data/spec/rails_root/test/test_helper.rb +13 -0
  33. data/spec/rails_root/vendor/Gemfile +17 -0
  34. data/spec/rails_root/vendor/Gemfile.lock +143 -0
  35. data/spec/rails_root/vendor/README +244 -0
  36. data/spec/rails_root/vendor/Rakefile +10 -0
  37. data/spec/rails_root/vendor/app/controllers/accounts_controller.rb +10 -0
  38. data/spec/rails_root/vendor/app/controllers/application_controller.rb +6 -0
  39. data/spec/rails_root/vendor/app/helpers/application_helper.rb +2 -0
  40. data/spec/rails_root/vendor/app/models/user.rb +3 -0
  41. data/spec/rails_root/vendor/app/views/accounts/edit.html.erb +0 -0
  42. data/spec/rails_root/vendor/app/views/layouts/application.html.erb +24 -0
  43. data/spec/rails_root/vendor/app/views/passwords/edit.html.erb +21 -0
  44. data/spec/rails_root/vendor/app/views/passwords/new.html.erb +15 -0
  45. data/spec/rails_root/vendor/app/views/sessions/new.html.erb +21 -0
  46. data/spec/rails_root/vendor/app/views/users/_inputs.html.erb +6 -0
  47. data/spec/rails_root/vendor/app/views/users/new.html.erb +10 -0
  48. data/spec/rails_root/vendor/config.ru +4 -0
  49. data/spec/rails_root/vendor/config/application.rb +46 -0
  50. data/spec/rails_root/vendor/config/boot.rb +6 -0
  51. data/spec/rails_root/vendor/config/cucumber.yml +8 -0
  52. data/spec/rails_root/vendor/config/database.yml +25 -0
  53. data/spec/rails_root/vendor/config/environment.rb +7 -0
  54. data/spec/rails_root/vendor/config/environments/development.rb +21 -0
  55. data/spec/rails_root/vendor/config/environments/production.rb +42 -0
  56. data/spec/rails_root/vendor/config/environments/test.rb +34 -0
  57. data/spec/rails_root/vendor/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/rails_root/vendor/config/initializers/clearance.rb +3 -0
  59. data/spec/rails_root/vendor/config/initializers/inflections.rb +10 -0
  60. data/spec/rails_root/vendor/config/initializers/mime_types.rb +5 -0
  61. data/spec/rails_root/vendor/config/initializers/secret_token.rb +7 -0
  62. data/spec/rails_root/vendor/config/initializers/session_store.rb +8 -0
  63. data/spec/rails_root/vendor/config/locales/en.yml +5 -0
  64. data/spec/rails_root/vendor/config/routes.rb +61 -0
  65. data/spec/rails_root/vendor/db/development.sqlite3 +0 -0
  66. data/spec/rails_root/vendor/db/migrate/20101220184900_clearance_create_users.rb +20 -0
  67. data/spec/rails_root/vendor/db/schema.rb +29 -0
  68. data/spec/rails_root/vendor/db/test.sqlite3 +0 -0
  69. data/spec/rails_root/vendor/doc/README_FOR_APP +2 -0
  70. data/spec/rails_root/vendor/features/password_reset.feature +33 -0
  71. data/spec/rails_root/vendor/features/sign_in.feature +35 -0
  72. data/spec/rails_root/vendor/features/sign_out.feature +15 -0
  73. data/spec/rails_root/vendor/features/sign_up.feature +45 -0
  74. data/spec/rails_root/vendor/features/step_definitions/clearance_steps.rb +138 -0
  75. data/spec/rails_root/vendor/features/step_definitions/web_steps.rb +219 -0
  76. data/spec/rails_root/vendor/features/support/env.rb +57 -0
  77. data/spec/rails_root/vendor/features/support/paths.rb +45 -0
  78. data/spec/rails_root/vendor/lib/tasks/cucumber.rake +53 -0
  79. data/spec/rails_root/vendor/log/development.log +663 -0
  80. data/spec/rails_root/vendor/log/test.log +22745 -0
  81. data/spec/rails_root/vendor/public/404.html +26 -0
  82. data/spec/rails_root/vendor/public/422.html +26 -0
  83. data/spec/rails_root/vendor/public/500.html +26 -0
  84. data/spec/rails_root/vendor/public/favicon.ico +0 -0
  85. data/spec/rails_root/vendor/public/images/rails.png +0 -0
  86. data/spec/rails_root/vendor/public/javascripts/application.js +2 -0
  87. data/spec/rails_root/vendor/public/javascripts/controls.js +965 -0
  88. data/spec/rails_root/vendor/public/javascripts/dragdrop.js +974 -0
  89. data/spec/rails_root/vendor/public/javascripts/effects.js +1123 -0
  90. data/spec/rails_root/vendor/public/javascripts/prototype.js +4874 -0
  91. data/spec/rails_root/vendor/public/javascripts/rails.js +118 -0
  92. data/spec/rails_root/vendor/public/robots.txt +5 -0
  93. data/spec/rails_root/vendor/script/cucumber +10 -0
  94. data/spec/rails_root/vendor/script/rails +9 -0
  95. data/spec/rails_root/vendor/test/factories/clearance.rb +13 -0
  96. data/spec/rails_root/vendor/test/functional/accounts_controller_test.rb +22 -0
  97. data/spec/rails_root/vendor/test/performance/browsing_test.rb +9 -0
  98. data/spec/rails_root/vendor/test/test_helper.rb +13 -0
  99. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
  100. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/README +13 -0
  101. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/Rakefile +10 -0
  102. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/init.rb +5 -0
  103. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
  104. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
  105. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
  106. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
  107. data/spec/rails_root/vendor/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
  108. data/test/controllers/passwords_controller_test.rb +19 -0
  109. data/test/models/clearance_mailer_test.rb +1 -1
  110. data/test/rails_root/Gemfile.lock +145 -0
  111. data/test/rails_root/app/views/passwords/edit.html.erb +21 -0
  112. data/test/rails_root/app/views/passwords/new.html.erb +15 -0
  113. data/test/rails_root/app/views/sessions/new.html.erb +21 -0
  114. data/test/rails_root/app/views/users/_inputs.html.erb +6 -0
  115. data/test/rails_root/app/views/users/new.html.erb +10 -0
  116. data/test/rails_root/db/development.sqlite3 +0 -0
  117. data/test/rails_root/db/migrate/20110209234101_clearance_create_users.rb +19 -0
  118. data/test/rails_root/db/schema.rb +28 -0
  119. data/test/rails_root/db/test.sqlite3 +0 -0
  120. data/test/rails_root/features/password_reset.feature +40 -0
  121. data/test/rails_root/features/sign_in.feature +28 -0
  122. data/test/rails_root/features/sign_out.feature +16 -0
  123. data/test/rails_root/features/sign_up.feature +21 -0
  124. data/test/rails_root/features/step_definitions/clearance_steps.rb +109 -0
  125. data/test/rails_root/log/development.log +938 -0
  126. data/test/rails_root/log/test.log +20303 -0
  127. data/test/test_helper.rb +1 -0
  128. metadata +263 -42
  129. data/clearance.gemspec +0 -198
  130. data/cucumber.yml +0 -4
  131. data/init.rb +0 -1
  132. data/lib/clearance/extensions/errors.rb +0 -6
  133. data/lib/clearance/extensions/rescue.rb +0 -5
@@ -0,0 +1,20 @@
1
+ class ClearanceCreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:users) do |t|
4
+ t.string :email
5
+ t.string :encrypted_password, :limit => 128
6
+ t.string :salt, :limit => 128
7
+ t.string :confirmation_token, :limit => 128
8
+ t.string :remember_token, :limit => 128
9
+ t.boolean :email_confirmed, :default => false, :null => false
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :users, :email
14
+ add_index :users, :remember_token
15
+ end
16
+
17
+ def self.down
18
+ drop_table :users
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20101220184900) do
14
+
15
+ create_table "users", :force => true do |t|
16
+ t.string "email"
17
+ t.string "encrypted_password", :limit => 128
18
+ t.string "salt", :limit => 128
19
+ t.string "confirmation_token", :limit => 128
20
+ t.string "remember_token", :limit => 128
21
+ t.boolean "email_confirmed", :default => false, :null => false
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ add_index "users", ["email"], :name => "index_users_on_email"
27
+ add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
28
+
29
+ end
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
@@ -0,0 +1,33 @@
1
+ Feature: Password reset
2
+ In order to sign in even if user forgot their password
3
+ A user
4
+ Should be able to reset it
5
+
6
+ Scenario: User is not signed up
7
+ Given no user exists with an email of "email@person.com"
8
+ When I request password reset link to be sent to "email@person.com"
9
+ Then I should see "Unknown email"
10
+
11
+ Scenario: User is signed up and requests password reset
12
+ Given I signed up with "email@person.com/password"
13
+ When I request password reset link to be sent to "email@person.com"
14
+ Then I should see "instructions for changing your password"
15
+ And a password reset message should be sent to "email@person.com"
16
+
17
+ Scenario: User is signed up updated his password and types wrong confirmation
18
+ Given I signed up with "email@person.com/password"
19
+ When I follow the password reset link sent to "email@person.com"
20
+ And I update my password with "newpassword/wrongconfirmation"
21
+ Then I should see an error message
22
+ And I should be signed out
23
+
24
+ Scenario: User is signed up and updates his password
25
+ Given I signed up with "email@person.com/password"
26
+ When I follow the password reset link sent to "email@person.com"
27
+ And I update my password with "newpassword/newpassword"
28
+ Then I should be signed in
29
+ When I sign out
30
+ Then I should be signed out
31
+ And I sign in as "email@person.com/newpassword"
32
+ Then I should be signed in
33
+
@@ -0,0 +1,35 @@
1
+ Feature: Sign in
2
+ In order to get access to protected sections of the site
3
+ A user
4
+ Should be able to sign in
5
+
6
+ Scenario: User is not signed up
7
+ Given no user exists with an email of "email@person.com"
8
+ When I go to the sign in page
9
+ And I sign in as "email@person.com/password"
10
+ Then I should see "Bad email or password"
11
+ And I should be signed out
12
+
13
+ Scenario: User is not confirmed
14
+ Given I signed up with "email@person.com/password"
15
+ When I go to the sign in page
16
+ And I sign in as "email@person.com/password"
17
+ Then I should see "User has not confirmed email"
18
+ And I should be signed out
19
+
20
+ Scenario: User enters wrong password
21
+ Given I am signed up and confirmed as "email@person.com/password"
22
+ When I go to the sign in page
23
+ And I sign in as "email@person.com/wrongpassword"
24
+ Then I should see "Bad email or password"
25
+ And I should be signed out
26
+
27
+ Scenario: User signs in successfully
28
+ Given I am signed up and confirmed as "email@person.com/password"
29
+ When I go to the sign in page
30
+ And I sign in as "email@person.com/password"
31
+ Then I should see "Signed in"
32
+ And I should be signed in
33
+ When I return next time
34
+ Then I should be signed in
35
+
@@ -0,0 +1,15 @@
1
+ Feature: Sign out
2
+ To protect my account from unauthorized access
3
+ A signed in user
4
+ Should be able to sign out
5
+
6
+ Scenario: User signs out
7
+ Given I am signed up and confirmed as "email@person.com/password"
8
+ When I sign in as "email@person.com/password"
9
+ Then I should be signed in
10
+ And I sign out
11
+ Then I should see "Signed out"
12
+ And I should be signed out
13
+ When I return next time
14
+ Then I should be signed out
15
+
@@ -0,0 +1,45 @@
1
+ Feature: Sign up
2
+ In order to get access to protected sections of the site
3
+ A user
4
+ Should be able to sign up
5
+
6
+ Scenario: User signs up with invalid data
7
+ When I go to the sign up page
8
+ And I fill in "Email" with "invalidemail"
9
+ And I fill in "Password" with "password"
10
+ And I fill in "Confirm password" with ""
11
+ And I press "Sign up"
12
+ Then I should see error messages
13
+
14
+ Scenario: User signs up with valid data
15
+ When I go to the sign up page
16
+ And I fill in "Email" with "email@person.com"
17
+ And I fill in "Password" with "password"
18
+ And I fill in "Confirm password" with "password"
19
+ And I press "Sign up"
20
+ Then I should see "instructions for confirming"
21
+ And a confirmation message should be sent to "email@person.com"
22
+
23
+ Scenario: User confirms his account
24
+ Given I signed up with "email@person.com/password"
25
+ When I follow the confirmation link sent to "email@person.com"
26
+ Then I should see "Confirmed email and signed in"
27
+ And I should be signed in
28
+
29
+ Scenario: Signed in user clicks confirmation link again
30
+ Given I signed up with "email@person.com/password"
31
+ When I follow the confirmation link sent to "email@person.com"
32
+ Then I should be signed in
33
+ When I follow the confirmation link sent to "email@person.com"
34
+ Then I should see "Confirmed email and signed in"
35
+ And I should be signed in
36
+
37
+ Scenario: Signed out user clicks confirmation link again
38
+ Given I signed up with "email@person.com/password"
39
+ When I follow the confirmation link sent to "email@person.com"
40
+ Then I should be signed in
41
+ When I sign out
42
+ And I follow the confirmation link sent to "email@person.com"
43
+ Then I should see "Already confirmed email. Please sign in."
44
+ And I should be signed out
45
+
@@ -0,0 +1,138 @@
1
+ # General
2
+
3
+ Then /^I should see error messages$/ do
4
+ Then %{I should see "errors prohibited"}
5
+ end
6
+
7
+ Then /^I should see an error message$/ do
8
+ Then %{I should see "error prohibited"}
9
+ end
10
+
11
+ # Database
12
+
13
+ Given /^no user exists with an email of "(.*)"$/ do |email|
14
+ assert_nil User.find_by_email(email)
15
+ end
16
+
17
+ Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
18
+ user = Factory :user,
19
+ :email => email,
20
+ :password => password,
21
+ :password_confirmation => password
22
+ end
23
+
24
+ Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
25
+ user = Factory :email_confirmed_user,
26
+ :email => email,
27
+ :password => password,
28
+ :password_confirmation => password
29
+ end
30
+
31
+ # Session
32
+
33
+ Then /^I should be signed in$/ do
34
+ Given %{I am on the homepage}
35
+ Then %{I should see "Sign out"}
36
+ end
37
+
38
+ Then /^I should be signed out$/ do
39
+ Given %{I am on the homepage}
40
+ Then %{I should see "Sign in"}
41
+ end
42
+
43
+ When /^session is cleared$/ do
44
+ # TODO: This doesn't work with Capybara
45
+ # TODO: I tried Capybara.reset_sessions! but that didn't work
46
+ #request.reset_session
47
+ #controller.instance_variable_set(:@_current_user, nil)
48
+ end
49
+
50
+ Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
51
+ Given %{I am signed up and confirmed as "#{email}/#{password}"}
52
+ And %{I sign in as "#{email}/#{password}"}
53
+ end
54
+
55
+ Given /^I sign in$/ do
56
+ email = Factory.next(:email)
57
+ Given %{I have signed in with "#{email}/password"}
58
+ end
59
+
60
+ # Emails
61
+
62
+ Then /^a confirmation message should be sent to "(.*)"$/ do |email|
63
+ user = User.find_by_email(email)
64
+ assert !user.confirmation_token.blank?
65
+ assert !ActionMailer::Base.deliveries.empty?
66
+ result = ActionMailer::Base.deliveries.any? do |email|
67
+ email.to == [user.email] &&
68
+ email.subject =~ /confirm/i &&
69
+ email.body =~ /#{user.confirmation_token}/
70
+ end
71
+ assert result
72
+ end
73
+
74
+ When /^I follow the confirmation link sent to "(.*)"$/ do |email|
75
+ user = User.find_by_email(email)
76
+ visit new_user_confirmation_path(:user_id => user,
77
+ :token => user.confirmation_token)
78
+ end
79
+
80
+ Then /^a password reset message should be sent to "(.*)"$/ do |email|
81
+ user = User.find_by_email(email)
82
+ assert !user.confirmation_token.blank?
83
+ assert !ActionMailer::Base.deliveries.empty?
84
+ result = ActionMailer::Base.deliveries.any? do |email|
85
+ email.to == [user.email] &&
86
+ email.subject =~ /password/i &&
87
+ email.body =~ /#{user.confirmation_token}/
88
+ end
89
+ assert result
90
+ end
91
+
92
+ When /^I follow the password reset link sent to "(.*)"$/ do |email|
93
+ user = User.find_by_email(email)
94
+ visit edit_user_password_path(:user_id => user,
95
+ :token => user.confirmation_token)
96
+ end
97
+
98
+ When /^I try to change the password of "(.*)" without token$/ do |email|
99
+ user = User.find_by_email(email)
100
+ visit edit_user_password_path(:user_id => user)
101
+ end
102
+
103
+ Then /^I should be forbidden$/ do
104
+ assert_response :forbidden
105
+ end
106
+
107
+ # Actions
108
+
109
+ When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
110
+ When %{I go to the sign in page}
111
+ And %{I fill in "Email" with "#{email}"}
112
+ And %{I fill in "Password" with "#{password}"}
113
+ And %{I press "Sign in"}
114
+ end
115
+
116
+ When "I sign out" do
117
+ steps %{
118
+ When I go to the homepage
119
+ And I follow "Sign out"
120
+ }
121
+ end
122
+
123
+ When /^I request password reset link to be sent to "(.*)"$/ do |email|
124
+ When %{I go to the password reset request page}
125
+ And %{I fill in "Email address" with "#{email}"}
126
+ And %{I press "Reset password"}
127
+ end
128
+
129
+ When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
130
+ And %{I fill in "Choose password" with "#{password}"}
131
+ And %{I fill in "Confirm password" with "#{confirmation}"}
132
+ And %{I press "Save this password"}
133
+ end
134
+
135
+ When /^I return next time$/ do
136
+ When %{session is cleared}
137
+ And %{I go to the homepage}
138
+ end
@@ -0,0 +1,219 @@
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 'uri'
9
+ require 'cgi'
10
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
11
+
12
+ module WithinHelpers
13
+ def with_scope(locator)
14
+ locator ? within(locator) { yield } : yield
15
+ end
16
+ end
17
+ World(WithinHelpers)
18
+
19
+ Given /^(?:|I )am on (.+)$/ do |page_name|
20
+ visit path_to(page_name)
21
+ end
22
+
23
+ When /^(?:|I )go to (.+)$/ do |page_name|
24
+ visit path_to(page_name)
25
+ end
26
+
27
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
28
+ with_scope(selector) do
29
+ click_button(button)
30
+ end
31
+ end
32
+
33
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
34
+ with_scope(selector) do
35
+ click_link(link)
36
+ end
37
+ end
38
+
39
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
40
+ with_scope(selector) do
41
+ fill_in(field, :with => value)
42
+ end
43
+ end
44
+
45
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
46
+ with_scope(selector) do
47
+ fill_in(field, :with => value)
48
+ end
49
+ end
50
+
51
+ # Use this to fill in an entire form with data from a table. Example:
52
+ #
53
+ # When I fill in the following:
54
+ # | Account Number | 5002 |
55
+ # | Expiry date | 2009-11-01 |
56
+ # | Note | Nice guy |
57
+ # | Wants Email? | |
58
+ #
59
+ # TODO: Add support for checkbox, select og option
60
+ # based on naming conventions.
61
+ #
62
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
63
+ with_scope(selector) do
64
+ fields.rows_hash.each do |name, value|
65
+ When %{I fill in "#{name}" with "#{value}"}
66
+ end
67
+ end
68
+ end
69
+
70
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
71
+ with_scope(selector) do
72
+ select(value, :from => field)
73
+ end
74
+ end
75
+
76
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
77
+ with_scope(selector) do
78
+ check(field)
79
+ end
80
+ end
81
+
82
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
83
+ with_scope(selector) do
84
+ uncheck(field)
85
+ end
86
+ end
87
+
88
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
89
+ with_scope(selector) do
90
+ choose(field)
91
+ end
92
+ end
93
+
94
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
95
+ with_scope(selector) do
96
+ attach_file(field, path)
97
+ end
98
+ end
99
+
100
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
101
+ require 'json'
102
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
103
+ actual = JSON.pretty_generate(JSON.parse(response.body))
104
+ expected.should == actual
105
+ end
106
+
107
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
108
+ with_scope(selector) do
109
+ if page.respond_to? :should
110
+ page.should have_content(text)
111
+ else
112
+ assert page.has_content?(text)
113
+ end
114
+ end
115
+ end
116
+
117
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
118
+ regexp = Regexp.new(regexp)
119
+ with_scope(selector) do
120
+ if page.respond_to? :should
121
+ page.should have_xpath('//*', :text => regexp)
122
+ else
123
+ assert page.has_xpath?('//*', :text => regexp)
124
+ end
125
+ end
126
+ end
127
+
128
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
129
+ with_scope(selector) do
130
+ if page.respond_to? :should
131
+ page.should have_no_content(text)
132
+ else
133
+ assert page.has_no_content?(text)
134
+ end
135
+ end
136
+ end
137
+
138
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
139
+ regexp = Regexp.new(regexp)
140
+ with_scope(selector) do
141
+ if page.respond_to? :should
142
+ page.should have_no_xpath('//*', :text => regexp)
143
+ else
144
+ assert page.has_no_xpath?('//*', :text => regexp)
145
+ end
146
+ end
147
+ end
148
+
149
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
150
+ with_scope(selector) do
151
+ field = find_field(field)
152
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
153
+ if field_value.respond_to? :should
154
+ field_value.should =~ /#{value}/
155
+ else
156
+ assert_match(/#{value}/, field_value)
157
+ end
158
+ end
159
+ end
160
+
161
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
162
+ with_scope(selector) do
163
+ field = find_field(field)
164
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
165
+ if field_value.respond_to? :should_not
166
+ field_value.should_not =~ /#{value}/
167
+ else
168
+ assert_no_match(/#{value}/, field_value)
169
+ end
170
+ end
171
+ end
172
+
173
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
174
+ with_scope(selector) do
175
+ field_checked = find_field(label)['checked']
176
+ if field_checked.respond_to? :should
177
+ field_checked.should be_true
178
+ else
179
+ assert field_checked
180
+ end
181
+ end
182
+ end
183
+
184
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
185
+ with_scope(selector) do
186
+ field_checked = find_field(label)['checked']
187
+ if field_checked.respond_to? :should
188
+ field_checked.should be_false
189
+ else
190
+ assert !field_checked
191
+ end
192
+ end
193
+ end
194
+
195
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
196
+ current_path = URI.parse(current_url).path
197
+ if current_path.respond_to? :should
198
+ current_path.should == path_to(page_name)
199
+ else
200
+ assert_equal path_to(page_name), current_path
201
+ end
202
+ end
203
+
204
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205
+ query = URI.parse(current_url).query
206
+ actual_params = query ? CGI.parse(query) : {}
207
+ expected_params = {}
208
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
+
210
+ if actual_params.respond_to? :should
211
+ actual_params.should == expected_params
212
+ else
213
+ assert_equal expected_params, actual_params
214
+ end
215
+ end
216
+
217
+ Then /^show me the page$/ do
218
+ save_and_open_page
219
+ end