counter_culture 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/counter_culture.gemspec +4 -3
- data/lib/counter_culture.rb +1 -1
- data/spec/counter_culture_spec.rb +39 -0
- data/spec/models/has_string_id.rb +4 -0
- data/spec/models/user.rb +2 -0
- data/spec/schema.rb +8 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
data/counter_culture.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "counter_culture"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Magnus von Koeller"]
|
12
|
-
s.date = "2013-03
|
12
|
+
s.date = "2013-04-03"
|
13
13
|
s.description = "counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback."
|
14
14
|
s.email = "magnus@vonkoeller.de"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"spec/counter_culture_spec.rb",
|
33
33
|
"spec/models/category.rb",
|
34
34
|
"spec/models/company.rb",
|
35
|
+
"spec/models/has_string_id.rb",
|
35
36
|
"spec/models/industry.rb",
|
36
37
|
"spec/models/product.rb",
|
37
38
|
"spec/models/review.rb",
|
@@ -90,7 +91,7 @@ Gem::Specification.new do |s|
|
|
90
91
|
s.homepage = "http://github.com/bestvendor/counter_culture"
|
91
92
|
s.licenses = ["MIT"]
|
92
93
|
s.require_paths = ["lib"]
|
93
|
-
s.rubygems_version = "1.8.
|
94
|
+
s.rubygems_version = "1.8.25"
|
94
95
|
s.summary = "Turbo-charged counter caches for your Rails app."
|
95
96
|
|
96
97
|
if s.respond_to? :specification_version then
|
data/lib/counter_culture.rb
CHANGED
@@ -113,7 +113,7 @@ module CounterCulture
|
|
113
113
|
}
|
114
114
|
# use update_all because it's faster and because a fixed counter-cache shouldn't
|
115
115
|
# update the timestamp
|
116
|
-
klass.update_all "#{column_name} = #{counts[model.id].to_i}", "id = #{model.id}"
|
116
|
+
klass.update_all "#{column_name} = #{counts[model.id].to_i}", "id = #{klass.connection.quote(model.id)}"
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -6,6 +6,7 @@ require 'models/product'
|
|
6
6
|
require 'models/review'
|
7
7
|
require 'models/user'
|
8
8
|
require 'models/category'
|
9
|
+
require 'models/has_string_id'
|
9
10
|
|
10
11
|
describe "CounterCulture" do
|
11
12
|
it "increments counter cache on create" do
|
@@ -886,6 +887,44 @@ describe "CounterCulture" do
|
|
886
887
|
company.reload
|
887
888
|
company.managers_count.should == 0
|
888
889
|
end
|
890
|
+
|
891
|
+
it "should work correctly with string keys" do
|
892
|
+
puts HasStringId.all.inspect
|
893
|
+
string_id = HasStringId.create({:id => "1"}, :without_protection => true)
|
894
|
+
puts HasStringId.all.inspect
|
895
|
+
string_id2 = HasStringId.create({:id => "abc"}, :without_protection => true)
|
896
|
+
puts HasStringId.all.inspect
|
897
|
+
|
898
|
+
user = User.create :has_string_id_id => string_id.id
|
899
|
+
|
900
|
+
string_id.reload
|
901
|
+
string_id.users_count.should == 1
|
902
|
+
|
903
|
+
user2 = User.create :has_string_id_id => string_id.id
|
904
|
+
|
905
|
+
string_id.reload
|
906
|
+
string_id.users_count.should == 2
|
907
|
+
|
908
|
+
user2.has_string_id_id = string_id2.id
|
909
|
+
user2.save!
|
910
|
+
|
911
|
+
string_id.reload
|
912
|
+
string_id2.reload
|
913
|
+
string_id.users_count.should == 1
|
914
|
+
string_id2.users_count.should == 1
|
915
|
+
|
916
|
+
user2.destroy
|
917
|
+
string_id.reload
|
918
|
+
string_id2.reload
|
919
|
+
string_id.users_count.should == 1
|
920
|
+
string_id2.users_count.should == 0
|
921
|
+
|
922
|
+
user.destroy
|
923
|
+
string_id.reload
|
924
|
+
string_id2.reload
|
925
|
+
string_id.users_count.should == 0
|
926
|
+
string_id2.users_count.should == 0
|
927
|
+
end
|
889
928
|
|
890
929
|
describe "#previous_model" do
|
891
930
|
let(:user){User.create :name => "John Smith", :manages_company_id => 1}
|
data/spec/models/user.rb
CHANGED
data/spec/schema.rb
CHANGED
@@ -51,6 +51,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
51
51
|
t.integer "reviews_count", :default => 0, :null => false
|
52
52
|
t.integer "using_count", :default => 0, :null => false
|
53
53
|
t.integer "tried_count", :default => 0, :null => false
|
54
|
+
t.string "has_string_id_id"
|
54
55
|
end
|
55
56
|
|
56
57
|
create_table "categories", :force => true do |t|
|
@@ -58,4 +59,11 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
58
59
|
t.integer "products_count", :default => 0, :null => false
|
59
60
|
end
|
60
61
|
|
62
|
+
create_table "has_string_ids", :force => true, :id => false do |t|
|
63
|
+
t.string "id", :default => '', :null => false
|
64
|
+
t.string "something"
|
65
|
+
t.integer "users_count", :null => false, :default => 0
|
66
|
+
end
|
67
|
+
add_index "has_string_ids", :id, :unique => true
|
68
|
+
|
61
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: counter_culture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03
|
12
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- spec/counter_culture_spec.rb
|
150
150
|
- spec/models/category.rb
|
151
151
|
- spec/models/company.rb
|
152
|
+
- spec/models/has_string_id.rb
|
152
153
|
- spec/models/industry.rb
|
153
154
|
- spec/models/product.rb
|
154
155
|
- spec/models/review.rb
|
@@ -218,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
219
|
version: '0'
|
219
220
|
segments:
|
220
221
|
- 0
|
221
|
-
hash:
|
222
|
+
hash: -4392423569258865680
|
222
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
224
|
none: false
|
224
225
|
requirements:
|
@@ -227,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
228
|
version: '0'
|
228
229
|
requirements: []
|
229
230
|
rubyforge_project:
|
230
|
-
rubygems_version: 1.8.
|
231
|
+
rubygems_version: 1.8.25
|
231
232
|
signing_key:
|
232
233
|
specification_version: 3
|
233
234
|
summary: Turbo-charged counter caches for your Rails app.
|