devise_invitable 1.7.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_invitable might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.rdoc +75 -82
  4. data/app/controllers/devise/invitations_controller.rb +10 -10
  5. data/app/controllers/devise_invitable/registrations_controller.rb +1 -1
  6. data/app/views/devise/invitations/edit.html.erb +14 -8
  7. data/app/views/devise/invitations/new.html.erb +11 -7
  8. data/lib/devise_invitable.rb +3 -3
  9. data/lib/devise_invitable/controllers/helpers.rb +1 -1
  10. data/lib/devise_invitable/mailer.rb +1 -1
  11. data/lib/devise_invitable/mapping.rb +1 -1
  12. data/lib/devise_invitable/models.rb +17 -17
  13. data/lib/devise_invitable/routes.rb +4 -4
  14. data/lib/devise_invitable/version.rb +1 -1
  15. data/lib/generators/active_record/devise_invitable_generator.rb +3 -3
  16. data/lib/generators/devise_invitable/devise_invitable_generator.rb +4 -8
  17. data/lib/generators/devise_invitable/install_generator.rb +7 -11
  18. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +10 -6
  19. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +10 -6
  20. data/lib/generators/devise_invitable/views_generator.rb +6 -6
  21. data/test/functional/registrations_controller_test.rb +24 -25
  22. data/test/integration/invitation_remove_test.rb +8 -8
  23. data/test/integration/invitation_test.rb +46 -46
  24. data/test/integration_tests_helper.rb +8 -8
  25. data/test/model_tests_helper.rb +5 -5
  26. data/test/models/invitable_test.rb +110 -110
  27. data/test/models_test.rb +3 -3
  28. data/test/orm/active_record.rb +2 -2
  29. data/test/orm/mongoid.rb +2 -2
  30. data/test/rails_app/app/controllers/admins_controller.rb +1 -1
  31. data/test/rails_app/app/controllers/application_controller.rb +1 -1
  32. data/test/rails_app/app/controllers/users_controller.rb +2 -2
  33. data/test/rails_app/app/models/admin.rb +7 -10
  34. data/test/rails_app/app/models/octopussy.rb +4 -4
  35. data/test/rails_app/app/models/user.rb +20 -20
  36. data/test/rails_app/app/views/admins/new.html.erb +9 -5
  37. data/test/rails_app/app/views/devise/sessions/new.html.erb +14 -6
  38. data/test/rails_app/app/views/free_invitations/new.html.erb +9 -5
  39. data/test/rails_app/app/views/layouts/application.html.erb +3 -4
  40. data/test/rails_app/app/views/users/invitations/new.html.erb +15 -9
  41. data/test/rails_app/config/application.rb +6 -6
  42. data/test/rails_app/config/boot.rb +2 -2
  43. data/test/rails_app/config/credentials.yml.enc +1 -0
  44. data/test/rails_app/config/initializers/session_store.rb +1 -1
  45. data/test/rails_app/config/initializers/wrap_parameters.rb +1 -1
  46. data/test/rails_app/config/master.key +1 -0
  47. data/test/rails_app/config/routes.rb +3 -3
  48. data/test/routes_test.rb +4 -4
  49. data/test/test_helper.rb +2 -2
  50. metadata +22 -20
  51. data/test/rails_app/config/initializers/secret_token.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51e6d03ee4dd325ebd51b67efc8efb5916b30031842c5bd327f6597bdc149b96
4
- data.tar.gz: 5fa1f5d1470086846959e4cf20a4d1161db9bd9a6030f82de8941e62db2bc157
3
+ metadata.gz: 2723ccf2ae328662f6728a699ac484ff5067dbb24248e59d7d596a9d445747ab
4
+ data.tar.gz: 7d95b8d919685e863dbe8126ce5823b78f949c67f6ada3e69adab431d29e7711
5
5
  SHA512:
6
- metadata.gz: 2f522400741c8c5668a51ec81864739d8cc4d295912e58f7b060b2532f3b1110290db2a0b4201d0522baa163b485c6ba53f225128d9b4288007f428e2ab0918b
7
- data.tar.gz: fe2b630bb65a1e30a939cd2c3b0cf2a6b86488e2acc728792935fdf358e73c414c3e5a06a82c8ce7a003e10c7614251ba085cc4b797ddfd9480da1b28a28cbf1
6
+ metadata.gz: ba422fbe6c9b3d7d13dae30f24daf9638ace499ceead90f7d3d18949655028b33d53c5275000aafecd4a9b75595ad174d3348a4511a7dbe70957bd9a43cd5945
7
+ data.tar.gz: b8eb68401a1fd5e41b861fbe8d8dd38b4f9050d87427d00cb5ea394630e5e5f5a16d6889da85199e597d8bdc2947aa8523208aca95fb731d39c50ba9f5d4a4d5
@@ -1,3 +1,9 @@
1
+ ## 2.0.0
2
+ - Remove deprecated devise_error_messages! from templates ([#786](https://github.com/scambra/devise_invitable/pull/785))
3
+ - Drop Devise < 4.6 support ([#786](https://github.com/scambra/devise_invitable/pull/786))
4
+ - Drop Rails 4.2 support ([#785](https://github.com/scambra/devise_invitable/pull/785))
5
+ - Drop Ruby 2.1 support
6
+
1
7
  ## 1.7.5
2
8
  - Add add_taken_error ([#768](https://github.com/scambra/devise_invitable/pull/768))
3
9
  - Add invitation_taken? ([#769](https://github.com/scambra/devise_invitable/pull/769))
@@ -1,27 +1,27 @@
1
1
  = DeviseInvitable
2
- {<img src="https://badge.fury.io/rb/devise_invitable.svg"/>}[http://badge.fury.io/rb/devise_invitable] {<img src="https://travis-ci.org/scambra/devise_invitable.png"/>}[https://travis-ci.org/scambra/devise_invitable] {<img src="https://codeclimate.com/github/scambra/devise_invitable/badges/gpa.svg"/}[https://codeclimate.com/github/scambra/devise_invitable]
2
+ {<img src="https://badge.fury.io/rb/devise_invitable.svg"/>}[http://badge.fury.io/rb/devise_invitable] {<img src="https://travis-ci.org/scambra/devise_invitable.png"/>}[https://travis-ci.org/scambra/devise_invitable] {<img src="https://codeclimate.com/github/scambra/devise_invitable/badges/gpa.svg"/>}[https://codeclimate.com/github/scambra/devise_invitable]
3
3
 
4
- It adds support to devise[https://github.com/plataformatec/devise] for sending invitations by email (it requires to be authenticated) and accept the invitation setting the password.
4
+ It adds support to Devise[https://github.com/plataformatec/devise] for sending invitations by email (it requires to be authenticated) and accept the invitation setting the password.
5
5
 
6
- It works with Devise >= 4.0
7
- If you want to use devise 3.0.x, you must use 1.2.1 or lower
8
- If you want to use devise 3.1.x, you must use 1.3.2 or lower
9
- If you want to use devise >= 3.2, you must use 1.6.1 or lower
6
+ == Requirements
7
+
8
+ The latest version of DeviseInvitable works with Devise >= 4.6.
9
+
10
+ If you want to use devise_invitable with earlier Devise releases (4.0 <= x < 4.6), use version 1.7.5.
10
11
 
11
12
  == Installation
12
13
 
13
- Install DeviseInvitable gem, it will also install dependencies (such as devise and warden):
14
+ Install DeviseInvitable gem:
14
15
 
15
16
  gem install devise_invitable
16
17
 
17
- Add DeviseInvitable to your Gemfile (and Devise if you weren't using them):
18
+ Add DeviseInvitable to your Gemfile:
18
19
 
19
- gem 'devise', '~> 4.2'
20
- gem 'devise_invitable', '~> 1.7.0'
20
+ gem 'devise_invitable', '~> 2.0.0'
21
21
 
22
22
  === Automatic installation
23
23
 
24
- Run the following generator to add DeviseInvitable’s configuration option in the Devise configuration file (config/initializers/devise.rb):
24
+ Run the following generator to add DeviseInvitable’s configuration option in the Devise configuration file (<tt>config/initializers/devise.rb</tt>):
25
25
 
26
26
  rails generate devise_invitable:install
27
27
 
@@ -29,21 +29,21 @@ When you are done, you are ready to add DeviseInvitable to any of your Devise mo
29
29
 
30
30
  rails generate devise_invitable MODEL
31
31
 
32
- Replace MODEL by the class name you want to add DeviseInvitable, like User, Admin, etc. This will add the :invitable flag to your model's Devise modules. The generator will also create a migration file (if your ORM supports them). Continue reading this file to understand exactly what the generator produces and how to use it.
32
+ Replace MODEL by the class name you want to add DeviseInvitable, like <tt>User</tt>, <tt>Admin</tt>, etc. This will add the <tt>:invitable</tt> flag to your model's Devise modules. The generator will also create a migration file (if your ORM supports them).
33
33
 
34
34
  === Manual installation
35
35
 
36
36
  Follow the walkthrough for Devise and after it's done, follow this walkthrough.
37
37
 
38
38
  == Devise Configuration
39
- Add :invitable to the <tt>devise</tt> call in your model (we’re assuming here you already have a User model with some Devise modules):
39
+ Add <tt>:invitable</tt> to the <tt>devise</tt> call in your model (we’re assuming here you already have a User model with some Devise modules):
40
40
 
41
41
  class User < ActiveRecord::Base
42
42
  devise :database_authenticatable, :confirmable, :invitable
43
43
  end
44
44
 
45
45
  == ActiveRecord Migration
46
- Add t.invitable to your Devise model migration:
46
+ Add <tt>t.invitable</tt> to your Devise model migration:
47
47
 
48
48
  create_table :users do
49
49
  ...
@@ -57,7 +57,7 @@ Add t.invitable to your Devise model migration:
57
57
  t.string :invited_by_type
58
58
  ...
59
59
  end
60
- add_index :users, :invitation_token, :unique => true
60
+ add_index :users, :invitation_token, unique: true
61
61
 
62
62
  or for a model that already exists, define a migration to add DeviseInvitable to your model:
63
63
 
@@ -69,7 +69,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
69
69
  add_column :users, :invitation_limit, :integer
70
70
  add_column :users, :invited_by_id, :integer
71
71
  add_column :users, :invited_by_type, :string
72
- add_index :users, :invitation_token, :unique => true
72
+ add_index :users, :invitation_token, unique: true
73
73
 
74
74
  # Allow null encrypted_password
75
75
  change_column_null :users, :encrypted_password, :string, true
@@ -77,14 +77,14 @@ or for a model that already exists, define a migration to add DeviseInvitable to
77
77
  change_column_null :users, :password_salt, :string, true
78
78
  end
79
79
 
80
- If you previously used devise_invitable with a :limit on :invitation_token, remove it:
80
+ If you previously used devise_invitable with a <tt>:limit</tt> on <tt>:invitation_token</tt>, remove it:
81
81
 
82
82
  def up
83
- change_column :users, :invitation_token, :string, :limit => nil
83
+ change_column :users, :invitation_token, :string, limit: nil
84
84
  end
85
85
 
86
86
  def down
87
- change_column :users, :invitation_token, :string, :limit => 60
87
+ change_column :users, :invitation_token, :string, limit: 60
88
88
  end
89
89
 
90
90
  == Mongoid Field Definitions
@@ -96,11 +96,11 @@ If you are using Mongoid, define the following fields and indexes within your in
96
96
  field :invitation_accepted_at, type: Time
97
97
  field :invitation_limit, type: Integer
98
98
 
99
- index( {invitation_token: 1}, {:background => true} )
100
- index( {invitation_by_id: 1}, {:background => true} )
99
+ index( { invitation_token: 1 }, { background: true} )
100
+ index( { invitation_by_id: 1 }, { background: true} )
101
101
 
102
- You do not need to define a belongs_to relationship, as DeviseInvitable does this on your behalf:
103
- belongs_to :invited_by, :polymorphic => true
102
+ You do not need to define a <tt>belongs_to</tt> relationship, as DeviseInvitable does this on your behalf:
103
+ belongs_to :invited_by, polymorphic: true
104
104
 
105
105
  Remember to create indexes within the MongoDB database after deploying your changes.
106
106
  rake db:mongoid:create_indexes
@@ -109,7 +109,7 @@ Remember to create indexes within the MongoDB database after deploying your chan
109
109
 
110
110
  DeviseInvitable adds some new configuration options:
111
111
 
112
- * invite_for: The period the generated invitation token is valid, after this period, the invited resource won't be able to accept the invitation. When invite_for is 0 (the default), the invitation won't expire.
112
+ * <tt>invite_for</tt>: The period the generated invitation token is valid, after this period, the invited resource won't be able to accept the invitation. When <tt>invite_for</tt> is <tt>0</tt> (the default), the invitation won't expire.
113
113
 
114
114
  You can set this configuration option in the Devise initializer as follow:
115
115
 
@@ -121,27 +121,27 @@ You can set this configuration option in the Devise initializer as follow:
121
121
 
122
122
  or directly as parameters to the <tt>devise</tt> method:
123
123
 
124
- devise :database_authenticatable, :confirmable, :invitable, :invite_for => 2.weeks
124
+ devise :database_authenticatable, :confirmable, :invitable, invite_for: 2.weeks
125
125
 
126
- * invitation_limit: The number of invitations users can send. The default value of nil means users can send as many invites as they want, there is no limit for any user, invitation_limit column is not used. A setting of 0 means they can't send invitations. A setting n > 0 means they can send n invitations. You can change invitation_limit column for some users so they can send more or less invitations, even with global invitation_limit = 0.
126
+ * <tt>invitation_limit</tt>: The number of invitations users can send. The default value of <tt>nil</tt> means users can send as many invites as they want, there is no limit for any user, <tt>invitation_limit</tt> column is not used. A setting of <tt>0</tt> means they can't send invitations. A setting <tt>n > 0</tt> means they can send <tt>n</tt> invitations. You can change <tt>invitation_limit</tt> column for some users so they can send more or less invitations, even with global <tt>invitation_limit = 0</tt>.
127
127
 
128
- * invite_key: The key to be used to check existing users when sending an invitation. You can use multiple keys. This value must be a hash with the invite key as hash keys, and values that respond to the === operator(includes procs and regexes). The default value is looking for users by email and validating with Devise.email_regexp {:email => Devise.email_regexp}.
128
+ * <tt>invite_key</tt>: The key to be used to check existing users when sending an invitation. You can use multiple keys. This value must be a hash with the invite key as hash keys, and values that respond to the <tt>===</tt> operator (including procs and regexes). The default value is looking for users by email and validating with <tt>Devise.email_regexp</tt>.
129
129
 
130
- * validate_on_invite: force a record to be valid before being actually invited.
130
+ * <tt>validate_on_invite</tt>: force a record to be valid before being actually invited.
131
131
 
132
- * resend_invitation: resend invitation if user with invited status is invited again. Enabled by default.
132
+ * <tt>resend_invitation</tt>: resend invitation if user with invited status is invited again. Enabled by default.
133
133
 
134
- * invited_by_class_name: the class name of the inviting model. If this is nil, polymorphic association is used.
134
+ * <tt>invited_by_class_name</tt>: the class name of the inviting model. If this is <tt>nil</tt>, polymorphic association is used.
135
135
 
136
- * invited_by_foreign_key: the foreign key to the inviting model (only used if invited_by_class_name is set, otherwise :invited_by_id)
136
+ * <tt>invited_by_foreign_key</tt>: the foreign key to the inviting model (only used if <tt>invited_by_class_name</tt> is set, otherwise <tt>:invited_by_id</tt>)
137
137
 
138
- * invited_by_counter_cache: the column name used for counter_cache column. If this is nil (default value), the invited_by association is declared without counter_cache.
138
+ * <tt>invited_by_counter_cache</tt>: the column name used for counter_cache column. If this is <tt>nil</tt> (default value), the <tt>invited_by</tt> association is declared without <tt>counter_cache</tt>.
139
139
 
140
- * allow_insecure_sign_in_after_accept: automatically sign in the user after they set a password. Enabled by default.
140
+ * <tt>allow_insecure_sign_in_after_accept</tt>: automatically sign in the user after they set a password. Enabled by default.
141
141
 
142
- * require_password_on_accepting: require password when user accepts the invitation. Enabled by default. Disable if you don't want to ask or enforce to set password while accepting, because is set when user is invited or it will be set later.
142
+ * <tt>require_password_on_accepting</tt>: require password when user accepts the invitation. Enabled by default. Disable if you don't want to ask or enforce to set password while accepting, because is set when user is invited or it will be set later.
143
143
 
144
- For more details, see <tt>config/initializers/devise.rb</tt> (after you invoked the "devise_invitable:install" generator described above).
144
+ For more details, see <tt>config/initializers/devise.rb</tt> (after you invoked the <tt>devise_invitable:install</tt> generator described above).
145
145
 
146
146
  == Configuring views
147
147
 
@@ -153,7 +153,7 @@ You can also use the generator to generate scoped views:
153
153
 
154
154
  rails generate devise_invitable:views users
155
155
 
156
- Then turn scoped views on in config/initializers/devise.rb:
156
+ Then turn scoped views on in <tt>config/initializers/devise.rb</tt>:
157
157
 
158
158
  config.scoped_views = true
159
159
 
@@ -161,7 +161,7 @@ Please refer to {Devise's README}[https://github.com/plataformatec/devise] for m
161
161
 
162
162
  == Configuring controllers
163
163
 
164
- To change the controller's behavior, create a controller that inherits from <tt>Devise::InvitationsController</tt>. The available methods are: new, create, edit, and update. You should read the {original controllers source}[https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb] before editing any of these actions. Your controller might now look something like this:
164
+ To change the controller's behavior, create a controller that inherits from <tt>Devise::InvitationsController</tt>. The available methods are: <tt>new</tt>, <tt>create</tt>, <tt>edit</tt>, and <tt>update</tt>. Refer to the {original controllers source}[https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb] before editing any of these actions. Your controller might now look something like this:
165
165
 
166
166
  class Users::InvitationsController < Devise::InvitationsController
167
167
  def update
@@ -173,9 +173,9 @@ To change the controller's behavior, create a controller that inherits from <tt>
173
173
  end
174
174
  end
175
175
 
176
- Now just tell Devise that you want to use your controller, the controller above is 'users/invitations', so our routes.rb would have this line:
176
+ Now just tell Devise that you want to use your controller, the controller above is <tt>'users/invitations'</tt>, so our routes.rb would have this line:
177
177
 
178
- devise_for :users, :controllers => { :invitations => 'users/invitations' }
178
+ devise_for :users, controllers: { invitations: 'users/invitations' }
179
179
 
180
180
  be sure that you generate the views and put them into the controller that you generated, so for this example it would be:
181
181
 
@@ -207,12 +207,12 @@ To change behaviour of inviting or accepting users, you can simply override two
207
207
 
208
208
  == Strong Parameters
209
209
 
210
- When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing DeviseInvitable to handle this concern at the controller as well. Read about it in {devise README}[https://github.com/plataformatec/devise#strong-parameters]
210
+ When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing DeviseInvitable to handle this concern at the controller as well. Read about it in {Devise README}[https://github.com/plataformatec/devise#strong-parameters]
211
211
 
212
212
  There are just two actions in DeviseInvitable that allows any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permited parameters by default are:
213
213
 
214
- * invite (Devise::InvitationsController#create) - Permits only the authentication keys (like email)
215
- * accept_invitation (Devise::InvitationsController#update) - Permits invitation_token plus password and password_confirmation
214
+ * <tt>invite</tt> (Devise::InvitationsController#create) - Permits only the authentication keys (like <tt>email</tt>)
215
+ * <tt>accept_invitation</tt> (Devise::InvitationsController#update) - Permits <tt>invitation_token</tt> plus <tt>password</tt> and <tt>password_confirmation</tt>.
216
216
 
217
217
  Here is an example of what your application controller might need to include in order to add these parameters to the invitation view:
218
218
 
@@ -220,9 +220,9 @@ Here is an example of what your application controller might need to include in
220
220
 
221
221
  protected
222
222
 
223
- def configure_permitted_parameters
224
- devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name, :phone])
225
- end
223
+ def configure_permitted_parameters
224
+ devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name, :phone])
225
+ end
226
226
 
227
227
 
228
228
  == Usage
@@ -231,12 +231,12 @@ Here is an example of what your application controller might need to include in
231
231
 
232
232
  To send an invitation to a user, use the <tt>invite!</tt> class method. <b>Note: This will create a user, and send an email for the invite.</b> <tt>:email</tt> must be present in the parameters hash. You can also include other attributes in the hash. The record will not be validated.
233
233
 
234
- User.invite!(:email => "new_user@example.com", :name => "John Doe")
234
+ User.invite!(email: 'new_user@example.com', name: 'John Doe')
235
235
  # => an invitation email will be sent to new_user@example.com
236
236
 
237
- If you want to create the invitation but not send it, you can set <tt>skip_invitation</tt> to true.
237
+ If you want to create the invitation but not send it, you can set <tt>skip_invitation</tt> to <tt>true</tt>.
238
238
 
239
- user = User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
239
+ user = User.invite!(email: 'new_user@example.com', name: 'John Doe') do |u|
240
240
  u.skip_invitation = true
241
241
  end
242
242
  # => the record will be created, but the invitation email will not be sent
@@ -244,32 +244,30 @@ If you want to create the invitation but not send it, you can set <tt>skip_invit
244
244
  When generating the <tt>accept_user_invitation_url</tt> yourself, you must use the <tt>raw_invitation_token</tt>
245
245
  the value is temporarily available when you invite a user and will be decrypted when recieved.
246
246
 
247
- accept_user_invitation_url(:invitation_token => user.raw_invitation_token)
247
+ accept_user_invitation_url(invitation_token: user.raw_invitation_token)
248
248
 
249
- When <tt>skip_invitation</tt> is used, you must also then set the <tt>invitation_sent_at</tt> field when the user is sent their
250
- token. Failure to do so will yield <tt>Invalid invitation token</tt> error when the user attempts to accept the invite.
249
+ When <tt>skip_invitation</tt> is used, you must also then set the <tt>invitation_sent_at</tt> field when the user is sent their token. Failure to do so will yield "Invalid invitation token" error when the user attempts to accept the invite.
251
250
  You can set column, or call <tt>deliver_invitation</tt> to sent invitation and set column:
252
251
 
253
252
  user.deliver_invitation
254
253
 
255
254
  You can add <tt>:skip_invitation</tt> to attributes hash if <tt>skip_invitation</tt> is added to <tt>attr_accessible</tt>.
256
255
 
257
- User.invite!(:email => "new_user@example.com", :name => "John Doe", :skip_invitation => true)
256
+ User.invite!(email: 'new_user@example.com', name: 'John Doe', skip_invitation: true)
258
257
  # => the record will be created, but the invitation email will not be sent
259
258
 
260
259
  <tt>skip_invitation</tt> skips sending the email, but sets <tt>invitation_token</tt>, so <tt>invited_to_sign_up?</tt> on the
261
- resulting user returns true.
260
+ resulting user returns <tt>true</tt>.
262
261
 
263
262
  To check if a particular user is created by invitation, irrespective to state of invitation one can use <tt>created_by_invite?</tt>
264
263
 
265
264
  **Warning**
266
265
 
267
- When using skip_invitation you must send the email with the user object instance that generated the tokens, as
268
- user.raw_invitation_token is available only to the instance and is not persisted in the database.
266
+ When using <tt>skip_invitation</tt> you must send the email with the user object instance that generated the tokens, as <tt>user.raw_invitation_token</tt> is available only to the instance and is not persisted in the database.
269
267
 
270
268
  You can also set <tt>invited_by</tt> when using the <tt>invite!</tt> class method:
271
269
 
272
- User.invite!({:email => "new_user@example.com"}, current_user) # current_user will be set as invited_by
270
+ User.invite!({ email: 'new_user@example.com' }, current_user) # current_user will be set as invited_by
273
271
 
274
272
  === Sending an invitation after user creation
275
273
 
@@ -284,12 +282,11 @@ To find by invitation token use the <tt>find_by_invitation_token</tt> class meth
284
282
 
285
283
  user = User.find_by_invitation_token(params[:invitation_token], true)
286
284
 
287
-
288
285
  === Accept an invitation
289
286
 
290
287
  To accept an invitation with a token use the <tt>accept_invitation!</tt> class method. <tt>:invitation_token</tt> must be present in the parameters hash. You can also include other attributes in the hash.
291
288
 
292
- User.accept_invitation!(:invitation_token => params[:invitation_token], :password => "ad97nwj3o2", :name => "John Doe")
289
+ User.accept_invitation!(invitation_token: params[:invitation_token], password: 'ad97nwj3o2', name: 'John Doe')
293
290
 
294
291
  === Callbacks
295
292
 
@@ -306,7 +303,7 @@ A callback event is fired before and after an invitation is created (User#invite
306
303
  # ...
307
304
  end
308
305
 
309
- The callbacks support all options and arguments available to the standard callbacks provided by AR.
306
+ The callbacks support all options and arguments available to the standard callbacks provided by ActiveRecord.
310
307
 
311
308
  === Scopes
312
309
 
@@ -321,30 +318,30 @@ A pair of scopes to find those users that have accepted, and those that have not
321
318
  Since the invitations controller take care of all the creation/acceptation of an invitation, in most cases you wouldn't call the <tt>invite!</tt> and <tt>accept_invitation!</tt> methods directly.
322
319
  Instead, in your views, put a link to <tt>new_user_invitation_path</tt> or <tt>new_invitation_path(:user)</tt> or even <tt>/users/invitation/new</tt> to prepare and send an invitation (to a user in this example).
323
320
 
324
- After an invitation is created and sent, the inviter will be redirected to after_invite_path_for(inviter, invitee), which is the same path as signed_in_root_path by default.
321
+ After an invitation is created and sent, the inviter will be redirected to <tt>after_invite_path_for(inviter, invitee)</tt>, which is the same path as <tt>signed_in_root_path</tt> by default.
325
322
 
326
- After an invitation is accepted, the invitee will be redirected to after_accept_path_for(resource), which is the same path as signed_in_root_path by default. If you want to override the path, override invitations controller and define after_accept_path_for method. This is useful in the common case that a user is invited to a specific location in your application. More on {Devise's README}[https://github.com/plataformatec/devise], "Controller filters and helpers" section.
323
+ After an invitation is accepted, the invitee will be redirected to <tt>after_accept_path_for(resource)</tt>, which is the same path as <tt>signed_in_root_path</tt> by default. If you want to override the path, override invitations controller and define <tt>after_accept_path_for</tt> method. This is useful in the common case that a user is invited to a specific location in your application. More on {Devise's README}[https://github.com/plataformatec/devise], "Controller filters and helpers" section.
327
324
 
328
- The invitation email includes a link to accept the invitation that looks like this: <tt>/users/invitation/accept?invitation_token=abcd123</tt>. When clicked, the invited must set a password in order to accept its invitation. Note that if the invitation_token is not present or not valid, the invited is redirected to after_sign_out_path_for(resource_name).
325
+ The invitation email includes a link to accept the invitation that looks like this: <tt>/users/invitation/accept?invitation_token=abcd123</tt>. When clicked, the invited must set a password in order to accept its invitation. Note that if the <tt>invitation_token</tt> is not present or not valid, the invited is redirected to <tt>after_sign_out_path_for(resource_name)</tt>.
329
326
 
330
- The controller sets the invited_by_id attribute for the new user to the current user. This will let you easily keep track of who invited who.
327
+ The controller sets the <tt>invited_by_id</tt> attribute for the new user to the current user. This will let you easily keep track of who invited who.
331
328
 
332
329
  == Controller filter
333
330
 
334
- InvitationsController uses authenticate_inviter! filter to restrict who can send invitations. You can override this method in your ApplicationController.
331
+ InvitationsController uses <tt>authenticate_inviter!</tt> filter to restrict who can send invitations. You can override this method in your <tt>ApplicationController</tt>.
335
332
 
336
- Default behavior requires authentication of the same resource as the invited one. For example, if your model User is invitable, it will allow all authenticated users to send invitations to other users.
333
+ Default behavior requires authentication of the same resource as the invited one. For example, if your model <tt>User</tt> is invitable, it will allow all authenticated users to send invitations to other users.
337
334
 
338
- You would have a User model which is configured as invitable and an Admin model which is not. If you want to allow only admins to send invitations, simply overwrite the authenticate_inviter! method as follow:
335
+ You would have a <tt>User</tt> model which is configured as invitable and an <tt>Admin</tt> model which is not. If you want to allow only admins to send invitations, simply overwrite the <tt>authenticate_inviter!</tt> method as follow:
339
336
 
340
337
  class ApplicationController < ActionController::Base
341
338
  protected
342
339
  def authenticate_inviter!
343
- authenticate_admin!(:force => true)
340
+ authenticate_admin!(force: true)
344
341
  end
345
342
  end
346
343
 
347
- And include DeviseInvitable::Inviter module into Admin model:
344
+ And include <tt>DeviseInvitable::Inviter</tt> module into <tt>Admin</tt> model:
348
345
 
349
346
  class Admin < ActiveRecord::Base
350
347
  devise :database_authenticatable, :validatable
@@ -353,15 +350,15 @@ And include DeviseInvitable::Inviter module into Admin model:
353
350
 
354
351
  == Has many invitations
355
352
 
356
- If you want to get all records invited by a resource, you should define has_many association in the model allowed to send invitations.
353
+ If you want to get all records invited by a resource, you should define <tt>has_many</tt> association in the model allowed to send invitations.
357
354
 
358
355
  For the default behavior, define it like this:
359
356
 
360
- has_many :invitations, :class_name => self.to_s, :as => :invited_by
357
+ has_many :invitations, class_name: self.to_s, as: :invited_by
361
358
 
362
359
  For the previous example, where admins send invitations to users, define it like this:
363
360
 
364
- has_many :invitations, :class_name => 'User', :as => :invited_by
361
+ has_many :invitations, class_name: 'User', as: :invited_by
365
362
 
366
363
  == I18n
367
364
 
@@ -395,9 +392,9 @@ The DeviseInvitable mailer uses the same pattern as Devise to create mail subjec
395
392
  subject: 'You got an invitation!'
396
393
  user_subject: 'You got a user invitation!'
397
394
 
398
- Take a look at the generated locale file (in <tt>config/locales/devise_invitable.en.yml</tt>) to check all available messages.
395
+ Take a look at the {generated locale file}[https://github.com/scambra/devise_invitable/blob/master/config/locales/en.yml] to check all available messages.
399
396
 
400
- Translations are not included in gem (and they won't), they are available at wiki[https://github.com/scambra/devise_invitable/wiki/I18n].
397
+ Check out wiki[https://github.com/scambra/devise_invitable/wiki/I18n] for translations.
401
398
 
402
399
  === Use with sub schema
403
400
  If you are using sub schema in you application, you need to make sure that you are prioritizing your sub schema scheme over Warden in Rack.
@@ -406,7 +403,7 @@ For instance, if you are using the Apartment gem go inside your <tt>config/appli
406
403
  module YourSite
407
404
  class Application < Rails::Application
408
405
  ...
409
- Rails.application.config.middleware.insert_before "Warden::Manager", Apartment::Elevators::Subdomain
406
+ Rails.application.config.middleware.insert_before Warden::Manager, Apartment::Elevators::Subdomain
410
407
  end
411
408
  end
412
409
 
@@ -422,14 +419,10 @@ https://github.com/scambra/devise_invitable/wiki
422
419
 
423
420
  == Testing
424
421
 
425
- To test DeviseInvitable for the ActiveRecord ORM with RVM, Ruby 2.2.2:
422
+ To run tests:
426
423
 
427
- rvm use 2.2.2
428
- rvm gemset create devise_invitable
429
- rvm gemset use devise_invitable
430
- gem install bundler
431
- bundle
432
- rake test DEVISE_ORM=active_record
424
+ bundle install
425
+ bundle exec rake test
433
426
 
434
427
  == Contributors
435
428
 
@@ -449,4 +442,4 @@ Special thanks to rymai[https://github.com/rymai] for the Rails 3 support, his f
449
442
 
450
443
  == Copyright
451
444
 
452
- Copyright (c) 2014 Sergio Cambra. See LICENSE for details.
445
+ Copyright (c) 2019 Sergio Cambra. See LICENSE for details.
@@ -1,8 +1,8 @@
1
1
  class Devise::InvitationsController < DeviseController
2
- prepend_before_action :authenticate_inviter!, :only => [:new, :create]
3
- prepend_before_action :has_invitations_left?, :only => [:create]
4
- prepend_before_action :require_no_authentication, :only => [:edit, :update, :destroy]
5
- prepend_before_action :resource_from_invitation_token, :only => [:edit, :destroy]
2
+ prepend_before_action :authenticate_inviter!, only: [:new, :create]
3
+ prepend_before_action :has_invitations_left?, only: [:create]
4
+ prepend_before_action :require_no_authentication, only: [:edit, :update, :destroy]
5
+ prepend_before_action :resource_from_invitation_token, only: [:edit, :destroy]
6
6
 
7
7
  if respond_to? :helper_method
8
8
  helper_method :after_sign_in_path_for
@@ -23,12 +23,12 @@ class Devise::InvitationsController < DeviseController
23
23
 
24
24
  if resource_invited
25
25
  if is_flashing_format? && self.resource.invitation_sent_at
26
- set_flash_message :notice, :send_instructions, :email => self.resource.email
26
+ set_flash_message :notice, :send_instructions, email: self.resource.email
27
27
  end
28
28
  if self.method(:after_invite_path_for).arity == 1
29
- respond_with resource, :location => after_invite_path_for(current_inviter)
29
+ respond_with resource, location: after_invite_path_for(current_inviter)
30
30
  else
31
- respond_with resource, :location => after_invite_path_for(current_inviter, resource)
31
+ respond_with resource, location: after_invite_path_for(current_inviter, resource)
32
32
  end
33
33
  else
34
34
  respond_with_navigational(resource) { render :new }
@@ -55,14 +55,14 @@ class Devise::InvitationsController < DeviseController
55
55
  flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
56
56
  set_flash_message :notice, flash_message if is_flashing_format?
57
57
  sign_in(resource_name, resource)
58
- respond_with resource, :location => after_accept_path_for(resource)
58
+ respond_with resource, location: after_accept_path_for(resource)
59
59
  else
60
60
  set_flash_message :notice, :updated_not_active if is_flashing_format?
61
- respond_with resource, :location => new_session_path(resource_name)
61
+ respond_with resource, location: new_session_path(resource_name)
62
62
  end
63
63
  else
64
64
  resource.invitation_token = raw_invitation_token
65
- respond_with_navigational(resource){ render :edit }
65
+ respond_with_navigational(resource) { render :edit }
66
66
  end
67
67
  end
68
68