thoughtbot-clearance 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile ADDED
@@ -0,0 +1,4 @@
1
+ h2. 0.4.4 (2/2/2009)
2
+
3
+ * Added a generator for Cucumber features
4
+ * Standarized naming for "Sign up," "Sign in," and "Sign out"
data/Rakefile CHANGED
@@ -1,41 +1,56 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'cucumber/rake/task'
3
4
 
4
5
  test_files_pattern = 'test/rails_root/test/{unit,functional,other}/**/*_test.rb'
6
+
5
7
  namespace :test do
6
8
  Rake::TestTask.new(:all => ['generator:cleanup', 'generator:generate']) do |task|
7
9
  task.libs << 'lib'
8
10
  task.pattern = test_files_pattern
9
11
  task.verbose = false
10
12
  end
13
+
14
+ Cucumber::Rake::Task.new(:features) do |t|
15
+ t.cucumber_opts = "--format progress"
16
+ t.feature_pattern = 'test/rails_root/features/*.feature'
17
+ end
11
18
  end
12
19
 
20
+ generators = %w(clearance clearance_features)
21
+
13
22
  namespace :generator do
14
23
  desc "Cleans up the test app before running the generator"
15
24
  task :cleanup do
16
- FileList["generators/clearance/templates/**/*.*"].each do |each|
17
- file = "test/rails_root/#{each.gsub("generators/clearance/templates/",'')}"
18
- File.delete(file) if File.exists?(file)
25
+ generators.each do |generator|
26
+ FileList["generators/#{generator}/templates/**/*.*"].each do |each|
27
+ file = "test/rails_root/#{each.gsub("generators/#{generator}/templates/",'')}"
28
+ File.delete(file) if File.exists?(file)
29
+ end
19
30
  end
20
31
 
21
- FileUtils.rm_rf("test/rails_root/db/migrate")
32
+ FileList["test/rails_root/db/**/*"].each do |each|
33
+ FileUtils.rm_rf(each)
34
+ end
22
35
  FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
23
36
  system "mkdir -p test/rails_root/vendor/plugins/clearance"
24
37
  system "cp -R generators test/rails_root/vendor/plugins/clearance"
25
38
  end
26
-
39
+
27
40
  desc "Run the generator on the tests"
28
41
  task :generate do
29
- system "cd test/rails_root && ./script/generate clearance"
42
+ generators.each do |generator|
43
+ system "cd test/rails_root && ./script/generate #{generator}"
44
+ end
30
45
  end
31
46
  end
32
47
 
33
48
  desc "Run the test suite"
34
- task :default => 'test:all'
49
+ task :default => ['test:all', 'test:features']
35
50
 
36
51
  gem_spec = Gem::Specification.new do |gem_spec|
37
52
  gem_spec.name = "clearance"
38
- gem_spec.version = "0.4.3"
53
+ gem_spec.version = "0.4.4"
39
54
  gem_spec.summary = "Rails authentication for developers who write tests."
40
55
  gem_spec.email = "support@thoughtbot.com"
41
56
  gem_spec.homepage = "http://github.com/thoughtbot/clearance"
@@ -36,9 +36,9 @@ The constant is used by mailers to generate URLs in emails.
36
36
  In config/environment.rb:
37
37
 
38
38
  DO_NOT_REPLY = "donotreply@example.com"
39
-
39
+
40
40
  3. Clearance depends on root_url, so please make sure that it is defined to
41
- *something* your config/routes.rb:
41
+ *something* in your config/routes.rb:
42
42
 
43
43
  map.root :controller => 'home'
44
44
 
@@ -51,4 +51,4 @@ test/test_helper.rb:
51
51
  include Clearance::Test::TestHelper
52
52
  end
53
53
 
54
- *******************************************************************************
54
+ *******************************************************************************
@@ -2,7 +2,7 @@ Factory.sequence :email do |n|
2
2
  "user#{n}@example.com"
3
3
  end
4
4
 
5
- Factory.define :registered_user, :class => 'user' do |user|
5
+ Factory.define :user do |user|
6
6
  user.email { Factory.next :email }
7
7
  user.password { "password" }
8
8
  user.password_confirmation { "password" }
@@ -0,0 +1 @@
1
+ script/generate clearance_stories
@@ -0,0 +1,16 @@
1
+ class ClearanceFeaturesGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.directory File.join("features", "step_definitions")
6
+
7
+ ["features/step_definitions/clearance_steps.rb",
8
+ "features/sign_in.feature",
9
+ "features/sign_out.feature",
10
+ "features/sign_up.feature"].each do |file|
11
+ m.file file, file
12
+ end
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,32 @@
1
+ Fature: Password Reset
2
+ In order to sign in even if he forgot his password
3
+ A user
4
+ Should be able to reset it
5
+
6
+ Scenario: User is not registered
7
+ Given there is no user with "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 requests password reset
12
+ Given I am signed up and confirmed as "email@person.com/password"
13
+ When I request password reset link to be sent to "email@person.com"
14
+ Then I should see "Details for changing your password have been sent to email@person.com"
15
+ And a password reset message should be sent to "email@person.com"
16
+
17
+ Scenario: User updated his password and types wrong confirmation
18
+ Given I am signed up and confirmed as "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 error messages
22
+ And I should not be signed in
23
+
24
+ Scenario: User updates his password
25
+ Given I am signed up and confirmed as "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
+ And I sign in as "email@person.com/newpassword"
31
+ Then I should be signed in
32
+
@@ -0,0 +1,41 @@
1
+ Feature: Sign in
2
+ In order to get access to protected sections of the site
3
+ A registered user
4
+ Should be able to sign in
5
+
6
+ Scenario User is not registered
7
+ Given there is no user with "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 not be signed in
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 not be signed in
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 not be signed in
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 successfully"
32
+ And I should be signed in
33
+
34
+ Scenario: User signs in and checks "remember me"
35
+ Given I am signed up and confirmed as "email@person.com/password"
36
+ When I go to the sign in page
37
+ And I sign in with "remember me" as "email@person.com/password"
38
+ Then I should see "Signed in successfully"
39
+ And I should be signed in
40
+ When I return next time
41
+ Then I should be signed in
@@ -0,0 +1,22 @@
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 "You have been signed out"
12
+ And I should not be signed in
13
+
14
+ Scenario: User who was remembered signs out
15
+ Given I am signed up and confirmed as "email@person.com/password"
16
+ When I sign in with "remember me" as "email@person.com/password"
17
+ Then I should be signed in
18
+ And I sign out
19
+ Then I should see "You have been signed out"
20
+ And I should not be signed in
21
+ When I return next time
22
+ Then I should not be signed in
@@ -0,0 +1,30 @@
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 "Verify 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 "Verify Password" with "password"
19
+ And I press "Sign Up"
20
+ Then I should see "You will receive an email within the next few minutes"
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
+
30
+
@@ -0,0 +1,103 @@
1
+ # General
2
+
3
+ Then /^I should see error messages$/ do
4
+ Then %{I should see "error(s)? prohibited"}
5
+ end
6
+
7
+ # DB
8
+
9
+ Given /^there is no user with "(.*)"$/ 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_not_nil request.session[:user_id]
31
+ assert_not_nil request.session[:salt]
32
+ end
33
+
34
+ Then /^I should not be signed in$/ do
35
+ assert_nil request.session[:user_id]
36
+ assert_nil request.session[:salt]
37
+ end
38
+
39
+ When /^session is cleared$/ do
40
+ request.session[:user_id] = nil
41
+ request.session[:salt] = nil
42
+ end
43
+
44
+ # Emails
45
+
46
+ Then /^a confirmation message should be sent to "(.*)"$/ do |email|
47
+ user = User.find_by_email(email)
48
+ sent = ActionMailer::Base.deliveries.first
49
+ assert_equal [user.email], sent.to
50
+ assert_equal 'Account confirmation', sent.subject
51
+ assert !user.token.blank?
52
+ assert_match /#{user.token}/, sent.body
53
+ end
54
+
55
+ When /^I follow the confirmation link sent to "(.*)"$/ do |email|
56
+ user = User.find_by_email(email)
57
+ visit new_user_confirmation_path(:user_id => user, :token => user.token)
58
+ end
59
+
60
+ Then /^a password reset message should be sent to "(.*)"$/ do |email|
61
+ user = User.find_by_email(email)
62
+ sent = ActionMailer::Base.deliveries.first
63
+ assert_equal [user.email], sent.to
64
+ assert_equal 'Change your password', sent.subject
65
+ assert !user.token.blank?
66
+ assert_match /#{user.token}/, sent.body
67
+ end
68
+
69
+ When /^I follow the password reset link sent to "(.*)"$/ do |email|
70
+ user = User.find_by_email(email)
71
+ visit edit_user_password_path(:user_id => user, :token => user.token)
72
+ end
73
+
74
+ # Actions
75
+
76
+ When /^I sign in( with "remember me")? as "(.*)\/(.*)"$/ do |remember, email, password|
77
+ When %{I go to the sign in page}
78
+ And %{I fill in "Email" with "#{email}"}
79
+ And %{I fill in "Password" with "#{password}"}
80
+ And %{I check "Remember me"} if remember
81
+ And %{I press "Sign In"}
82
+ end
83
+
84
+ When /^I sign out$/ do
85
+ visit '/session', :delete
86
+ end
87
+
88
+ When /^I request password reset link to be sent to "(.*)"$/ do |email|
89
+ When %{I go to the password reset request page}
90
+ And %{I fill in "Email address" with "#{email}"}
91
+ And %{I press "Reset password"}
92
+ end
93
+
94
+ When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
95
+ And %{I fill in "Choose password" with "#{password}"}
96
+ And %{I fill in "Verify password" with "#{confirmation}"}
97
+ And %{I press "Save this password"}
98
+ end
99
+
100
+ When /^I return next time$/ do
101
+ When %{session is cleared}
102
+ And %{I go to the homepage}
103
+ end
@@ -9,8 +9,8 @@ module Clearance
9
9
  should_filter_params :token
10
10
 
11
11
  context "Given a user whose email has not been confirmed" do
12
- setup { @user = Factory(:registered_user) }
13
-
12
+ setup { @user = Factory(:user) }
13
+
14
14
  context "on GET to #new with correct id and token" do
15
15
  setup do
16
16
  get :new, :user_id => @user.to_param, :token => @user.token
@@ -11,7 +11,7 @@ module Clearance
11
11
 
12
12
  context "with a confirmed user" do
13
13
  setup do
14
- @user = Factory(:registered_user)
14
+ @user = Factory(:user)
15
15
  @user.confirm_email!
16
16
  end
17
17
 
@@ -18,8 +18,8 @@ module Clearance
18
18
  should_display_a_sign_in_form
19
19
  end
20
20
 
21
- context "Given a registered user" do
22
- setup { @user = Factory(:registered_user) }
21
+ context "Given a user" do
22
+ setup { @user = Factory(:user) }
23
23
 
24
24
  context "a POST to #create with good credentials" do
25
25
  setup do
@@ -41,7 +41,7 @@ module Clearance
41
41
 
42
42
  context "Given an email confirmed user" do
43
43
  setup do
44
- @user = Factory(:registered_user)
44
+ @user = Factory(:user)
45
45
  @user.confirm_email!
46
46
  end
47
47
 
@@ -16,7 +16,7 @@ module Clearance
16
16
  should_render_template :new
17
17
  should_not_set_the_flash
18
18
 
19
- should_display_a_registration_form
19
+ should_display_a_sign_up_form
20
20
  end
21
21
 
22
22
  context "Given email parameter when getting new User view" do
@@ -32,7 +32,7 @@ module Clearance
32
32
 
33
33
  context "Given valid attributes when creating a new user" do
34
34
  setup do
35
- user_attributes = Factory.attributes_for(:registered_user)
35
+ user_attributes = Factory.attributes_for(:user)
36
36
  post :create, :user => user_attributes
37
37
  end
38
38
 
@@ -7,7 +7,7 @@ module Clearance
7
7
 
8
8
  def sign_in_as(user = nil)
9
9
  unless user
10
- user = Factory(:registered_user)
10
+ user = Factory(:user)
11
11
  user.confirm_email!
12
12
  end
13
13
  @request.session[:user_id] = user.id
@@ -8,7 +8,7 @@ module Clearance
8
8
 
9
9
  context "A change password email" do
10
10
  setup do
11
- @user = Factory(:registered_user)
11
+ @user = Factory(:user)
12
12
  @email = ClearanceMailer.create_change_password @user
13
13
  end
14
14
 
@@ -33,7 +33,7 @@ module Clearance
33
33
 
34
34
  context "A confirmation email" do
35
35
  setup do
36
- @user = Factory(:registered_user)
36
+ @user = Factory(:user)
37
37
  @email = ClearanceMailer.create_confirmation @user
38
38
  end
39
39
 
@@ -10,24 +10,24 @@ module Clearance
10
10
  :salt, :encrypted_password,
11
11
  :token, :token_expires_at
12
12
 
13
- # registering
13
+ # signing up
14
14
 
15
- context "When registering" do
15
+ context "When signing up" do
16
16
  should_require_attributes :email, :password
17
17
  should_allow_values_for :email, "foo@example.com"
18
18
  should_not_allow_values_for :email, "foo"
19
19
  should_not_allow_values_for :email, "example.com"
20
20
 
21
21
  should_validate_confirmation_of :password,
22
- :factory => :registered_user
22
+ :factory => :user
23
23
 
24
24
  should "initialize salt" do
25
- assert_not_nil Factory(:registered_user).salt
25
+ assert_not_nil Factory(:user).salt
26
26
  end
27
27
 
28
28
  should "initialize token witout expiry date" do
29
- assert_not_nil Factory(:registered_user).token
30
- assert_nil Factory(:registered_user).token_expires_at
29
+ assert_not_nil Factory(:user).token
30
+ assert_nil Factory(:user).token_expires_at
31
31
  end
32
32
 
33
33
  context "encrypt password" do
@@ -35,7 +35,7 @@ module Clearance
35
35
  @salt = "salt"
36
36
  User.any_instance.stubs(:initialize_salt)
37
37
 
38
- @user = Factory(:registered_user, :salt => @salt)
38
+ @user = Factory(:user, :salt => @salt)
39
39
  @password = @user.password
40
40
 
41
41
  @user.encrypt(@password)
@@ -49,22 +49,22 @@ module Clearance
49
49
  end
50
50
 
51
51
  should "store email in lower case" do
52
- user = Factory(:registered_user, :email => "John.Doe@example.com")
52
+ user = Factory(:user, :email => "John.Doe@example.com")
53
53
  assert_equal "john.doe@example.com", user.email
54
54
  end
55
55
  end
56
56
 
57
- context "When multiple users have registerd" do
58
- setup { @user = Factory(:registered_user) }
57
+ context "When multiple users have signed up" do
58
+ setup { @user = Factory(:user) }
59
59
 
60
60
  should_require_unique_attributes :email
61
61
  end
62
62
 
63
63
  # confirming email
64
64
 
65
- context "A registered user without email confirmation" do
65
+ context "A user without email confirmation" do
66
66
  setup do
67
- @user = Factory(:registered_user)
67
+ @user = Factory(:user)
68
68
  assert ! @user.email_confirmed?
69
69
  end
70
70
 
@@ -88,7 +88,7 @@ module Clearance
88
88
 
89
89
  context "A user" do
90
90
  setup do
91
- @user = Factory(:registered_user)
91
+ @user = Factory(:user)
92
92
  @password = @user.password
93
93
  end
94
94
 
@@ -176,7 +176,7 @@ module Clearance
176
176
 
177
177
  context "An email confirmed user" do
178
178
  setup do
179
- @user = Factory(:registered_user)
179
+ @user = Factory(:user)
180
180
  @user.confirm_email!
181
181
  end
182
182
 
@@ -61,7 +61,7 @@ module Clearance
61
61
  def signed_in_user_context(&blk)
62
62
  context "A signed in user" do
63
63
  setup do
64
- @user = Factory(:registered_user)
64
+ @user = Factory(:user)
65
65
  @user.confirm_email!
66
66
  sign_in_as @user
67
67
  end
@@ -184,10 +184,10 @@ module Clearance
184
184
  end
185
185
  end
186
186
 
187
- def should_display_a_registration_form
188
- should "display a form to register" do
187
+ def should_display_a_sign_up_form
188
+ should "display a form to sign up" do
189
189
  assert_select "form[action=#{users_path}][method=post]",
190
- true, "There must be a form to register" do
190
+ true, "There must be a form to sign up" do
191
191
  assert_select "input[type=text][name=?]",
192
192
  "user[email]", true, "There must be an email field"
193
193
  assert_select "input[type=password][name=?]",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2009-01-29 21:00:00 -08:00
18
+ date: 2009-02-01 21:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,6 +28,7 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
+ - CHANGELOG.textile
31
32
  - LICENSE
32
33
  - Rakefile
33
34
  - README.textile
@@ -78,6 +79,17 @@ files:
78
79
  - generators/clearance/templates/test/unit/clearance_mailer_test.rb
79
80
  - generators/clearance/templates/test/unit/user_test.rb
80
81
  - generators/clearance/USAGE
82
+ - generators/clearance_features
83
+ - generators/clearance_features/clearance_features_generator.rb
84
+ - generators/clearance_features/templates
85
+ - generators/clearance_features/templates/features
86
+ - generators/clearance_features/templates/features/password_reset.feature
87
+ - generators/clearance_features/templates/features/sign_in.feature
88
+ - generators/clearance_features/templates/features/sign_out.feature
89
+ - generators/clearance_features/templates/features/sign_up.feature
90
+ - generators/clearance_features/templates/features/step_definitions
91
+ - generators/clearance_features/templates/features/step_definitions/clearance_steps.rb
92
+ - generators/clearance_features/USAGE
81
93
  - lib/clearance
82
94
  - lib/clearance/app
83
95
  - lib/clearance/app/controllers