counter_culture 0.1.21 → 0.1.22

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: 89e6e595dc3bfd04dc2c43689a2e92551a0d1e62
4
- data.tar.gz: 0eaa6cb18bd4f31a0c93a75b65dd87e3f88c864d
3
+ metadata.gz: 19dc37789d383bb90f0f02f4c23c60b05db6a5db
4
+ data.tar.gz: f7514a2a2d9bfd9c525dbec1fbfa88b5c03ae11c
5
5
  SHA512:
6
- metadata.gz: 327ffa770c20fb19cb62997fbb7b5e731edda014e892ec1eed971f8cc9488e430d64e922036e018603f766705f057cd2732545d5a947a2c802e5a2534ac79b70
7
- data.tar.gz: cf7382c2e12317c8c6b358db94bfdf254b3f8e5af12a7d26437644376d31125902441988fcb445260994d5f719061b9db6fd05d828d0297701a0850c7d98b1a3
6
+ metadata.gz: 377e5dce3e1cdcb30992e3f3361e9aa330a3333d5e527d2d9ebf02f2f37b1ddb78e61e38aae3c5dc951ede2f5fefb7fb50fbe8e0355da366c2d665f51cb0fbd6
7
+ data.tar.gz: dfa309282057df45419d50f62bcf6f951e8195f3ed3f60c36116da51ff8a6b66780e0c038c752178507d56085a052e81a3f8214f017c2a526353dcd29700c3f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.1.22 (May 24, 2014)
2
+
3
+ Bugfixes:
4
+ - support for single-table inheritance in counter_culture_fix_counts
5
+
6
+ ## 0.1.21 (May 24, 2014)
7
+
8
+ Bugfixes:
9
+ - makes the migration generator compatible with Rails 4.1
10
+
1
11
  ## 0.1.20 (May 14, 2014)
2
12
 
3
13
  Bugfixes:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.21
1
+ 0.1.22
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: counter_culture 0.1.21 ruby lib
5
+ # stub: counter_culture 0.1.22 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "counter_culture"
9
- s.version = "0.1.21"
9
+ s.version = "0.1.22"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Magnus von Koeller"]
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "spec/models/review.rb",
45
45
  "spec/models/simple_dependent.rb",
46
46
  "spec/models/simple_main.rb",
47
+ "spec/models/twitter_review.rb",
47
48
  "spec/models/user.rb",
48
49
  "spec/rails_app/.gitignore",
49
50
  "spec/rails_app/Gemfile",
@@ -101,7 +101,10 @@ module CounterCulture
101
101
  # lives in
102
102
  reverse_relation.each do |cur_relation|
103
103
  reflect = relation_reflect(cur_relation)
104
- counts_query = counts_query.joins("LEFT JOIN #{reflect.active_record.table_name} ON #{reflect.table_name}.id = #{reflect.active_record.table_name}.#{reflect.foreign_key}")
104
+ joins_query = "LEFT JOIN #{reflect.active_record.table_name} ON #{reflect.table_name}.id = #{reflect.active_record.table_name}.#{reflect.foreign_key}"
105
+ # adds 'type' condition to JOIN clause if the current model is a child in a Single Table Inheritance
106
+ joins_query = "#{joins_query} AND #{reflect.active_record.table_name}.type IN ('#{self.name}')" if self.column_names.include?('type') and not(self.descends_from_active_record?)
107
+ counts_query = counts_query.joins(joins_query)
105
108
  end
106
109
 
107
110
  # iterate in batches; otherwise we might run out of memory when there's a lot of
@@ -4,6 +4,7 @@ require 'models/company'
4
4
  require 'models/industry'
5
5
  require 'models/product'
6
6
  require 'models/review'
7
+ require 'models/twitter_review'
7
8
  require 'models/user'
8
9
  require 'models/category'
9
10
  require 'models/has_string_id'
@@ -864,6 +865,32 @@ describe "CounterCulture" do
864
865
 
865
866
  end
866
867
 
868
+ it "should fix a STI counter cache correctly" do
869
+ company = Company.create
870
+ user = User.create :manages_company_id => company.id
871
+ product = Product.create
872
+
873
+ product.twitter_reviews_count.should == 0
874
+
875
+ review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 42
876
+ twitter_review = TwitterReview.create :user_id => user.id, :product_id => product.id, :approvals => 32
877
+
878
+ company.reload
879
+ user.reload
880
+ product.reload
881
+
882
+ product.twitter_reviews_count.should == 1
883
+
884
+ product.twitter_reviews_count = 2
885
+ product.save!
886
+
887
+ TwitterReview.counter_culture_fix_counts
888
+
889
+ product.reload
890
+
891
+ product.twitter_reviews_count.should == 1
892
+ end
893
+
867
894
  it "should fix a second-level counter cache correctly" do
868
895
  company = Company.create
869
896
  user = User.create :manages_company_id => company.id
@@ -0,0 +1,3 @@
1
+ class TwitterReview < Review
2
+ counter_culture :product, column_name: 'twitter_reviews_count'
3
+ end
data/spec/schema.rb CHANGED
@@ -40,6 +40,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
40
40
  t.string "name"
41
41
  t.integer "reviews_count", :default => 0, :null => false
42
42
  t.integer "rexiews_count", :default => 0, :null => false
43
+ t.integer "twitter_reviews_count", :default => 0, :null => false
43
44
  t.integer "category_id"
44
45
  t.datetime "created_at"
45
46
  t.datetime "updated_at"
@@ -52,6 +53,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
52
53
  t.integer "product_id"
53
54
  t.integer "approvals"
54
55
  t.float "value"
56
+ t.string "type"
55
57
  t.datetime "created_at"
56
58
  t.datetime "updated_at"
57
59
  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.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
@@ -173,6 +173,7 @@ files:
173
173
  - spec/models/review.rb
174
174
  - spec/models/simple_dependent.rb
175
175
  - spec/models/simple_main.rb
176
+ - spec/models/twitter_review.rb
176
177
  - spec/models/user.rb
177
178
  - spec/rails_app/.gitignore
178
179
  - spec/rails_app/Gemfile