voting 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/voting/models/voting/vote.rb +1 -0
- data/lib/voting/version.rb +1 -1
- data/spec/models/extension/vote_spec.rb +26 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 773d5bef0344e32f9145f9914d658e294a8f7a54
|
4
|
+
data.tar.gz: 8dc4829ed97d9221f2f5c3e1d59beb1d39e84f86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d86bbbd61fa28632c1de5ae3b8f91a9bdc36efa7c2f7218b0cf906b26d94d13d565d687d58ca48e3657427ea68a11903b62bedd002c04d2dcd22891618afeee
|
7
|
+
data.tar.gz: 9e838b03931f25a28cd3bf3895d96014a807432099ef6e0a5d732eecf9314b75bbe91c8b10fcef3a9f6f1251ffbc8b14f7a2653f3812e142c9829c614dee0636
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,7 @@ module Voting
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.create(author:, resource:, scopeable: nil, value:)
|
28
|
+
value = value.to_i
|
28
29
|
record = find_or_initialize_by(author: author, resource: resource, scopeable: scopeable)
|
29
30
|
attribute = value.positive? ? :positive : :negative
|
30
31
|
canceled = record.persisted? && value.abs == record[attribute]
|
data/lib/voting/version.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
5
|
RSpec.describe Voting::Extension, ':vote' do
|
6
|
-
let!(:author)
|
7
|
-
let!(:
|
6
|
+
let!(:author) { create :author }
|
7
|
+
let!(:resource) { create :comment }
|
8
8
|
|
9
9
|
context 'with no scopeable' do
|
10
10
|
it 'delegates to vote object' do
|
11
|
-
expect(Voting::Vote).to receive(:create).with author: author, resource:
|
11
|
+
expect(Voting::Vote).to receive(:create).with author: author, resource: resource, scopeable: nil, value: 1
|
12
12
|
|
13
|
-
author.vote
|
13
|
+
author.vote resource, 1
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,9 +18,29 @@ RSpec.describe Voting::Extension, ':vote' do
|
|
18
18
|
let!(:category) { build :category }
|
19
19
|
|
20
20
|
it 'delegates to vote object' do
|
21
|
-
expect(Voting::Vote).to receive(:create).with author: author, resource:
|
21
|
+
expect(Voting::Vote).to receive(:create).with author: author, resource: resource, scopeable: category, value: 1
|
22
22
|
|
23
|
-
author.vote
|
23
|
+
author.vote resource, 1, scope: category
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'creates the vote with string value' do
|
28
|
+
author.vote resource, '1'
|
29
|
+
|
30
|
+
vote = Voting::Vote.last
|
31
|
+
|
32
|
+
expect(vote.author).to eq author
|
33
|
+
expect(vote.negative).to eq 0
|
34
|
+
expect(vote.positive).to eq 1
|
35
|
+
expect(vote.resource).to eq resource
|
36
|
+
|
37
|
+
author.vote resource, '-1'
|
38
|
+
|
39
|
+
vote.reload
|
40
|
+
|
41
|
+
expect(vote.author).to eq author
|
42
|
+
expect(vote.negative).to eq 1
|
43
|
+
expect(vote.positive).to eq 0
|
44
|
+
expect(vote.resource).to eq resource
|
45
|
+
end
|
26
46
|
end
|