clearance 0.11.1 → 0.11.2

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 (40) hide show
  1. data/.gitignore +4 -2
  2. data/Appraisals +11 -0
  3. data/CHANGELOG.md +7 -0
  4. data/Gemfile +12 -10
  5. data/Gemfile.lock +101 -83
  6. data/README.md +23 -2
  7. data/Rakefile +9 -4
  8. data/VERSION +1 -1
  9. data/app/mailers/clearance_mailer.rb +5 -5
  10. data/app/views/clearance_mailer/change_password.html.erb +1 -3
  11. data/clearance.gemspec +1 -1
  12. data/features/engine/visitor_resets_password.feature +7 -4
  13. data/features/engine/visitor_signs_in.feature +10 -12
  14. data/features/engine/visitor_signs_out.feature +2 -4
  15. data/features/integration.feature +13 -14
  16. data/features/step_definitions/configuration_steps.rb +6 -1
  17. data/features/step_definitions/engine/clearance_steps.rb +8 -17
  18. data/features/step_definitions/web_steps.rb +82 -90
  19. data/features/support/appraisal.rb +18 -0
  20. data/features/support/aruba.rb +3 -0
  21. data/features/support/clearance.rb +16 -0
  22. data/features/support/env.rb +40 -29
  23. data/features/support/selectors.rb +39 -0
  24. data/gemfiles/3.0.9.gemfile +18 -0
  25. data/gemfiles/3.0.9.gemfile.lock +176 -0
  26. data/gemfiles/3.1.0.rc4.gemfile +22 -0
  27. data/gemfiles/3.1.0.rc4.gemfile.lock +212 -0
  28. data/lib/clearance.rb +0 -1
  29. data/lib/clearance/test_matchers.rb +60 -0
  30. data/lib/clearance/user.rb +16 -4
  31. data/lib/generators/clearance/install/templates/README +6 -6
  32. data/spec/controllers/passwords_controller_spec.rb +4 -4
  33. data/spec/factories.rb +5 -5
  34. data/spec/spec_helper.rb +3 -47
  35. data/spec/support/clearance.rb +12 -0
  36. metadata +19 -8
  37. data/.bundle/config +0 -2
  38. data/lib/clearance/shoulda_macros.rb +0 -73
  39. data/spec/support/authorization.rb +0 -18
  40. data/spec/support/clearance_redirects.rb +0 -21
@@ -10,13 +10,13 @@ Feature: Password reset
10
10
  Then I should see "Unknown email"
11
11
 
12
12
  Scenario: User is signed up and requests password reset
13
- Given I signed up with "email@example.com/password"
13
+ Given I signed up with "email@example.com"
14
14
  When I request password reset link to be sent to "email@example.com"
15
15
  Then I should see "instructions for changing your password"
16
16
  And a password reset message should be sent to "email@example.com"
17
17
 
18
18
  Scenario: User tries to reset his password with a blank password
19
- Given I signed up with "email@example.com/password"
19
+ Given I signed up with "email@example.com"
20
20
  And I go to the password reset request page
21
21
  Then I should see an email field
22
22
  And I fill in "Email address" with "email@example.com"
@@ -27,7 +27,7 @@ Feature: Password reset
27
27
  And I should be signed out
28
28
 
29
29
  Scenario: User is signed up and updates his password
30
- Given I signed up with "email@example.com/password"
30
+ Given I signed up with "email@example.com"
31
31
  And I go to the password reset request page
32
32
  And I fill in "Email address" with "email@example.com"
33
33
  And I press "Reset password"
@@ -36,7 +36,10 @@ Feature: Password reset
36
36
  Then I should be signed in
37
37
  When I sign out
38
38
  Then I should be signed out
39
- And I sign in as "email@example.com/newpassword"
39
+ When I go to the sign in page
40
+ And I fill in "Email" with "email@example.com"
41
+ And I fill in "Password" with "newpassword"
42
+ And I press "Sign in"
40
43
  Then I should be signed in
41
44
 
42
45
  Scenario: User who was created before Clearance was installed creates password for first time
@@ -5,34 +5,32 @@ Feature: Sign in
5
5
  I want to sign in
6
6
 
7
7
  Scenario: Visitor is not signed up
8
- Given no user exists with an email of "email@person.com"
8
+ Given no user exists with an email of "email@example.com"
9
9
  When I go to the sign in page
10
- And I sign in as "email@person.com/password"
10
+ And I sign in as "email@example.com"
11
11
  Then I should see "Bad email or password"
12
12
  And I should be signed out
13
13
 
14
14
  Scenario: Visitor enters wrong password
15
- Given I am signed up as "email@person.com/password"
15
+ Given I am signed up as "email@example.com"
16
16
  When I go to the sign in page
17
- And I sign in as "email@person.com/wrongpassword"
17
+ And I fill in "Email" with "email@example.com"
18
+ And I fill in "Password" with "badpassword"
19
+ And I press "Sign in"
18
20
  Then I should see "Bad email or password"
19
21
  And I should be signed out
20
22
 
21
23
  Scenario: Visitor signs in successfully
22
- Given I am signed up as "email@person.com/password"
24
+ Given I am signed up as "email@example.com"
23
25
  When I go to the sign in page
24
26
  Then I should see an email field
25
- And I sign in as "email@person.com/password"
27
+ And I sign in as "email@example.com"
26
28
  Then I should see "Signed in"
27
29
  And I should be signed in
28
- When I return next time
29
- Then I should be signed in
30
30
 
31
31
  Scenario: Visitor signs in successfully with uppercase email
32
- Given I am signed up as "email@person.com/password"
32
+ Given I am signed up as "email@example.com"
33
33
  When I go to the sign in page
34
- And I sign in as "Email@person.com/password"
34
+ And I sign in as "Email@example.com"
35
35
  Then I should see "Signed in"
36
36
  And I should be signed in
37
- When I return next time
38
- Then I should be signed in
@@ -5,11 +5,9 @@ Feature: Sign out
5
5
  I want to sign out
6
6
 
7
7
  Scenario: User signs out
8
- Given I am signed up as "email@person.com/password"
9
- When I sign in as "email@person.com/password"
8
+ Given I am signed up as "email@example.com"
9
+ When I sign in as "email@example.com"
10
10
  Then I should be signed in
11
11
  And I sign out
12
12
  Then I should see "Signed out"
13
13
  And I should be signed out
14
- When I return next time
15
- Then I should be signed out
@@ -1,8 +1,7 @@
1
- @disable-bundler
2
1
  Feature: integrate with application
3
2
 
4
3
  Background:
5
- When I successfully run "rails new testapp"
4
+ When I successfully run `bundle exec rails new testapp`
6
5
  And I cd to "testapp"
7
6
  And I remove the file "public/index.html"
8
7
  And I remove the file "app/views/layouts/application.html.erb"
@@ -12,20 +11,20 @@ Feature: integrate with application
12
11
  And I add the "capybara" gem
13
12
  And I add the "rspec-rails" gem
14
13
  And I add the "factory_girl_rails" gem
15
- And I add the "dynamic_form" gem
16
14
  And I add the "database_cleaner" gem
17
15
  And I add the "clearance" gem from this project
18
- And I add the "diesel" gem
19
- And I run "bundle install --local"
20
- And I successfully run "rails generate cucumber:install"
16
+ And I add the "diesel" gem from git "git://github.com/thoughtbot/diesel.git"
17
+ And I reset Bundler environment variable
18
+ And I run `bundle install --local`
19
+ And I successfully run `bundle exec rails generate cucumber:install`
21
20
  And I disable Capybara Javascript emulation
22
- And I successfully run "rails generate clearance:features"
21
+ And I successfully run `bundle exec rails generate clearance:features`
23
22
 
24
23
  Scenario: generate a Rails app, run the generators, and run the tests
25
- When I successfully run "rails generate clearance:install"
24
+ When I successfully run `bundle exec rails generate clearance:install`
26
25
  Then the output should contain "Next steps"
27
- When I successfully run "rake db:migrate --trace"
28
- And I successfully run "rake --trace"
26
+ When I successfully run `bundle exec rake db:migrate --trace`
27
+ And I successfully run `bundle exec rake --trace`
29
28
  Then the output should contain "passed"
30
29
  And the output should not contain "failed"
31
30
  And the output should not contain "Could not find generator"
@@ -44,10 +43,10 @@ Feature: integrate with application
44
43
  end
45
44
  end
46
45
  """
47
- And I successfully run "rake db:migrate --trace"
48
- And I successfully run "rails generate clearance:install"
49
- And I successfully run "rake db:migrate --trace"
50
- And I successfully run "rake --trace"
46
+ And I successfully run `bundle exec rake db:migrate --trace`
47
+ And I successfully run `bundle exec rails generate clearance:install`
48
+ And I successfully run `bundle exec rake db:migrate --trace`
49
+ And I successfully run `bundle exec rake --trace`
51
50
  Then the output should contain "passed"
52
51
  And the output should not contain "failed"
53
52
  And the output should not contain "Could not find generator"
@@ -16,7 +16,7 @@ When /^I configure a root route$/ do
16
16
  contents.sub!(/(\.routes\.draw do)/, "\\1\n#{route}\n")
17
17
  File.open(path, "w") { |file| file.write(contents) }
18
18
  end
19
- create_file("app/controllers/home_controller.rb", <<-CONTROLLER)
19
+ write_file("app/controllers/home_controller.rb", <<-CONTROLLER)
20
20
  class HomeController < ApplicationController
21
21
  def show
22
22
  render :text => "", :layout => "application"
@@ -35,3 +35,8 @@ When /^I disable Capybara Javascript emulation$/ do
35
35
  end
36
36
  end
37
37
 
38
+ When /^I copy the locked Gemfile from this project$/ do
39
+ in_current_dir do
40
+ FileUtils.cp(File.join(PROJECT_ROOT, 'Gemfile.lock'), 'Gemfile.lock')
41
+ end
42
+ end
@@ -22,10 +22,8 @@ Given /^no user exists with an email of "(.*)"$/ do |email|
22
22
  assert_nil User.find_by_email(email)
23
23
  end
24
24
 
25
- Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)\/(.*)"$/ do |email, password|
26
- Factory(:user,
27
- :email => email,
28
- :password => password)
25
+ Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)"$/ do |email|
26
+ Factory(:user, :email => email)
29
27
  end
30
28
 
31
29
  Given /^a user "([^"]*)" exists without a salt, remember token, or password$/ do |email|
@@ -46,21 +44,14 @@ Then /^I should be signed out$/ do
46
44
  Then %{I should see "Sign in"}
47
45
  end
48
46
 
49
- When /^session is cleared$/ do
50
- # TODO: This doesn't work with Capybara
51
- # TODO: I tried Capybara.reset_sessions! but that didn't work
52
- #request.reset_session
53
- #controller.instance_variable_set(:@_current_user, nil)
54
- end
55
-
56
- Given /^(?:I am|I have|I) signed in (?:with|as) "(.*)\/(.*)"$/ do |email, password|
57
- Given %{I am signed up as "#{email}/#{password}"}
58
- And %{I sign in as "#{email}/#{password}"}
47
+ Given /^(?:I am|I have|I) signed in (?:with|as) "(.*)"$/ do |email|
48
+ Given %{I am signed up as "#{email}"}
49
+ And %{I sign in as "#{email}"}
59
50
  end
60
51
 
61
52
  Given /^I sign in$/ do
62
53
  email = Factory.next(:email)
63
- Given %{I have signed in with "#{email}/password"}
54
+ Given %{I have signed in with "#{email}"}
64
55
  end
65
56
 
66
57
  # Emails
@@ -90,10 +81,10 @@ end
90
81
 
91
82
  # Actions
92
83
 
93
- When /^I sign in (?:with|as) "(.*)\/(.*)"$/ do |email, password|
84
+ When /^I sign in (?:with|as) "(.*)"$/ do |email|
94
85
  When %{I go to the sign in page}
95
86
  And %{I fill in "Email" with "#{email}"}
96
- And %{I fill in "Password" with "#{password}"}
87
+ And %{I fill in "Password" with "password"}
97
88
  And %{I press "Sign in"}
98
89
  end
99
90
 
@@ -1,21 +1,46 @@
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.
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
6
20
 
7
21
 
8
22
  require 'uri'
9
23
  require 'cgi'
10
24
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
11
26
 
12
27
  module WithinHelpers
13
28
  def with_scope(locator)
14
- locator ? within(locator) { yield } : yield
29
+ locator ? within(*selector_for(locator)) { yield } : yield
15
30
  end
16
31
  end
17
32
  World(WithinHelpers)
18
33
 
34
+ # Single-line step scoper
35
+ When /^(.*) within ([^:]+)$/ do |step, parent|
36
+ with_scope(parent) { When step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { When "#{step}:", table_or_string }
42
+ end
43
+
19
44
  Given /^(?:|I )am on (.+)$/ do |page_name|
20
45
  visit path_to(page_name)
21
46
  end
@@ -24,28 +49,20 @@ When /^(?:|I )go to (.+)$/ do |page_name|
24
49
  visit path_to(page_name)
25
50
  end
26
51
 
27
- When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
28
- with_scope(selector) do
29
- click_button(button)
30
- end
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
31
54
  end
32
55
 
33
- When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
34
- with_scope(selector) do
35
- click_link(link)
36
- end
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
37
58
  end
38
59
 
39
- When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
40
- with_scope(selector) do
41
- fill_in(field, :with => value)
42
- end
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
43
62
  end
44
63
 
45
- When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
46
- with_scope(selector) do
47
- fill_in(field, :with => value)
48
- end
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
49
66
  end
50
67
 
51
68
  # Use this to fill in an entire form with data from a table. Example:
@@ -59,95 +76,70 @@ end
59
76
  # TODO: Add support for checkbox, select og option
60
77
  # based on naming conventions.
61
78
  #
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)
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ When %{I fill in "#{name}" with "#{value}"}
73
82
  end
74
83
  end
75
84
 
76
- When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
77
- with_scope(selector) do
78
- check(field)
79
- end
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
80
87
  end
81
88
 
82
- When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
83
- with_scope(selector) do
84
- uncheck(field)
85
- end
89
+ When /^(?:|I )check "([^"]*)"$/ do |field|
90
+ check(field)
86
91
  end
87
92
 
88
- When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
89
- with_scope(selector) do
90
- choose(field)
91
- end
93
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
+ uncheck(field)
92
95
  end
93
96
 
94
- When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
95
- with_scope(selector) do
96
- attach_file(field, path)
97
- end
97
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
98
+ choose(field)
98
99
  end
99
100
 
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
101
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
+ attach_file(field, File.expand_path(path))
105
103
  end
106
104
 
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
105
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
+ if page.respond_to? :should
107
+ page.should have_content(text)
108
+ else
109
+ assert page.has_content?(text)
114
110
  end
115
111
  end
116
112
 
117
- Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
113
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
118
114
  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
115
+
116
+ if page.respond_to? :should
117
+ page.should have_xpath('//*', :text => regexp)
118
+ else
119
+ assert page.has_xpath?('//*', :text => regexp)
125
120
  end
126
121
  end
127
122
 
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
123
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
+ if page.respond_to? :should
125
+ page.should have_no_content(text)
126
+ else
127
+ assert page.has_no_content?(text)
135
128
  end
136
129
  end
137
130
 
138
- Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
131
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
139
132
  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
133
+
134
+ if page.respond_to? :should
135
+ page.should have_no_xpath('//*', :text => regexp)
136
+ else
137
+ assert page.has_no_xpath?('//*', :text => regexp)
146
138
  end
147
139
  end
148
140
 
149
- Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
150
- with_scope(selector) do
141
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
+ with_scope(parent) do
151
143
  field = find_field(field)
152
144
  field_value = (field.tag_name == 'textarea') ? field.text : field.value
153
145
  if field_value.respond_to? :should
@@ -158,8 +150,8 @@ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |
158
150
  end
159
151
  end
160
152
 
161
- Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
162
- with_scope(selector) do
153
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
154
+ with_scope(parent) do
163
155
  field = find_field(field)
164
156
  field_value = (field.tag_name == 'textarea') ? field.text : field.value
165
157
  if field_value.respond_to? :should_not
@@ -170,8 +162,8 @@ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/
170
162
  end
171
163
  end
172
164
 
173
- Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
174
- with_scope(selector) do
165
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
166
+ with_scope(parent) do
175
167
  field_checked = find_field(label)['checked']
176
168
  if field_checked.respond_to? :should
177
169
  field_checked.should be_true
@@ -181,8 +173,8 @@ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |labe
181
173
  end
182
174
  end
183
175
 
184
- Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
185
- with_scope(selector) do
176
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
177
+ with_scope(parent) do
186
178
  field_checked = find_field(label)['checked']
187
179
  if field_checked.respond_to? :should
188
180
  field_checked.should be_false