devise_invitable 1.1.8 → 1.2.1
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.
- data/README.rdoc +12 -2
- data/app/controllers/devise/invitations_controller.rb +13 -5
- data/app/controllers/devise_invitable/registrations_controller.rb +2 -2
- data/lib/devise_invitable.rb +1 -0
- data/lib/devise_invitable/model.rb +18 -22
- data/lib/devise_invitable/parameter_sanitizer.rb +11 -0
- data/lib/devise_invitable/rails.rb +1 -0
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +2 -1
- data/test/functional/controller_helpers_test.rb +39 -0
- data/test/functional/registrations_controller_test.rb +59 -0
- data/test/generators/views_generator_test.rb +40 -0
- data/test/generators_test.rb +34 -0
- data/test/integration/invitation_remove_test.rb +29 -0
- data/test/integration/invitation_test.rb +223 -0
- data/test/integration_tests_helper.rb +48 -0
- data/test/mailers/invitation_mail_test.rb +59 -0
- data/test/model_tests_helper.rb +33 -0
- data/test/models/invitable_test.rb +533 -0
- data/test/models_test.rb +74 -0
- data/test/orm/active_record.rb +4 -0
- data/test/orm/mongoid.rb +20 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/free_invitations_controller.rb +6 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +12 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/admin.rb +23 -0
- data/test/rails_app/app/models/octopussy.rb +15 -0
- data/test/rails_app/app/models/user.rb +51 -0
- data/test/rails_app/app/views/admins/new.html.erb +12 -0
- data/test/rails_app/app/views/free_invitations/new.html.erb +12 -0
- data/test/rails_app/app/views/home/index.html.erb +0 -0
- data/test/rails_app/app/views/layouts/application.html.erb +16 -0
- data/test/rails_app/app/views/users/invitations/new.html.erb +15 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +24 -0
- data/test/rails_app/config/boot.rb +11 -0
- data/test/rails_app/config/database.yml +22 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +25 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +207 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails_app/config/locales/devise.en.yml +57 -0
- data/test/rails_app/config/locales/en.yml +14 -0
- data/test/rails_app/config/routes.rb +9 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +39 -0
- data/test/rails_app/mongoid.yml +10 -0
- data/test/rails_app/script/rails +6 -0
- data/test/routes_test.rb +20 -0
- data/test/test_helper.rb +24 -0
- metadata +128 -40
- data/app/controllers/devise_invitable/registrations_controller.rb~ +0 -15
- data/lib/devise_invitable.rb~ +0 -65
- data/lib/devise_invitable/controllers/helpers.rb~ +0 -21
- data/lib/devise_invitable/controllers/registrations.rb~ +0 -21
- data/lib/devise_invitable/model.rb~ +0 -224
- data/lib/devise_invitable/rails.rb~ +0 -21
data/README.rdoc
CHANGED
@@ -5,6 +5,10 @@ It adds support to devise[http://github.com/plataformatec/devise] for send invit
|
|
5
5
|
|
6
6
|
DeviseInvitable currently only support Rails 3, if you want to use it with Rails 2.3 you must install version {0.2.3}[http://rubygems.org/gems/devise_invitable/versions/0.2.3]
|
7
7
|
|
8
|
+
If you want to use Rails 4 or devise 3, you must use git:
|
9
|
+
|
10
|
+
gem 'devise_invitable', :github => 'scambra/devise_invitable'
|
11
|
+
|
8
12
|
== Installation
|
9
13
|
|
10
14
|
Install DeviseInvitable gem, it will also install dependencies (such as devise and warden):
|
@@ -46,6 +50,7 @@ Add t.invitable to your Devise model migration:
|
|
46
50
|
...
|
47
51
|
## Invitable
|
48
52
|
t.string :invitation_token, :limit => 60
|
53
|
+
t.datetime :invitation_created_at
|
49
54
|
t.datetime :invitation_sent_at
|
50
55
|
t.datetime :invitation_accepted_at
|
51
56
|
t.integer :invitation_limit
|
@@ -59,6 +64,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
|
|
59
64
|
|
60
65
|
change_table :users do |t|
|
61
66
|
t.string :invitation_token, :limit => 60
|
67
|
+
t.datetime :invitation_created_at
|
62
68
|
t.datetime :invitation_sent_at
|
63
69
|
t.datetime :invitation_accepted_at
|
64
70
|
t.integer :invitation_limit
|
@@ -76,6 +82,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
|
|
76
82
|
If you are using Mongoid, define the following fields and indexes within your invitable model:
|
77
83
|
|
78
84
|
field :invitation_token, type: String
|
85
|
+
field :invitation_created_at, type: Time
|
79
86
|
field :invitation_sent_at, type: Time
|
80
87
|
field :invitation_accepted_at, type: Time
|
81
88
|
field :invitation_limit, type: Integer
|
@@ -129,6 +136,10 @@ You can also use the generator to generate scoped views:
|
|
129
136
|
|
130
137
|
rails generate devise_invitable:views users
|
131
138
|
|
139
|
+
Then turn scoped views on in config/initializers/devise.rb:
|
140
|
+
|
141
|
+
config.scoped_views = true
|
142
|
+
|
132
143
|
Please refer to {Devise's README}[http://github.com/plataformatec/devise] for more information about views.
|
133
144
|
|
134
145
|
== Configuring controllers
|
@@ -173,8 +184,7 @@ When skip_invitation is used, you must also then set the invitation_sent_at fiel
|
|
173
184
|
token. Failure to do so will yield "Invalid invitation token" errors when the user attempts to accept the invite.
|
174
185
|
You can set it like so:
|
175
186
|
|
176
|
-
user.
|
177
|
-
user.save!
|
187
|
+
user.deliver_invitation
|
178
188
|
|
179
189
|
You can add :skip_invitation to attributes hash if skip_invitation is added to attr_accessible.
|
180
190
|
|
@@ -8,16 +8,16 @@ class Devise::InvitationsController < DeviseController
|
|
8
8
|
|
9
9
|
# GET /resource/invitation/new
|
10
10
|
def new
|
11
|
-
|
11
|
+
self.resource = resource_class.new
|
12
12
|
render :new
|
13
13
|
end
|
14
14
|
|
15
15
|
# POST /resource/invitation
|
16
16
|
def create
|
17
|
-
self.resource = resource_class.invite!(
|
17
|
+
self.resource = resource_class.invite!(invite_params, current_inviter)
|
18
18
|
|
19
19
|
if resource.errors.empty?
|
20
|
-
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
20
|
+
set_flash_message :notice, :send_instructions, :email => self.resource.email if self.resource.invitation_sent_at
|
21
21
|
respond_with resource, :location => after_invite_path_for(resource)
|
22
22
|
else
|
23
23
|
respond_with_navigational(resource) { render :new }
|
@@ -31,7 +31,7 @@ class Devise::InvitationsController < DeviseController
|
|
31
31
|
|
32
32
|
# PUT /resource/invitation
|
33
33
|
def update
|
34
|
-
self.resource = resource_class.accept_invitation!(
|
34
|
+
self.resource = resource_class.accept_invitation!(update_resource_params)
|
35
35
|
|
36
36
|
if resource.errors.empty?
|
37
37
|
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
@@ -57,7 +57,7 @@ class Devise::InvitationsController < DeviseController
|
|
57
57
|
|
58
58
|
def has_invitations_left?
|
59
59
|
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
60
|
-
|
60
|
+
self.resource = resource_class.new
|
61
61
|
set_flash_message :alert, :no_invitations_remaining
|
62
62
|
respond_with_navigational(resource) { render :new }
|
63
63
|
end
|
@@ -69,6 +69,14 @@ class Devise::InvitationsController < DeviseController
|
|
69
69
|
redirect_to after_sign_out_path_for(resource_name)
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
def invite_params
|
74
|
+
devise_parameter_sanitizer.for(:invite)
|
75
|
+
end
|
76
|
+
|
77
|
+
def update_resource_params
|
78
|
+
devise_parameter_sanitizer.for(:accept_invitation)
|
79
|
+
end
|
72
80
|
|
73
81
|
end
|
74
82
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class DeviseInvitable::RegistrationsController < Devise::RegistrationsController
|
2
2
|
protected
|
3
3
|
|
4
|
-
def build_resource(
|
5
|
-
hash
|
4
|
+
def build_resource(hash = nil)
|
5
|
+
hash ||= resource_params || {}
|
6
6
|
if hash[:email]
|
7
7
|
self.resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
|
8
8
|
if self.resource
|
data/lib/devise_invitable.rb
CHANGED
@@ -2,6 +2,7 @@ module DeviseInvitable
|
|
2
2
|
autoload :Inviter, 'devise_invitable/inviter'
|
3
3
|
autoload :Mailer, 'devise_invitable/mailer'
|
4
4
|
autoload :Mapping, 'devise_invitable/mapping'
|
5
|
+
autoload :ParameterSanitizer, 'devise_invitable/parameter_sanitizer'
|
5
6
|
module Controllers
|
6
7
|
autoload :UrlHelpers, 'devise_invitable/controllers/url_helpers'
|
7
8
|
autoload :Registrations, 'devise_invitable/controllers/registrations'
|
@@ -42,7 +42,7 @@ module Devise
|
|
42
42
|
attr_writer :skip_password
|
43
43
|
|
44
44
|
scope :active, lambda { where(:invitation_token => nil) }
|
45
|
-
if defined?(Mongoid) && self < Mongoid::Document
|
45
|
+
if defined?(Mongoid) && defined?(Mongoid::Document) && self < Mongoid::Document
|
46
46
|
scope :invitation_not_accepted, lambda { where(:invitation_accepted_at => nil, :invitation_token.ne => nil) }
|
47
47
|
scope :invitation_accepted, lambda { where(:invitation_accepted_at.ne => nil) }
|
48
48
|
else
|
@@ -50,15 +50,13 @@ module Devise
|
|
50
50
|
scope :invitation_accepted, lambda { where(arel_table[:invitation_accepted_at].not_eq(nil)) }
|
51
51
|
|
52
52
|
[:before_invitation_accepted, :after_invitation_accepted].each do |callback_method|
|
53
|
-
send callback_method
|
54
|
-
notify_observers callback_method
|
55
|
-
end
|
53
|
+
send callback_method
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
58
|
def self.required_fields(klass)
|
61
|
-
fields = [:invitation_token, :invitation_sent_at, :invitation_accepted_at,
|
59
|
+
fields = [:invitation_token, :invitation_created_at, :invitation_sent_at, :invitation_accepted_at,
|
62
60
|
:invitation_limit, :invited_by_id, :invited_by_type]
|
63
61
|
if Devise.invited_by_class_name
|
64
62
|
fields -= [:invited_by_type]
|
@@ -67,7 +65,7 @@ module Devise
|
|
67
65
|
end
|
68
66
|
|
69
67
|
def invitation_fields
|
70
|
-
fields = [:invitation_sent_at, :invited_by_id, :invited_by_type]
|
68
|
+
fields = [:invitation_created_at, :invitation_sent_at, :invited_by_id, :invited_by_type]
|
71
69
|
if Devise.invited_by_class_name
|
72
70
|
fields -= [:invited_by_type]
|
73
71
|
end
|
@@ -129,7 +127,8 @@ module Devise
|
|
129
127
|
end
|
130
128
|
|
131
129
|
generate_invitation_token if self.invitation_token.nil?
|
132
|
-
self.
|
130
|
+
self.invitation_created_at = Time.now.utc
|
131
|
+
self.invitation_sent_at = self.invitation_created_at unless @skip_invitation
|
133
132
|
self.invited_by = invited_by if invited_by
|
134
133
|
|
135
134
|
# Call these before_validate methods since we aren't validating on save
|
@@ -178,6 +177,7 @@ module Devise
|
|
178
177
|
|
179
178
|
# Deliver the invitation email
|
180
179
|
def deliver_invitation
|
180
|
+
self.update_attribute :invitation_sent_at, Time.now.utc unless self.invitation_sent_at
|
181
181
|
send_devise_notification(:invitation_instructions)
|
182
182
|
end
|
183
183
|
|
@@ -201,7 +201,8 @@ module Devise
|
|
201
201
|
# invitation_period_valid? # will always return true
|
202
202
|
#
|
203
203
|
def invitation_period_valid?
|
204
|
-
|
204
|
+
time = invitation_created_at || invitation_sent_at
|
205
|
+
time && (self.class.invite_for.to_i.zero? || time.utc >= self.class.invite_for.ago)
|
205
206
|
end
|
206
207
|
|
207
208
|
# Generates a new random token for invitation, and stores the time
|
@@ -221,12 +222,13 @@ module Devise
|
|
221
222
|
end
|
222
223
|
end
|
223
224
|
|
224
|
-
# Attempt to find a user by
|
225
|
-
# user and send invitation to it. If user is found,
|
226
|
-
# email already exists error.
|
227
|
-
# If user is found and still
|
228
|
-
# resend_invitation is set to false
|
229
|
-
# Attributes must contain the user email, other attributes will be
|
225
|
+
# Attempt to find a user by its email. If a record is not found,
|
226
|
+
# create a new user and send an invitation to it. If the user is found,
|
227
|
+
# return the user with an email already exists error.
|
228
|
+
# If the user is found and still has a pending invitation, invitation
|
229
|
+
# email is resent unless resend_invitation is set to false.
|
230
|
+
# Attributes must contain the user's email, other attributes will be
|
231
|
+
# set in the record
|
230
232
|
def _invite(attributes={}, invited_by=nil, &block)
|
231
233
|
invite_key_array = invite_key_fields
|
232
234
|
attributes_hash = {}
|
@@ -235,7 +237,7 @@ module Devise
|
|
235
237
|
end
|
236
238
|
|
237
239
|
invitable = find_or_initialize_with_errors(invite_key_array, attributes_hash)
|
238
|
-
invitable.assign_attributes(attributes
|
240
|
+
invitable.assign_attributes(attributes)
|
239
241
|
invitable.invited_by = invited_by
|
240
242
|
|
241
243
|
invitable.skip_password = true
|
@@ -255,12 +257,6 @@ module Devise
|
|
255
257
|
[invitable, mail]
|
256
258
|
end
|
257
259
|
|
258
|
-
# Override this method if the invitable is using Mass Assignment Security
|
259
|
-
# and the inviter has a non-default role.
|
260
|
-
def inviter_role(inviter)
|
261
|
-
:default
|
262
|
-
end
|
263
|
-
|
264
260
|
def invite!(attributes={}, invited_by=nil, &block)
|
265
261
|
invitable, mail = _invite(attributes, invited_by, &block)
|
266
262
|
invitable
|
@@ -280,7 +276,7 @@ module Devise
|
|
280
276
|
invitable = find_or_initialize_with_error_by(:invitation_token, attributes.delete(:invitation_token))
|
281
277
|
invitable.errors.add(:invitation_token, :invalid) if invitable.invitation_token && invitable.persisted? && !invitable.valid_invitation?
|
282
278
|
if invitable.errors.empty?
|
283
|
-
invitable.assign_attributes(attributes
|
279
|
+
invitable.assign_attributes(attributes)
|
284
280
|
invitable.accept_invitation!
|
285
281
|
end
|
286
282
|
invitable
|
@@ -17,6 +17,7 @@ module DeviseInvitable
|
|
17
17
|
# extend mapping with after_initialize becuase is not reloaded
|
18
18
|
config.after_initialize do
|
19
19
|
Devise::Mapping.send :include, DeviseInvitable::Mapping
|
20
|
+
Devise::ParameterSanitizer.send :include, DeviseInvitable::ParameterSanitizer
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def up
|
3
3
|
change_table :<%= table_name %> do |t|
|
4
|
-
t.string :invitation_token
|
4
|
+
t.string :invitation_token
|
5
|
+
t.datetime :invitation_created_at
|
5
6
|
t.datetime :invitation_sent_at
|
6
7
|
t.datetime :invitation_accepted_at
|
7
8
|
t.integer :invitation_limit
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ControllerHelpersTest < ActionController::TestCase
|
4
|
+
tests ApplicationController
|
5
|
+
|
6
|
+
test "after invite path defaults to after sign in path" do
|
7
|
+
assert_equal @controller.after_sign_in_path_for(:user), @controller.after_invite_path_for(:user)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "after accept path defaults to after sign in path" do
|
11
|
+
assert_equal @controller.after_sign_in_path_for(:user), @controller.after_accept_path_for(:user)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'after invite path is customizable from application controller' do
|
15
|
+
custom_path = 'customized/after/invite/path'
|
16
|
+
@controller.instance_eval "def after_invite_path_for(resource) '#{custom_path}' end"
|
17
|
+
assert_equal @controller.after_invite_path_for(:user), custom_path
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'after accept path is customizable from application controller' do
|
21
|
+
custom_path = 'customized/after/accept/path'
|
22
|
+
@controller.instance_eval "def after_accept_path_for(resource) '#{custom_path}' end"
|
23
|
+
assert_equal @controller.after_accept_path_for(:user), custom_path
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'is not a devise controller' do
|
27
|
+
assert !@controller.devise_controller?
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'invitations controller respects definition for after invite path in application controller' do
|
31
|
+
assert Devise::InvitationsController.method_defined? :after_invite_path_for
|
32
|
+
assert !Devise::InvitationsController.instance_methods(false).include?(:after_invite_path_for)
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'invitations controller respects definition for after accept path in application controller' do
|
36
|
+
assert Devise::InvitationsController.method_defined? :after_accept_path_for
|
37
|
+
assert !Devise::InvitationsController.instance_methods(false).include?(:after_accept_path_for)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'model_tests_helper'
|
3
|
+
|
4
|
+
class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
5
|
+
def setup
|
6
|
+
@issuer = new_user#users(:issuer)
|
7
|
+
@issuer.valid?
|
8
|
+
assert @issuer.valid?, 'starting with a valid user record'
|
9
|
+
|
10
|
+
# josevalim: you are required to do that because the routes sets this kind
|
11
|
+
# of stuff automatically. But functional tests are not using the routes.
|
12
|
+
# see https://github.com/plataformatec/devise/issues/1196
|
13
|
+
@request.env["devise.mapping"] = Devise.mappings[:user]
|
14
|
+
end
|
15
|
+
|
16
|
+
test "invited users may still sign up directly by themselves" do
|
17
|
+
# invite the invitee
|
18
|
+
sign_in @issuer
|
19
|
+
invitee_email = "invitee@example.org"
|
20
|
+
|
21
|
+
User.invite!(:email => invitee_email) do |u|
|
22
|
+
u.skip_invitation = true
|
23
|
+
u.invited_by = @issuer
|
24
|
+
end
|
25
|
+
sign_out @issuer
|
26
|
+
|
27
|
+
@invitee = User.where(:email => invitee_email).first
|
28
|
+
assert_blank @invitee.encrypted_password, "the password should be unset"
|
29
|
+
|
30
|
+
# sign_up the invitee
|
31
|
+
assert_difference('ActionMailer::Base.deliveries.size') do
|
32
|
+
post :create, :user => {:email => invitee_email, :password => "1password", :bio => '.'}
|
33
|
+
end
|
34
|
+
|
35
|
+
@invitee = User.where(:email => invitee_email).first
|
36
|
+
assert_present @invitee.encrypted_password
|
37
|
+
assert_not_nil @invitee.invitation_accepted_at
|
38
|
+
assert_nil @invitee.invitation_token
|
39
|
+
assert_present @invitee.invited_by_id
|
40
|
+
assert_present @invitee.invited_by_type
|
41
|
+
assert !@invitee.confirmed?
|
42
|
+
assert_present @invitee.confirmation_token
|
43
|
+
end
|
44
|
+
|
45
|
+
test "not invitable resources can register" do
|
46
|
+
@request.env["devise.mapping"] = Devise.mappings[:admin]
|
47
|
+
invitee_email = "invitee@example.org"
|
48
|
+
|
49
|
+
post :create, :admin => {:email => invitee_email, :password => "1password"}
|
50
|
+
|
51
|
+
@invitee = Admin.where(:email => invitee_email).first
|
52
|
+
assert_present @invitee.encrypted_password
|
53
|
+
end
|
54
|
+
|
55
|
+
test "missing params on a create should not cause an error" do
|
56
|
+
|
57
|
+
assert_nothing_raised { post :create }
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rails/generators'
|
4
|
+
require File.expand_path('../../lib/generators/devise_invitable/views_generator.rb', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
class ViewsGeneratorTest < ::Rails::Generators::TestCase
|
7
|
+
tests DeviseInvitable::Generators::ViewsGenerator
|
8
|
+
destination File.expand_path('../../tmp', File.dirname(__FILE__))
|
9
|
+
|
10
|
+
test 'views get copied' do
|
11
|
+
run_generator
|
12
|
+
|
13
|
+
assert_directory @mailer_path = 'app/views/devise/mailer'
|
14
|
+
assert_directory @invitations_path = 'app/views/devise/invitations'
|
15
|
+
assert_files
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'views can be scoped' do
|
19
|
+
run_generator %w(octopussies)
|
20
|
+
|
21
|
+
assert_directory @mailer_path = 'app/views/octopussies/mailer'
|
22
|
+
assert_directory @invitations_path = 'app/views/octopussies/invitations'
|
23
|
+
assert_files
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
FileUtils.rm_r Dir['../../tmp/*']
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def assert_files
|
32
|
+
assert views = { @invitations_path => %w/edit.html.erb new.html.erb/, @mailer_path => %w/invitation_instructions.html.erb/ }
|
33
|
+
|
34
|
+
views.each do |path, files|
|
35
|
+
files.each do |file|
|
36
|
+
assert_file File.join path, file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
require 'test_helper'
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'generators/devise_invitable/devise_invitable_generator'
|
5
|
+
|
6
|
+
class GeneratorsTest < ActiveSupport::TestCase
|
7
|
+
RAILS_APP_PATH = File.expand_path("../rails_app", __FILE__)
|
8
|
+
|
9
|
+
test "rails g should include the 6 generators" do
|
10
|
+
@output = `cd #{RAILS_APP_PATH} && rails g`
|
11
|
+
generators = %w/devise_invitable devise_invitable:form_for devise_invitable:install devise_invitable:invitation_views devise_invitable:simple_form_for devise_invitable:views/
|
12
|
+
|
13
|
+
generators.each do |generator|
|
14
|
+
@output.include? generator
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "rails g devise_invitable:install" do
|
19
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
|
20
|
+
assert @output.match(%r{(inject|insert).+ config/initializers/devise\.rb\n})
|
21
|
+
assert @output.match(%r|create.+ config/locales/devise_invitable\.en\.yml\n|)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "rails g devise_invitable Octopussy" do
|
25
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
|
26
|
+
assert @output.match(%r{(inject|insert).+ app/models/octopussy\.rb\n})
|
27
|
+
assert @output.match(%r|invoke.+ #{DEVISE_ORM}\n|)
|
28
|
+
if DEVISE_ORM == :active_record
|
29
|
+
assert @output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
30
|
+
elsif DEVISE_ORM == :mongoid
|
31
|
+
assert !@output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|