devise_invitable 0.1.3 → 0.1.4
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/Rakefile +1 -1
- data/VERSION +1 -1
- data/devise_invitable.gemspec +20 -20
- data/lib/devise/models/invitable.rb +5 -17
- data/test/integration_tests_helper.rb +1 -0
- data/test/mailers/invitation_test.rb +1 -1
- data/test/model_tests_helper.rb +1 -0
- data/test/models/invitable_test.rb +7 -5
- metadata +18 -18
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["Sergio Cambra"]
|
13
13
|
gem.add_development_dependency 'mocha'
|
14
14
|
gem.add_development_dependency 'webrat'
|
15
|
-
gem.add_dependency 'devise', '
|
15
|
+
gem.add_dependency 'devise', '~> 0.7.2'
|
16
16
|
end
|
17
17
|
Jeweler::GemcutterTasks.new
|
18
18
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/devise_invitable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{devise_invitable}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sergio Cambra"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-23}
|
13
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
14
|
s.email = %q{sergio@entrecables.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -73,31 +73,31 @@ Gem::Specification.new do |s|
|
|
73
73
|
s.rubygems_version = %q{1.3.5}
|
74
74
|
s.summary = %q{An invitation strategy for devise}
|
75
75
|
s.test_files = [
|
76
|
-
"test/
|
76
|
+
"test/integration/invitable_test.rb",
|
77
77
|
"test/integration_tests_helper.rb",
|
78
|
-
"test/models_test.rb",
|
79
78
|
"test/mailers/invitation_test.rb",
|
80
|
-
"test/
|
81
|
-
"test/integration/invitable_test.rb",
|
79
|
+
"test/model_tests_helper.rb",
|
82
80
|
"test/models/invitable_test.rb",
|
83
|
-
"test/
|
84
|
-
"test/rails_app/app/controllers/application_controller.rb",
|
81
|
+
"test/models_test.rb",
|
85
82
|
"test/rails_app/app/controllers/admins_controller.rb",
|
83
|
+
"test/rails_app/app/controllers/application_controller.rb",
|
86
84
|
"test/rails_app/app/controllers/home_controller.rb",
|
87
85
|
"test/rails_app/app/controllers/users_controller.rb",
|
88
|
-
"test/rails_app/app/models/user.rb",
|
89
86
|
"test/rails_app/app/helpers/application_helper.rb",
|
90
|
-
"test/rails_app/
|
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",
|
91
93
|
"test/rails_app/config/initializers/backtrace_silencers.rb",
|
94
|
+
"test/rails_app/config/initializers/inflections.rb",
|
92
95
|
"test/rails_app/config/initializers/new_rails_defaults.rb",
|
93
96
|
"test/rails_app/config/initializers/session_store.rb",
|
94
|
-
"test/rails_app/config/
|
95
|
-
"test/rails_app/
|
96
|
-
"test/
|
97
|
-
"test/
|
98
|
-
"test/rails_app/config/environment.rb",
|
99
|
-
"test/rails_app/config/boot.rb",
|
100
|
-
"test/rails_app/vendor/plugins/devise_invitable/init.rb"
|
97
|
+
"test/rails_app/config/routes.rb",
|
98
|
+
"test/rails_app/vendor/plugins/devise_invitable/init.rb",
|
99
|
+
"test/routes_test.rb",
|
100
|
+
"test/test_helper.rb"
|
101
101
|
]
|
102
102
|
|
103
103
|
if s.respond_to? :specification_version then
|
@@ -107,16 +107,16 @@ Gem::Specification.new do |s|
|
|
107
107
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
108
108
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
109
109
|
s.add_development_dependency(%q<webrat>, [">= 0"])
|
110
|
-
s.add_runtime_dependency(%q<devise>, ["
|
110
|
+
s.add_runtime_dependency(%q<devise>, ["~> 0.7.2"])
|
111
111
|
else
|
112
112
|
s.add_dependency(%q<mocha>, [">= 0"])
|
113
113
|
s.add_dependency(%q<webrat>, [">= 0"])
|
114
|
-
s.add_dependency(%q<devise>, ["
|
114
|
+
s.add_dependency(%q<devise>, ["~> 0.7.2"])
|
115
115
|
end
|
116
116
|
else
|
117
117
|
s.add_dependency(%q<mocha>, [">= 0"])
|
118
118
|
s.add_dependency(%q<webrat>, [">= 0"])
|
119
|
-
s.add_dependency(%q<devise>, ["
|
119
|
+
s.add_dependency(%q<devise>, ["~> 0.7.2"])
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -17,32 +17,19 @@ module Devise
|
|
17
17
|
# User.send_invitation(:email => 'someone@example.com') # send invitation
|
18
18
|
# User.accept_invitation!(:invitation_token => '...') # accept invitation with a token
|
19
19
|
# User.find(1).accept_invitation! # accept invitation
|
20
|
-
# User.find(1).
|
20
|
+
# User.find(1).resend_invitation! # reset invitation status and send invitation again
|
21
21
|
module Invitable
|
22
22
|
|
23
23
|
def self.included(base)
|
24
24
|
base.class_eval do
|
25
25
|
extend ClassMethods
|
26
|
-
callbacks = []
|
27
|
-
callbacks.concat before_create_callback_chain.select {|c| c.method == :generate_confirmation_token}
|
28
|
-
callbacks.concat after_create_callback_chain.select {|c| c.method == :send_confirmation_instructions}
|
29
|
-
callbacks.each do |c|
|
30
|
-
c.options[:unless] = lambda{|r| r.class.devise_modules.include?(:invitable) && r.invitation_token}
|
31
|
-
end
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
35
29
|
# Accept an invitation by clearing invitation token and confirming it if model
|
36
30
|
# is confirmable
|
37
31
|
def accept_invitation!
|
38
|
-
if self.invited?
|
39
|
-
self.invitation_token = nil
|
40
|
-
if self.class.devise_modules.include? :confirmable
|
41
|
-
self.confirm!
|
42
|
-
else
|
43
|
-
save
|
44
|
-
end
|
45
|
-
end
|
32
|
+
self.update_attribute :invitation_token, nil if self.invited?
|
46
33
|
end
|
47
34
|
|
48
35
|
# Verifies whether a user has been invited or not
|
@@ -56,8 +43,9 @@ module Devise
|
|
56
43
|
end
|
57
44
|
|
58
45
|
# Reset invitation token and send invitation again
|
59
|
-
def
|
46
|
+
def resend_invitation!
|
60
47
|
if new_record? || invited?
|
48
|
+
self.skip_confirmation! if self.new_record? and self.respond_to? :skip_confirmation!
|
61
49
|
generate_invitation_token
|
62
50
|
save(false)
|
63
51
|
send_invitation
|
@@ -113,7 +101,7 @@ module Devise
|
|
113
101
|
if invitable.email.blank?
|
114
102
|
invitable.errors.add(:email, :blank)
|
115
103
|
elsif invitable.new_record? || invitable.invited?
|
116
|
-
invitable.
|
104
|
+
invitable.resend_invitation!
|
117
105
|
else
|
118
106
|
invitable.errors.add(:email, :already_exits, :default => 'already exists')
|
119
107
|
end
|
data/test/model_tests_helper.rb
CHANGED
@@ -36,6 +36,7 @@ class ActiveSupport::TestCase
|
|
36
36
|
|
37
37
|
def create_user_with_invitation(invitation_token, attributes={})
|
38
38
|
user = new_user({:password => nil, :password_confirmation => nil}.update(attributes))
|
39
|
+
user.skip_confirmation!
|
39
40
|
user.invitation_token = invitation_token
|
40
41
|
user.invitation_sent_at = Time.now.utc
|
41
42
|
user.save(false)
|
@@ -15,7 +15,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
15
15
|
user = new_user
|
16
16
|
3.times do
|
17
17
|
token = user.invitation_token
|
18
|
-
user.
|
18
|
+
user.resend_invitation!
|
19
19
|
assert_not_equal token, user.invitation_token
|
20
20
|
end
|
21
21
|
end
|
@@ -52,7 +52,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
52
52
|
invitation_tokens = []
|
53
53
|
3.times do
|
54
54
|
user = new_user
|
55
|
-
user.
|
55
|
+
user.resend_invitation!
|
56
56
|
token = user.invitation_token
|
57
57
|
assert !invitation_tokens.include?(token)
|
58
58
|
invitation_tokens << token
|
@@ -74,6 +74,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
74
74
|
|
75
75
|
test 'should clear invitation token while setting the password' do
|
76
76
|
user = new_user
|
77
|
+
user.skip_confirmation!
|
77
78
|
user.update_attribute(:invitation_token, 'valid_token')
|
78
79
|
assert_present user.invitation_token
|
79
80
|
assert user.accept_invitation!
|
@@ -82,6 +83,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
82
83
|
|
83
84
|
test 'should not clear invitation token if record is invalid' do
|
84
85
|
user = new_user
|
86
|
+
user.skip_confirmation!
|
85
87
|
user.update_attribute(:invitation_token, 'valid_token')
|
86
88
|
assert_present user.invitation_token
|
87
89
|
User.any_instance.stubs(:valid?).returns(false)
|
@@ -94,7 +96,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
94
96
|
user = new_user
|
95
97
|
assert_difference('ActionMailer::Base.deliveries.size') do
|
96
98
|
token = user.invitation_token
|
97
|
-
user.
|
99
|
+
user.resend_invitation!
|
98
100
|
assert_not_equal token, user.invitation_token
|
99
101
|
end
|
100
102
|
end
|
@@ -121,7 +123,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
121
123
|
|
122
124
|
test 'should find a user to set his password based on invitation_token' do
|
123
125
|
user = new_user
|
124
|
-
user.
|
126
|
+
user.resend_invitation!
|
125
127
|
|
126
128
|
invited_user = User.accept_invitation!(:invitation_token => user.invitation_token)
|
127
129
|
assert_equal invited_user, user
|
@@ -150,7 +152,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
150
152
|
|
151
153
|
test 'should set successfully user password given the new password and confirmation' do
|
152
154
|
user = new_user(:password => nil, :password_confirmation => nil)
|
153
|
-
user.
|
155
|
+
user.resend_invitation!
|
154
156
|
|
155
157
|
invited_user = User.accept_invitation!(
|
156
158
|
:invitation_token => user.invitation_token,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_invitable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Cambra
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-23 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,9 +38,9 @@ dependencies:
|
|
38
38
|
version_requirement:
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.7.
|
43
|
+
version: 0.7.2
|
44
44
|
version:
|
45
45
|
description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password
|
46
46
|
email: sergio@entrecables.com
|
@@ -130,28 +130,28 @@ signing_key:
|
|
130
130
|
specification_version: 3
|
131
131
|
summary: An invitation strategy for devise
|
132
132
|
test_files:
|
133
|
-
- test/
|
133
|
+
- test/integration/invitable_test.rb
|
134
134
|
- test/integration_tests_helper.rb
|
135
|
-
- test/models_test.rb
|
136
135
|
- test/mailers/invitation_test.rb
|
137
|
-
- test/
|
138
|
-
- test/integration/invitable_test.rb
|
136
|
+
- test/model_tests_helper.rb
|
139
137
|
- test/models/invitable_test.rb
|
140
|
-
- test/
|
141
|
-
- test/rails_app/app/controllers/application_controller.rb
|
138
|
+
- test/models_test.rb
|
142
139
|
- test/rails_app/app/controllers/admins_controller.rb
|
140
|
+
- test/rails_app/app/controllers/application_controller.rb
|
143
141
|
- test/rails_app/app/controllers/home_controller.rb
|
144
142
|
- test/rails_app/app/controllers/users_controller.rb
|
145
|
-
- test/rails_app/app/models/user.rb
|
146
143
|
- test/rails_app/app/helpers/application_helper.rb
|
147
|
-
- test/rails_app/
|
144
|
+
- test/rails_app/app/models/user.rb
|
145
|
+
- test/rails_app/config/boot.rb
|
146
|
+
- test/rails_app/config/environment.rb
|
147
|
+
- test/rails_app/config/environments/development.rb
|
148
|
+
- test/rails_app/config/environments/production.rb
|
149
|
+
- test/rails_app/config/environments/test.rb
|
148
150
|
- test/rails_app/config/initializers/backtrace_silencers.rb
|
151
|
+
- test/rails_app/config/initializers/inflections.rb
|
149
152
|
- test/rails_app/config/initializers/new_rails_defaults.rb
|
150
153
|
- test/rails_app/config/initializers/session_store.rb
|
151
|
-
- test/rails_app/config/
|
152
|
-
- test/rails_app/config/environments/test.rb
|
153
|
-
- test/rails_app/config/environments/development.rb
|
154
|
-
- test/rails_app/config/environments/production.rb
|
155
|
-
- test/rails_app/config/environment.rb
|
156
|
-
- test/rails_app/config/boot.rb
|
154
|
+
- test/rails_app/config/routes.rb
|
157
155
|
- test/rails_app/vendor/plugins/devise_invitable/init.rb
|
156
|
+
- test/routes_test.rb
|
157
|
+
- test/test_helper.rb
|