devise_invitable 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/README.rdoc +158 -45
  2. data/app/controllers/devise/invitations_controller.rb +61 -0
  3. data/app/views/devise/invitations/edit.html.erb +14 -0
  4. data/app/views/devise/invitations/new.html.erb +12 -0
  5. data/app/views/devise/mailer/invitation_instructions.html.erb +8 -0
  6. data/config/locales/en.yml +10 -0
  7. data/lib/devise_invitable/controllers/helpers.rb +4 -3
  8. data/lib/devise_invitable/controllers/url_helpers.rb +21 -17
  9. data/lib/devise_invitable/mailer.rb +8 -3
  10. data/lib/devise_invitable/model.rb +92 -38
  11. data/lib/devise_invitable/rails.rb +12 -2
  12. data/lib/devise_invitable/routes.rb +10 -26
  13. data/lib/devise_invitable/schema.rb +28 -3
  14. data/lib/devise_invitable/version.rb +3 -0
  15. data/lib/devise_invitable.rb +40 -12
  16. data/lib/generators/active_record/devise_invitable_generator.rb +13 -0
  17. data/lib/generators/active_record/templates/migration.rb +25 -0
  18. data/lib/generators/devise_invitable/devise_invitable_generator.rb +20 -0
  19. data/lib/generators/devise_invitable/install_generator.rb +49 -0
  20. data/lib/generators/devise_invitable/views_generator.rb +10 -0
  21. data/lib/generators/mongoid/devise_invitable_generator.rb +8 -0
  22. metadata +64 -95
  23. data/.document +0 -5
  24. data/.gitignore +0 -22
  25. data/Rakefile +0 -54
  26. data/VERSION +0 -1
  27. data/app/controllers/invitations_controller.rb +0 -44
  28. data/app/views/devise_mailer/invitation.html.erb +0 -8
  29. data/app/views/invitations/edit.html.erb +0 -14
  30. data/app/views/invitations/new.html.erb +0 -12
  31. data/devise_invitable.gemspec +0 -123
  32. data/init.rb +0 -1
  33. data/lib/devise_invitable/locales/en.yml +0 -5
  34. data/test/integration/invitable_test.rb +0 -122
  35. data/test/integration_tests_helper.rb +0 -39
  36. data/test/mailers/invitation_test.rb +0 -62
  37. data/test/model_tests_helper.rb +0 -41
  38. data/test/models/invitable_test.rb +0 -172
  39. data/test/models_test.rb +0 -35
  40. data/test/rails_app/app/controllers/admins_controller.rb +0 -6
  41. data/test/rails_app/app/controllers/application_controller.rb +0 -10
  42. data/test/rails_app/app/controllers/home_controller.rb +0 -4
  43. data/test/rails_app/app/controllers/users_controller.rb +0 -12
  44. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  45. data/test/rails_app/app/models/user.rb +0 -4
  46. data/test/rails_app/app/views/home/index.html.erb +0 -0
  47. data/test/rails_app/config/boot.rb +0 -110
  48. data/test/rails_app/config/database.yml +0 -22
  49. data/test/rails_app/config/environment.rb +0 -44
  50. data/test/rails_app/config/environments/development.rb +0 -17
  51. data/test/rails_app/config/environments/production.rb +0 -28
  52. data/test/rails_app/config/environments/test.rb +0 -28
  53. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  54. data/test/rails_app/config/initializers/devise.rb +0 -105
  55. data/test/rails_app/config/initializers/inflections.rb +0 -2
  56. data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -21
  57. data/test/rails_app/config/initializers/session_store.rb +0 -15
  58. data/test/rails_app/config/routes.rb +0 -3
  59. data/test/rails_app/vendor/plugins/devise_invitable/init.rb +0 -1
  60. data/test/routes_test.rb +0 -20
  61. data/test/test_helper.rb +0 -58
@@ -1,12 +0,0 @@
1
- <h2>Send invitation</h2>
2
-
3
- <% form_for resource_name, resource, :url => invitation_path(resource_name) do |f| %>
4
- <%= f.error_messages %>
5
-
6
- <p><%= f.label :email %></p>
7
- <p><%= f.text_field :email %></p>
8
-
9
- <p><%= f.submit "Send an invitation" %></p>
10
- <% end %>
11
-
12
- <%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
@@ -1,123 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{devise_invitable}
8
- s.version = "0.3.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sergio Cambra"]
12
- s.date = %q{2010-05-17}
13
- s.description = %q{It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password}
14
- s.email = %q{sergio@entrecables.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "app/controllers/invitations_controller.rb",
27
- "app/views/devise_mailer/invitation.html.erb",
28
- "app/views/invitations/edit.html.erb",
29
- "app/views/invitations/new.html.erb",
30
- "devise_invitable.gemspec",
31
- "init.rb",
32
- "lib/devise_invitable.rb",
33
- "lib/devise_invitable/controllers/helpers.rb",
34
- "lib/devise_invitable/controllers/url_helpers.rb",
35
- "lib/devise_invitable/locales/en.yml",
36
- "lib/devise_invitable/mailer.rb",
37
- "lib/devise_invitable/model.rb",
38
- "lib/devise_invitable/rails.rb",
39
- "lib/devise_invitable/routes.rb",
40
- "lib/devise_invitable/schema.rb",
41
- "test/integration/invitable_test.rb",
42
- "test/integration_tests_helper.rb",
43
- "test/mailers/invitation_test.rb",
44
- "test/model_tests_helper.rb",
45
- "test/models/invitable_test.rb",
46
- "test/models_test.rb",
47
- "test/rails_app/app/controllers/admins_controller.rb",
48
- "test/rails_app/app/controllers/application_controller.rb",
49
- "test/rails_app/app/controllers/home_controller.rb",
50
- "test/rails_app/app/controllers/users_controller.rb",
51
- "test/rails_app/app/helpers/application_helper.rb",
52
- "test/rails_app/app/models/user.rb",
53
- "test/rails_app/app/views/home/index.html.erb",
54
- "test/rails_app/config/boot.rb",
55
- "test/rails_app/config/database.yml",
56
- "test/rails_app/config/environment.rb",
57
- "test/rails_app/config/environments/development.rb",
58
- "test/rails_app/config/environments/production.rb",
59
- "test/rails_app/config/environments/test.rb",
60
- "test/rails_app/config/initializers/backtrace_silencers.rb",
61
- "test/rails_app/config/initializers/devise.rb",
62
- "test/rails_app/config/initializers/inflections.rb",
63
- "test/rails_app/config/initializers/new_rails_defaults.rb",
64
- "test/rails_app/config/initializers/session_store.rb",
65
- "test/rails_app/config/routes.rb",
66
- "test/rails_app/vendor/plugins/devise_invitable/init.rb",
67
- "test/routes_test.rb",
68
- "test/test_helper.rb"
69
- ]
70
- s.homepage = %q{http://github.com/scambra/devise_invitable}
71
- s.rdoc_options = ["--charset=UTF-8"]
72
- s.require_paths = ["lib"]
73
- s.rubygems_version = %q{1.3.6}
74
- s.summary = %q{An invitation strategy for devise}
75
- s.test_files = [
76
- "test/integration/invitable_test.rb",
77
- "test/integration_tests_helper.rb",
78
- "test/mailers/invitation_test.rb",
79
- "test/model_tests_helper.rb",
80
- "test/models/invitable_test.rb",
81
- "test/models_test.rb",
82
- "test/rails_app/app/controllers/admins_controller.rb",
83
- "test/rails_app/app/controllers/application_controller.rb",
84
- "test/rails_app/app/controllers/home_controller.rb",
85
- "test/rails_app/app/controllers/users_controller.rb",
86
- "test/rails_app/app/helpers/application_helper.rb",
87
- "test/rails_app/app/models/user.rb",
88
- "test/rails_app/config/boot.rb",
89
- "test/rails_app/config/environment.rb",
90
- "test/rails_app/config/environments/development.rb",
91
- "test/rails_app/config/environments/production.rb",
92
- "test/rails_app/config/environments/test.rb",
93
- "test/rails_app/config/initializers/backtrace_silencers.rb",
94
- "test/rails_app/config/initializers/inflections.rb",
95
- "test/rails_app/config/initializers/new_rails_defaults.rb",
96
- "test/rails_app/config/initializers/session_store.rb",
97
- "test/rails_app/config/initializers/devise.rb",
98
- "test/rails_app/config/routes.rb",
99
- "test/rails_app/vendor/plugins/devise_invitable/init.rb",
100
- "test/routes_test.rb",
101
- "test/test_helper.rb"
102
- ]
103
-
104
- if s.respond_to? :specification_version then
105
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
106
- s.specification_version = 3
107
-
108
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
109
- s.add_development_dependency(%q<mocha>, [">= 0"])
110
- s.add_development_dependency(%q<webrat>, [">= 0"])
111
- s.add_runtime_dependency(%q<devise>, ["~> 1.1.0"])
112
- else
113
- s.add_dependency(%q<mocha>, [">= 0"])
114
- s.add_dependency(%q<webrat>, [">= 0"])
115
- s.add_dependency(%q<devise>, ["~> 1.1.0"])
116
- end
117
- else
118
- s.add_dependency(%q<mocha>, [">= 0"])
119
- s.add_dependency(%q<webrat>, [">= 0"])
120
- s.add_dependency(%q<devise>, ["~> 1.1.0"])
121
- end
122
- end
123
-
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'devise_invitable'
@@ -1,5 +0,0 @@
1
- en:
2
- devise:
3
- invitations:
4
- send_instructions: 'An email with instructions about how to set the password has been sent.'
5
- updated: 'Your password was set successfully. You are now signed in.'
@@ -1,122 +0,0 @@
1
- require 'test/test_helper'
2
- require 'test/integration_tests_helper'
3
-
4
- class InvitationTest < ActionController::IntegrationTest
5
-
6
- def send_invitation(&block)
7
- visit new_user_invitation_path
8
-
9
- assert_response :success
10
- assert_template 'invitations/new'
11
- assert warden.authenticated?(:user)
12
-
13
- fill_in 'email', :with => 'user@test.com'
14
- yield if block_given?
15
- click_button 'Send an invitation'
16
- end
17
-
18
- def set_password(options={}, &block)
19
- unless options[:visit] == false
20
- visit accept_user_invitation_path(:invitation_token => options[:invitation_token])
21
- end
22
- assert_response :success
23
- assert_template 'invitations/edit'
24
-
25
- fill_in 'Password', :with => '987654321'
26
- fill_in 'Password confirmation', :with => '987654321'
27
- yield if block_given?
28
- click_button 'Set my password'
29
- end
30
-
31
- test 'not authenticated user should not be able to send an invitation' do
32
- get new_user_invitation_path
33
- assert_not warden.authenticated?(:user)
34
-
35
- assert_redirected_to new_user_session_path(:unauthenticated => true)
36
- end
37
-
38
- test 'authenticated user should be able to send an invitation' do
39
- sign_in_as_user
40
-
41
- send_invitation
42
- assert_template 'home/index'
43
- assert_equal 'An email with instructions about how to set the password has been sent.', flash[:notice]
44
- end
45
-
46
- test 'authenticated user with invalid email should receive an error message' do
47
- user = create_user
48
- sign_in_as_user
49
- send_invitation do
50
- fill_in 'email', :with => user.email
51
- end
52
-
53
- assert_response :success
54
- assert_template 'invitations/new'
55
- assert_have_selector "input[type=text][value='#{user.email}']"
56
- assert_contain 'Email has already been taken'
57
- end
58
-
59
- test 'authenticated user should not be able to visit edit invitation page' do
60
- sign_in_as_user
61
-
62
- get accept_user_invitation_path
63
-
64
- assert_response :redirect
65
- assert_redirected_to root_path
66
- assert warden.authenticated?(:user)
67
- end
68
-
69
- test 'not authenticated user with invalid invitation token should not be able to set his password' do
70
- user = create_user
71
- set_password :invitation_token => 'invalid_token'
72
-
73
- assert_response :success
74
- assert_template 'invitations/edit'
75
- assert_have_selector '#errorExplanation'
76
- assert_contain 'Invitation token is invalid'
77
- assert_not user.reload.valid_password?('987654321')
78
- end
79
-
80
- test 'not authenticated user with valid invitation token but invalid password should not be able to set his password' do
81
- user = create_user(false)
82
- set_password :invitation_token => user.invitation_token do
83
- fill_in 'Password confirmation', :with => 'other_password'
84
- end
85
-
86
- assert_response :success
87
- assert_template 'invitations/edit'
88
- assert_have_selector '#errorExplanation'
89
- assert_contain 'Password doesn\'t match confirmation'
90
- assert_not user.reload.valid_password?('987654321')
91
- end
92
-
93
- test 'not authenticated user with valid data should be able to change his password' do
94
- user = create_user(false)
95
- set_password :invitation_token => user.invitation_token
96
-
97
- assert_template 'home/index'
98
- assert_equal 'Your password was set successfully. You are now signed in.', flash[:notice]
99
- assert user.reload.valid_password?('987654321')
100
- end
101
-
102
- test 'after entering invalid data user should still be able to set his password' do
103
- user = create_user(false)
104
- set_password :invitation_token => user.invitation_token do
105
- fill_in 'Password confirmation', :with => 'other_password'
106
- end
107
- assert_response :success
108
- assert_have_selector '#errorExplanation'
109
- assert_not user.reload.valid_password?('987654321')
110
-
111
- set_password :invitation_token => user.invitation_token
112
- assert_equal 'Your password was set successfully. You are now signed in.', flash[:notice]
113
- assert user.reload.valid_password?('987654321')
114
- end
115
-
116
- test 'sign in user automatically after setting it\'s password' do
117
- user = create_user(false)
118
- set_password :invitation_token => user.invitation_token
119
-
120
- assert warden.authenticated?(:user)
121
- end
122
- end
@@ -1,39 +0,0 @@
1
- class ActionController::IntegrationTest
2
-
3
- def warden
4
- request.env['warden']
5
- end
6
-
7
- def sign_in_as_user
8
- Warden::Proxy.any_instance.stubs(:user).at_least_once.returns(User.new)
9
- end
10
-
11
- def create_user(accept_invitation = true)
12
- user = User.new :email => 'newuser@test.com'
13
- user.skip_confirmation!
14
- user.invitation_token = 'token'
15
- user.invitation_sent_at = Time.now.utc
16
- user.save(false)
17
- user.accept_invitation! if accept_invitation
18
- user
19
- end
20
-
21
- # Fix assert_redirect_to in integration sessions because they don't take into
22
- # account Middleware redirects.
23
- #
24
- def assert_redirected_to(url)
25
- assert [301, 302].include?(@integration_session.status),
26
- "Expected status to be 301 or 302, got #{@integration_session.status}"
27
-
28
- url = prepend_host(url)
29
- location = prepend_host(@integration_session.headers["Location"])
30
- assert_equal url, location
31
- end
32
-
33
- protected
34
-
35
- def prepend_host(url)
36
- url = "http://#{request.host}#{url}" if url[0] == ?/
37
- url
38
- end
39
- end
@@ -1,62 +0,0 @@
1
- require 'test/test_helper'
2
-
3
- class InvitationMailTest < ActionMailer::TestCase
4
-
5
- def setup
6
- setup_mailer
7
- Devise.mailer_sender = 'test@example.com'
8
- end
9
-
10
- def user
11
- @user ||= begin
12
- user = create_user_with_invitation('token')
13
- user.send_invitation
14
- user
15
- end
16
- end
17
-
18
- def mail
19
- @mail ||= begin
20
- user
21
- ActionMailer::Base.deliveries.last
22
- end
23
- end
24
-
25
- test 'email sent after reseting the user password' do
26
- assert_not_nil mail
27
- end
28
-
29
- test 'content type should be set to html' do
30
- assert_equal 'text/html', mail.content_type
31
- end
32
-
33
- test 'send invitation to the user email' do
34
- assert_equal [user.email], mail.to
35
- end
36
-
37
- test 'setup sender from configuration' do
38
- assert_equal ['test@example.com'], mail.from
39
- end
40
-
41
- test 'setup subject from I18n' do
42
- store_translations :en, :devise => { :mailer => { :invitation => 'Invitation' } } do
43
- assert_equal 'Invitation', mail.subject
44
- end
45
- end
46
-
47
- test 'subject namespaced by model' do
48
- store_translations :en, :devise => { :mailer => { :user => { :invitation => 'User Invitation' } } } do
49
- assert_equal 'User Invitation', mail.subject
50
- end
51
- end
52
-
53
- test 'body should have user info' do
54
- assert_match /#{user.email}/, mail.body
55
- end
56
-
57
- test 'body should have link to confirm the account' do
58
- host = ActionMailer::Base.default_url_options[:host]
59
- invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/accept\?invitation_token=#{user.invitation_token}">}
60
- assert_match invitation_url_regexp, mail.body
61
- end
62
- end
@@ -1,41 +0,0 @@
1
- class ActiveSupport::TestCase
2
- def setup_mailer
3
- ActionMailer::Base.deliveries = []
4
- end
5
-
6
- def store_translations(locale, translations, &block)
7
- begin
8
- I18n.backend.store_translations locale, translations
9
- yield
10
- ensure
11
- I18n.reload!
12
- end
13
- end
14
-
15
- # Helpers for creating new users
16
- #
17
- def generate_unique_email
18
- @@email_count ||= 0
19
- @@email_count += 1
20
- "test#{@@email_count}@email.com"
21
- end
22
-
23
- def valid_attributes(attributes={})
24
- { :email => generate_unique_email,
25
- :password => '123456',
26
- :password_confirmation => '123456' }.update(attributes)
27
- end
28
-
29
- def new_user(attributes={})
30
- User.new(valid_attributes(attributes))
31
- end
32
-
33
- def create_user_with_invitation(invitation_token, attributes={})
34
- user = new_user({:password => nil, :password_confirmation => nil}.update(attributes))
35
- user.skip_confirmation!
36
- user.invitation_token = invitation_token
37
- user.invitation_sent_at = Time.now.utc
38
- user.save(false)
39
- user
40
- end
41
- end
@@ -1,172 +0,0 @@
1
- require 'test/test_helper'
2
- require 'test/model_tests_helper'
3
-
4
- class InvitableTest < ActiveSupport::TestCase
5
-
6
- def setup
7
- setup_mailer
8
- end
9
-
10
- test 'should not generate invitation token after creating a record' do
11
- assert_nil new_user.invitation_token
12
- end
13
-
14
- test 'should regenerate invitation token each time' do
15
- user = new_user
16
- 3.times do
17
- token = user.invitation_token
18
- user.resend_invitation!
19
- assert_not_equal token, user.invitation_token
20
- end
21
- end
22
-
23
- test 'should test invitation sent at with invite_for configuration value' do
24
- user = create_user_with_invitation('')
25
-
26
- User.stubs(:invite_for).returns(nil)
27
- user.invitation_sent_at = Time.now.utc
28
- assert user.valid_invitation?
29
-
30
- User.stubs(:invite_for).returns(nil)
31
- user.invitation_sent_at = 1.year.ago
32
- assert user.valid_invitation?
33
-
34
- User.stubs(:invite_for).returns(0)
35
- user.invitation_sent_at = Time.now.utc
36
- assert user.valid_invitation?
37
-
38
- User.stubs(:invite_for).returns(0)
39
- user.invitation_sent_at = 1.day.ago
40
- assert user.valid_invitation?
41
-
42
- User.stubs(:invite_for).returns(1.day)
43
- user.invitation_sent_at = Time.now.utc
44
- assert user.valid_invitation?
45
-
46
- User.stubs(:invite_for).returns(1.day)
47
- user.invitation_sent_at = 1.day.ago
48
- assert_not user.valid_invitation?
49
- end
50
-
51
- test 'should never generate the same invitation token for different users' do
52
- invitation_tokens = []
53
- 3.times do
54
- user = new_user
55
- user.resend_invitation!
56
- token = user.invitation_token
57
- assert !invitation_tokens.include?(token)
58
- invitation_tokens << token
59
- end
60
- end
61
-
62
- test 'should set password and password confirmation from params' do
63
- create_user_with_invitation('valid_token', :password => nil, :password_confirmation => nil)
64
- user = User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '123456789')
65
- assert user.valid_password?('123456789')
66
- end
67
-
68
- test 'should set password and save the record' do
69
- user = create_user_with_invitation('valid_token', :password => nil, :password_confirmation => nil)
70
- old_encrypted_password = user.encrypted_password
71
- user = User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '123456789')
72
- assert_not_equal old_encrypted_password, user.encrypted_password
73
- end
74
-
75
- test 'should clear invitation token while setting the password' do
76
- user = new_user
77
- user.skip_confirmation!
78
- user.update_attribute(:invitation_token, 'valid_token')
79
- assert_present user.invitation_token
80
- assert user.accept_invitation!
81
- assert_nil user.invitation_token
82
- end
83
-
84
- test 'should not clear invitation token if record is invalid' do
85
- user = new_user
86
- user.skip_confirmation!
87
- user.update_attribute(:invitation_token, 'valid_token')
88
- assert_present user.invitation_token
89
- User.any_instance.stubs(:valid?).returns(false)
90
- User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '987654321')
91
- user.reload
92
- assert_present user.invitation_token
93
- end
94
-
95
- test 'should reset invitation token and send invitation by email' do
96
- user = new_user
97
- assert_difference('ActionMailer::Base.deliveries.size') do
98
- token = user.invitation_token
99
- user.resend_invitation!
100
- assert_not_equal token, user.invitation_token
101
- end
102
- end
103
-
104
- test 'should return a record with invitation token and no errors to send invitation by email' do
105
- invited_user = User.send_invitation(:email => "valid@email.com")
106
- assert invited_user.errors.blank?
107
- assert_present invited_user.invitation_token
108
- end
109
-
110
- test 'should return a record with errors if user was found by e-mail' do
111
- user = create_user_with_invitation('')
112
- user.update_attribute(:invitation_token, nil)
113
- invited_user = User.send_invitation(:email => user.email)
114
- assert_equal invited_user, user
115
- assert_equal 'has already been taken', invited_user.errors[:email]
116
- end
117
-
118
- test 'should return a new record with errors if e-mail is blank' do
119
- invited_user = User.send_invitation(:email => '')
120
- assert invited_user.new_record?
121
- assert_equal ["can't be blank", "is invalid"], invited_user.errors[:email]
122
- end
123
-
124
- test 'should return a new record with errors if e-mail is invalid' do
125
- invited_user = User.send_invitation(:email => 'invalid_email')
126
- assert invited_user.new_record?
127
- assert_equal "is invalid", invited_user.errors[:email]
128
- end
129
-
130
- test 'should find a user to set his password based on invitation_token' do
131
- user = new_user
132
- user.resend_invitation!
133
-
134
- invited_user = User.accept_invitation!(:invitation_token => user.invitation_token)
135
- assert_equal invited_user, user
136
- end
137
-
138
- test 'should return a new record with errors if no invitation_token is found' do
139
- invited_user = User.accept_invitation!(:invitation_token => 'invalid_token')
140
- assert invited_user.new_record?
141
- assert_equal 'is invalid', invited_user.errors[:invitation_token]
142
- end
143
-
144
- test 'should return a new record with errors if invitation_token is blank' do
145
- invited_user = User.accept_invitation!(:invitation_token => '')
146
- assert invited_user.new_record?
147
- assert_equal "can't be blank", invited_user.errors[:invitation_token]
148
- end
149
-
150
- test 'should return record with errors if invitation_token has expired' do
151
- user = create_user_with_invitation('valid_token')
152
- user.update_attribute(:invitation_sent_at, 1.day.ago)
153
- User.stubs(:invite_for).returns(10.hours)
154
- invited_user = User.accept_invitation!(:invitation_token => 'valid_token')
155
- assert_equal user, invited_user
156
- assert_equal "is invalid", invited_user.errors[:invitation_token]
157
- end
158
-
159
- test 'should set successfully user password given the new password and confirmation' do
160
- user = new_user(:password => nil, :password_confirmation => nil)
161
- user.resend_invitation!
162
-
163
- invited_user = User.accept_invitation!(
164
- :invitation_token => user.invitation_token,
165
- :password => 'new_password',
166
- :password_confirmation => 'new_password'
167
- )
168
- user.reload
169
-
170
- assert user.valid_password?('new_password')
171
- end
172
- end
data/test/models_test.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'test/test_helper'
2
-
3
- class Invitable < User
4
- devise :database_authenticatable, :invitable, :invite_for => 5.days
5
- end
6
-
7
- class ActiveRecordTest < ActiveSupport::TestCase
8
- def include_module?(klass, mod)
9
- klass.devise_modules.include?(mod) &&
10
- klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
11
- end
12
-
13
- def assert_include_modules(klass, *modules)
14
- modules.each do |mod|
15
- assert include_module?(klass, mod), "#{klass} not include #{mod}"
16
- end
17
-
18
- (Devise::ALL - modules).each do |mod|
19
- assert_not include_module?(klass, mod), "#{klass} include #{mod}"
20
- end
21
- end
22
-
23
- test 'add invitable module only' do
24
- assert_include_modules Invitable, :database_authenticatable, :invitable
25
- end
26
-
27
- test 'set a default value for invite_for' do
28
- assert_equal 5.days, Invitable.invite_for
29
- end
30
-
31
- test 'invitable attributes' do
32
- assert_not_nil Invitable.columns_hash['invitation_token']
33
- assert_not_nil Invitable.columns_hash['invitation_sent_at']
34
- end
35
- end
@@ -1,6 +0,0 @@
1
- class AdminsController < ApplicationController
2
- before_filter :authenticate_admin!
3
-
4
- def index
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- # Filters added to this controller apply to all controllers in the application.
2
- # Likewise, all the methods added will be available for all controllers.
3
-
4
- class ApplicationController < ActionController::Base
5
- helper :all # include all helpers, all the time
6
- protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
-
8
- # Scrub sensitive parameters from your log
9
- filter_parameter_logging :password
10
- end
@@ -1,4 +0,0 @@
1
- class HomeController < ApplicationController
2
- def index
3
- end
4
- end
@@ -1,12 +0,0 @@
1
- class UsersController < ApplicationController
2
- before_filter :authenticate_user!
3
-
4
- def index
5
- user_session[:cart] = "Cart"
6
- end
7
-
8
- def expire
9
- user_session['last_request_at'] = 31.minutes.ago.utc
10
- render :text => 'User will be expired on next request'
11
- end
12
- end
@@ -1,3 +0,0 @@
1
- # Methods added to this helper will be available to all templates in the application.
2
- module ApplicationHelper
3
- end
@@ -1,4 +0,0 @@
1
- class User < ActiveRecord::Base
2
- devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :validatable
3
- attr_accessible :username, :email, :password, :password_confirmation
4
- end
File without changes