devise_invitable 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/devise/invitations_controller.rb~ +48 -0
- data/config/locales/en.yml +1 -1
- data/lib/devise_invitable/model.rb +5 -0
- data/lib/devise_invitable/model.rb~ +129 -0
- data/lib/devise_invitable/version.rb +3 -0
- metadata +42 -104
- data/.document +0 -5
- data/.gitignore +0 -22
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -117
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/devise_invitable.gemspec +0 -146
- data/test/generators_test.rb +0 -45
- data/test/integration/invitable_test.rb +0 -109
- data/test/integration_tests_helper.rb +0 -58
- data/test/mailers/invitation_test.rb +0 -62
- data/test/model_tests_helper.rb +0 -41
- data/test/models/invitable_test.rb +0 -188
- data/test/models_test.rb +0 -31
- data/test/rails_app/app/controllers/admins_controller.rb +0 -6
- data/test/rails_app/app/controllers/application_controller.rb +0 -3
- data/test/rails_app/app/controllers/home_controller.rb +0 -4
- data/test/rails_app/app/controllers/users_controller.rb +0 -12
- data/test/rails_app/app/helpers/application_helper.rb +0 -2
- data/test/rails_app/app/models/octopussy.rb +0 -11
- data/test/rails_app/app/models/user.rb +0 -4
- data/test/rails_app/app/views/home/index.html.erb +0 -0
- data/test/rails_app/app/views/layouts/application.html.erb +0 -15
- data/test/rails_app/app/views/users/invitations/new.html.erb +0 -15
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/config/application.rb +0 -46
- data/test/rails_app/config/boot.rb +0 -13
- data/test/rails_app/config/database.yml +0 -22
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -26
- data/test/rails_app/config/environments/production.rb +0 -49
- data/test/rails_app/config/environments/test.rb +0 -35
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -144
- data/test/rails_app/config/initializers/inflections.rb +0 -10
- data/test/rails_app/config/initializers/mime_types.rb +0 -5
- data/test/rails_app/config/initializers/secret_token.rb +0 -7
- data/test/rails_app/config/initializers/session_store.rb +0 -8
- data/test/rails_app/config/locales/en.yml +0 -5
- data/test/rails_app/config/routes.rb +0 -4
- data/test/rails_app/script/rails +0 -6
- data/test/routes_test.rb +0 -20
- data/test/test_helper.rb +0 -30
data/test/model_tests_helper.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
class ActiveSupport::TestCase
|
2
|
-
def setup_mailer
|
3
|
-
ActionMailer::Base.deliveries = []
|
4
|
-
end
|
5
|
-
|
6
|
-
def store_translations(locale, translations, &block)
|
7
|
-
begin
|
8
|
-
I18n.backend.store_translations locale, translations
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
I18n.reload!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Helpers for creating new users
|
16
|
-
#
|
17
|
-
def generate_unique_email
|
18
|
-
@@email_count ||= 0
|
19
|
-
@@email_count += 1
|
20
|
-
"test#{@@email_count}@email.com"
|
21
|
-
end
|
22
|
-
|
23
|
-
def valid_attributes(attributes={})
|
24
|
-
{ :email => generate_unique_email,
|
25
|
-
:password => '123456',
|
26
|
-
:password_confirmation => '123456' }.update(attributes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def new_user(attributes={})
|
30
|
-
User.new(valid_attributes(attributes))
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_user_with_invitation(invitation_token, attributes={})
|
34
|
-
user = new_user({:password => nil, :password_confirmation => nil}.update(attributes))
|
35
|
-
user.skip_confirmation!
|
36
|
-
user.invitation_token = invitation_token
|
37
|
-
user.invitation_sent_at = Time.now.utc
|
38
|
-
user.save(:validate => false)
|
39
|
-
user
|
40
|
-
end
|
41
|
-
end
|
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'test/test_helper'
|
2
|
-
require 'test/model_tests_helper'
|
3
|
-
|
4
|
-
class InvitableTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
setup_mailer
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'should not generate invitation token after creating a record' do
|
11
|
-
assert_nil new_user.invitation_token
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'should regenerate invitation token each time' do
|
15
|
-
user = new_user
|
16
|
-
3.times do
|
17
|
-
token = user.invitation_token
|
18
|
-
user.invite!
|
19
|
-
assert_not_equal token, user.invitation_token
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'should test invitation sent at with invite_for configuration value' do
|
24
|
-
user = create_user_with_invitation('token')
|
25
|
-
|
26
|
-
User.stubs(:invite_for).returns(nil)
|
27
|
-
user.invitation_sent_at = Time.now.utc
|
28
|
-
assert user.valid_invitation?
|
29
|
-
|
30
|
-
User.stubs(:invite_for).returns(nil)
|
31
|
-
user.invitation_sent_at = 1.year.ago
|
32
|
-
assert user.valid_invitation?
|
33
|
-
|
34
|
-
User.stubs(:invite_for).returns(0)
|
35
|
-
user.invitation_sent_at = Time.now.utc
|
36
|
-
assert user.valid_invitation?
|
37
|
-
|
38
|
-
User.stubs(:invite_for).returns(0)
|
39
|
-
user.invitation_sent_at = 1.day.ago
|
40
|
-
assert user.valid_invitation?
|
41
|
-
|
42
|
-
User.stubs(:invite_for).returns(1.day)
|
43
|
-
user.invitation_sent_at = Time.now.utc
|
44
|
-
assert user.valid_invitation?
|
45
|
-
|
46
|
-
User.stubs(:invite_for).returns(1.day)
|
47
|
-
user.invitation_sent_at = 1.day.ago
|
48
|
-
assert !user.valid_invitation?
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'should never generate the same invitation token for different users' do
|
52
|
-
invitation_tokens = []
|
53
|
-
3.times do
|
54
|
-
user = new_user
|
55
|
-
user.invite!
|
56
|
-
token = user.invitation_token
|
57
|
-
assert !invitation_tokens.include?(token)
|
58
|
-
invitation_tokens << token
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test 'should set password and password confirmation from params' do
|
63
|
-
create_user_with_invitation('valid_token', :password => nil, :password_confirmation => nil)
|
64
|
-
user = User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '123456789')
|
65
|
-
assert user.valid_password?('123456789')
|
66
|
-
end
|
67
|
-
|
68
|
-
test 'should set password and save the record' do
|
69
|
-
user = create_user_with_invitation('valid_token', :password => nil, :password_confirmation => nil)
|
70
|
-
old_encrypted_password = user.encrypted_password
|
71
|
-
user = User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '123456789')
|
72
|
-
assert_not_equal old_encrypted_password, user.encrypted_password
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'should clear invitation token while setting the password' do
|
76
|
-
user = new_user
|
77
|
-
user.skip_confirmation!
|
78
|
-
user.update_attribute(:invitation_token, 'valid_token')
|
79
|
-
assert_present user.invitation_token
|
80
|
-
assert user.accept_invitation!
|
81
|
-
assert_nil user.invitation_token
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'should not clear invitation token if record is invalid' do
|
85
|
-
user = new_user
|
86
|
-
user.skip_confirmation!
|
87
|
-
user.update_attribute(:invitation_token, 'valid_token')
|
88
|
-
assert_present user.invitation_token
|
89
|
-
User.any_instance.stubs(:valid?).returns(false)
|
90
|
-
User.accept_invitation!(:invitation_token => 'valid_token', :password => '123456789', :password_confirmation => '987654321')
|
91
|
-
user.reload
|
92
|
-
assert_present user.invitation_token
|
93
|
-
end
|
94
|
-
|
95
|
-
test 'should reset invitation token and send invitation by email' do
|
96
|
-
user = new_user
|
97
|
-
assert_difference('ActionMailer::Base.deliveries.size') do
|
98
|
-
token = user.invitation_token
|
99
|
-
user.invite!
|
100
|
-
assert_not_equal token, user.invitation_token
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
test 'should return a record with invitation token and no errors to send invitation by email' do
|
105
|
-
invited_user = User.invite!(:email => "valid@email.com")
|
106
|
-
assert invited_user.errors.blank?
|
107
|
-
assert_present invited_user.invitation_token
|
108
|
-
assert_equal 'valid@email.com', invited_user.email
|
109
|
-
assert invited_user.persisted?
|
110
|
-
end
|
111
|
-
|
112
|
-
test 'should set all attributes with no errors' do
|
113
|
-
invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
|
114
|
-
assert invited_user.errors.blank?
|
115
|
-
assert_equal 'first name', invited_user.username
|
116
|
-
assert invited_user.persisted?
|
117
|
-
end
|
118
|
-
|
119
|
-
test 'should return a record with errors if user was found by e-mail' do
|
120
|
-
user = create_user_with_invitation('')
|
121
|
-
user.update_attribute(:invitation_token, nil)
|
122
|
-
invited_user = User.invite!(:email => user.email)
|
123
|
-
assert_equal invited_user, user
|
124
|
-
assert_equal ['has already been taken'], invited_user.errors[:email]
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'should return a new record with errors if e-mail is blank' do
|
128
|
-
invited_user = User.invite!(:email => '')
|
129
|
-
assert invited_user.new_record?
|
130
|
-
assert_equal ["can't be blank"], invited_user.errors[:email]
|
131
|
-
end
|
132
|
-
|
133
|
-
test 'should return a new record with errors if e-mail is invalid' do
|
134
|
-
invited_user = User.invite!(:email => 'invalid_email')
|
135
|
-
assert invited_user.new_record?
|
136
|
-
assert_equal ["is invalid"], invited_user.errors[:email]
|
137
|
-
end
|
138
|
-
|
139
|
-
test 'should set all attributes with errors if e-mail is invalid' do
|
140
|
-
invited_user = User.invite!(:email => "invalid_email.com", :username => 'first name')
|
141
|
-
assert invited_user.new_record?
|
142
|
-
assert_equal 'first name', invited_user.username
|
143
|
-
assert invited_user.errors.present?
|
144
|
-
end
|
145
|
-
|
146
|
-
test 'should find a user to set his password based on invitation_token' do
|
147
|
-
user = new_user
|
148
|
-
user.invite!
|
149
|
-
|
150
|
-
invited_user = User.accept_invitation!(:invitation_token => user.invitation_token)
|
151
|
-
assert_equal invited_user, user
|
152
|
-
end
|
153
|
-
|
154
|
-
test 'should return a new record with errors if no invitation_token is found' do
|
155
|
-
invited_user = User.accept_invitation!(:invitation_token => 'invalid_token')
|
156
|
-
assert invited_user.new_record?
|
157
|
-
assert_equal ['is invalid'], invited_user.errors[:invitation_token]
|
158
|
-
end
|
159
|
-
|
160
|
-
test 'should return a new record with errors if invitation_token is blank' do
|
161
|
-
invited_user = User.accept_invitation!(:invitation_token => '')
|
162
|
-
assert invited_user.new_record?
|
163
|
-
assert_equal ["can't be blank"], invited_user.errors[:invitation_token]
|
164
|
-
end
|
165
|
-
|
166
|
-
test 'should return record with errors if invitation_token has expired' do
|
167
|
-
user = create_user_with_invitation('valid_token')
|
168
|
-
user.update_attribute(:invitation_sent_at, 1.day.ago)
|
169
|
-
User.stubs(:invite_for).returns(10.hours)
|
170
|
-
invited_user = User.accept_invitation!(:invitation_token => 'valid_token')
|
171
|
-
assert_equal user, invited_user
|
172
|
-
assert_equal ["is invalid"], invited_user.errors[:invitation_token]
|
173
|
-
end
|
174
|
-
|
175
|
-
test 'should set successfully user password given the new password and confirmation' do
|
176
|
-
user = new_user(:password => nil, :password_confirmation => nil)
|
177
|
-
user.invite!
|
178
|
-
|
179
|
-
invited_user = User.accept_invitation!(
|
180
|
-
:invitation_token => user.invitation_token,
|
181
|
-
:password => 'new_password',
|
182
|
-
:password_confirmation => 'new_password'
|
183
|
-
)
|
184
|
-
user.reload
|
185
|
-
|
186
|
-
assert user.valid_password?('new_password')
|
187
|
-
end
|
188
|
-
end
|
data/test/models_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test/test_helper'
|
2
|
-
|
3
|
-
class Invitable < User
|
4
|
-
devise :database_authenticatable, :invitable, :invite_for => 5.days
|
5
|
-
end
|
6
|
-
|
7
|
-
class ActiveRecordTest < ActiveSupport::TestCase
|
8
|
-
def include_module?(klass, mod)
|
9
|
-
klass.devise_modules.include?(mod) &&
|
10
|
-
klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
|
11
|
-
end
|
12
|
-
|
13
|
-
def assert_include_modules(klass, *modules)
|
14
|
-
modules.each do |mod|
|
15
|
-
assert include_module?(klass, mod), "#{klass} not include #{mod}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'add invitable module only' do
|
20
|
-
assert_include_modules Invitable, :invitable
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'set a default value for invite_for' do
|
24
|
-
assert_equal 5.days, Invitable.invite_for
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'invitable attributes' do
|
28
|
-
assert_not_nil Invitable.columns_hash['invitation_token']
|
29
|
-
assert_not_nil Invitable.columns_hash['invitation_sent_at']
|
30
|
-
end
|
31
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class UsersController < ApplicationController
|
2
|
-
before_filter :authenticate_user!
|
3
|
-
|
4
|
-
def index
|
5
|
-
user_session[:cart] = "Cart"
|
6
|
-
end
|
7
|
-
|
8
|
-
def expire
|
9
|
-
user_session['last_request_at'] = 31.minutes.ago.utc
|
10
|
-
render :text => 'User will be expired on next request'
|
11
|
-
end
|
12
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# This model is here for the generators' specs
|
2
|
-
if DEVISE_ORM == :active_record
|
3
|
-
class Octopussy < ActiveRecord::Base
|
4
|
-
devise :database_authenticatable, :validatable, :confirmable
|
5
|
-
end
|
6
|
-
elsif DEVISE_ORM == :mongoid
|
7
|
-
class Octopussy
|
8
|
-
include Mongoid::Document
|
9
|
-
devise :database_authenticatable, :validatable, :confirmable
|
10
|
-
end
|
11
|
-
end
|
File without changes
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>RailsApp</title>
|
5
|
-
<%= stylesheet_link_tag :all %>
|
6
|
-
<%= javascript_include_tag :defaults %>
|
7
|
-
<%= csrf_meta_tag %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= content_tag :p, flash[:notice], :id => 'notice' unless flash[:notice].blank? %>
|
12
|
-
<%= yield %>
|
13
|
-
|
14
|
-
</body>
|
15
|
-
</html>
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<h2>Send an invitation</h2>
|
2
|
-
|
3
|
-
<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :post } do |f| %>
|
4
|
-
<%= devise_error_messages! %>
|
5
|
-
|
6
|
-
<p><%= f.label :username %></p>
|
7
|
-
<p><%= f.text_field :username %></p>
|
8
|
-
|
9
|
-
<p><%= f.label :email %></p>
|
10
|
-
<p><%= f.text_field :email %></p>
|
11
|
-
|
12
|
-
<p><%= f.submit "Send an invitation" %></p>
|
13
|
-
<% end %>
|
14
|
-
|
15
|
-
<%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
|
data/test/rails_app/config.ru
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym unless defined? DEVISE_ORM
|
3
|
-
|
4
|
-
require 'rails/all'
|
5
|
-
|
6
|
-
# If you have a Gemfile, require the gems listed there, including any gems
|
7
|
-
# you've limited to :test, :development, or :production.
|
8
|
-
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
9
|
-
|
10
|
-
require 'devise'
|
11
|
-
require 'devise_invitable'
|
12
|
-
|
13
|
-
module RailsApp
|
14
|
-
class Application < Rails::Application
|
15
|
-
# Settings in config/environments/* take precedence over those specified here.
|
16
|
-
# Application configuration should go into files in config/initializers
|
17
|
-
# -- all .rb files in that directory are automatically loaded.
|
18
|
-
|
19
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
20
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
21
|
-
|
22
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
23
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
24
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
25
|
-
|
26
|
-
# Activate observers that should always be running.
|
27
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
28
|
-
|
29
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
30
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
31
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
32
|
-
|
33
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
34
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
35
|
-
# config.i18n.default_locale = :de
|
36
|
-
|
37
|
-
# JavaScript files you want as :defaults (application.js is always included).
|
38
|
-
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
39
|
-
|
40
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
41
|
-
config.encoding = "utf-8"
|
42
|
-
|
43
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
44
|
-
config.filter_parameters += [:password]
|
45
|
-
end
|
46
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
# Set up gems listed in the Gemfile.
|
4
|
-
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
-
begin
|
6
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
-
require 'bundler'
|
8
|
-
Bundler.setup
|
9
|
-
rescue Bundler::GemNotFound => e
|
10
|
-
STDERR.puts e.message
|
11
|
-
STDERR.puts "Try running `bundle install`."
|
12
|
-
exit!
|
13
|
-
end if File.exist?(gemfile)
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
-
development:
|
4
|
-
adapter: sqlite3
|
5
|
-
database: ":memory:"
|
6
|
-
pool: 5
|
7
|
-
timeout: 5000
|
8
|
-
|
9
|
-
# Warning: The database defined as "test" will be erased and
|
10
|
-
# re-generated from your development database when you run "rake".
|
11
|
-
# Do not set this db to the same as development or production.
|
12
|
-
test:
|
13
|
-
adapter: sqlite3
|
14
|
-
database: ":memory:"
|
15
|
-
pool: 5
|
16
|
-
timeout: 5000
|
17
|
-
|
18
|
-
production:
|
19
|
-
adapter: sqlite3
|
20
|
-
database: db/production.sqlite3
|
21
|
-
pool: 5
|
22
|
-
timeout: 5000
|