Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

record original http_referer on signature

  • Loading branch information...
commit d16c18624c1a4fc35788ac1875ba78f8b626ba08 1 parent 4736c4a
@manderdev manderdev authored
View
10 app/controllers/application_controller.rb
@@ -4,7 +4,15 @@ class ApplicationController < ActionController::Base
helper_method :win!, :spin!, :spin_if_cool_browser!, :is_admin
protect_from_forgery
- before_filter :add_environment_to_title
+ before_filter :add_environment_to_title, :stash_http_referer
+
+ def stash_http_referer
+ session['http_referer'] = request.referer || "none" unless session['http_referer']
+ end
+
+ def retrieve_http_referer
+ session['http_referer'] == "none" ? nil : session['http_referer']
+ end
def add_environment_to_title
@title = "Watchdog.net"
View
2  app/controllers/signatures_controller.rb
@@ -10,6 +10,8 @@ def create
signature.browser_name = browser.id.to_s
signature.member = Member.find_or_initialize_by_email(email: signature.email, first_name: signature.first_name, last_name: signature.last_name)
signature.created_member = signature.member.new_record?
+ signature.http_referer = retrieve_http_referer
+
member_hash = nil
if signature.valid?
begin
View
2  app/models/signature.rb
@@ -1,5 +1,5 @@
class Signature < ActiveRecord::Base
- attr_accessible :email, :first_name, :last_name, :reference_type, :referer, :referring_url, :browser_name
+ attr_accessible :email, :first_name, :last_name, :reference_type, :referer, :referring_url, :http_referer, :browser_name
belongs_to :petition
belongs_to :member
belongs_to :referer, :class_name => 'Member', :foreign_key => 'referer_id'
View
23 spec/controllers/application_controller_spec.rb
@@ -38,4 +38,27 @@ def controller.spin! test_name, goals, options, my_session
end
end
end
+
+ describe "stashing and retrieving http referer" do
+ it "should return value once initially stashed as that value" do
+ request.stub(:referer).and_return "www.initial.com"
+ controller.stash_http_referer
+ controller.retrieve_http_referer.should == "www.initial.com"
+
+ request.stub(:referer).and_return "www.elsewhere.com"
+ controller.stash_http_referer
+ controller.retrieve_http_referer.should == "www.initial.com"
+ end
+
+ it "should return nil once initially stashed as nil" do
+ request.stub(:referer).and_return nil
+ controller.stash_http_referer
+ controller.retrieve_http_referer.should be_nil
+
+ request.stub(:referer).and_return "www.elsewhere.com"
+ controller.stash_http_referer
+ controller.retrieve_http_referer.should be_nil
+ end
+ end
+
end
View
13 spec/controllers/signatures_controller_spec.rb
@@ -8,11 +8,13 @@
let(:petition) { create(:petition) }
let(:signature_fields) { {first_name: 'Bob', last_name: 'Loblaw', email: 'bob@my.com'} }
- let(:referring_url) { 'http://petitionator.com/456?other_stuff=etc' }
+ let(:referring_url) { 'http://watchdog.net/123?ref=bzzt' }
+ let(:http_referer) { 'http://petitionator.com/456?other_stuff=etc' }
describe 'POST create' do
before do
Resque.stub(:enqueue)
+ request.stub(:referer).and_return http_referer
end
context 'when the user supplies both a name and an email' do
@@ -26,9 +28,9 @@
member.signatures.each &:destroy
member.destroy
end
-
+
subject { petition.signatures.first }
-
+
context 'new signature' do
its(:first_name) { should == signature_fields[:first_name] }
its(:last_name) { should == signature_fields[:last_name] }
@@ -65,6 +67,7 @@
subject { Signature.last }
its(:reference_type) { should == type }
its(:referring_url) { should == referring_url }
+ its(:http_referer) { should == http_referer }
its(:referer) { should == member }
end
@@ -167,7 +170,7 @@
end
subject { Signature.last }
-
+
its(:reference_type) { should == type }
its(:referring_url) { should be_nil }
its(:referer) { should == member }
@@ -217,7 +220,7 @@ def sign_petition params = {}
request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'
post :create, params.merge({petition_id: petition.id, signature: signature_fields, referring_url: referring_url})
end
-
+
def sign_without_name_or_email
post :create, petition_id: petition.id
end
Please sign in to comment.
Something went wrong with that request. Please try again.