advert_selector 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +132 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/advert_selector/application.js +15 -0
  5. data/app/assets/stylesheets/advert_selector/application.css +29 -0
  6. data/app/controllers/advert_selector/application_controller.rb +26 -0
  7. data/app/controllers/advert_selector/banners_controller.rb +122 -0
  8. data/app/controllers/advert_selector/main_controller.rb +13 -0
  9. data/app/controllers/advert_selector/placements_controller.rb +89 -0
  10. data/app/helpers/advert_selector/application_helper.rb +155 -0
  11. data/app/models/advert_selector/banner.rb +107 -0
  12. data/app/models/advert_selector/helper_item.rb +21 -0
  13. data/app/models/advert_selector/placement.rb +58 -0
  14. data/app/views/advert_selector/banners/_form.html.erb +42 -0
  15. data/app/views/advert_selector/banners/edit.html.erb +29 -0
  16. data/app/views/advert_selector/banners/index.html.erb +38 -0
  17. data/app/views/advert_selector/banners/new.html.erb +5 -0
  18. data/app/views/advert_selector/banners/show.html.erb +50 -0
  19. data/app/views/advert_selector/helper_items/_form.html.erb +37 -0
  20. data/app/views/advert_selector/helper_items/edit.html.erb +6 -0
  21. data/app/views/advert_selector/helper_items/index.html.erb +31 -0
  22. data/app/views/advert_selector/helper_items/new.html.erb +5 -0
  23. data/app/views/advert_selector/helper_items/show.html.erb +30 -0
  24. data/app/views/advert_selector/main/index.html.erb +20 -0
  25. data/app/views/advert_selector/placements/_form.html.erb +40 -0
  26. data/app/views/advert_selector/placements/edit.html.erb +6 -0
  27. data/app/views/advert_selector/placements/index.html.erb +25 -0
  28. data/app/views/advert_selector/placements/new.html.erb +5 -0
  29. data/app/views/advert_selector/placements/show.html.erb +20 -0
  30. data/app/views/layouts/advert_selector/application.html.erb +89 -0
  31. data/config/routes.rb +17 -0
  32. data/db/migrate/20120924165938_create_advert_selector_placements.rb +11 -0
  33. data/db/migrate/20120925122858_create_advert_selector_banners.rb +23 -0
  34. data/db/migrate/20120926132649_create_advert_selector_helper_items.rb +18 -0
  35. data/lib/advert_selector.rb +26 -0
  36. data/lib/advert_selector/engine.rb +18 -0
  37. data/lib/advert_selector/errors_cache.rb +21 -0
  38. data/lib/advert_selector/version.rb +3 -0
  39. data/lib/tasks/advert_selector_tasks.rake +4 -0
  40. data/test/advert_selector_test.rb +7 -0
  41. data/test/dummy/README.rdoc +261 -0
  42. data/test/dummy/Rakefile +7 -0
  43. data/test/dummy/app/assets/javascripts/application.js +15 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  46. data/test/dummy/app/controllers/application_controller.rb +4 -0
  47. data/test/dummy/app/controllers/examples_controller.rb +4 -0
  48. data/test/dummy/app/helpers/advert_selector_helper.rb +23 -0
  49. data/test/dummy/app/helpers/application_helper.rb +2 -0
  50. data/test/dummy/app/views/examples/index.html.erb +34 -0
  51. data/test/dummy/app/views/layouts/application.html.erb +20 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/config/application.rb +59 -0
  54. data/test/dummy/config/boot.rb +10 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +37 -0
  58. data/test/dummy/config/environments/production.rb +67 -0
  59. data/test/dummy/config/environments/test.rb +37 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/inflections.rb +15 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +7 -0
  64. data/test/dummy/config/initializers/session_store.rb +8 -0
  65. data/test/dummy/config/initializers/silence_assets.rb +20 -0
  66. data/test/dummy/config/initializers/simple_form.rb +178 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +5 -0
  69. data/test/dummy/config/locales/simple_form.en.yml +26 -0
  70. data/test/dummy/config/routes.rb +8 -0
  71. data/test/dummy/db/development.sqlite3 +0 -0
  72. data/test/dummy/db/migrate/20120928114159_create_advert_selector_placements.advert_selector.rb +12 -0
  73. data/test/dummy/db/migrate/20120928114160_create_advert_selector_banners.advert_selector.rb +24 -0
  74. data/test/dummy/db/migrate/20120928114161_create_advert_selector_helper_items.advert_selector.rb +19 -0
  75. data/test/dummy/db/schema.rb +53 -0
  76. data/test/dummy/db/test.sqlite3 +0 -0
  77. data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  78. data/test/dummy/log/development.log +11516 -0
  79. data/test/dummy/log/test.log +66467 -0
  80. data/test/dummy/public/404.html +26 -0
  81. data/test/dummy/public/422.html +26 -0
  82. data/test/dummy/public/500.html +25 -0
  83. data/test/dummy/public/favicon.ico +0 -0
  84. data/test/dummy/script/rails +6 -0
  85. data/test/dummy/test/unit/helpers/examples_helper_test.rb +4 -0
  86. data/test/dummy/tmp/cache/88F/B60/AdvertSelectorBanner_2 +0 -0
  87. data/test/dummy/tmp/cache/943/570/advert_selector_errors +0 -0
  88. data/test/dummy/tmp/cache/A2C/760/AdvertSelectorBanner_207249520 +0 -0
  89. data/test/dummy/tmp/cache/A3E/CF0/AdvertSelectorBanner_394627963 +0 -0
  90. data/test/dummy/tmp/cache/A3F/BF0/AdvertSelectorBanner_814558298 +0 -0
  91. data/test/dummy/tmp/cache/A40/C00/AdvertSelectorBanner_814558299 +0 -0
  92. data/test/dummy/tmp/cache/assets/C57/D40/sprockets%2F4f1a95218761045e0b23975e889644aa +0 -0
  93. data/test/dummy/tmp/cache/assets/C5F/E80/sprockets%2F01c5361554f26407988a43647d88c5fe +0 -0
  94. data/test/dummy/tmp/cache/assets/C75/2E0/sprockets%2F23135a6eb5317973d290438c359a3c0a +0 -0
  95. data/test/dummy/tmp/cache/assets/C77/A40/sprockets%2F3b3d6c1426796a7024c7d3f42c283026 +0 -0
  96. data/test/dummy/tmp/cache/assets/C86/C20/sprockets%2Ffe1477ea429411b3b581466c928b6860 +0 -0
  97. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  98. data/test/dummy/tmp/cache/assets/CBA/C70/sprockets%2F26288ca60ed05d24b8189328e4df9373 +0 -0
  99. data/test/dummy/tmp/cache/assets/CD1/A90/sprockets%2F433a791e2f93c0d8391aaa62203943ca +0 -0
  100. data/test/dummy/tmp/cache/assets/CD3/DE0/sprockets%2F0406286714c3c0abfcb4573336f7e33c +0 -0
  101. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  102. data/test/dummy/tmp/cache/assets/CD9/E80/sprockets%2F9052578aacc61253aa3854fa03b4895d +0 -0
  103. data/test/dummy/tmp/cache/assets/CEB/040/sprockets%2F644677c3bb57b6ed6b675229cfe54305 +0 -0
  104. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  105. data/test/dummy/tmp/cache/assets/CF2/EF0/sprockets%2F30ffd128655c9f04e88fba233248e997 +0 -0
  106. data/test/dummy/tmp/cache/assets/CF7/B60/sprockets%2F2c2a2af94201088a2a815ba90b8d344c +0 -0
  107. data/test/dummy/tmp/cache/assets/D05/4D0/sprockets%2F2d14560f81284bfb61fc0e187a803f1d +0 -0
  108. data/test/dummy/tmp/cache/assets/D0E/380/sprockets%2Ff27b6f5008c5a7324a7d8a382f21e7f2 +0 -0
  109. data/test/dummy/tmp/cache/assets/D19/820/sprockets%2Fccd0e907b49615494cc88c43a4781a9c +0 -0
  110. data/test/dummy/tmp/cache/assets/D28/910/sprockets%2F79b8a6fa551206c9996cfe98b80492cb +0 -0
  111. data/test/dummy/tmp/cache/assets/D2D/C20/sprockets%2Ff7d7fd5892b198e1588dd7d90a29a717 +0 -0
  112. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  113. data/test/dummy/tmp/cache/assets/D36/570/sprockets%2Fadfccb7c2436e006496eae16d6901523 +0 -0
  114. data/test/dummy/tmp/cache/assets/D40/110/sprockets%2Fbc5fcd75a352287c59787234ccbb11a8 +0 -0
  115. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  116. data/test/dummy/tmp/cache/assets/D50/030/sprockets%2F90296cd1ff74af449206b4fbd57cc995 +0 -0
  117. data/test/dummy/tmp/cache/assets/D50/BD0/sprockets%2F9c4832ce629b45b57ed8a55fbc717a86 +0 -0
  118. data/test/dummy/tmp/cache/assets/D55/240/sprockets%2F4b378a9f8c71e387569adfd712a26ce9 +0 -0
  119. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  120. data/test/dummy/tmp/cache/assets/D68/0A0/sprockets%2F17a08f579f5d1585bbd0c6ce2bac4351 +0 -0
  121. data/test/dummy/tmp/cache/assets/D68/220/sprockets%2F701db0b265a7c593768caebb904de9a1 +0 -0
  122. data/test/dummy/tmp/cache/assets/D6A/EF0/sprockets%2F2eb65cc490ad96cc38604918b0caeb90 +0 -0
  123. data/test/dummy/tmp/cache/assets/D6F/040/sprockets%2Fbd56a4cbc86673dbf2242fb85571bf61 +0 -0
  124. data/test/dummy/tmp/cache/assets/D70/540/sprockets%2Ffb1dbed4c6b15bc994454964bd455a43 +0 -0
  125. data/test/dummy/tmp/cache/assets/D83/400/sprockets%2Fc5adb5e35a83a7e10361f02afa42d4c1 +0 -0
  126. data/test/dummy/tmp/cache/assets/D88/7F0/sprockets%2Fe3b83e01d5f51e442ec9c11b40cca81a +0 -0
  127. data/test/dummy/tmp/cache/assets/DA3/080/sprockets%2Ffb77a66783db0b5812e3fdbabe4608f6 +0 -0
  128. data/test/dummy/tmp/cache/assets/DCE/810/sprockets%2F6eeb2d90a03c9de3ce8f5f30acf58118 +0 -0
  129. data/test/dummy/tmp/cache/assets/DCE/D50/sprockets%2F2232ec55b4deca5e8120ced9bd79ef54 +0 -0
  130. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  131. data/test/dummy/tmp/cache/assets/DF1/360/sprockets%2F23acf8b0d41e15db4d6ac2729f3eed1d +0 -0
  132. data/test/dummy/tmp/cache/assets/DF5/B00/sprockets%2Ff93edea94ff32d205acd8cdc4532b12b +0 -0
  133. data/test/dummy/tmp/cache/assets/DFB/9A0/sprockets%2Fb9a29f57d1ebf045452ed6cbd62eae1d +0 -0
  134. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  135. data/test/dummy/tmp/cache/assets/E53/3C0/sprockets%2Fcd0f7cae0b53d5ff22db8bf547d6a1bc +0 -0
  136. data/test/fixtures/advert_selector/banners.yml +38 -0
  137. data/test/fixtures/advert_selector/helper_items.yml +28 -0
  138. data/test/fixtures/advert_selector/placements.yml +17 -0
  139. data/test/functional/advert_selector/banners_controller_test.rb +64 -0
  140. data/test/functional/advert_selector/main_controller_test.rb +30 -0
  141. data/test/functional/advert_selector/placements_controller_test.rb +58 -0
  142. data/test/functional/examples_controller_test.rb +13 -0
  143. data/test/integration/banner_shows_test.rb +154 -0
  144. data/test/integration/navigation_test.rb +10 -0
  145. data/test/test_helper.rb +43 -0
  146. data/test/unit/advert_selector/banner_test.rb +160 -0
  147. data/test/unit/advert_selector/helper_item_test.rb +9 -0
  148. data/test/unit/advert_selector/placement_test.rb +50 -0
  149. data/test/unit/helpers/advert_selector/banners_helper_test.rb +6 -0
  150. data/test/unit/helpers/advert_selector/placements_helper_test.rb +6 -0
  151. metadata +425 -0
@@ -0,0 +1,154 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ #require 'test/test_helper'
3
+
4
+ class BannerShowsTest < ActionDispatch::IntegrationTest
5
+ fixtures :all
6
+
7
+ setup do
8
+ @coke.fast_mode = true
9
+ @coke.save!
10
+ assert @coke.show_now_basics?, "fixtures problem"
11
+ @pepsi.update_attribute(:confirmed, false)
12
+ assert !@pepsi.show_now_basics?
13
+ end
14
+
15
+ def response_includes_banner?(banner)
16
+ @response.body.include?(banner.helper_items.where(:content_for => true).last.content)
17
+ end
18
+ def assert_response_includes_banner(banner)
19
+ assert response_includes_banner?(banner), "should have default banner content in response"
20
+ end
21
+
22
+ test "normal request and banner loading asdf" do
23
+ AdvertSelector::Banner.expects(:find_current).twice.returns(AdvertSelector::Banner.find_future)
24
+
25
+ get '/'
26
+ assert_response :success
27
+
28
+ assert_response_includes_banner(@coke)
29
+
30
+ assert $advert_selector_banners_load_time > 1.minute.ago
31
+ original_time = $advert_selector_banners_load_time
32
+
33
+ #assert_equal $advert_selector_banners, AdvertSelector::Banner.find_current
34
+
35
+ get '/'
36
+ assert_response :success
37
+
38
+ assert_equal $advert_selector_banners_load_time, original_time
39
+
40
+ Timecop.travel( 15.minutes.from_now ) do
41
+ get '/'
42
+ assert $advert_selector_banners_load_time != original_time
43
+ assert $advert_selector_banners_load_time > 1.minute.ago
44
+ end
45
+ end
46
+
47
+ test "only_once_per_session banners" do
48
+ placement = @coke.placement
49
+ placement.only_once_per_session = true
50
+ placement.save!
51
+
52
+ get '/'
53
+ assert_response :success
54
+ assert_response_includes_banner(@coke)
55
+
56
+ assert_equal ["Leaderboard"], session["advert_selector_session_shown"], "should have info in session"
57
+
58
+ get '/'
59
+ assert_response :success
60
+ assert !response_includes_banner?(@coke), "should not include banner on second view"
61
+ end
62
+
63
+ test "banner_frequency, limit frequency within one week" do
64
+ @coke.update_attribute(:frequency, 2)
65
+
66
+ get '/'
67
+ assert_response :success
68
+ assert_response_includes_banner(@coke)
69
+
70
+ cookie_expiration_date_org = cookies.send(:eval, '@cookies').first.send(:eval, '@options')["expires"].to_time
71
+ assert 6.days.from_now < cookie_expiration_date_org
72
+ assert 7.days.from_now > cookie_expiration_date_org
73
+
74
+ Timecop.travel( 3.days.from_now )
75
+
76
+ get '/'
77
+ assert_response :success
78
+ assert_response_includes_banner(@coke)
79
+
80
+ cookie_expiration_date_new = cookies.send(:eval, '@cookies').first.send(:eval, '@options')["expires"].to_time
81
+ assert_equal cookie_expiration_date_new, cookie_expiration_date_org
82
+
83
+ get '/'
84
+ assert_response :success
85
+ assert !response_includes_banner?(@coke), "should not include banner after expiration date"
86
+
87
+ end
88
+
89
+ test "HelperItem runned" do
90
+ get '/'
91
+ assert_response :success
92
+ assert_response_includes_banner(@coke)
93
+
94
+ $advert_selector_banners_load_time = nil
95
+
96
+ @coke.helper_items.create!(:position => 0, :name => 'always_false')
97
+ get '/'
98
+ assert_response :success
99
+ assert !response_includes_banner?(@coke), "should not include banner if helper_item returned false"
100
+
101
+ end
102
+
103
+ test "HelperItem with raising error and common error displays" do
104
+
105
+ @coke.helper_items.create!(:position => 0, :name => 'raise_error')
106
+ get '/'
107
+ assert_response :success
108
+ assert !response_includes_banner?(@coke), "should not include banner if helper_item raised error"
109
+
110
+ get '/advert_selector/placements'
111
+ assert_response :success
112
+ assert_select '.alert-error', :text => /Error with banner Coke in placement Leaderboard/
113
+
114
+ end
115
+
116
+
117
+ test "complex setup conflicting banners placements" do
118
+ @parade_banner.update_attributes!(:confirmed => true, :frequency => 1)
119
+ get '/'
120
+ assert_response :success
121
+ assert response_includes_banner?(@parade_banner)
122
+ assert !response_includes_banner?(@coke)
123
+
124
+ get '/'
125
+ assert_response :success
126
+ assert !response_includes_banner?(@parade_banner)
127
+ assert response_includes_banner?(@coke)
128
+ end
129
+
130
+ test "complex setup multiple banners placements" do
131
+ @parade_banner.update_attributes!(:confirmed => true, :frequency => 1)
132
+ @parade_banner.placement.conflicting_placements_array = ""
133
+ @parade_banner.placement.save!
134
+
135
+ get '/'
136
+ assert_response :success
137
+ assert response_includes_banner?(@parade_banner)
138
+ assert response_includes_banner?(@coke)
139
+ end
140
+
141
+ test "banner preview url forces banner and displays information" do
142
+ get '/'
143
+ assert !response_includes_banner?(@parade_banner)
144
+ assert_select '#advert_selector_info', :count => 0
145
+
146
+ get "/?advert_selector_force=#{@parade_banner.id}"
147
+ assert_response :success
148
+ assert response_includes_banner?(@parade_banner)
149
+
150
+ assert_select '#advert_selector_info', :count => 1
151
+ end
152
+
153
+ end
154
+
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,43 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "mocha"
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ # Load fixtures from the engine
14
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
15
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
16
+ end
17
+
18
+
19
+ class ActiveSupport::TestCase
20
+
21
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
22
+ # -- they do not yet inherit this setting
23
+ fixtures :all
24
+
25
+ setup do
26
+
27
+ $advert_selector_banners_load_time = nil # force reload of banners in every tests
28
+ @coke = advert_selector_banners(:coke)
29
+ @pepsi = advert_selector_banners(:pepsi)
30
+ @parade_banner = advert_selector_banners(:parade_banner)
31
+
32
+ Timecop.travel( Time.now.at_midnight + 12.hours ) unless [6..20].include?(Time.now.hour)
33
+ end
34
+
35
+ teardown do
36
+ $advert_selector_avoid_cache = false
37
+ @coke.reset_cache
38
+ @pepsi.reset_cache
39
+ @parade_banner.reset_cache
40
+ AdvertSelector::ErrorsCache.clear
41
+ end
42
+
43
+ end
@@ -0,0 +1,160 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module AdvertSelector
4
+ class BannerTest < ActiveSupport::TestCase
5
+ fixtures :all
6
+
7
+ setup do
8
+ $advert_selector_avoid_cache = true
9
+ end
10
+
11
+ test 'find_future && find_current scopes' do
12
+ #binding.pry
13
+ assert_equal 3, Banner.find_future.size
14
+ assert_equal 3, Banner.find_current.size
15
+
16
+ Timecop.travel( 1.year.ago ) do
17
+ assert_equal 3, Banner.find_future.size
18
+ assert_equal 0, Banner.find_current.size
19
+ end
20
+
21
+ end
22
+
23
+ test "name_sym" do
24
+ assert_equal :coke, @coke.name_sym
25
+ end
26
+
27
+ test "running_viewcount & add_one_viewcount" do
28
+ $advert_selector_avoid_cache = false
29
+ @coke.reset_cache
30
+ @coke[:running_view_count] = 0
31
+ @coke.save
32
+
33
+ assert_equal 0, @coke.running_view_count
34
+ @coke.add_one_viewcount
35
+ @coke.add_one_viewcount
36
+ assert_equal 2, @coke.running_view_count
37
+
38
+ coke_second = Banner.find(@coke)
39
+ assert_equal 0, coke_second[:running_view_count], "should not save value to db after every reload"
40
+ assert_equal 2, coke_second.running_view_count, "should fetch value from rails cache in every view"
41
+
42
+ Rails.cache.write(@coke.cache_key, 550, :expires_in => 2.weeks)
43
+ @coke.add_one_viewcount
44
+
45
+ coke_third = Banner.find(@coke)
46
+ assert_equal 551, coke_third[:running_view_count], "should have saved value to db after so many views"
47
+ end
48
+ test "running_viewcount & add_one_viewcount reaching target" do
49
+ $advert_selector_avoid_cache = false
50
+ @coke.reset_cache
51
+ @coke[:running_view_count] = 0
52
+ @coke.target_view_count = 10
53
+ @coke.save
54
+
55
+ assert_equal 0, @coke.running_view_count
56
+ Rails.cache.write(@coke.cache_key, @coke.target_view_count-1, :expires_in => 2.weeks)
57
+ @coke.add_one_viewcount
58
+ assert_equal 10, @coke.running_view_count
59
+
60
+ coke_second = Banner.find(@coke)
61
+ assert_equal 10, coke_second[:running_view_count], "should save if reaching target"
62
+ end
63
+
64
+ test "view_count_per_day" do
65
+ @coke.update_attributes!(:start_time => Time.now.at_beginning_of_day, :end_time => 10.days.from_now.at_beginning_of_day,
66
+ :target_view_count => 100)
67
+ @coke.running_view_count = 0
68
+ @coke.save!
69
+
70
+ assert @coke.show_today_has_viewcounts?
71
+
72
+ @coke.reload
73
+ @coke.running_view_count = 13
74
+ assert !@coke.show_today_has_viewcounts?, "daily limit should be full"
75
+
76
+ @coke.fast_mode = true
77
+ assert @coke.show_today_has_viewcounts?, "fast_mode true, always true"
78
+ @coke.fast_mode = false
79
+
80
+
81
+ Timecop.travel( 5.days.from_now.at_midnight + 12.hours ) do
82
+ @coke.reload
83
+ @coke.running_view_count = 30
84
+ assert @coke.show_today_has_viewcounts?
85
+ assert @coke.show_today_has_viewcounts?(30)
86
+ assert !@coke.show_today_has_viewcounts?(60), "should compare with given value"
87
+
88
+ @coke.reload
89
+ @coke.running_view_count = 60
90
+ assert !@coke.show_today_has_viewcounts?
91
+ end
92
+
93
+ Timecop.travel( 9.days.from_now.at_midnight + 12.hours ) do
94
+ @coke.reload
95
+ assert @coke.show_today_has_viewcounts?(99), "last day should always be true"
96
+ end
97
+
98
+ @coke.reload
99
+ assert !@coke.show_today_has_viewcounts?(101), "should be false if viewcount has been achieved"
100
+
101
+ @coke.reload
102
+ @coke.target_view_count = nil
103
+ assert @coke.show_today_has_viewcounts?(1), "should be true if no target viewcount"
104
+ end
105
+
106
+ test "show_now_basic? for default banners" do
107
+ @coke.confirmed = false
108
+ @coke.save!
109
+ assert !@coke.show_now_basics?, "not confirmed"
110
+
111
+ @coke.confirmed = true
112
+ @coke.save!
113
+ assert @coke.show_now_basics?
114
+
115
+ @coke.reload
116
+ @coke.running_view_count = 100000000
117
+ assert !@coke.show_now_basics?, "target reached"
118
+ end
119
+
120
+ test "show_now_basic? time usages" do
121
+ assert @coke.show_now_basics?, "setup is wrong"
122
+
123
+ @coke.start_time = 1.hour.from_now
124
+ @coke.save!
125
+ assert !@coke.show_now_basics?, "should not display if advert in future"
126
+
127
+ @coke.start_time = 2.hour.ago
128
+ @coke.end_time = 1.hour.ago
129
+ @coke.save!
130
+ assert !@coke.show_now_basics?, "should not display if advert in past"
131
+
132
+ @coke.start_time = nil
133
+ @coke.end_time = 1.hour.from_now
134
+ @coke.save!
135
+ assert @coke.show_now_basics?, "should display if advert has only end_time in the future"
136
+
137
+ end
138
+
139
+ test "HelperItems" do
140
+ helper_items_count = HelperItem.count
141
+ @coke.helper_items.build
142
+ @coke.helper_items.build(:name => 'content_for_invalid', :content_for => true, :position => 10)
143
+ @coke.helper_items.build(:name => 'some_limit_helper_here', :position => 0)
144
+ assert @coke.save
145
+
146
+ banner = Banner.find(@coke)
147
+
148
+ assert_equal helper_items_count+2, HelperItem.count
149
+
150
+ assert 'some_limit_helper_here', banner.helper_items.first.name
151
+
152
+ assert 'content_for_invalid', banner.helper_items.last.name
153
+ end
154
+
155
+
156
+ # test "the truth" do
157
+ # assert true
158
+ # end
159
+ end
160
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module AdvertSelector
4
+ class HelperItemTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ #require 'test_helper'
3
+
4
+ module AdvertSelector
5
+ class PlacementTest < ActiveSupport::TestCase
6
+
7
+ setup do
8
+ @parade = advert_selector_placements(:parade)
9
+ @leaderboard = advert_selector_placements(:leaderboard)
10
+ end
11
+
12
+ test "name_sym" do
13
+ assert_equal :parade, @parade.name_sym
14
+ end
15
+
16
+ test "conflicting_placements" do
17
+ assert_equal 'leaderboard,video', @parade.conflicting_placements_array
18
+ assert_equal [:parade, :leaderboard, :video], @parade.conflicting_placements
19
+ end
20
+
21
+ test "conflicting_placements string handling" do
22
+ arr = Placement.conflicting_placements("a, b c,a,d")
23
+ assert_equal [:a,:b,:c,:d], arr
24
+ end
25
+
26
+ test "conflicting_with" do
27
+ assert @parade.conflicting_with?(@parade), "should conflict with itself"
28
+
29
+ assert @parade.conflicting_placements_array.include?("leaderboard"), "wrong setup"
30
+ assert @parade.conflicting_with?(@leaderboard)
31
+
32
+ dummy = Placement.new(:name => 'test1')
33
+ assert !@parade.conflicting_with?([dummy])
34
+ assert @parade.conflicting_with?([dummy, @leaderboard])
35
+ end
36
+
37
+ test "conflicting_placements_array=" do
38
+ assert_equal 'leaderboard,video', @parade.conflicting_placements_array
39
+ @parade.conflicting_placements_array = 'video,not_found'
40
+ assert @parade.save
41
+
42
+ new_parade = Placement.find(@parade)
43
+ assert_equal [:parade, :not_found, :video], new_parade.conflicting_placements
44
+
45
+ new_leaderboard = Placement.find(@leaderboard)
46
+ assert_blank new_leaderboard.conflicting_placements_array
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module AdvertSelector
4
+ class BannersHelperTest < ActionView::TestCase
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module AdvertSelector
4
+ class PlacementsHelperTest < ActionView::TestCase
5
+ end
6
+ end