devise_invitable 0.3.4 → 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.
- data/README.rdoc +63 -42
- data/app/controllers/devise/invitations_controller.rb +23 -6
- data/config/locales/en.yml +5 -3
- data/lib/devise_invitable/controllers/helpers.rb +1 -6
- data/lib/devise_invitable/mailer.rb +8 -2
- data/lib/devise_invitable/model.rb +85 -38
- data/lib/devise_invitable/rails.rb +1 -1
- data/lib/devise_invitable/routes.rb +8 -5
- data/lib/devise_invitable/schema.rb +27 -2
- data/lib/devise_invitable/version.rb +3 -0
- data/lib/devise_invitable.rb +37 -8
- data/lib/generators/active_record/templates/migration.rb +14 -7
- data/lib/generators/devise_invitable/devise_invitable_generator.rb +4 -0
- data/lib/generators/devise_invitable/install_generator.rb +17 -2
- data/lib/generators/mongoid/devise_invitable_generator.rb +8 -0
- metadata +49 -142
- data/.document +0 -5
- data/.gitignore +0 -22
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -108
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/devise_invitable.gemspec +0 -146
- data/test/generators_test.rb +0 -45
- data/test/integration/invitable_test.rb +0 -109
- data/test/integration_tests_helper.rb +0 -58
- data/test/mailers/invitation_test.rb +0 -62
- data/test/model_tests_helper.rb +0 -41
- data/test/models/invitable_test.rb +0 -188
- data/test/models_test.rb +0 -31
- data/test/rails_app/app/controllers/admins_controller.rb +0 -6
- data/test/rails_app/app/controllers/application_controller.rb +0 -3
- data/test/rails_app/app/controllers/home_controller.rb +0 -4
- data/test/rails_app/app/controllers/users_controller.rb +0 -12
- data/test/rails_app/app/helpers/application_helper.rb +0 -2
- data/test/rails_app/app/models/octopussy.rb +0 -11
- data/test/rails_app/app/models/user.rb +0 -4
- data/test/rails_app/app/views/home/index.html.erb +0 -0
- data/test/rails_app/app/views/layouts/application.html.erb +0 -15
- data/test/rails_app/app/views/users/invitations/new.html.erb +0 -15
- data/test/rails_app/config/application.rb +0 -46
- data/test/rails_app/config/boot.rb +0 -13
- data/test/rails_app/config/database.yml +0 -22
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -26
- data/test/rails_app/config/environments/production.rb +0 -49
- data/test/rails_app/config/environments/test.rb +0 -35
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -144
- data/test/rails_app/config/initializers/inflections.rb +0 -10
- data/test/rails_app/config/initializers/mime_types.rb +0 -5
- data/test/rails_app/config/initializers/secret_token.rb +0 -7
- data/test/rails_app/config/initializers/session_store.rb +0 -8
- data/test/rails_app/config/locales/en.yml +0 -5
- data/test/rails_app/config/routes.rb +0 -4
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/script/rails +0 -6
- data/test/routes_test.rb +0 -20
- data/test/test_helper.rb +0 -30
- /data/app/views/devise/mailer/{invitation.html.erb → invitation_instructions.html.erb} +0 -0
data/devise_invitable.gemspec
DELETED
|
@@ -1,146 +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.4"
|
|
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-10-02}
|
|
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
|
-
"Gemfile",
|
|
23
|
-
"Gemfile.lock",
|
|
24
|
-
"LICENSE",
|
|
25
|
-
"README.rdoc",
|
|
26
|
-
"Rakefile",
|
|
27
|
-
"VERSION",
|
|
28
|
-
"app/controllers/devise/invitations_controller.rb",
|
|
29
|
-
"app/views/devise/invitations/edit.html.erb",
|
|
30
|
-
"app/views/devise/invitations/new.html.erb",
|
|
31
|
-
"app/views/devise/mailer/invitation.html.erb",
|
|
32
|
-
"config/locales/en.yml",
|
|
33
|
-
"devise_invitable.gemspec",
|
|
34
|
-
"lib/devise_invitable.rb",
|
|
35
|
-
"lib/devise_invitable/controllers/helpers.rb",
|
|
36
|
-
"lib/devise_invitable/controllers/url_helpers.rb",
|
|
37
|
-
"lib/devise_invitable/mailer.rb",
|
|
38
|
-
"lib/devise_invitable/model.rb",
|
|
39
|
-
"lib/devise_invitable/rails.rb",
|
|
40
|
-
"lib/devise_invitable/routes.rb",
|
|
41
|
-
"lib/devise_invitable/schema.rb",
|
|
42
|
-
"lib/generators/active_record/devise_invitable_generator.rb",
|
|
43
|
-
"lib/generators/active_record/templates/migration.rb",
|
|
44
|
-
"lib/generators/devise_invitable/devise_invitable_generator.rb",
|
|
45
|
-
"lib/generators/devise_invitable/install_generator.rb",
|
|
46
|
-
"lib/generators/devise_invitable/views_generator.rb",
|
|
47
|
-
"test/generators_test.rb",
|
|
48
|
-
"test/integration/invitable_test.rb",
|
|
49
|
-
"test/integration_tests_helper.rb",
|
|
50
|
-
"test/mailers/invitation_test.rb",
|
|
51
|
-
"test/model_tests_helper.rb",
|
|
52
|
-
"test/models/invitable_test.rb",
|
|
53
|
-
"test/models_test.rb",
|
|
54
|
-
"test/rails_app/app/controllers/admins_controller.rb",
|
|
55
|
-
"test/rails_app/app/controllers/application_controller.rb",
|
|
56
|
-
"test/rails_app/app/controllers/home_controller.rb",
|
|
57
|
-
"test/rails_app/app/controllers/users_controller.rb",
|
|
58
|
-
"test/rails_app/app/helpers/application_helper.rb",
|
|
59
|
-
"test/rails_app/app/models/octopussy.rb",
|
|
60
|
-
"test/rails_app/app/models/user.rb",
|
|
61
|
-
"test/rails_app/app/views/home/index.html.erb",
|
|
62
|
-
"test/rails_app/app/views/layouts/application.html.erb",
|
|
63
|
-
"test/rails_app/app/views/users/invitations/new.html.erb",
|
|
64
|
-
"test/rails_app/config.ru",
|
|
65
|
-
"test/rails_app/config/application.rb",
|
|
66
|
-
"test/rails_app/config/boot.rb",
|
|
67
|
-
"test/rails_app/config/database.yml",
|
|
68
|
-
"test/rails_app/config/environment.rb",
|
|
69
|
-
"test/rails_app/config/environments/development.rb",
|
|
70
|
-
"test/rails_app/config/environments/production.rb",
|
|
71
|
-
"test/rails_app/config/environments/test.rb",
|
|
72
|
-
"test/rails_app/config/initializers/backtrace_silencers.rb",
|
|
73
|
-
"test/rails_app/config/initializers/devise.rb",
|
|
74
|
-
"test/rails_app/config/initializers/inflections.rb",
|
|
75
|
-
"test/rails_app/config/initializers/mime_types.rb",
|
|
76
|
-
"test/rails_app/config/initializers/secret_token.rb",
|
|
77
|
-
"test/rails_app/config/initializers/session_store.rb",
|
|
78
|
-
"test/rails_app/config/locales/en.yml",
|
|
79
|
-
"test/rails_app/config/routes.rb",
|
|
80
|
-
"test/rails_app/script/rails",
|
|
81
|
-
"test/routes_test.rb",
|
|
82
|
-
"test/test_helper.rb"
|
|
83
|
-
]
|
|
84
|
-
s.homepage = %q{http://github.com/scambra/devise_invitable}
|
|
85
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
86
|
-
s.require_paths = ["lib"]
|
|
87
|
-
s.rubygems_version = %q{1.3.7}
|
|
88
|
-
s.summary = %q{An invitation strategy for devise}
|
|
89
|
-
s.test_files = [
|
|
90
|
-
"test/generators_test.rb",
|
|
91
|
-
"test/test_helper.rb",
|
|
92
|
-
"test/integration/invitable_test.rb",
|
|
93
|
-
"test/routes_test.rb",
|
|
94
|
-
"test/rails_app/app/helpers/application_helper.rb",
|
|
95
|
-
"test/rails_app/app/models/octopussy.rb",
|
|
96
|
-
"test/rails_app/app/models/user.rb",
|
|
97
|
-
"test/rails_app/app/controllers/admins_controller.rb",
|
|
98
|
-
"test/rails_app/app/controllers/application_controller.rb",
|
|
99
|
-
"test/rails_app/app/controllers/home_controller.rb",
|
|
100
|
-
"test/rails_app/app/controllers/users_controller.rb",
|
|
101
|
-
"test/rails_app/config/initializers/devise.rb",
|
|
102
|
-
"test/rails_app/config/initializers/inflections.rb",
|
|
103
|
-
"test/rails_app/config/initializers/mime_types.rb",
|
|
104
|
-
"test/rails_app/config/initializers/secret_token.rb",
|
|
105
|
-
"test/rails_app/config/initializers/session_store.rb",
|
|
106
|
-
"test/rails_app/config/initializers/backtrace_silencers.rb",
|
|
107
|
-
"test/rails_app/config/environment.rb",
|
|
108
|
-
"test/rails_app/config/environments/production.rb",
|
|
109
|
-
"test/rails_app/config/environments/test.rb",
|
|
110
|
-
"test/rails_app/config/environments/development.rb",
|
|
111
|
-
"test/rails_app/config/routes.rb",
|
|
112
|
-
"test/rails_app/config/application.rb",
|
|
113
|
-
"test/rails_app/config/boot.rb",
|
|
114
|
-
"test/integration_tests_helper.rb",
|
|
115
|
-
"test/model_tests_helper.rb",
|
|
116
|
-
"test/models_test.rb",
|
|
117
|
-
"test/mailers/invitation_test.rb",
|
|
118
|
-
"test/models/invitable_test.rb"
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
if s.respond_to? :specification_version then
|
|
122
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
123
|
-
s.specification_version = 3
|
|
124
|
-
|
|
125
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
126
|
-
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
|
127
|
-
s.add_development_dependency(%q<capybara>, [">= 0.3.9"])
|
|
128
|
-
s.add_development_dependency(%q<rails>, ["~> 3.0.0"])
|
|
129
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
|
130
|
-
s.add_runtime_dependency(%q<devise>, ["~> 1.1.0"])
|
|
131
|
-
else
|
|
132
|
-
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
|
133
|
-
s.add_dependency(%q<capybara>, [">= 0.3.9"])
|
|
134
|
-
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
|
135
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
|
136
|
-
s.add_dependency(%q<devise>, ["~> 1.1.0"])
|
|
137
|
-
end
|
|
138
|
-
else
|
|
139
|
-
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
|
140
|
-
s.add_dependency(%q<capybara>, [">= 0.3.9"])
|
|
141
|
-
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
|
142
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
|
143
|
-
s.add_dependency(%q<devise>, ["~> 1.1.0"])
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
data/test/generators_test.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require 'test/test_helper'
|
|
2
|
-
require 'rails/generators'
|
|
3
|
-
require 'generators/devise_invitable/devise_invitable_generator'
|
|
4
|
-
|
|
5
|
-
class GeneratorsTest < ActiveSupport::TestCase
|
|
6
|
-
RAILS_APP_PATH = File.expand_path("../rails_app", __FILE__)
|
|
7
|
-
|
|
8
|
-
test "rails g should include the 3 generators" do
|
|
9
|
-
@output = `cd #{RAILS_APP_PATH} && rails g`
|
|
10
|
-
assert @output.match(%r|DeviseInvitable:\n devise_invitable\n devise_invitable:install\n devise_invitable:views|)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "rails g devise_invitable:install" do
|
|
14
|
-
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
|
|
15
|
-
assert @output.match(%r|inject.+ config/initializers/devise\.rb\n|)
|
|
16
|
-
assert @output.match(%r|create.+ config/locales/devise_invitable\.en\.yml\n|)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test "rails g devise_invitable:views not scoped" do
|
|
20
|
-
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views -p`
|
|
21
|
-
assert @output.match(%r|create.+ app/views/devise\n|)
|
|
22
|
-
assert @output.match(%r|create.+ app/views/devise/invitations/edit\.html\.erb\n|)
|
|
23
|
-
assert @output.match(%r|create.+ app/views/devise/invitations/new\.html\.erb\n|)
|
|
24
|
-
assert @output.match(%r|create.+ app/views/devise/mailer/invitation\.html\.erb\n|)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test "rails g devise_invitable:views scoped" do
|
|
28
|
-
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views octopussies -p`
|
|
29
|
-
assert @output.match(%r|create.+ app/views/octopussies\n|)
|
|
30
|
-
assert @output.match(%r|create.+ app/views/octopussies/invitations/edit\.html\.erb\n|)
|
|
31
|
-
assert @output.match(%r|create.+ app/views/octopussies/invitations/new\.html\.erb\n|)
|
|
32
|
-
assert @output.match(%r|create.+ app/views/octopussies/mailer/invitation\.html\.erb\n|)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "rails g devise_invitable Octopussy" do
|
|
36
|
-
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
|
|
37
|
-
assert @output.match(%r|inject.+ app/models/octopussy\.rb\n|)
|
|
38
|
-
assert @output.match(%r|invoke.+ #{DEVISE_ORM}\n|)
|
|
39
|
-
if DEVISE_ORM == :active_record
|
|
40
|
-
assert @output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
|
41
|
-
elsif DEVISE_ORM == :mongoid
|
|
42
|
-
assert !@output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
require 'test/test_helper'
|
|
2
|
-
require 'test/integration_tests_helper'
|
|
3
|
-
|
|
4
|
-
class InvitationTest < ActionDispatch::IntegrationTest
|
|
5
|
-
def teardown
|
|
6
|
-
Capybara.reset_sessions!
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def send_invitation(&block)
|
|
10
|
-
visit new_user_invitation_path
|
|
11
|
-
|
|
12
|
-
fill_in 'user_email', :with => 'user@test.com'
|
|
13
|
-
yield if block_given?
|
|
14
|
-
click_button 'Send an invitation'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def set_password(options={}, &block)
|
|
18
|
-
unless options[:visit] == false
|
|
19
|
-
visit accept_user_invitation_path(:invitation_token => options[:invitation_token])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
fill_in 'user_password', :with => '987654321'
|
|
23
|
-
fill_in 'user_password_confirmation', :with => '987654321'
|
|
24
|
-
yield if block_given?
|
|
25
|
-
click_button 'Set my password'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test 'not authenticated user should not be able to send an invitation' do
|
|
29
|
-
get new_user_invitation_path
|
|
30
|
-
assert_redirected_to new_user_session_path
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test 'authenticated user should be able to send an invitation' do
|
|
34
|
-
sign_in_as_user
|
|
35
|
-
|
|
36
|
-
send_invitation
|
|
37
|
-
assert_equal root_path, current_path
|
|
38
|
-
assert page.has_css?('p#notice', :text => 'An email with instructions about how to set the password has been sent.')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test 'authenticated user with invalid email should receive an error message' do
|
|
42
|
-
user = create_full_user
|
|
43
|
-
sign_in_as_user(user)
|
|
44
|
-
send_invitation do
|
|
45
|
-
fill_in 'user_email', :with => user.email
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
assert_equal user_invitation_path, current_path
|
|
49
|
-
assert page.has_css?("input[type=text][value='#{user.email}']")
|
|
50
|
-
assert page.has_css?('#error_explanation li', :text => 'Email has already been taken')
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
test 'authenticated user should not be able to visit edit invitation page' do
|
|
54
|
-
sign_in_as_user
|
|
55
|
-
|
|
56
|
-
visit accept_user_invitation_path
|
|
57
|
-
|
|
58
|
-
assert_equal root_path, current_path
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test 'not authenticated user with invalid invitation token should not be able to set his password' do
|
|
62
|
-
user = create_user
|
|
63
|
-
set_password :invitation_token => 'invalid_token'
|
|
64
|
-
|
|
65
|
-
assert_equal user_invitation_path, current_path
|
|
66
|
-
assert page.has_css?('#error_explanation li', :text => 'Invitation token is invalid')
|
|
67
|
-
assert !user.reload.valid_password?('987654321')
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
test 'not authenticated user with valid invitation token but invalid password should not be able to set his password' do
|
|
71
|
-
user = create_user(false)
|
|
72
|
-
set_password :invitation_token => user.invitation_token do
|
|
73
|
-
fill_in 'Password confirmation', :with => 'other_password'
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
assert_equal user_invitation_path, current_path
|
|
77
|
-
assert page.has_css?('#error_explanation li', :text => 'Password doesn\'t match confirmation')
|
|
78
|
-
assert !user.reload.valid_password?('987654321')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test 'not authenticated user with valid data should be able to change his password' do
|
|
82
|
-
user = create_user(false)
|
|
83
|
-
set_password :invitation_token => user.invitation_token
|
|
84
|
-
|
|
85
|
-
assert_equal root_path, current_path
|
|
86
|
-
assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
|
|
87
|
-
assert user.reload.valid_password?('987654321')
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
test 'after entering invalid data user should still be able to set his password' do
|
|
91
|
-
user = create_user(false)
|
|
92
|
-
set_password :invitation_token => user.invitation_token do
|
|
93
|
-
fill_in 'Password confirmation', :with => 'other_password'
|
|
94
|
-
end
|
|
95
|
-
assert_equal user_invitation_path, current_path
|
|
96
|
-
assert page.has_css?('#error_explanation')
|
|
97
|
-
assert !user.reload.valid_password?('987654321')
|
|
98
|
-
|
|
99
|
-
set_password :invitation_token => user.invitation_token
|
|
100
|
-
assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
|
|
101
|
-
assert user.reload.valid_password?('987654321')
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
test 'sign in user automatically after setting it\'s password' do
|
|
105
|
-
user = create_user(false)
|
|
106
|
-
set_password :invitation_token => user.invitation_token
|
|
107
|
-
assert_equal root_path, current_path
|
|
108
|
-
end
|
|
109
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
class ActionController::IntegrationTest
|
|
2
|
-
|
|
3
|
-
def warden
|
|
4
|
-
request.env['warden']
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def create_full_user
|
|
8
|
-
@user ||= begin
|
|
9
|
-
user = User.create!(
|
|
10
|
-
:username => 'usertest',
|
|
11
|
-
:email => 'fulluser@test.com',
|
|
12
|
-
:password => '123456',
|
|
13
|
-
:password_confirmation => '123456',
|
|
14
|
-
:created_at => Time.now.utc
|
|
15
|
-
)
|
|
16
|
-
user.confirm!
|
|
17
|
-
user
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def sign_in_as_user(user = nil)
|
|
22
|
-
user ||= create_full_user
|
|
23
|
-
visit new_user_session_path
|
|
24
|
-
fill_in 'user_email', :with => user.email
|
|
25
|
-
fill_in 'user_password', :with => '123456'
|
|
26
|
-
fill_in 'user_password', :with => user.password
|
|
27
|
-
click_button 'Sign in'
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def create_user(accept_invitation = true)
|
|
31
|
-
user = User.new :email => 'newuser@test.com'
|
|
32
|
-
user.skip_confirmation!
|
|
33
|
-
user.invitation_token = 'token'
|
|
34
|
-
user.invitation_sent_at = Time.now.utc
|
|
35
|
-
user.save(:validate => false)
|
|
36
|
-
user.accept_invitation! if accept_invitation
|
|
37
|
-
user
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Fix assert_redirect_to in integration sessions because they don't take into
|
|
41
|
-
# account Middleware redirects.
|
|
42
|
-
#
|
|
43
|
-
def assert_redirected_to(url)
|
|
44
|
-
assert [301, 302].include?(@integration_session.status),
|
|
45
|
-
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
|
46
|
-
|
|
47
|
-
url = prepend_host(url)
|
|
48
|
-
location = prepend_host(@integration_session.headers["Location"])
|
|
49
|
-
assert_equal url, location
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
protected
|
|
53
|
-
|
|
54
|
-
def prepend_host(url)
|
|
55
|
-
url = "http://#{request.host}#{url}" if url[0] == ?/
|
|
56
|
-
url
|
|
57
|
-
end
|
|
58
|
-
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; charset=UTF-8', 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 => { :subject => 'Localized Invitation' } } } do
|
|
43
|
-
assert_equal 'Localized Invitation', mail.subject
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test 'subject namespaced by model' do
|
|
48
|
-
store_translations :en, :devise => { :mailer => { :invitation => { :user_subject => '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
|
data/test/model_tests_helper.rb
DELETED
|
@@ -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(:validate => false)
|
|
39
|
-
user
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,188 +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.invite!
|
|
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('token')
|
|
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 !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.invite!
|
|
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.invite!
|
|
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.invite!(:email => "valid@email.com")
|
|
106
|
-
assert invited_user.errors.blank?
|
|
107
|
-
assert_present invited_user.invitation_token
|
|
108
|
-
assert_equal 'valid@email.com', invited_user.email
|
|
109
|
-
assert invited_user.persisted?
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
test 'should set all attributes with no errors' do
|
|
113
|
-
invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
|
|
114
|
-
assert invited_user.errors.blank?
|
|
115
|
-
assert_equal 'first name', invited_user.username
|
|
116
|
-
assert invited_user.persisted?
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test 'should return a record with errors if user was found by e-mail' do
|
|
120
|
-
user = create_user_with_invitation('')
|
|
121
|
-
user.update_attribute(:invitation_token, nil)
|
|
122
|
-
invited_user = User.invite!(:email => user.email)
|
|
123
|
-
assert_equal invited_user, user
|
|
124
|
-
assert_equal ['has already been taken'], invited_user.errors[:email]
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test 'should return a new record with errors if e-mail is blank' do
|
|
128
|
-
invited_user = User.invite!(:email => '')
|
|
129
|
-
assert invited_user.new_record?
|
|
130
|
-
assert_equal ["can't be blank"], invited_user.errors[:email]
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
test 'should return a new record with errors if e-mail is invalid' do
|
|
134
|
-
invited_user = User.invite!(:email => 'invalid_email')
|
|
135
|
-
assert invited_user.new_record?
|
|
136
|
-
assert_equal ["is invalid"], invited_user.errors[:email]
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
test 'should set all attributes with errors if e-mail is invalid' do
|
|
140
|
-
invited_user = User.invite!(:email => "invalid_email.com", :username => 'first name')
|
|
141
|
-
assert invited_user.new_record?
|
|
142
|
-
assert_equal 'first name', invited_user.username
|
|
143
|
-
assert invited_user.errors.present?
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
test 'should find a user to set his password based on invitation_token' do
|
|
147
|
-
user = new_user
|
|
148
|
-
user.invite!
|
|
149
|
-
|
|
150
|
-
invited_user = User.accept_invitation!(:invitation_token => user.invitation_token)
|
|
151
|
-
assert_equal invited_user, user
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
test 'should return a new record with errors if no invitation_token is found' do
|
|
155
|
-
invited_user = User.accept_invitation!(:invitation_token => 'invalid_token')
|
|
156
|
-
assert invited_user.new_record?
|
|
157
|
-
assert_equal ['is invalid'], invited_user.errors[:invitation_token]
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
test 'should return a new record with errors if invitation_token is blank' do
|
|
161
|
-
invited_user = User.accept_invitation!(:invitation_token => '')
|
|
162
|
-
assert invited_user.new_record?
|
|
163
|
-
assert_equal ["can't be blank"], invited_user.errors[:invitation_token]
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
test 'should return record with errors if invitation_token has expired' do
|
|
167
|
-
user = create_user_with_invitation('valid_token')
|
|
168
|
-
user.update_attribute(:invitation_sent_at, 1.day.ago)
|
|
169
|
-
User.stubs(:invite_for).returns(10.hours)
|
|
170
|
-
invited_user = User.accept_invitation!(:invitation_token => 'valid_token')
|
|
171
|
-
assert_equal user, invited_user
|
|
172
|
-
assert_equal ["is invalid"], invited_user.errors[:invitation_token]
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
test 'should set successfully user password given the new password and confirmation' do
|
|
176
|
-
user = new_user(:password => nil, :password_confirmation => nil)
|
|
177
|
-
user.invite!
|
|
178
|
-
|
|
179
|
-
invited_user = User.accept_invitation!(
|
|
180
|
-
:invitation_token => user.invitation_token,
|
|
181
|
-
:password => 'new_password',
|
|
182
|
-
:password_confirmation => 'new_password'
|
|
183
|
-
)
|
|
184
|
-
user.reload
|
|
185
|
-
|
|
186
|
-
assert user.valid_password?('new_password')
|
|
187
|
-
end
|
|
188
|
-
end
|
data/test/models_test.rb
DELETED
|
@@ -1,31 +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
|
-
end
|
|
18
|
-
|
|
19
|
-
test 'add invitable module only' do
|
|
20
|
-
assert_include_modules Invitable, :invitable
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test 'set a default value for invite_for' do
|
|
24
|
-
assert_equal 5.days, Invitable.invite_for
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test 'invitable attributes' do
|
|
28
|
-
assert_not_nil Invitable.columns_hash['invitation_token']
|
|
29
|
-
assert_not_nil Invitable.columns_hash['invitation_sent_at']
|
|
30
|
-
end
|
|
31
|
-
end
|