counter_culture 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.1.12
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "counter_culture"
8
- s.version = "0.1.11"
8
+ s.version = "0.1.12"
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-04-03"
12
+ s.date = "2013-05-24"
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 = [
@@ -49,6 +49,8 @@ module CounterCulture
49
49
  # :right => the newly fixed, correct count }
50
50
  #
51
51
  def counter_culture_fix_counts(options = {})
52
+ raise "No counter cache defined on #{self.name}" unless @after_commit_counter_cache
53
+
52
54
  options[:exclude] = [options[:exclude]] if options[:exclude] && !options[:exclude].is_a?(Enumerable)
53
55
  options[:exclude] = options[:exclude].try(:map) {|x| x.is_a?(Enumerable) ? x : [x] }
54
56
  options[:only] = [options[:only]] if options[:only] && !options[:only].is_a?(Enumerable)
@@ -113,7 +115,7 @@ module CounterCulture
113
115
  }
114
116
  # use update_all because it's faster and because a fixed counter-cache shouldn't
115
117
  # update the timestamp
116
- klass.update_all "#{column_name} = #{counts[model.id].to_i}", "id = #{klass.connection.quote(model.id)}"
118
+ klass.where(:id => model.id).update_all(column_name => counts[model.id])
117
119
  end
118
120
  end
119
121
  end
@@ -863,6 +863,31 @@ describe "CounterCulture" do
863
863
  user.tried_count.should == 1
864
864
  end
865
865
 
866
+ it "should fix a string counter cache correctly" do
867
+ string_id = HasStringId.create({:id => "bbb"}, :without_protection => true)
868
+
869
+ user = User.create :has_string_id_id => string_id.id
870
+
871
+ string_id.reload
872
+ string_id.users_count.should == 1
873
+
874
+ user2 = User.create :has_string_id_id => string_id.id
875
+
876
+ string_id.reload
877
+ string_id.users_count.should == 2
878
+
879
+ string_id.users_count = 123
880
+ string_id.save!
881
+
882
+ string_id.reload
883
+ string_id.users_count.should == 123
884
+
885
+ User.counter_culture_fix_counts
886
+
887
+ string_id.reload
888
+ string_id.users_count.should == 2
889
+ end
890
+
866
891
  it "should work correctly for relationships with custom names" do
867
892
  company = Company.create
868
893
  user1 = User.create :manages_company_id => company.id
@@ -889,11 +914,8 @@ describe "CounterCulture" do
889
914
  end
890
915
 
891
916
  it "should work correctly with string keys" do
892
- puts HasStringId.all.inspect
893
917
  string_id = HasStringId.create({:id => "1"}, :without_protection => true)
894
- puts HasStringId.all.inspect
895
918
  string_id2 = HasStringId.create({:id => "abc"}, :without_protection => true)
896
- puts HasStringId.all.inspect
897
919
 
898
920
  user = User.create :has_string_id_id => string_id.id
899
921
 
@@ -925,6 +947,10 @@ describe "CounterCulture" do
925
947
  string_id.users_count.should == 0
926
948
  string_id2.users_count.should == 0
927
949
  end
950
+
951
+ it "should raise a good error message when calling fix_counts with no caches defined" do
952
+ expect { Category.counter_culture_fix_counts }.to raise_error "No counter cache defined on Category"
953
+ end
928
954
 
929
955
  describe "#previous_model" do
930
956
  let(:user){User.create :name => "John Smith", :manages_company_id => 1}
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.11
4
+ version: 0.1.12
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-04-03 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -219,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  segments:
221
221
  - 0
222
- hash: -4392423569258865680
222
+ hash: 209272298773152950
223
223
  required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  none: false
225
225
  requirements: