devise_invitable 0.1.0

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.
Files changed (49) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +18 -0
  5. data/Rakefile +54 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/invitations_controller.rb +48 -0
  8. data/app/views/devise_mailer/invitation.html.erb +8 -0
  9. data/app/views/invitations/edit.html.erb +14 -0
  10. data/app/views/invitations/new.html.erb +10 -0
  11. data/devise_invitable.gemspec +121 -0
  12. data/init.rb +1 -0
  13. data/lib/devise/controllers/url_helpers.rb +20 -0
  14. data/lib/devise/models/invitable.rb +143 -0
  15. data/lib/devise_invitable.rb +14 -0
  16. data/lib/devise_invitable/locales/en.yml +5 -0
  17. data/lib/devise_invitable/mailer.rb +9 -0
  18. data/lib/devise_invitable/rails.rb +3 -0
  19. data/lib/devise_invitable/routes.rb +28 -0
  20. data/lib/devise_invitable/schema.rb +11 -0
  21. data/rails/init.rb +1 -0
  22. data/test/integration/invitable_test.rb +122 -0
  23. data/test/integration_tests_helper.rb +38 -0
  24. data/test/mailers/invitation_test.rb +62 -0
  25. data/test/model_tests_helper.rb +59 -0
  26. data/test/models/invitable_test.rb +164 -0
  27. data/test/models_test.rb +35 -0
  28. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  29. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  30. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  31. data/test/rails_app/app/controllers/users_controller.rb +12 -0
  32. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  33. data/test/rails_app/app/models/user.rb +4 -0
  34. data/test/rails_app/app/views/home/index.html.erb +0 -0
  35. data/test/rails_app/config/boot.rb +110 -0
  36. data/test/rails_app/config/database.yml +22 -0
  37. data/test/rails_app/config/environment.rb +44 -0
  38. data/test/rails_app/config/environments/development.rb +17 -0
  39. data/test/rails_app/config/environments/production.rb +28 -0
  40. data/test/rails_app/config/environments/test.rb +28 -0
  41. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/rails_app/config/initializers/inflections.rb +2 -0
  43. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  44. data/test/rails_app/config/initializers/session_store.rb +15 -0
  45. data/test/rails_app/config/routes.rb +3 -0
  46. data/test/rails_app/vendor/plugins/devise_invitable/init.rb +1 -0
  47. data/test/routes_test.rb +20 -0
  48. data/test/test_helper.rb +58 -0
  49. metadata +156 -0
@@ -0,0 +1,35 @@
1
+ require 'test/test_helper'
2
+
3
+ class Invitable < User
4
+ devise :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
+
18
+ (Devise::ALL - modules).each do |mod|
19
+ assert_not include_module?(klass, mod), "#{klass} include #{mod}"
20
+ end
21
+ end
22
+
23
+ test 'add invitable module only' do
24
+ assert_include_modules Invitable, :authenticatable, :invitable
25
+ end
26
+
27
+ test 'set a default value for invit_for' do
28
+ assert_equal 5.days, Invitable.invite_for
29
+ end
30
+
31
+ test 'invitable attributes' do
32
+ assert_not_nil Invitable.columns_hash['invitation_token']
33
+ assert_not_nil Invitable.columns_hash['invitation_sent_at']
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ class AdminsController < ApplicationController
2
+ before_filter :authenticate_admin!
3
+
4
+ def index
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ filter_parameter_logging :password
10
+ end
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ 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,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ devise :all
3
+ attr_accessible :username, :email, :password, :password_confirmation
4
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ min_version = '1.3.2'
86
+ require 'rubygems'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -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,44 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '~> 2.3.4' unless defined? RAILS_GEM_VERSION
5
+
6
+ # Bootstrap the Rails environment, frameworks, and default configuration
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ Rails::Initializer.run do |config|
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Add additional load paths for your own custom dirs
15
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
+
17
+ # Specify gems that this application depends on and have them installed with rake gems:install
18
+ # config.gem "bj"
19
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
+ # config.gem "aws-s3", :lib => "aws/s3"
22
+ config.gem 'devise'
23
+
24
+ # Only load the plugins named here, in the order given (default is alphabetical).
25
+ # :all can be used as a placeholder for all plugins not explicitly named
26
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
27
+ #config.plugin_paths += %W( #{RAILS_ROOT}/../../.. )
28
+ #config.plugins = [:devise_invitable]
29
+
30
+ # Skip frameworks you're not going to use. To use Rails without a database,
31
+ # you must remove the Active Record framework.
32
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
33
+
34
+ # Activate observers that should always be running
35
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
36
+
37
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
38
+ # Run "rake -D time" for a list of tasks for finding time zone names.
39
+ config.time_zone = 'UTC'
40
+
41
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
42
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
43
+ # config.i18n.default_locale = :en
44
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = 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
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
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.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
7
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,2 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ end
@@ -0,0 +1,21 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ ActionController::Routing.generate_best_match = false
15
+
16
+ # Use ISO 8601 format for JSON serialized times and dates.
17
+ ActiveSupport.use_standard_json_time_format = true
18
+
19
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
+ # if you're including raw json in an HTML page.
21
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_rails_app_session',
9
+ :secret => '89e8147901a0d7c221ac130e0ded3eeab6dab4a97127255909f08fedaae371918b41dec9d4d75c5b27a55c3772d43c2b6a3cbac232c5cc2ce4b8ec22242f5e60'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.root :controller => :home
3
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '../../../../../init')
@@ -0,0 +1,20 @@
1
+ require 'test/test_helper'
2
+
3
+ class MapRoutingTest < ActionController::TestCase
4
+
5
+ test 'map new user invitation' do
6
+ assert_recognizes({:controller => 'invitations', :action => 'new'}, {:path => 'users/invitation/new', :method => :get})
7
+ end
8
+
9
+ test 'map create user invitation' do
10
+ assert_recognizes({:controller => 'invitations', :action => 'create'}, {:path => 'users/invitation', :method => :post})
11
+ end
12
+
13
+ test 'map edit user invitation' do
14
+ assert_recognizes({:controller => 'invitations', :action => 'edit'}, 'users/invitation/edit')
15
+ end
16
+
17
+ test 'map update user invitation' do
18
+ assert_recognizes({:controller => 'invitations', :action => 'update'}, {:path => 'users/invitation', :method => :put})
19
+ end
20
+ end
@@ -0,0 +1,58 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.join(File.dirname(__FILE__), 'rails_app', 'config', 'environment')
3
+
4
+ require 'test_help'
5
+ require 'mocha'
6
+ require 'webrat'
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'devise', 'models', 'invitable')
8
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'devise', 'controllers', 'url_helpers')
9
+ ActionView::Base.send :include, Devise::Controllers::UrlHelpers
10
+
11
+ path = File.join(File.dirname(__FILE__), '..', 'app', 'views')
12
+ ActionController::Base.view_paths << path
13
+ DeviseMailer.view_paths << path
14
+
15
+ ActionMailer::Base.delivery_method = :test
16
+ ActionMailer::Base.perform_deliveries = true
17
+ ActionMailer::Base.default_url_options[:host] = 'test.com'
18
+
19
+ ActiveRecord::Migration.verbose = false
20
+ ActiveRecord::Base.logger = Logger.new(nil)
21
+
22
+ ActiveRecord::Schema.define(:version => 1) do
23
+ create_table :users do |t|
24
+ t.authenticatable :null => true
25
+ t.string :username
26
+ t.confirmable
27
+ t.invitable
28
+
29
+ t.timestamps
30
+ end
31
+ end
32
+ class User
33
+ devise :authenticatable, :invitable
34
+ end
35
+ ActionController::Routing::Routes.draw do |map|
36
+ map.devise_for :users
37
+ end
38
+ require File.join(File.dirname(__FILE__), '..', 'app', 'controllers', 'invitations_controller')
39
+ InvitationsController.send :include, Devise::Controllers::Filters
40
+
41
+ Webrat.configure do |config|
42
+ config.mode = :rails
43
+ config.open_error_files = false
44
+ end
45
+
46
+ class ActiveSupport::TestCase
47
+ self.use_transactional_fixtures = true
48
+ self.use_instantiated_fixtures = false
49
+
50
+ def assert_not(assertion, message = nil)
51
+ assert !assertion, message
52
+ end
53
+
54
+ def assert_not_blank(assertion)
55
+ assert !assertion.blank?
56
+ end
57
+ alias :assert_present :assert_not_blank
58
+ end