devise_referable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +81 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/app/controllers/referrals_controller.rb +12 -0
- data/app/models/referral.rb +38 -0
- data/devise_referable.gemspec +117 -0
- data/init.rb +1 -0
- data/lib/devise/hooks/referable.rb +13 -0
- data/lib/devise_referable/model.rb +47 -0
- data/lib/devise_referable/routes.rb +12 -0
- data/lib/devise_referable.rb +12 -0
- data/rails/init.rb +1 -0
- data/test/integration/referable_test.rb +59 -0
- data/test/integration_tests_helper.rb +35 -0
- data/test/model_tests_helper.rb +64 -0
- data/test/models/referral_test.rb +40 -0
- data/test/models_test.rb +31 -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/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 +3 -0
- data/test/rails_app/app/models/blog.rb +3 -0
- data/test/rails_app/app/models/user.rb +4 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/database.yml +22 -0
- data/test/rails_app/config/environment.rb +44 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +76 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +4 -0
- data/test/rails_app/vendor/plugins/devise_referable/init.rb +1 -0
- data/test/routes_test.rb +21 -0
- data/test/test_helper.rb +66 -0
- metadata +167 -0
data/test/models_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class Referable < User
|
4
|
+
devise :authenticatable, :referable, :referrer_types => [:foo, :bar]
|
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 referable module only' do
|
24
|
+
assert_include_modules Referable, :authenticatable, :referable
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'set a default value for invite_for' do
|
28
|
+
assert_equal [:foo, :bar], Referable.referrer_types
|
29
|
+
end
|
30
|
+
|
31
|
+
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,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 @@
|
|
1
|
+
home page
|
@@ -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_referable]
|
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,76 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# Configure Devise modules used by default. You should always set this value
|
5
|
+
# because if Devise adds a new strategy, it won't be added to your application
|
6
|
+
# by default, unless you configure it here.
|
7
|
+
#
|
8
|
+
# Remember that Devise includes other modules on its own (like :activatable
|
9
|
+
# and :timeoutable) which are not included here and also plugins. So be sure
|
10
|
+
# to check the docs for a complete set.
|
11
|
+
config.all = [:authenticatable, :recoverable, :rememberable, :trackable, :validatable]
|
12
|
+
|
13
|
+
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
14
|
+
# the encrypted password. By default no pepper is used.
|
15
|
+
# config.pepper = "rake secret output"
|
16
|
+
|
17
|
+
# Configure how many times you want the password is reencrypted. Default is 10.
|
18
|
+
# config.stretches = 10
|
19
|
+
|
20
|
+
# Define which will be the encryption algorithm. Supported algorithms are :sha1
|
21
|
+
# (default) and :sha512. Devise also supports encryptors from others authentication
|
22
|
+
# frameworks as :clearance_sha1, :authlogic_sha512 (then you should set stretches
|
23
|
+
# above to 20 for default behavior) and :restful_authentication_sha1 (then you
|
24
|
+
# should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
25
|
+
# config.encryptor = :sha1
|
26
|
+
|
27
|
+
# Configure which keys are used when authenticating an user. By default is
|
28
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
29
|
+
# authenticating an user, both parameters are required. Remember that those
|
30
|
+
# parameters are used only when authenticating and not when retrieving from
|
31
|
+
# session. If you need permissions, you should implement that in a before filter.
|
32
|
+
# config.authentication_keys = [ :email ]
|
33
|
+
|
34
|
+
# The time you want give to your user to confirm his account. During this time
|
35
|
+
# he will be able to access your application without confirming. Default is nil.
|
36
|
+
# config.confirm_within = 2.days
|
37
|
+
|
38
|
+
# The time the user will be remembered without asking for credentials again.
|
39
|
+
# config.remember_for = 2.weeks
|
40
|
+
|
41
|
+
# The time you want to timeout the user session without activity. After this
|
42
|
+
# time the user will be asked for credentials again.
|
43
|
+
# config.timeout_in = 10.minutes
|
44
|
+
|
45
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
46
|
+
# config.mailer_sender = "foo.bar@yourapp.com"
|
47
|
+
|
48
|
+
# Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
|
49
|
+
# require 'devise/orm/mongo_mapper'
|
50
|
+
# config.orm = :mongo_mapper
|
51
|
+
|
52
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
53
|
+
# "sessions/users/new". It's turned off by default because it's slower if you
|
54
|
+
# are using only default views.
|
55
|
+
# config.scoped_views = true
|
56
|
+
|
57
|
+
# If you want to use other strategies, that are not (yet) supported by Devise,
|
58
|
+
# you can configure them inside the config.warden block. The example below
|
59
|
+
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
60
|
+
#
|
61
|
+
# config.warden do |manager|
|
62
|
+
# manager.oauth(:twitter) do |twitter|
|
63
|
+
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
64
|
+
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
65
|
+
# twitter.options :site => 'http://twitter.com'
|
66
|
+
# end
|
67
|
+
# manager.default_strategies.unshift :twitter_oauth
|
68
|
+
# end
|
69
|
+
|
70
|
+
# Configure default_url_options if you are using dynamic segments in :path_prefix
|
71
|
+
# for devise_for.
|
72
|
+
#
|
73
|
+
# config.default_url_options do
|
74
|
+
# { :locale => I18n.locale }
|
75
|
+
# end
|
76
|
+
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 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../../../../init')
|
data/test/routes_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class MapRoutingTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test 'map referral ' do
|
6
|
+
assert_recognizes({:controller => 'referrals', :action => 'create', :referrer_token => 'abc123', :path => []}, {:path => 'ref/abc123/', :method => :get})
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'map referral landing' do
|
10
|
+
assert_recognizes({:controller => 'referrals', :action => 'create', :referrer_token => 'abc123', :path => []}, {:path => 'ref/abc123/', :method => :get})
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'map referral landing with path' do
|
14
|
+
assert_recognizes({:controller => 'referrals', :action => 'create', :referrer_token => 'abc123', :path => %w(some path here)}, {:path => 'ref/abc123/some/path/here', :method => :get})
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'map referral landing with no path' do
|
18
|
+
assert_recognizes({:controller => 'referrals', :action => 'create', :referrer_token => 'abc123', :path => []}, {:path => 'ref/abc123', :method => :get})
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
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
|
+
|
8
|
+
ActiveRecord::Migration.verbose = false
|
9
|
+
ActiveRecord::Base.logger = Logger.new(nil)
|
10
|
+
|
11
|
+
ActiveRecord::Schema.define(:version => 1) do
|
12
|
+
create_table :users do |t|
|
13
|
+
t.authenticatable :null => true
|
14
|
+
t.registerable
|
15
|
+
t.string :username
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :blogs do |t|
|
20
|
+
t.string :name
|
21
|
+
t.string :referrer_token, :default => 'abc123'
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :referrals, :force => true do |t|
|
26
|
+
t.integer :referrer_id
|
27
|
+
t.string :referrer_type
|
28
|
+
t.integer :recipient_id
|
29
|
+
t.string :referral_token
|
30
|
+
t.datetime :registered_at
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Blog
|
36
|
+
end
|
37
|
+
|
38
|
+
class User
|
39
|
+
devise :authenticatable, :registerable, :referable, :referrer_types => [:blog]
|
40
|
+
end
|
41
|
+
|
42
|
+
ActionController::Routing::Routes.draw do |map|
|
43
|
+
map.devise_for :users
|
44
|
+
end
|
45
|
+
|
46
|
+
require File.join(File.dirname(__FILE__), '..', 'app', 'controllers', 'referrals_controller')
|
47
|
+
require File.join(File.dirname(__FILE__), '..', 'app', 'models', 'referral')
|
48
|
+
|
49
|
+
Webrat.configure do |config|
|
50
|
+
config.mode = :rails
|
51
|
+
config.open_error_files = false
|
52
|
+
end
|
53
|
+
|
54
|
+
class ActiveSupport::TestCase
|
55
|
+
self.use_transactional_fixtures = true
|
56
|
+
self.use_instantiated_fixtures = false
|
57
|
+
|
58
|
+
def assert_not(assertion, message = nil)
|
59
|
+
assert !assertion, message
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_not_blank(assertion)
|
63
|
+
assert !assertion.blank?
|
64
|
+
end
|
65
|
+
alias :assert_present :assert_not_blank
|
66
|
+
end
|