devise_invitable 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
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', '~> 1.0.0'
15
+ gem.add_dependency 'devise', '~> 1.0.6'
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
18
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_invitable}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
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{2010-02-12}
12
+ s.date = %q{2010-05-17}
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 = [
@@ -71,7 +71,7 @@ Gem::Specification.new do |s|
71
71
  s.homepage = %q{http://github.com/scambra/devise_invitable}
72
72
  s.rdoc_options = ["--charset=UTF-8"]
73
73
  s.require_paths = ["lib"]
74
- s.rubygems_version = %q{1.3.5}
74
+ s.rubygems_version = %q{1.3.6}
75
75
  s.summary = %q{An invitation strategy for devise}
76
76
  s.test_files = [
77
77
  "test/integration/invitable_test.rb",
@@ -109,16 +109,16 @@ Gem::Specification.new do |s|
109
109
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
110
110
  s.add_development_dependency(%q<mocha>, [">= 0"])
111
111
  s.add_development_dependency(%q<webrat>, [">= 0"])
112
- s.add_runtime_dependency(%q<devise>, ["~> 1.0.0"])
112
+ s.add_runtime_dependency(%q<devise>, ["~> 1.0.6"])
113
113
  else
114
114
  s.add_dependency(%q<mocha>, [">= 0"])
115
115
  s.add_dependency(%q<webrat>, [">= 0"])
116
- s.add_dependency(%q<devise>, ["~> 1.0.0"])
116
+ s.add_dependency(%q<devise>, ["~> 1.0.6"])
117
117
  end
118
118
  else
119
119
  s.add_dependency(%q<mocha>, [">= 0"])
120
120
  s.add_dependency(%q<webrat>, [">= 0"])
121
- s.add_dependency(%q<devise>, ["~> 1.0.0"])
121
+ s.add_dependency(%q<devise>, ["~> 1.0.6"])
122
122
  end
123
123
  end
124
124
 
@@ -98,13 +98,15 @@ module Devise
98
98
  # Options must contain the user email
99
99
  def send_invitation(attributes={})
100
100
  invitable = find_or_initialize_by_email(attributes[:email])
101
- if invitable.email.blank?
102
- invitable.errors.add(:email, :blank)
103
- elsif invitable.new_record? || invitable.invited?
104
- invitable.resend_invitation!
101
+
102
+ if invitable.new_record?
103
+ invitable.errors.add(:email, :blank) if invitable.email.blank?
104
+ invitable.errors.add(:email, :invalid) unless invitable.email.match Devise::EMAIL_REGEX
105
105
  else
106
- invitable.errors.add(:email, :already_exits, :default => 'already exists')
106
+ invitable.errors.add(:email, :taken) unless invitable.invited?
107
107
  end
108
+
109
+ invitable.resend_invitation! if invitable.errors.empty?
108
110
  invitable
109
111
  end
110
112
 
@@ -53,7 +53,7 @@ class InvitationTest < ActionController::IntegrationTest
53
53
  assert_response :success
54
54
  assert_template 'invitations/new'
55
55
  assert_have_selector "input[type=text][value='#{user.email}']"
56
- assert_contain 'Email already exists'
56
+ assert_contain 'Email has already been taken'
57
57
  end
58
58
 
59
59
  test 'authenticated user should not be able to visit edit invitation page' do
@@ -30,10 +30,6 @@ class ActiveSupport::TestCase
30
30
  User.new(valid_attributes(attributes))
31
31
  end
32
32
 
33
- def create_user(attributes={})
34
- User.create!(valid_attributes(attributes))
35
- end
36
-
37
33
  def create_user_with_invitation(invitation_token, attributes={})
38
34
  user = new_user({:password => nil, :password_confirmation => nil}.update(attributes))
39
35
  user.skip_confirmation!
@@ -42,19 +38,4 @@ class ActiveSupport::TestCase
42
38
  user.save(false)
43
39
  user
44
40
  end
45
-
46
- # Execute the block setting the given values and restoring old values after
47
- # the block is executed.
48
- def swap(object, new_values)
49
- old_values = {}
50
- new_values.each do |key, value|
51
- old_values[key] = object.send key
52
- object.send :"#{key}=", value
53
- end
54
- yield
55
- ensure
56
- old_values.each do |key, value|
57
- object.send :"#{key}=", value
58
- end
59
- end
60
41
  end
@@ -92,7 +92,7 @@ class InvitableTest < ActiveSupport::TestCase
92
92
  assert_present user.invitation_token
93
93
  end
94
94
 
95
- test 'should reset reset password token and send invitation by email' do
95
+ test 'should reset invitation token and send invitation by email' do
96
96
  user = new_user
97
97
  assert_difference('ActionMailer::Base.deliveries.size') do
98
98
  token = user.invitation_token
@@ -102,7 +102,7 @@ class InvitableTest < ActiveSupport::TestCase
102
102
  end
103
103
 
104
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 => "invalid@email.com")
105
+ invited_user = User.send_invitation(:email => "valid@email.com")
106
106
  assert invited_user.errors.blank?
107
107
  assert_present invited_user.invitation_token
108
108
  end
@@ -112,13 +112,19 @@ class InvitableTest < ActiveSupport::TestCase
112
112
  user.update_attribute(:invitation_token, nil)
113
113
  invited_user = User.send_invitation(:email => user.email)
114
114
  assert_equal invited_user, user
115
- assert_equal 'already exists', invited_user.errors[:email]
115
+ assert_equal 'has already been taken', invited_user.errors[:email]
116
116
  end
117
117
 
118
118
  test 'should return a new record with errors if e-mail is blank' do
119
119
  invited_user = User.send_invitation(:email => '')
120
120
  assert invited_user.new_record?
121
- assert_equal "can't be blank", invited_user.errors[:email]
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]
122
128
  end
123
129
 
124
130
  test 'should find a user to set his password based on invitation_token' do
@@ -1,7 +1,7 @@
1
1
  require 'test/test_helper'
2
2
 
3
3
  class Invitable < User
4
- devise :authenticatable, :invitable, :invite_for => 5.days
4
+ devise :database_authenticatable, :invitable, :invite_for => 5.days
5
5
  end
6
6
 
7
7
  class ActiveRecordTest < ActiveSupport::TestCase
@@ -21,10 +21,10 @@ class ActiveRecordTest < ActiveSupport::TestCase
21
21
  end
22
22
 
23
23
  test 'add invitable module only' do
24
- assert_include_modules Invitable, :authenticatable, :invitable
24
+ assert_include_modules Invitable, :database_authenticatable, :invitable
25
25
  end
26
26
 
27
- test 'set a default value for invit_for' do
27
+ test 'set a default value for invite_for' do
28
28
  assert_equal 5.days, Invitable.invite_for
29
29
  end
30
30
 
@@ -1,4 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
- devise :authenticatable, :confirmable, :recoverable, :rememberable, :validatable
2
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :validatable
3
3
  attr_accessible :username, :email, :password, :password_confirmation
4
4
  end
@@ -1,15 +1,13 @@
1
1
  # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
2
  # four configuration values can also be set straight in your models.
3
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]
4
+ # Configure the e-mail address which will be shown in DeviseMailer.
5
+ config.mailer_sender = "please-change-me@config-initializers-devise.com"
6
+
7
+ # Configure the content type of DeviseMailer mails (defaults to text/html")
8
+ # config.mailer_content_type = "text/plain"
12
9
 
10
+ # ==> Configuration for :authenticatable
13
11
  # Invoke `rake secret` and use the printed value to setup a pepper to generate
14
12
  # the encrypted password. By default no pepper is used.
15
13
  # config.pepper = "rake secret output"
@@ -18,10 +16,10 @@ Devise.setup do |config|
18
16
  # config.stretches = 10
19
17
 
20
18
  # 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)
19
+ # (default), :sha512 and :bcrypt. Devise also supports encryptors from others
20
+ # authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
21
+ # stretches above to 20 for default behavior) and :restful_authentication_sha1
22
+ # (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
25
23
  # config.encryptor = :sha1
26
24
 
27
25
  # Configure which keys are used when authenticating an user. By default is
@@ -31,21 +29,43 @@ Devise.setup do |config|
31
29
  # session. If you need permissions, you should implement that in a before filter.
32
30
  # config.authentication_keys = [ :email ]
33
31
 
32
+ # The realm used in Http Basic Authentication
33
+ # config.http_authentication_realm = "Application"
34
+
35
+ # ==> Configuration for :confirmable
34
36
  # The time you want give to your user to confirm his account. During this time
35
37
  # he will be able to access your application without confirming. Default is nil.
36
38
  # config.confirm_within = 2.days
37
39
 
40
+ # ==> Configuration for :rememberable
38
41
  # The time the user will be remembered without asking for credentials again.
39
42
  # config.remember_for = 2.weeks
40
43
 
44
+ # ==> Configuration for :timeoutable
41
45
  # The time you want to timeout the user session without activity. After this
42
46
  # time the user will be asked for credentials again.
43
47
  # config.timeout_in = 10.minutes
44
48
 
45
- # Configure the e-mail address which will be shown in DeviseMailer.
46
- # config.mailer_sender = "foo.bar@yourapp.com"
49
+ # ==> Configuration for :lockable
50
+ # Number of authentication tries before locking an account.
51
+ # config.maximum_attempts = 20
52
+
53
+ # Defines which strategy will be used to unlock an account.
54
+ # :email = Sends an unlock link to the user email
55
+ # :time = Reanables login after a certain ammount of time (see :unlock_in below)
56
+ # :both = enables both strategies
57
+ # config.unlock_strategy = :both
47
58
 
48
- # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
59
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
60
+ # config.unlock_in = 1.hour
61
+
62
+ # ==> Configuration for :token_authenticatable
63
+ # Defines name of the authentication token params key
64
+ # config.token_authentication_key = :auth_token
65
+
66
+ # ==> General configuration
67
+ # Load and configure the ORM. Supports :active_record (default), :mongo_mapper
68
+ # (requires mongo_ext installed) and :data_mapper (experimental).
49
69
  # require 'devise/orm/mongo_mapper'
50
70
  # config.orm = :mongo_mapper
51
71
 
@@ -54,6 +74,16 @@ Devise.setup do |config|
54
74
  # are using only default views.
55
75
  # config.scoped_views = true
56
76
 
77
+ # By default, devise detects the role accessed based on the url. So whenever
78
+ # accessing "/users/sign_in", it knows you are accessing an User. This makes
79
+ # routes as "/sign_in" not possible, unless you tell Devise to use the default
80
+ # scope, setting true below.
81
+ # config.use_default_scope = true
82
+
83
+ # Configure the default scope used by Devise. By default it's the first devise
84
+ # role declared in your routes.
85
+ # config.default_scope = :user
86
+
57
87
  # If you want to use other strategies, that are not (yet) supported by Devise,
58
88
  # you can configure them inside the config.warden block. The example below
59
89
  # allows you to setup OAuth, using http://github.com/roman/warden_oauth
@@ -69,7 +99,6 @@ Devise.setup do |config|
69
99
 
70
100
  # Configure default_url_options if you are using dynamic segments in :path_prefix
71
101
  # for devise_for.
72
- #
73
102
  # config.default_url_options do
74
103
  # { :locale => I18n.locale }
75
104
  # end
@@ -21,7 +21,7 @@ ActiveRecord::Base.logger = Logger.new(nil)
21
21
 
22
22
  ActiveRecord::Schema.define(:version => 1) do
23
23
  create_table :users do |t|
24
- t.authenticatable :null => true
24
+ t.database_authenticatable :null => true
25
25
  t.string :username
26
26
  t.confirmable
27
27
  t.invitable
@@ -30,7 +30,7 @@ ActiveRecord::Schema.define(:version => 1) do
30
30
  end
31
31
  end
32
32
  class User
33
- devise :authenticatable, :invitable
33
+ devise :database_authenticatable, :invitable
34
34
  end
35
35
  ActionController::Routing::Routes.draw do |map|
36
36
  map.devise_for :users
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 3
9
+ version: 0.2.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Sergio Cambra
@@ -9,39 +14,47 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-12 00:00:00 +01:00
17
+ date: 2010-05-17 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: mocha
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: webrat
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
33
41
  version: "0"
34
- version:
42
+ type: :development
43
+ version_requirements: *id002
35
44
  - !ruby/object:Gem::Dependency
36
45
  name: devise
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ~>
42
50
  - !ruby/object:Gem::Version
43
- version: 1.0.0
44
- version:
51
+ segments:
52
+ - 1
53
+ - 0
54
+ - 6
55
+ version: 1.0.6
56
+ type: :runtime
57
+ version_requirements: *id003
45
58
  description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password
46
59
  email: sergio@entrecables.com
47
60
  executables: []
@@ -115,18 +128,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
128
  requirements:
116
129
  - - ">="
117
130
  - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
118
133
  version: "0"
119
- version:
120
134
  required_rubygems_version: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
124
140
  version: "0"
125
- version:
126
141
  requirements: []
127
142
 
128
143
  rubyforge_project:
129
- rubygems_version: 1.3.5
144
+ rubygems_version: 1.3.6
130
145
  signing_key:
131
146
  specification_version: 3
132
147
  summary: An invitation strategy for devise