punching_bag 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/punching_bag.rb +3 -2
- data/lib/punching_bag/acts_as_punchable.rb +3 -2
- data/lib/punching_bag/acts_as_taggable_on.rb +7 -1
- data/lib/punching_bag/version.rb +1 -1
- data/lib/tasks/punching_bag.rake +2 -2
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/log/test.log +2605 -18891
- data/spec/lib/punching_bag_spec.rb +24 -8
- data/spec/models/punchable_spec.rb +7 -1
- metadata +6 -5
@@ -2,22 +2,38 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe PunchingBag do
|
4
4
|
let(:article) { Article.create title: 'Hector', content: 'Ding, ding ding... ding. Ding. DING. DING! ' }
|
5
|
-
let(:human_request) { OpenStruct.new(bot?: false) }
|
6
|
-
let(:bot_request) { OpenStruct.new(bot?: true) }
|
7
5
|
|
8
6
|
subject { PunchingBag }
|
9
7
|
|
10
8
|
describe '.punch' do
|
11
|
-
|
12
|
-
|
9
|
+
let(:request) { nil }
|
10
|
+
|
11
|
+
context 'when request is from a bot' do
|
12
|
+
let(:request) { instance_double(ActionDispatch::Request, bot?: true) }
|
13
|
+
|
14
|
+
it 'does nothing' do
|
15
|
+
expect(PunchingBag.punch(article, request)).to be false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when the request is valid' do
|
20
|
+
let(:request) { instance_double(ActionDispatch::Request, bot?: false) }
|
21
|
+
|
22
|
+
it 'creates a new punch' do
|
23
|
+
expect { PunchingBag.punch(article, request) }.to change { Punch.count }.by 1
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
|
-
|
16
|
-
|
27
|
+
context 'when there is no request' do
|
28
|
+
it 'creates a new punch' do
|
29
|
+
expect { PunchingBag.punch(article) }.to change { Punch.count }.by 1
|
30
|
+
end
|
17
31
|
end
|
18
32
|
|
19
|
-
|
20
|
-
|
33
|
+
context 'when count is more than one' do
|
34
|
+
it 'creates a new punch with a higher count' do
|
35
|
+
expect { PunchingBag.punch(article, nil, 2) }.to change { Punch.sum(:hits) }.by 2
|
36
|
+
end
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
@@ -24,6 +24,12 @@ describe Article do
|
|
24
24
|
it 'incleases hits by one' do
|
25
25
|
expect { subject.punch }.to change { subject.hits }.by 1
|
26
26
|
end
|
27
|
+
|
28
|
+
context 'when count is set to two' do
|
29
|
+
it 'increases hits by two' do
|
30
|
+
expect { subject.punch(nil, count: 2) }.to change { subject.hits }.by 2
|
31
|
+
end
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
@@ -54,4 +60,4 @@ describe Article do
|
|
54
60
|
its('sort_by_popularity.second') { should eql article_1 }
|
55
61
|
end
|
56
62
|
end
|
57
|
-
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punching_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Crownoble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -165,12 +165,13 @@ signing_key:
|
|
165
165
|
specification_version: 4
|
166
166
|
summary: PunchingBag hit conter and trending plugin
|
167
167
|
test_files:
|
168
|
-
- spec/spec_helper.rb
|
169
168
|
- spec/lib/punching_bag_spec.rb
|
170
|
-
- spec/
|
171
|
-
- spec/models/punchable_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
172
170
|
- spec/internal/db/schema.rb
|
173
171
|
- spec/internal/db/combustion_test.sqlite
|
174
172
|
- spec/internal/config/database.yml
|
175
173
|
- spec/internal/app/models/article.rb
|
176
174
|
- spec/internal/log/test.log
|
175
|
+
- spec/models/punchable_spec.rb
|
176
|
+
- spec/models/punch_spec.rb
|
177
|
+
has_rdoc:
|