devise_invitable 0.1.3 → 0.2.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/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', '>= 0.7.1'
15
+ gem.add_dependency 'devise', '~> 0.8.0'
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
18
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -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.3"
8
+ s.version = "0.2.0"
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}
12
+ s.date = %q{2010-01-08}
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 = [
@@ -59,6 +59,7 @@ Gem::Specification.new do |s|
59
59
  "test/rails_app/config/environments/production.rb",
60
60
  "test/rails_app/config/environments/test.rb",
61
61
  "test/rails_app/config/initializers/backtrace_silencers.rb",
62
+ "test/rails_app/config/initializers/devise.rb",
62
63
  "test/rails_app/config/initializers/inflections.rb",
63
64
  "test/rails_app/config/initializers/new_rails_defaults.rb",
64
65
  "test/rails_app/config/initializers/session_store.rb",
@@ -73,31 +74,32 @@ Gem::Specification.new do |s|
73
74
  s.rubygems_version = %q{1.3.5}
74
75
  s.summary = %q{An invitation strategy for devise}
75
76
  s.test_files = [
76
- "test/model_tests_helper.rb",
77
+ "test/integration/invitable_test.rb",
77
78
  "test/integration_tests_helper.rb",
78
- "test/models_test.rb",
79
79
  "test/mailers/invitation_test.rb",
80
- "test/routes_test.rb",
81
- "test/integration/invitable_test.rb",
80
+ "test/model_tests_helper.rb",
82
81
  "test/models/invitable_test.rb",
83
- "test/test_helper.rb",
84
- "test/rails_app/app/controllers/application_controller.rb",
82
+ "test/models_test.rb",
85
83
  "test/rails_app/app/controllers/admins_controller.rb",
84
+ "test/rails_app/app/controllers/application_controller.rb",
86
85
  "test/rails_app/app/controllers/home_controller.rb",
87
86
  "test/rails_app/app/controllers/users_controller.rb",
88
- "test/rails_app/app/models/user.rb",
89
87
  "test/rails_app/app/helpers/application_helper.rb",
90
- "test/rails_app/config/routes.rb",
88
+ "test/rails_app/app/models/user.rb",
89
+ "test/rails_app/config/boot.rb",
90
+ "test/rails_app/config/environment.rb",
91
+ "test/rails_app/config/environments/development.rb",
92
+ "test/rails_app/config/environments/production.rb",
93
+ "test/rails_app/config/environments/test.rb",
91
94
  "test/rails_app/config/initializers/backtrace_silencers.rb",
95
+ "test/rails_app/config/initializers/inflections.rb",
92
96
  "test/rails_app/config/initializers/new_rails_defaults.rb",
93
97
  "test/rails_app/config/initializers/session_store.rb",
94
- "test/rails_app/config/initializers/inflections.rb",
95
- "test/rails_app/config/environments/test.rb",
96
- "test/rails_app/config/environments/development.rb",
97
- "test/rails_app/config/environments/production.rb",
98
- "test/rails_app/config/environment.rb",
99
- "test/rails_app/config/boot.rb",
100
- "test/rails_app/vendor/plugins/devise_invitable/init.rb"
98
+ "test/rails_app/config/initializers/devise.rb",
99
+ "test/rails_app/config/routes.rb",
100
+ "test/rails_app/vendor/plugins/devise_invitable/init.rb",
101
+ "test/routes_test.rb",
102
+ "test/test_helper.rb"
101
103
  ]
102
104
 
103
105
  if s.respond_to? :specification_version then
@@ -107,16 +109,16 @@ Gem::Specification.new do |s|
107
109
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
108
110
  s.add_development_dependency(%q<mocha>, [">= 0"])
109
111
  s.add_development_dependency(%q<webrat>, [">= 0"])
110
- s.add_runtime_dependency(%q<devise>, [">= 0.7.1"])
112
+ s.add_runtime_dependency(%q<devise>, ["~> 0.8.0"])
111
113
  else
112
114
  s.add_dependency(%q<mocha>, [">= 0"])
113
115
  s.add_dependency(%q<webrat>, [">= 0"])
114
- s.add_dependency(%q<devise>, [">= 0.7.1"])
116
+ s.add_dependency(%q<devise>, ["~> 0.8.0"])
115
117
  end
116
118
  else
117
119
  s.add_dependency(%q<mocha>, [">= 0"])
118
120
  s.add_dependency(%q<webrat>, [">= 0"])
119
- s.add_dependency(%q<devise>, [">= 0.7.1"])
121
+ s.add_dependency(%q<devise>, ["~> 0.8.0"])
120
122
  end
121
123
  end
122
124
 
@@ -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).reset_invitation! # reset invitation status and send invitation again
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 reset_invitation!
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.reset_invitation!
104
+ invitable.resend_invitation!
117
105
  else
118
106
  invitable.errors.add(:email, :already_exits, :default => 'already exists')
119
107
  end
@@ -10,6 +10,7 @@ class ActionController::IntegrationTest
10
10
 
11
11
  def create_user(accept_invitation = true)
12
12
  user = User.new :email => 'newuser@test.com'
13
+ user.skip_confirmation!
13
14
  user.invitation_token = 'token'
14
15
  user.invitation_sent_at = Time.now.utc
15
16
  user.save(false)
@@ -1,10 +1,10 @@
1
1
  require 'test/test_helper'
2
2
 
3
- class InviationTest < ActionMailer::TestCase
3
+ class InvitationMailTest < ActionMailer::TestCase
4
4
 
5
5
  def setup
6
6
  setup_mailer
7
- DeviseMailer.sender = 'test@example.com'
7
+ Devise.mailer_sender = 'test@example.com'
8
8
  end
9
9
 
10
10
  def user
@@ -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.reset_invitation!
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.reset_invitation!
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.reset_invitation!
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.reset_invitation!
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.reset_invitation!
155
+ user.resend_invitation!
154
156
 
155
157
  invited_user = User.accept_invitation!(
156
158
  :invitation_token => user.invitation_token,
@@ -1,4 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
- devise :all
2
+ devise :authenticatable, :confirmable, :recoverable, :rememberable, :validatable
3
3
  attr_accessible :username, :email, :password, :password_confirmation
4
4
  end
@@ -0,0 +1,76 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # Configure Devise modules used by default. You should always set this value
5
+ # because if Devise adds a new strategy, it won't be added to your application
6
+ # by default, unless you configure it here.
7
+ #
8
+ # Remember that Devise includes other modules on its own (like :activatable
9
+ # and :timeoutable) which are not included here and also plugins. So be sure
10
+ # to check the docs for a complete set.
11
+ config.all = [:authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable]
12
+
13
+ # Invoke `rake secret` and use the printed value to setup a pepper to generate
14
+ # the encrypted password. By default no pepper is used.
15
+ # config.pepper = "rake secret output"
16
+
17
+ # Configure how many times you want the password is reencrypted. Default is 10.
18
+ # config.stretches = 10
19
+
20
+ # Define which will be the encryption algorithm. Supported algorithms are :sha1
21
+ # (default) and :sha512. Devise also supports encryptors from others authentication
22
+ # frameworks as :clearance_sha1, :authlogic_sha512 (then you should set stretches
23
+ # above to 20 for default behavior) and :restful_authentication_sha1 (then you
24
+ # should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
25
+ # config.encryptor = :sha1
26
+
27
+ # Configure which keys are used when authenticating an user. By default is
28
+ # just :email. You can configure it to use [:username, :subdomain], so for
29
+ # authenticating an user, both parameters are required. Remember that those
30
+ # parameters are used only when authenticating and not when retrieving from
31
+ # session. If you need permissions, you should implement that in a before filter.
32
+ # config.authentication_keys = [ :email ]
33
+
34
+ # The time you want give to your user to confirm his account. During this time
35
+ # he will be able to access your application without confirming. Default is nil.
36
+ # config.confirm_within = 2.days
37
+
38
+ # The time the user will be remembered without asking for credentials again.
39
+ # config.remember_for = 2.weeks
40
+
41
+ # The time you want to timeout the user session without activity. After this
42
+ # time the user will be asked for credentials again.
43
+ # config.timeout_in = 10.minutes
44
+
45
+ # Configure the e-mail address which will be shown in DeviseMailer.
46
+ # config.mailer_sender = "foo.bar@yourapp.com"
47
+
48
+ # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
49
+ # require 'devise/orm/mongo_mapper'
50
+ # config.orm = :mongo_mapper
51
+
52
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
53
+ # "sessions/users/new". It's turned off by default because it's slower if you
54
+ # are using only default views.
55
+ # config.scoped_views = true
56
+
57
+ # If you want to use other strategies, that are not (yet) supported by Devise,
58
+ # you can configure them inside the config.warden block. The example below
59
+ # allows you to setup OAuth, using http://github.com/roman/warden_oauth
60
+ #
61
+ # config.warden do |manager|
62
+ # manager.oauth(:twitter) do |twitter|
63
+ # twitter.consumer_secret = <YOUR CONSUMER SECRET>
64
+ # twitter.consumer_key = <YOUR CONSUMER KEY>
65
+ # twitter.options :site => 'http://twitter.com'
66
+ # end
67
+ # manager.default_strategies.unshift :twitter_oauth
68
+ # end
69
+
70
+ # Configure default_url_options if you are using dynamic segments in :path_prefix
71
+ # for devise_for.
72
+ #
73
+ # config.default_url_options do
74
+ # { :locale => I18n.locale }
75
+ # end
76
+ end
data/test/test_helper.rb CHANGED
@@ -31,7 +31,7 @@ ActiveRecord::Schema.define(:version => 1) do
31
31
  end
32
32
  end
33
33
  class User
34
- devise :authenticatable, :invitable
34
+ devise :invitable
35
35
  end
36
36
  ActionController::Routing::Routes.draw do |map|
37
37
  map.devise_for :users
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.3
4
+ version: 0.2.0
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 00:00:00 +01:00
12
+ date: 2010-01-08 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.1
43
+ version: 0.8.0
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
@@ -94,6 +94,7 @@ files:
94
94
  - test/rails_app/config/environments/production.rb
95
95
  - test/rails_app/config/environments/test.rb
96
96
  - test/rails_app/config/initializers/backtrace_silencers.rb
97
+ - test/rails_app/config/initializers/devise.rb
97
98
  - test/rails_app/config/initializers/inflections.rb
98
99
  - test/rails_app/config/initializers/new_rails_defaults.rb
99
100
  - test/rails_app/config/initializers/session_store.rb
@@ -130,28 +131,29 @@ signing_key:
130
131
  specification_version: 3
131
132
  summary: An invitation strategy for devise
132
133
  test_files:
133
- - test/model_tests_helper.rb
134
+ - test/integration/invitable_test.rb
134
135
  - test/integration_tests_helper.rb
135
- - test/models_test.rb
136
136
  - test/mailers/invitation_test.rb
137
- - test/routes_test.rb
138
- - test/integration/invitable_test.rb
137
+ - test/model_tests_helper.rb
139
138
  - test/models/invitable_test.rb
140
- - test/test_helper.rb
141
- - test/rails_app/app/controllers/application_controller.rb
139
+ - test/models_test.rb
142
140
  - test/rails_app/app/controllers/admins_controller.rb
141
+ - test/rails_app/app/controllers/application_controller.rb
143
142
  - test/rails_app/app/controllers/home_controller.rb
144
143
  - test/rails_app/app/controllers/users_controller.rb
145
- - test/rails_app/app/models/user.rb
146
144
  - test/rails_app/app/helpers/application_helper.rb
147
- - test/rails_app/config/routes.rb
145
+ - test/rails_app/app/models/user.rb
146
+ - test/rails_app/config/boot.rb
147
+ - test/rails_app/config/environment.rb
148
+ - test/rails_app/config/environments/development.rb
149
+ - test/rails_app/config/environments/production.rb
150
+ - test/rails_app/config/environments/test.rb
148
151
  - test/rails_app/config/initializers/backtrace_silencers.rb
152
+ - test/rails_app/config/initializers/inflections.rb
149
153
  - test/rails_app/config/initializers/new_rails_defaults.rb
150
154
  - test/rails_app/config/initializers/session_store.rb
151
- - test/rails_app/config/initializers/inflections.rb
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
155
+ - test/rails_app/config/initializers/devise.rb
156
+ - test/rails_app/config/routes.rb
157
157
  - test/rails_app/vendor/plugins/devise_invitable/init.rb
158
+ - test/routes_test.rb
159
+ - test/test_helper.rb