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 +4 -4
- data/CHANGELOG.md +10 -0
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -2
- data/lib/counter_culture.rb +4 -1
- data/spec/counter_culture_spec.rb +27 -0
- data/spec/models/twitter_review.rb +3 -0
- data/spec/schema.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19dc37789d383bb90f0f02f4c23c60b05db6a5db
|
4
|
+
data.tar.gz: f7514a2a2d9bfd9c525dbec1fbfa88b5c03ae11c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
1
|
+
0.1.22
|
data/counter_culture.gemspec
CHANGED
@@ -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.
|
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.
|
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",
|
data/lib/counter_culture.rb
CHANGED
@@ -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
|
-
|
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
|
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.
|
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
|