mongoid_atomic_votes 0.2.0 → 0.2.1

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: 1471df3a89ef9456b35bc2e078fb8b73d0fc89a9
4
- data.tar.gz: 561f2eac6abec232a1966ee23181bbb09b290325
3
+ metadata.gz: 474842edee2815d2d65750077a75894ac7f67dc0
4
+ data.tar.gz: 414e249a6a8bd8c9bfb4852381f7d47f6131bdf7
5
5
  SHA512:
6
- metadata.gz: 3583b0c8a866dab57c14cfeef6e98555d7ceab20779e83d89e7722be0e076607ae13d8d0b2ba0a787866e33131892d608792366504bc12fffce836e1ac8da472
7
- data.tar.gz: 0151bda82246b40cb8bc37e62fda203d66b2c95a9dcd1fee9f4bd34688e6d2495ba30c30efe3347d9cc4870316745cfd699c92469bf3a5a63b18cb49f7670c25
6
+ metadata.gz: d7e410e7eb861576dde400586ee450bf7514ce6202a4c14b5aa01b4c2b9b97339cfd6d06cde5006ca21ab6d62f2d9a616bcb76b7a916904cdaf509fa6582b6ad
7
+ data.tar.gz: 2bbbc2ff81776a89cef0f4878d6bd3ff6f72c7cc6338d97c96c2b8c71cabda3cfb653fe01cf0abc33a049814e0126f2427da34515ebad156ab7aa82b2ad8e875
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  group :test do
7
7
  gem 'rspec'
8
8
  gem 'factory_girl'
9
- gem 'simplecov'
9
+ gem 'simplecov', require: false
10
10
  gem 'database_cleaner'
11
11
  gem 'pry'
12
12
  end
@@ -10,7 +10,7 @@ module Mongoid
10
10
  private
11
11
  def define_relations(base)
12
12
  base.field :vote_count, type: Integer, default: 0
13
- base.field :vote_value, type: Float, default: nil
13
+ base.field :vote_value, type: Float, default: nil
14
14
  base.embeds_many :votes, class_name: 'Mongoid::AtomicVotes::Vote', as: :atomic_voteable
15
15
  end
16
16
 
@@ -59,21 +59,21 @@ module Mongoid
59
59
  private
60
60
  def update_votes(mark, retract=false)
61
61
  opts = {
62
- '$inc' => {vote_count: retract ? -1 : 1},
63
- '$set' => {vote_value: self.vote_value}
62
+ '$inc' => { vote_count: retract ? -1 : 1 },
63
+ '$set' => { vote_value: self.vote_value }
64
64
  }
65
65
 
66
66
  if retract
67
- opts['$pull'] = {votes: {_id: mark.id}}
67
+ opts['$pull'] = { votes: { _id: mark.id } }
68
68
  else
69
- opts['$push'] = {votes: mark.as_json}
69
+ opts['$push'] = { votes: mark.as_json }
70
70
  end
71
71
 
72
- self.collection.find(_id: self.id).update(opts)['ok'] > 0
72
+ self.collection.find(_id: self.id).update_one(opts).modified_count > 0
73
73
  end
74
74
 
75
75
  def update_vote_value(mark, retract=false)
76
- value, vote_count_diff = [mark.value, 1].map{|v| v * (retract ? -1 : 1)}
76
+ value, vote_count_diff = [mark.value, 1].map { |v| v * (retract ? -1 : 1) }
77
77
  self.vote_value = if self.vote_count == 1 && retract
78
78
  nil
79
79
  else
@@ -92,7 +92,7 @@ module Mongoid
92
92
 
93
93
  def remove_vote_mark(mark)
94
94
  _assigning do
95
- self.votes.reject!{|v| v.id == mark.id}
95
+ self.votes.reject! { |v| v.id == mark.id }
96
96
  update_vote_value(mark, true)
97
97
  end
98
98
  update_votes(mark, true)
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module AtomicVotes
3
- VERSION = "0.2.0"
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -4,14 +4,14 @@ class Mongoid::AtomicVotes::Vote
4
4
 
5
5
  embedded_in :atomic_voteable, polymorphic: true
6
6
 
7
- field :value, type: Integer
7
+ field :value, type: Integer
8
8
  field :voted_by_id, type: BSON::ObjectId
9
- field :voter_type, type: String
9
+ field :voter_type, type: String
10
10
 
11
- validates_presence_of :value, :voted_by_id, :voter_type
12
- validates_inclusion_of :value, in: ->(vote){ vote.class.vote_range }, if: ->(vote){ vote.class.vote_range }
11
+ validates_presence_of :value, :voted_by_id, :voter_type
12
+ validates_inclusion_of :value, in: ->(vote) { vote.class.vote_range }, if: ->(vote) { vote.class.vote_range }
13
13
 
14
- index({voted_by_id: 1, mark: 1}, {unique: true, background: true})
14
+ index({ voted_by_id: 1, mark: 1 }, unique: true, background: true)
15
15
 
16
16
  class << self
17
17
  @@vote_range = nil
@@ -1,3 +1,3 @@
1
- require "mongoid_atomic_votes/version"
2
- require "mongoid_atomic_votes/atomic_votes"
3
- require "mongoid_atomic_votes/vote"
1
+ require 'mongoid_atomic_votes/version'
2
+ require 'mongoid_atomic_votes/atomic_votes'
3
+ require 'mongoid_atomic_votes/vote'
@@ -14,5 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = Mongoid::AtomicVotes::VERSION
16
16
 
17
- gem.add_runtime_dependency 'mongoid', ['>= 4.0']
17
+ gem.add_runtime_dependency 'mongoid', ['~> 5.0']
18
18
  end
@@ -7,7 +7,7 @@ describe Post do
7
7
  @post = FactoryGirl.create(:post)
8
8
  end
9
9
 
10
- it "has Mongoid::AtomicVotes module" do
10
+ it 'has Mongoid::AtomicVotes module' do
11
11
  expect(subject.class.ancestors).to include(Mongoid::AtomicVotes)
12
12
  end
13
13
 
@@ -19,7 +19,7 @@ describe Post do
19
19
  it { expect(subject).to respond_to(:votes) }
20
20
 
21
21
  it { expect(subject.class).to respond_to(:set_vote_range) }
22
- it { expect { subject.class.set_vote_range(1) }.to raise_exception }
22
+ it { expect { subject.class.set_vote_range(1) }.to raise_error('argument should be a Range') }
23
23
 
24
24
  describe '#votes' do
25
25
  it 'is array of votes' do
@@ -71,7 +71,7 @@ describe Post do
71
71
  end
72
72
 
73
73
  vote_value = @post.votes.map(&:value).sum.to_f/@post.votes.size
74
-
74
+
75
75
  expect(@post.vote_value).to eq(vote_value)
76
76
  expect(@post.vote_count).to eq(@users.size)
77
77
  expect(@post.votes.size).to eq(@users.size)
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,17 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
-
4
1
  MODELS = File.join(File.dirname(__FILE__), 'models')
5
2
 
3
+ require 'rubygems'
4
+ require 'database_cleaner'
5
+ require 'factory_girl'
6
6
  require 'simplecov'
7
7
 
8
- SimpleCov.start
8
+ SimpleCov.start do
9
+ add_filter '/.gems/'
10
+ add_filter '/.bundle/'
11
+ end
9
12
 
10
- require 'rubygems'
11
13
  require 'mongoid'
12
14
  require 'mongoid_atomic_votes'
13
- require 'database_cleaner'
14
- require 'factory_girl'
15
15
 
16
16
  Dir["#{MODELS}/*.rb"].each { |f| require f }
17
17
 
@@ -19,11 +19,8 @@ Mongoid.configure do |config|
19
19
  config.connect_to 'mongoid_atomic_votes_test'
20
20
  end
21
21
 
22
- #Mongoid.logger = Logger.new($stdout)
23
- #Moped.logger = Logger.new($stdout)
24
-
25
- #Mongoid.logger.level = Logger::DEBUG
26
- #Moped.logger.level = Logger::DEBUG
22
+ Mongoid.logger.level = Logger::ERROR
23
+ Mongo::Logger.logger.level = Logger::ERROR
27
24
 
28
25
  FactoryGirl.definition_file_paths = [File.join(File.dirname(__FILE__), 'factories')]
29
26
  FactoryGirl.find_definitions
@@ -42,4 +39,4 @@ RSpec.configure do |config|
42
39
  config.after(:each) do
43
40
  DatabaseCleaner.clean
44
41
  end
45
- end
42
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_atomic_votes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.0'
27
27
  description: Atomic votes for mongoid models
28
28
  email:
29
29
  executables: []
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.2.2
69
+ rubygems_version: 2.4.5
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Atomic votes implementation for mongoid