advert_selector 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,14 @@ class BannerShowsTest < ActionDispatch::IntegrationTest
5
5
  fixtures :all
6
6
 
7
7
  setup do
8
+ @coke.reload
8
9
  @coke.fast_mode = true
9
10
  @coke.save!
10
11
  assert @coke.show_now_basics?, "fixtures problem"
12
+ @pepsi.reload
11
13
  @pepsi.update_attribute(:confirmed, false)
12
- assert !@pepsi.show_now_basics?
14
+ assert !@pepsi.show_now_basics?, "fixtures prolbem 2"
15
+ AdvertSelector.admin_access_class = AdvertSelector::AdminAccessClassAlwaysTrue
13
16
  end
14
17
 
15
18
  def response_includes_banner?(banner)
@@ -19,7 +22,7 @@ class BannerShowsTest < ActionDispatch::IntegrationTest
19
22
  assert response_includes_banner?(banner), "should have default banner content in response"
20
23
  end
21
24
 
22
- test "normal request and banner loading asdf" do
25
+ test "normal request and banner loading" do
23
26
  AdvertSelector::Banner.expects(:find_current).twice.returns(AdvertSelector::Banner.find_future)
24
27
 
25
28
  get '/'
@@ -29,10 +29,12 @@ class ActiveSupport::TestCase
29
29
  @pepsi = advert_selector_banners(:pepsi)
30
30
  @parade_banner = advert_selector_banners(:parade_banner)
31
31
 
32
+ Timecop.return
32
33
  Timecop.travel( Time.now.at_midnight + 12.hours ) unless [6..20].include?(Time.now.hour)
33
34
  end
34
35
 
35
36
  teardown do
37
+ Timecop.return
36
38
  $advert_selector_avoid_cache = false
37
39
  @coke.reset_cache
38
40
  @pepsi.reset_cache
@@ -45,6 +45,7 @@ module AdvertSelector
45
45
  coke_third = Banner.find(@coke)
46
46
  assert_equal 551, coke_third[:running_view_count], "should have saved value to db after so many views"
47
47
  end
48
+
48
49
  test "running_viewcount & add_one_viewcount reaching target" do
49
50
  $advert_selector_avoid_cache = false
50
51
  @coke.reset_cache
@@ -61,16 +62,79 @@ module AdvertSelector
61
62
  assert_equal 10, coke_second[:running_view_count], "should save if reaching target"
62
63
  end
63
64
 
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)
65
+ test "view_count per_hour" do
66
+
67
+ start_time = Time.now.at_beginning_of_day
68
+
69
+ # 10 views per hour
70
+ @coke.update_attributes!(:start_time => start_time, :end_time => start_time + 112.hours,
71
+ :target_view_count => 1000, :fast_mode => false)
67
72
  @coke.running_view_count = 0
68
73
  @coke.save!
69
74
 
75
+ Timecop.travel( start_time + 4.5.hours )
76
+ assert @coke.show_today_has_viewcounts?
77
+
78
+ @coke.reload
79
+ @coke.running_view_count = 39
80
+ assert @coke.show_today_has_viewcounts?
81
+
82
+ @coke.reload
83
+ @coke.running_view_count = 49
84
+ assert @coke.show_today_has_viewcounts?
85
+
86
+ @coke.reload
87
+ @coke.running_view_count = 51
88
+ assert !@coke.show_today_has_viewcounts?
89
+
90
+ Timecop.travel( start_time + 90.hours )
91
+ @coke.reload
92
+ @coke.running_view_count = 990
93
+ assert @coke.show_today_has_viewcounts?, "should let last 24h to display everything straight away"
94
+
95
+ end
96
+
97
+ test "view_count basics compare_value and per_fast_mode" do
98
+ start_time = Time.now.at_beginning_of_day
99
+
100
+ # 10 views per hour
101
+ @coke.update_attributes!(:start_time => start_time, :end_time => start_time + 112.hours,
102
+ :target_view_count => 1000, :fast_mode => false)
103
+ @coke.running_view_count = 0
104
+ @coke.save!
105
+
106
+ Timecop.travel( start_time + 4.5.hours )
107
+
108
+ assert @coke.show_today_has_viewcounts?
109
+ @coke.reload
110
+ assert !@coke.show_today_has_viewcounts?(900), "use given value in has_viewcounts"
111
+
112
+ @coke.reload
113
+ @coke.fast_mode = true
114
+ assert @coke.show_today_has_viewcounts?(900), "true always with fast_mode on"
115
+
116
+ @coke.reload
117
+ @coke.fast_mode = true
118
+ assert !@coke.show_today_has_viewcounts?(1010), "should be false if viewcount has been achieved even though in fast mode"
119
+
120
+ @coke.reload
121
+ @coke.target_view_count = nil
122
+ assert @coke.show_today_has_viewcounts?(2000), "should be true if no target viewcount"
123
+ end
124
+
125
+ test "view_count daily tests" do
126
+ start_time = Time.now.at_beginning_of_day
127
+ @coke.update_attributes!(:start_time => start_time, :end_time => 10.days.from_now.at_beginning_of_day,
128
+ :target_view_count => 1000, :fast_mode => false)
129
+ @coke.running_view_count = 0
130
+ @coke.save!
131
+
132
+ Timecop.travel( start_time + 11.hours )
133
+
70
134
  assert @coke.show_today_has_viewcounts?
71
135
 
72
136
  @coke.reload
73
- @coke.running_view_count = 13
137
+ @coke.running_view_count = 130
74
138
  assert !@coke.show_today_has_viewcounts?, "daily limit should be full"
75
139
 
76
140
  @coke.fast_mode = true
@@ -80,32 +144,32 @@ module AdvertSelector
80
144
 
81
145
  Timecop.travel( 5.days.from_now.at_midnight + 12.hours ) do
82
146
  @coke.reload
83
- @coke.running_view_count = 30
147
+ @coke.running_view_count = 300
84
148
  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"
149
+ assert @coke.show_today_has_viewcounts?(300)
150
+ assert !@coke.show_today_has_viewcounts?(600), "should compare with given value"
87
151
 
88
152
  @coke.reload
89
- @coke.running_view_count = 60
153
+ @coke.running_view_count = 600
90
154
  assert !@coke.show_today_has_viewcounts?
91
155
  end
92
156
 
93
157
  Timecop.travel( 9.days.from_now.at_midnight + 12.hours ) do
94
158
  @coke.reload
95
- assert @coke.show_today_has_viewcounts?(99), "last day should always be true"
159
+ assert @coke.show_today_has_viewcounts?(990), "last day should always be true"
96
160
  end
97
161
 
98
162
  @coke.reload
99
- assert !@coke.show_today_has_viewcounts?(101), "should be false if viewcount has been achieved"
163
+ assert !@coke.show_today_has_viewcounts?(1010), "should be false if viewcount has been achieved"
100
164
 
101
165
  @coke.reload
102
166
  @coke.target_view_count = nil
103
- assert @coke.show_today_has_viewcounts?(1), "should be true if no target viewcount"
167
+ assert @coke.show_today_has_viewcounts?(1000), "should be true if no target viewcount"
104
168
 
105
- Timecop.travel( Time.now.at_midnight + 19.hours ) do
169
+ Timecop.travel( start_time + 19.hours ) do
106
170
  @coke.reload
107
- @coke.update_attributes!(:start_time => 1.hour.ago, :end_time => 10.days.from_now.at_beginning_of_day,
108
- :target_view_count => 100)
171
+ @coke.update_attributes!(:start_time => start_time + 18.hours, :end_time => 10.days.from_now.at_beginning_of_day,
172
+ :target_view_count => 1000)
109
173
  @coke.running_view_count = 0
110
174
  assert @coke.show_today_has_viewcounts?(), "should be true for the first day even if start is later in the evening"
111
175
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advert_selector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Olli Huotari
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-04 00:00:00 Z
18
+ date: 2012-12-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails