devise_referable 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,12 +1,12 @@
1
1
  class ReferralsController < ApplicationController
2
2
 
3
3
  def create
4
+
4
5
  unless user_signed_in?
5
6
  @referral = Referral.from_token(params[:referrer_token])
6
- session[:referral_token] = @referral.referral_token if @referral
7
+ cookies['referral_token'] = {:value => @referral.referral_token, :expires => 1.month.from_now} if @referral
7
8
  end
8
9
  redirect_to "/#{params[:path].join('/')}"
9
10
  end
10
-
11
+
11
12
  end
12
-
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_referable}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Van Horn, based on work by Sergio Cambra"]
12
- s.date = %q{2010-03-22}
12
+ s.date = %q{2010-03-25}
13
13
  s.description = %q{It tracks the referring entity via cookie, and creates a record when user registers.}
14
14
  s.email = %q{mattvanhorn@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -4,10 +4,10 @@
4
4
  # in other circumstances where a user was existing in a legacy db for example.
5
5
 
6
6
  Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
7
- token = warden.env['rack.session'][:referral_token]
7
+ token = warden.env['rack.request.cookie_hash']['referral_token']
8
8
  scope = options[:scope]
9
9
  if record.respond_to?(:referral) && record.referral.nil? && warden.authenticated?(scope) && token
10
10
  record.update_referral(token) if record.respond_to?(:update_referral)
11
- warden.env['rack.session'][:referral_token] = nil
11
+ warden.response.delete_cookie 'referral_token'
12
12
  end
13
- end
13
+ end
@@ -5,7 +5,7 @@ Devise.module_eval do
5
5
  end
6
6
  Devise.add_module :referable, :controller => :referrals, :model => 'devise_referable/model'
7
7
 
8
- module DeviseReferable; end
8
+ module DeviseReferable;end
9
9
 
10
10
  require 'devise_referable/routes'
11
11
  require 'devise_referable/referral'
@@ -11,15 +11,15 @@ module Devise
11
11
  # When a visitor arrives at the site via the referral_landing_path, the following things happen:
12
12
  # - The referrer is looked up, by doing finds against the referrer_types in order.
13
13
  # - If found, a referral record is created with a unique referral_token.
14
- # - The referral_token is also stored in the session
14
+ # - The referral_token is also stored in a cookie
15
15
  # - The visitor is then redirected to the path appended to the referral_landing_path (i.e. /path/to/destination above)
16
16
  # - If no path is given, they're redirected to the root path.
17
- # - If the visitor registers during the session, the referral record is updated with the new user id, and the session token is cleared.
17
+ # - If the visitor registers before the cookie expires, the referral record is updated with the new user id, and the cookie is cleared.
18
18
  #
19
19
  # Configuration:
20
20
  #
21
21
  # referrer_types: an array of symbols for classes that can refer users. i.e. [:blog, :customer, :user]
22
- #
22
+
23
23
  module Referable
24
24
 
25
25
  def self.included(base)
@@ -12,7 +12,7 @@ class ReferralTest < ActionController::IntegrationTest
12
12
  visit referral_landing_path(:referrer_token => 'abc123')
13
13
  assert :success
14
14
  assert_equal 1, Referral.count
15
- assert_not_nil session[:referral_token]
15
+ assert_not_nil cookies['referral_token']
16
16
 
17
17
  visit new_user_registration_path
18
18
  assert :success
@@ -22,8 +22,7 @@ class ReferralTest < ActionController::IntegrationTest
22
22
  fill_in 'password confirmation', :with => 'new_user123'
23
23
  click_button 'Sign up'
24
24
 
25
- user = User.last :order => "id"
26
-
25
+ user = User.last :order => "id ASC"
27
26
  assert user.referral.referrer == @blog
28
27
  end
29
28
 
@@ -53,7 +52,7 @@ class ReferralTest < ActionController::IntegrationTest
53
52
  assert :success
54
53
 
55
54
  assert_equal 0, Referral.count
56
- assert_nil session[:referral_token]
55
+ assert_nil cookies['referral_token']
57
56
  end
58
57
 
59
58
  end
@@ -38,15 +38,6 @@ class ActiveSupport::TestCase
38
38
  User.create!(valid_attributes(attributes))
39
39
  end
40
40
 
41
- # def create_user_with_invitation(invitation_token, attributes={})
42
- # user = new_user({:password => nil, :password_confirmation => nil}.update(attributes))
43
- # user.skip_confirmation!
44
- # user.invitation_token = invitation_token
45
- # user.invitation_sent_at = Time.now.utc
46
- # user.save(false)
47
- # user
48
- # end
49
-
50
41
  # Execute the block setting the given values and restoring old values after
51
42
  # the block is executed.
52
43
  def swap(object, new_values)
data/test/models_test.rb CHANGED
@@ -24,8 +24,9 @@ class ActiveRecordTest < ActiveSupport::TestCase
24
24
  assert_include_modules Referable, :authenticatable, :referable
25
25
  end
26
26
 
27
- test 'set a default value for invite_for' do
27
+ test 'set a value for referrer_types' do
28
28
  assert_equal [:foo, :bar], Referable.referrer_types
29
29
  end
30
+
30
31
 
31
32
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt Van Horn, based on work by Sergio Cambra
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-22 00:00:00 -04:00
17
+ date: 2010-03-25 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency