acts_as_referred 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +89 -0
  4. data/Rakefile +30 -0
  5. data/lib/acts_as_referred.rb +21 -0
  6. data/lib/acts_as_referred/class_methods.rb +14 -0
  7. data/lib/acts_as_referred/controller.rb +87 -0
  8. data/lib/acts_as_referred/instance_methods.rb +20 -0
  9. data/lib/acts_as_referred/model.rb +146 -0
  10. data/lib/acts_as_referred/version.rb +3 -0
  11. data/lib/tasks/acts_as_referred_tasks.rake +20 -0
  12. data/test/acts_as_referred_test.rb +97 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/Rakefile +6 -0
  15. data/test/dummy/app/assets/javascripts/application.js +13 -0
  16. data/test/dummy/app/assets/javascripts/bookings.js +2 -0
  17. data/test/dummy/app/assets/javascripts/orders.js +2 -0
  18. data/test/dummy/app/assets/javascripts/referees.js +2 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  20. data/test/dummy/app/assets/stylesheets/bookings.css +4 -0
  21. data/test/dummy/app/assets/stylesheets/orders.css +4 -0
  22. data/test/dummy/app/assets/stylesheets/referees.css +4 -0
  23. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  24. data/test/dummy/app/controllers/application_controller.rb +8 -0
  25. data/test/dummy/app/controllers/bookings_controller.rb +58 -0
  26. data/test/dummy/app/controllers/orders_controller.rb +58 -0
  27. data/test/dummy/app/helpers/referees_helper.rb +2 -0
  28. data/test/dummy/app/models/booking.rb +3 -0
  29. data/test/dummy/app/models/order.rb +3 -0
  30. data/test/dummy/app/views/bookings/_form.html.erb +25 -0
  31. data/test/dummy/app/views/bookings/edit.html.erb +6 -0
  32. data/test/dummy/app/views/bookings/index.html.erb +29 -0
  33. data/test/dummy/app/views/bookings/new.html.erb +5 -0
  34. data/test/dummy/app/views/bookings/show.html.erb +18 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/app/views/orders/_form.html.erb +25 -0
  37. data/test/dummy/app/views/orders/edit.html.erb +6 -0
  38. data/test/dummy/app/views/orders/index.html.erb +29 -0
  39. data/test/dummy/app/views/orders/new.html.erb +5 -0
  40. data/test/dummy/app/views/orders/show.html.erb +14 -0
  41. data/test/dummy/bin/bundle +3 -0
  42. data/test/dummy/bin/rails +4 -0
  43. data/test/dummy/bin/rake +4 -0
  44. data/test/dummy/config.ru +4 -0
  45. data/test/dummy/config/application.rb +23 -0
  46. data/test/dummy/config/boot.rb +5 -0
  47. data/test/dummy/config/database.yml +25 -0
  48. data/test/dummy/config/environment.rb +5 -0
  49. data/test/dummy/config/environments/development.rb +29 -0
  50. data/test/dummy/config/environments/production.rb +80 -0
  51. data/test/dummy/config/environments/test.rb +36 -0
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  54. data/test/dummy/config/initializers/inflections.rb +16 -0
  55. data/test/dummy/config/initializers/mime_types.rb +5 -0
  56. data/test/dummy/config/initializers/secret_token.rb +12 -0
  57. data/test/dummy/config/initializers/session_store.rb +3 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/locales/en.yml +23 -0
  60. data/test/dummy/config/routes.rb +59 -0
  61. data/test/dummy/db/development.sqlite3 +0 -0
  62. data/test/dummy/db/migrate/20130926092411_create_bookings.rb +10 -0
  63. data/test/dummy/db/migrate/20131001152526_create_referee.rb +19 -0
  64. data/test/dummy/db/schema.rb +40 -0
  65. data/test/dummy/db/test.sqlite3 +0 -0
  66. data/test/dummy/lib/tasks/acts_as_referred_tasks.rake +20 -0
  67. data/test/dummy/log/development.log +2650 -0
  68. data/test/dummy/log/test.log +7254 -0
  69. data/test/dummy/public/404.html +58 -0
  70. data/test/dummy/public/422.html +58 -0
  71. data/test/dummy/public/500.html +57 -0
  72. data/test/dummy/public/favicon.ico +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/00e0c908a950734c71f87d732990a88e +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/0bd337b765d2a19a6d65ec976c83d97e +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/12274417909f62d494c4179d6f8bcbe3 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/2fdee9aa34e89b0182a7523c4484e5f6 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/31da0321b4952412da9e1d9a1118e056 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/36a1fb9df9acb7490c5ac1284b2de56b +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/5c9d9893cd8a52cf99a46b89383cc603 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/7fa2dc3bb1d9661e45d7e10e8b2f9190 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/a3756bfb305f629747ba5349a5b02be0 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/b1e18c11e5c99b4c7871deabd029f38e +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/b78b6f63e1fe791ab77083cd45eb5105 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/bb1f3aab6b0702db7f17992ade69175a +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/cb9b952d9398fec90275bc0ef98f4b0c +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/d1558f1aaf36f9640ae86479f11375df +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/e4468469b981ba614a29626880137332 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/e66cbc95d30d07acdf168b5c0de354d7 +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/f464df872844f50aadec7fd7d56783af +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/fd365928616248fd8efc56ed88d265ad +0 -0
  100. data/test/test_helper.rb +15 -0
  101. metadata +261 -0
@@ -0,0 +1,3 @@
1
+ module ActsAsReferred
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ namespace :acts_as_referred do
2
+
3
+ desc "This will setup a database-table 'referees'"
4
+ task :create_table do
5
+ args = %w{ referable_id:integer:index
6
+ referable_type:string:index
7
+ is_campaign:boolean:index
8
+ origin:string
9
+ origin_host:string
10
+ request:string
11
+ request_query:string
12
+ campaign:string
13
+ keywords:string
14
+ visits:integer
15
+
16
+ }
17
+ system("bundle exec rails g migration CreateReferee #{args.join(' ')}")
18
+ end
19
+
20
+ end
@@ -0,0 +1,97 @@
1
+ require 'test_helper'
2
+
3
+ class ActsAsReferredTest < ActiveSupport::TestCase
4
+
5
+ def prepare_booking(params)
6
+ struct = OpenStruct.new( request_url: params[:request], referrer_url: params[:referrer], count: 0)
7
+ Booking.send(:define_method, '_get_reqref', -> { struct } )
8
+ Booking.create
9
+ end
10
+
11
+ def prepare_booking_no_referrer(params)
12
+ struct = OpenStruct.new( request_url: params[:request], referrer_url: nil, count: 0)
13
+ Booking.send(:define_method, '_get_reqref', -> { struct } )
14
+ Booking.create
15
+ end
16
+
17
+
18
+
19
+ test "truth" do
20
+ assert_kind_of Module, ActsAsReferred
21
+ end
22
+
23
+ test "test_a_booking_referrer_host_should_be_nsa" do
24
+ booking = prepare_booking(piwik_params)
25
+ assert_equal "www.nsa.gov", booking.referee.origin_host
26
+ end
27
+
28
+ test "test_a_booking_referrer_host_should_be_google" do
29
+ assert_equal 'google.com', prepare_booking(google_params).referee.origin_host
30
+ end
31
+
32
+ test "test_a_booking_request_path_should_be_foo" do
33
+ assert_equal '/foo', prepare_booking(piwik_params).referee.request_path
34
+ end
35
+
36
+ test 'test_a_booking_query' do
37
+ assert_equal 'pk_campaign=Explosives&pk_term=dynamite', prepare_booking(piwik_params).referee.request_query
38
+ end
39
+
40
+ test 'test_a_order_with_no_referrer_should_return_nil' do
41
+ assert_equal nil, prepare_booking_no_referrer(no_referer_params).referee.origin
42
+ end
43
+
44
+ test 'test_a_booking_autotagged_should_return_campaign' do
45
+ assert_equal true, prepare_booking(google_params_autotagged).referee.is_campaign
46
+ end
47
+
48
+ test 'test_a_booking_with_no_campaign_should_return_is_campaign_nil' do
49
+ assert_equal nil, prepare_booking(direct_params).referee.is_campaign
50
+ end
51
+
52
+ test 'test_referee_scope_campaigns_should_return_one' do
53
+ prepare_booking(google_params)
54
+ assert_equal 1, Referee.campaigns.count
55
+ end
56
+
57
+ test 'test_booking_keywords_should_be_present' do
58
+ assert_equal 'dynamite', prepare_booking(google_params).referee.keywords
59
+ end
60
+
61
+ def no_referer_params
62
+ {
63
+ request: "http://domain.com/foo?pk_campaign=Explosives&pk_term=dynamite"
64
+ }
65
+
66
+ end
67
+
68
+ def direct_params
69
+ {
70
+ request: "http://domain.com/foo",
71
+ referrer: "http://domain.com"
72
+ }
73
+ end
74
+
75
+ def piwik_params
76
+ {
77
+ referrer: 'http://www.nsa.gov/about/values/index.shtml?attr=terror&reason=politics',
78
+ request: "http://domain.com/foo?pk_campaign=Explosives&pk_term=dynamite"
79
+ }
80
+ end
81
+
82
+ def google_params
83
+ {
84
+ referrer: 'https://google.com?q=store',
85
+ request: "http://domain.com/foo?utm_campaign=Explosives&utm_term=dynamite"
86
+ }
87
+ end
88
+
89
+ def google_params_autotagged
90
+ {
91
+ referrer: 'https://google.com?q=store',
92
+ request: "http://domain.com/foo?gclid=236428346782346283434"
93
+ }
94
+ end
95
+
96
+ end
97
+
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
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
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,8 @@
1
+ class ApplicationController < ActionController::Base
2
+ include ActsAsReferred::Controller
3
+
4
+ # Prevent CSRF attacks by raising an exception.
5
+ # For APIs, you may want to use :null_session instead.
6
+ protect_from_forgery with: :exception
7
+
8
+ end
@@ -0,0 +1,58 @@
1
+ class BookingsController < ApplicationController
2
+ before_action :set_booking, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /bookings
5
+ def index
6
+ @bookings = Booking.all
7
+ end
8
+
9
+ # GET /bookings/1
10
+ def show
11
+ end
12
+
13
+ # GET /bookings/new
14
+ def new
15
+ @booking = Booking.new
16
+ end
17
+
18
+ # GET /bookings/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /bookings
23
+ def create
24
+ @booking = Booking.new(booking_params)
25
+
26
+ if @booking.save
27
+ redirect_to @booking, notice: 'Booking was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /bookings/1
34
+ def update
35
+ if @booking.update(booking_params)
36
+ redirect_to @booking, notice: 'Booking was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /bookings/1
43
+ def destroy
44
+ @booking.destroy
45
+ redirect_to bookings_url, notice: 'Booking was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_booking
51
+ @booking = Booking.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def booking_params
56
+ params.require(:booking).permit(:thing, :referrer)
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ class OrdersController < ApplicationController
2
+ before_action :set_order, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /orders
5
+ def index
6
+ @orders = Order.all
7
+ end
8
+
9
+ # GET /orders/1
10
+ def show
11
+ end
12
+
13
+ # GET /orders/new
14
+ def new
15
+ @order = Order.new
16
+ end
17
+
18
+ # GET /orders/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /orders
23
+ def create
24
+ @order = Order.new(order_params)
25
+
26
+ if @order.save
27
+ redirect_to @order, notice: 'Order was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /orders/1
34
+ def update
35
+ if @order.update(order_params)
36
+ redirect_to @order, notice: 'Order was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /orders/1
43
+ def destroy
44
+ @order.destroy
45
+ redirect_to orders_url, notice: 'Order was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_order
51
+ @order = Order.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def order_params
56
+ params.require(:order).permit(:thing, :referred_from)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module RefereesHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Booking < ActiveRecord::Base
2
+ acts_as_referred
3
+ end
@@ -0,0 +1,3 @@
1
+ class Order < ActiveRecord::Base
2
+ acts_as_referred
3
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@booking) do |f| %>
2
+ <% if @booking.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@booking.errors.count, "error") %> prohibited this booking from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @booking.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :thing %><br>
16
+ <%= f.text_field :thing %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :referrer %><br>
20
+ <%= f.text_field :referrer %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>