devise_invitable 1.1.8 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/test/models_test.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Invitable < User
|
4
|
+
devise :invitable, :invite_for => 5.days, :validate_on_invite => true
|
5
|
+
end
|
6
|
+
|
7
|
+
class ModelsTest < 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
|
+
|
18
|
+
(Devise::ALL - modules).each do |mod|
|
19
|
+
assert !include_module?(klass, mod), "#{klass} include #{mod}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should include Devise modules' do
|
24
|
+
assert_include_modules User, :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'should have a default value for invite_for' do
|
28
|
+
assert_equal 0, User.invite_for
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should have a default value for invitation_limit' do
|
32
|
+
assert_nil User.invitation_limit
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'should have a default value for invite_key' do
|
36
|
+
assert !User.invite_key.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'set a custom value for invite_for' do
|
40
|
+
old_invite_for = User.invite_for
|
41
|
+
User.invite_for = 5.days
|
42
|
+
|
43
|
+
assert_equal 5.days, User.invite_for
|
44
|
+
|
45
|
+
User.invite_for = old_invite_for
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'set a custom value for invite_key' do
|
49
|
+
old_invite_key = User.invite_key
|
50
|
+
User.invite_key = {:username => /\A.+\z/}
|
51
|
+
|
52
|
+
assert_equal({:username => /\A.+\z/}, User.invite_key)
|
53
|
+
|
54
|
+
User.invite_key = old_invite_key
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'set a custom value for invitation_limit' do
|
58
|
+
old_invitation_limit = User.invitation_limit
|
59
|
+
User.invitation_limit = 2
|
60
|
+
|
61
|
+
assert_equal 2, User.invitation_limit
|
62
|
+
|
63
|
+
User.invitation_limit = old_invitation_limit
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'set a default value for validate_on_invite' do
|
67
|
+
assert_equal true, Invitable.validate_on_invite
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'invitable attributes' do
|
71
|
+
assert_nil User.new.invitation_token
|
72
|
+
assert_nil User.new.invitation_sent_at
|
73
|
+
end
|
74
|
+
end
|
data/test/orm/mongoid.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Mongoid.configure do |config|
|
2
|
+
if Mongoid::VERSION < '3.0.0'
|
3
|
+
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise_invitable-test-suite")
|
4
|
+
else
|
5
|
+
config.connect_to("devise_invitable-test-suite")
|
6
|
+
config.use_utc = true
|
7
|
+
config.include_root_in_json = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActiveSupport::TestCase
|
12
|
+
setup do
|
13
|
+
if Mongoid::VERSION < '3.0.0'
|
14
|
+
User.delete_all
|
15
|
+
Admin.delete_all
|
16
|
+
else
|
17
|
+
Mongoid.purge!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
RailsApp::Application.load_tasks
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery
|
3
|
+
before_filter :configure_permitted_parameters, :if => :devise_controller?
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def configure_permitted_parameters
|
8
|
+
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :bio) } if defined?(ActionController::StrongParameters)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Admin < PARENT_MODEL_CLASS
|
2
|
+
if DEVISE_ORM == :mongoid
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Attributes::Dynamic if defined?(Mongoid::Attributes::Dynamic)
|
5
|
+
## Database authenticatable
|
6
|
+
field :email, :type => String, :default => ""
|
7
|
+
field :encrypted_password, :type => String, :default => ""
|
8
|
+
validates_presence_of :email
|
9
|
+
validates_presence_of :encrypted_password, :if => :password_required?
|
10
|
+
|
11
|
+
## Confirmable
|
12
|
+
field :confirmation_token, :type => String
|
13
|
+
field :confirmed_at, :type => Time
|
14
|
+
field :confirmation_sent_at, :type => Time
|
15
|
+
field :unconfirmed_email, :type => String # Only if using reconfirmable
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
devise :database_authenticatable, :validatable, :registerable
|
22
|
+
include DeviseInvitable::Inviter
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This model is here for the generators' specs
|
2
|
+
class Octopussy < PARENT_MODEL_CLASS
|
3
|
+
if DEVISE_ORM == :mongoid
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Attributes::Dynamic if defined?(Mongoid::Attributes::Dynamic)
|
6
|
+
|
7
|
+
## Database authenticatable
|
8
|
+
field :email, :type => String, :default => ""
|
9
|
+
field :encrypted_password, :type => String, :default => ""
|
10
|
+
validates_presence_of :email
|
11
|
+
validates_presence_of :encrypted_password, :if => :password_required?
|
12
|
+
|
13
|
+
end
|
14
|
+
devise :database_authenticatable, :validatable, :confirmable
|
15
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class User < PARENT_MODEL_CLASS
|
2
|
+
if DEVISE_ORM == :mongoid
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Attributes::Dynamic if defined?(Mongoid::Attributes::Dynamic)
|
5
|
+
|
6
|
+
## Database authenticatable
|
7
|
+
field :email, :type => String, :default => ""
|
8
|
+
field :encrypted_password, :type => String, :default => ""
|
9
|
+
|
10
|
+
## Recoverable
|
11
|
+
field :reset_password_token, :type => String
|
12
|
+
field :reset_password_sent_at, :type => Time
|
13
|
+
|
14
|
+
## Confirmable
|
15
|
+
field :confirmation_token, :type => String
|
16
|
+
field :confirmed_at, :type => Time
|
17
|
+
field :confirmation_sent_at, :type => Time
|
18
|
+
field :unconfirmed_email, :type => String # Only if using reconfirmable
|
19
|
+
|
20
|
+
## Invitable
|
21
|
+
field :invitation_token, :type => String
|
22
|
+
field :invitation_created_at, :type => Time
|
23
|
+
field :invitation_sent_at, :type => Time
|
24
|
+
field :invitation_accepted_at, :type => Time
|
25
|
+
field :invitation_limit, :type => Integer
|
26
|
+
field :invited_by_id, :type => Integer
|
27
|
+
field :invited_by_type, :type => String
|
28
|
+
|
29
|
+
|
30
|
+
field :username
|
31
|
+
validates_presence_of :email
|
32
|
+
validates_presence_of :encrypted_password, :if => :password_required?
|
33
|
+
end
|
34
|
+
|
35
|
+
devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
|
36
|
+
|
37
|
+
attr_accessor :callback_works, :bio
|
38
|
+
validates :username, :length => { :maximum => 20 }
|
39
|
+
|
40
|
+
attr_accessor :testing_accepting_or_not_invited
|
41
|
+
validates :username, :presence => true, :if => :testing_accepting_or_not_invited_validator?
|
42
|
+
validates :bio, :presence => true, :if => :invitation_accepted?
|
43
|
+
|
44
|
+
def testing_accepting_or_not_invited_validator?
|
45
|
+
testing_accepting_or_not_invited && accepting_or_not_invited?
|
46
|
+
end
|
47
|
+
|
48
|
+
after_invitation_accepted do |object|
|
49
|
+
object.callback_works = true
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Send invitation</h2>
|
2
|
+
|
3
|
+
<%= form_for resource, :as => resource_name, :url => admin_path do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Send an invitation" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2>Send invitation</h2>
|
2
|
+
|
3
|
+
<%= form_for resource, :as => resource_name, :url => free_invitation_path do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %><br />
|
7
|
+
<%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Send an invitation" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
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
|
+
<%= content_tag :p, flash[:alert], :id => 'alert' unless flash[:alert].blank? %>
|
13
|
+
<%= yield %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,15 @@
|
|
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 />
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "action_mailer/railtie"
|
5
|
+
require "rails/test_unit/railtie"
|
6
|
+
|
7
|
+
Bundler.require(:default, DEVISE_ORM) if defined?(Bundler)
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "#{DEVISE_ORM}/railtie"
|
11
|
+
rescue LoadError
|
12
|
+
end
|
13
|
+
PARENT_MODEL_CLASS = DEVISE_ORM == :active_record ? ActiveRecord::Base : Object
|
14
|
+
Mongoid.load!(File.expand_path('../../mongoid.yml', __FILE__)) if DEVISE_ORM == :mongoid && Mongoid::VERSION < '3.0.0'
|
15
|
+
|
16
|
+
require "devise"
|
17
|
+
require "devise_invitable"
|
18
|
+
|
19
|
+
module RailsApp
|
20
|
+
class Application < Rails::Application
|
21
|
+
config.filter_parameters << :password
|
22
|
+
config.action_mailer.default_url_options = { :host => "localhost:3000" }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
unless defined?(DEVISE_ORM)
|
2
|
+
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
3
|
+
end
|
4
|
+
|
5
|
+
begin
|
6
|
+
require File.expand_path("../../../../.bundle/environment", __FILE__)
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.setup :default, :test, DEVISE_ORM
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|