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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb95d0887656cb736919fb5ab9fda2b3689dc3d3
4
- data.tar.gz: 5078155552f020da3f0a75434caceeb81b8c1355
3
+ metadata.gz: 773d5bef0344e32f9145f9914d658e294a8f7a54
4
+ data.tar.gz: 8dc4829ed97d9221f2f5c3e1d59beb1d39e84f86
5
5
  SHA512:
6
- metadata.gz: c9b1fc20e7a7d4b4524121a54ec98bf3f98f6e835ff431466fba4aa2b55eeedba562b9e6b07ad86b4209da3a9bb65db3a1b56c8940c53a2576de686daec07df6
7
- data.tar.gz: 02d4e5c839d2a71fb8209bbf35cee97d15532491c4a9ff968de4f3054e2fdd3becdd694e7c30f4e68cdb2c14a09984d16b3f4588b46269a91b53148350037268
6
+ metadata.gz: 8d86bbbd61fa28632c1de5ae3b8f91a9bdc36efa7c2f7218b0cf906b26d94d13d565d687d58ca48e3657427ea68a11903b62bedd002c04d2dcd22891618afeee
7
+ data.tar.gz: 9e838b03931f25a28cd3bf3895d96014a807432099ef6e0a5d732eecf9314b75bbe91c8b10fcef3a9f6f1251ffbc8b14f7a2653f3812e142c9829c614dee0636
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.4.0
2
+
3
+ ### Updates
4
+
5
+ - Now is possible pass string on vote value.
6
+
1
7
  ## v0.3.0
2
8
 
3
9
  ### News
data/README.md CHANGED
@@ -47,7 +47,7 @@ Now this model can vote or receive votes.
47
47
 
48
48
  ### vote
49
49
 
50
- You can vote on some resource:
50
+ You can vote on some resource using integer or string as value:
51
51
 
52
52
  ```ruby
53
53
  author_1 = Author.first
@@ -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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Voting
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -3,14 +3,14 @@
3
3
  require 'rails_helper'
4
4
 
5
5
  RSpec.describe Voting::Extension, ':vote' do
6
- let!(:author) { create :author }
7
- let!(:comment) { create :comment }
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: comment, scopeable: nil, value: 1
11
+ expect(Voting::Vote).to receive(:create).with author: author, resource: resource, scopeable: nil, value: 1
12
12
 
13
- author.vote comment, 1
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: comment, scopeable: category, value: 1
21
+ expect(Voting::Vote).to receive(:create).with author: author, resource: resource, scopeable: category, value: 1
22
22
 
23
- author.vote comment, 1, scope: category
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho