set_counters 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d82f1508eecf735452eb2ea22f8fca76ce67dcaa
4
+ data.tar.gz: 69c79103c690e706fa45fed288aa45d2f181c322
5
+ SHA512:
6
+ metadata.gz: 7277425cb0cd712365ba9fc3a8670451803670b1de4f7b19b01c0ddc29342ef53f99ee1722921017dbb5ebdeb3c6255ad632e577e44bbeddfa13b80815a60acc
7
+ data.tar.gz: cef42b0a418d0017d89961087148616e449d0b949ccea2b19c1c80a23ab8e525c8c20a49b3396acd552128ed3cca340b923efe2c66eb7b5d973990ba761b6ddd
data/Gemfile CHANGED
@@ -1,9 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- group :test do
4
- gem 'rails', '> 3.2.0'
5
- gem 'sqlite3'
6
- end
7
-
8
3
  # Specify your gem's dependencies in set_counters.gemspec
9
4
  gemspec
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- require 'rake/testtask'
4
- Rake::TestTask.new(:test) do |test|
5
- test.libs << 'lib'
6
- test.libs << 'test'
7
- test.pattern = 'test/**/test_*.rb'
8
- test.verbose = true
9
- end
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/set_counters.rb CHANGED
@@ -34,7 +34,7 @@ module SetCounters
34
34
  updates = counters.inject([]) { |list, (counter_name, value)|
35
35
  list << "#{connection.quote_column_name(counter_name)} = #{value.to_i}"
36
36
  }.join(", ")
37
- update_all(updates, "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}")
37
+ where(id: id).update_all(updates)
38
38
  end
39
39
  end
40
40
 
@@ -1,3 +1,3 @@
1
1
  module SetCounters
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/set_counters.gemspec CHANGED
@@ -17,4 +17,11 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'activerecord', '~> 4.1'
22
+
23
+ gem.add_development_dependency 'bundler', '~> 1.7'
24
+ gem.add_development_dependency 'rake', '~> 10.0'
25
+ gem.add_development_dependency 'rspec'
26
+ gem.add_development_dependency 'sqlite3'
20
27
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SetCounters do
4
+ before do
5
+ @w1 = Widget.create!(x: 0, y: 0)
6
+ @w2 = Widget.create!(x: 0, y: 0)
7
+ end
8
+
9
+ specify { expect(@w1.x).to eq 0 }
10
+ specify { expect(@w1.y).to eq 0 }
11
+ specify { expect(@w2.x).to eq 0 }
12
+ specify { expect(@w2.y).to eq 0 }
13
+
14
+ describe "after setting counters" do
15
+ before do
16
+ Widget.set_counters(@w2.id, x: 1, y: 2)
17
+ @w2.reload
18
+ end
19
+
20
+ specify { expect(@w1.x).to eq 0 }
21
+ specify { expect(@w1.y).to eq 0 }
22
+ specify { expect(@w2.x).to eq 1 }
23
+ specify { expect(@w2.y).to eq 2 }
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'set_counters'
3
+
4
+ RSpec.configure do |config|
5
+ config.filter_run focus: true
6
+ config.run_all_when_everything_filtered = true
7
+
8
+ config.before(:suite) do
9
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
10
+
11
+ silence_stream(STDOUT) do
12
+ ActiveRecord::Schema.define(:version => 1) do
13
+ create_table :widgets do |t|
14
+ t.column :x, :integer
15
+ t.column :y, :integer
16
+ end
17
+ end
18
+ end
19
+
20
+ class Widget < ActiveRecord::Base
21
+ self.table_name = 'widgets'
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe SetCounters do
4
+
5
+ it 'has a version number' do
6
+ expect(SetCounters::VERSION).not_to be nil
7
+ end
8
+
9
+ end
metadata CHANGED
@@ -1,16 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set_counters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Philip Hallstrom
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-30 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
14
83
  description: Easy setting of multiple counters in Active Record models.
15
84
  email:
16
85
  - philip@pjkh.com
@@ -18,7 +87,7 @@ executables: []
18
87
  extensions: []
19
88
  extra_rdoc_files: []
20
89
  files:
21
- - .gitignore
90
+ - ".gitignore"
22
91
  - Gemfile
23
92
  - LICENSE.txt
24
93
  - README.md
@@ -26,37 +95,34 @@ files:
26
95
  - lib/set_counters.rb
27
96
  - lib/set_counters/version.rb
28
97
  - set_counters.gemspec
29
- - test/test_set_counters.rb
98
+ - spec/set_counters_spec.rb
99
+ - spec/spec_helper.rb
100
+ - spec/version_spec.rb
30
101
  homepage: https://github.com/phallstrom/set_counters
31
102
  licenses:
32
103
  - MIT
104
+ metadata: {}
33
105
  post_install_message:
34
106
  rdoc_options: []
35
107
  require_paths:
36
108
  - lib
37
109
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
110
  requirements:
40
- - - ! '>='
111
+ - - ">="
41
112
  - !ruby/object:Gem::Version
42
113
  version: '0'
43
- segments:
44
- - 0
45
- hash: -1665367932952071886
46
114
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
115
  requirements:
49
- - - ! '>='
116
+ - - ">="
50
117
  - !ruby/object:Gem::Version
51
118
  version: '0'
52
- segments:
53
- - 0
54
- hash: -1665367932952071886
55
119
  requirements: []
56
120
  rubyforge_project:
57
- rubygems_version: 1.8.24
121
+ rubygems_version: 2.2.2
58
122
  signing_key:
59
- specification_version: 3
123
+ specification_version: 4
60
124
  summary: Easy setting of multiple counters in Active Record models.
61
125
  test_files:
62
- - test/test_set_counters.rb
126
+ - spec/set_counters_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/version_spec.rb
@@ -1,55 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'active_record'
4
- require 'set_counters'
5
-
6
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
7
-
8
- def setup_db
9
- silence_stream(STDOUT) do
10
- ActiveRecord::Schema.define(:version => 1) do
11
- create_table :widgets do |t|
12
- t.column :x, :integer
13
- t.column :y, :integer
14
- end
15
- end
16
- end
17
- end
18
-
19
- def teardown_db
20
- silence_stream(STDOUT) do
21
- ActiveRecord::Base.connection.tables.each do |table|
22
- ActiveRecord::Base.connection.drop_table(table)
23
- end
24
- end
25
- end
26
-
27
- class Widget < ActiveRecord::Base
28
- def self.table_name() "widgets" end
29
- end
30
-
31
- class SetCountersTest < Test::Unit::TestCase
32
-
33
- def setup
34
- setup_db
35
- @w1 = Widget.create!(:x => 0, :y => 0)
36
- @w2 = Widget.create!(:x => 0, :y => 0)
37
- end
38
-
39
- def teardown
40
- teardown_db
41
- end
42
-
43
- def test_set_counters
44
- assert_equal 0, @w1.x
45
- assert_equal 0, @w1.y
46
- assert_equal 0, @w2.x
47
- assert_equal 0, @w2.y
48
- Widget.set_counters(@w2.id, :x => 1, :y => 2)
49
- assert_equal 0, @w1.x
50
- assert_equal 0, @w1.y
51
- assert_equal 1, Widget.find(@w2.id).x
52
- assert_equal 2, Widget.find(@w2.id).y
53
- end
54
-
55
- end