counter_culture 0.1.23 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +1 -1
- data/README.md +2 -2
- data/VERSION +1 -1
- data/counter_culture.gemspec +4 -3
- data/lib/counter_culture.rb +11 -10
- data/lib/generators/counter_culture_generator.rb +1 -1
- data/spec/counter_culture_spec.rb +73 -59
- data/spec/models/post.rb +6 -0
- data/spec/models/user.rb +1 -0
- data/spec/schema.rb +8 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e9a0ab9e01e7417d2c32fb3b6d142018f2616be
|
4
|
+
data.tar.gz: 5ca2eb2a8cd0ccd2f7af333fae3685cbb9f7606c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a301eed807af138528e03fc33edb9c0e8317874d31584bee4a43166f965b1ea91b4cdf9c7edd75a92d0d294919e60c6f568554ee441d24631ab4ba0914e6ec0
|
7
|
+
data.tar.gz: 1ed11abdefe33c23b3af92212a7df337390e6ef412394dbfeb8e8db86ea314c756c20232ef34b21b167c7df3200d4a15c29247cbb63da89b633d224234bc0d43
|
data/.document
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# counter_culture [![Build Status](https://travis-ci.org/magnusvk/counter_culture.
|
1
|
+
# counter_culture [![Build Status](https://travis-ci.org/magnusvk/counter_culture.svg)](https://travis-ci.org/magnusvk/counter_culture)
|
2
2
|
|
3
3
|
Turbo-charged counter caches for your Rails app. Huge improvements over the Rails standard counter caches:
|
4
4
|
|
@@ -13,7 +13,7 @@ Turbo-charged counter caches for your Rails app. Huge improvements over the Rail
|
|
13
13
|
Add counter_culture to your Gemfile:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem 'counter_culture', '~> 0.1.
|
16
|
+
gem 'counter_culture', '~> 0.1.23'
|
17
17
|
```
|
18
18
|
|
19
19
|
Then run ```bundle update ```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.24
|
data/counter_culture.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
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.24 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.24"
|
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"]
|
13
|
-
s.date = "2014-
|
13
|
+
s.date = "2014-06-27"
|
14
14
|
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."
|
15
15
|
s.email = "magnus@vonkoeller.de"
|
16
16
|
s.extra_rdoc_files = [
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"spec/models/conditional_main.rb",
|
43
43
|
"spec/models/has_string_id.rb",
|
44
44
|
"spec/models/industry.rb",
|
45
|
+
"spec/models/post.rb",
|
45
46
|
"spec/models/product.rb",
|
46
47
|
"spec/models/review.rb",
|
47
48
|
"spec/models/simple_dependent.rb",
|
data/lib/counter_culture.rb
CHANGED
@@ -182,7 +182,7 @@ module CounterCulture
|
|
182
182
|
def relation_foreign_key(relation)
|
183
183
|
relation_reflect(relation).foreign_key
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
# gets the foreign key name of the relation. will look at the first
|
187
187
|
# level only -- i.e., if passed an array will consider only its
|
188
188
|
# first element
|
@@ -193,7 +193,7 @@ module CounterCulture
|
|
193
193
|
relation = relation.first if relation.is_a?(Enumerable)
|
194
194
|
relation_reflect(relation).foreign_key
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
end
|
198
198
|
|
199
199
|
private
|
@@ -257,7 +257,7 @@ module CounterCulture
|
|
257
257
|
#
|
258
258
|
# options:
|
259
259
|
# :increment => true to increment, false to decrement
|
260
|
-
# :relation => which relation to increment the count on,
|
260
|
+
# :relation => which relation to increment the count on,
|
261
261
|
# :counter_cache_name => the column name of the counter cache
|
262
262
|
# :counter_column => overrides :counter_cache_name
|
263
263
|
# :delta_column => override the default count delta (1) with the value of this column in the counted record
|
@@ -265,7 +265,7 @@ module CounterCulture
|
|
265
265
|
# first part of the relation
|
266
266
|
def change_counter_cache(options)
|
267
267
|
options[:counter_column] = counter_cache_name_for(self, options[:counter_cache_name]) unless options.has_key?(:counter_column)
|
268
|
-
|
268
|
+
|
269
269
|
# default to the current foreign key value
|
270
270
|
id_to_change = foreign_key_value(options[:relation], options[:was])
|
271
271
|
# allow overwriting of foreign key value by the caller
|
@@ -296,20 +296,21 @@ module CounterCulture
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
|
-
relation_klass(options[:relation])
|
299
|
+
klass = relation_klass(options[:relation])
|
300
|
+
klass.where(klass.primary_key => id_to_change).update_all updates.join(', ')
|
300
301
|
end
|
301
302
|
end
|
302
303
|
end
|
303
304
|
|
304
305
|
# Gets the name of the counter cache for a specific object
|
305
|
-
#
|
306
|
+
#
|
306
307
|
# obj: object to calculate the counter cache name for
|
307
308
|
# cache_name_finder: object used to calculate the cache name
|
308
309
|
def counter_cache_name_for(obj, cache_name_finder)
|
309
310
|
# figure out what the column name is
|
310
311
|
if cache_name_finder.is_a? Proc
|
311
312
|
# dynamic column name -- call the Proc
|
312
|
-
cache_name_finder.call(obj)
|
313
|
+
cache_name_finder.call(obj)
|
313
314
|
else
|
314
315
|
# static column name
|
315
316
|
cache_name_finder
|
@@ -319,11 +320,11 @@ module CounterCulture
|
|
319
320
|
# Creates a copy of the current model with changes rolled back
|
320
321
|
def previous_model
|
321
322
|
prev = self.dup
|
322
|
-
|
323
|
+
|
323
324
|
self.changed_attributes.each_pair do |key, value|
|
324
325
|
prev.send("#{key}=".to_sym, value)
|
325
326
|
end
|
326
|
-
|
327
|
+
|
327
328
|
prev
|
328
329
|
end
|
329
330
|
|
@@ -356,7 +357,7 @@ module CounterCulture
|
|
356
357
|
def relation_reflect(relation)
|
357
358
|
self.class.send :relation_reflect, relation
|
358
359
|
end
|
359
|
-
|
360
|
+
|
360
361
|
def relation_foreign_key(relation)
|
361
362
|
self.class.send :relation_foreign_key, relation
|
362
363
|
end
|
@@ -4,7 +4,7 @@ class CounterCultureGenerator < ActiveRecord::Generators::Base
|
|
4
4
|
|
5
5
|
desc "Create a migration that adds counter-cache columns to a model"
|
6
6
|
|
7
|
-
argument :counter_cache_columns, :required => true, :type => :array,
|
7
|
+
argument :counter_cache_columns, :required => true, :type => :array,
|
8
8
|
:desc => "The names of the counter cache columns to add",
|
9
9
|
:banner => "counter_cache_one counter_cache_two counter_cache_three ..."
|
10
10
|
|
@@ -12,6 +12,7 @@ require 'models/simple_main'
|
|
12
12
|
require 'models/simple_dependent'
|
13
13
|
require 'models/conditional_main'
|
14
14
|
require 'models/conditional_dependent'
|
15
|
+
require 'models/post'
|
15
16
|
|
16
17
|
require 'database_cleaner'
|
17
18
|
DatabaseCleaner.strategy = :deletion
|
@@ -30,7 +31,7 @@ describe "CounterCulture" do
|
|
30
31
|
user.review_approvals_count.should == 0
|
31
32
|
|
32
33
|
user.reviews.create :user_id => user.id, :product_id => product.id, :approvals => 13
|
33
|
-
|
34
|
+
|
34
35
|
user.reload
|
35
36
|
product.reload
|
36
37
|
|
@@ -48,7 +49,7 @@ describe "CounterCulture" do
|
|
48
49
|
user.review_approvals_count.should == 0
|
49
50
|
|
50
51
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 69
|
51
|
-
|
52
|
+
|
52
53
|
user.reload
|
53
54
|
product.reload
|
54
55
|
|
@@ -78,7 +79,7 @@ describe "CounterCulture" do
|
|
78
79
|
user2.review_approvals_count.should == 0
|
79
80
|
|
80
81
|
review = Review.create :user_id => user1.id, :product_id => product.id, :approvals => 42
|
81
|
-
|
82
|
+
|
82
83
|
user1.reload
|
83
84
|
user2.reload
|
84
85
|
product.reload
|
@@ -135,7 +136,7 @@ describe "CounterCulture" do
|
|
135
136
|
company.review_approvals_count.should == 0
|
136
137
|
|
137
138
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 314
|
138
|
-
|
139
|
+
|
139
140
|
company.reload
|
140
141
|
user.reload
|
141
142
|
product.reload
|
@@ -157,7 +158,7 @@ describe "CounterCulture" do
|
|
157
158
|
company.review_approvals_count.should == 0
|
158
159
|
|
159
160
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 314
|
160
|
-
|
161
|
+
|
161
162
|
user.reload
|
162
163
|
product.reload
|
163
164
|
company.reload
|
@@ -195,7 +196,7 @@ describe "CounterCulture" do
|
|
195
196
|
company2.review_approvals_count.should == 0
|
196
197
|
|
197
198
|
review = Review.create :user_id => user1.id, :product_id => product.id, :approvals => 69
|
198
|
-
|
199
|
+
|
199
200
|
user1.reload
|
200
201
|
user2.reload
|
201
202
|
company1.reload
|
@@ -238,7 +239,7 @@ describe "CounterCulture" do
|
|
238
239
|
product.rexiews_count.should == 0
|
239
240
|
|
240
241
|
review = Review.create :user_id => user.id, :product_id => product.id
|
241
|
-
|
242
|
+
|
242
243
|
product.reload
|
243
244
|
|
244
245
|
product.rexiews_count.should == 1
|
@@ -251,7 +252,7 @@ describe "CounterCulture" do
|
|
251
252
|
product.rexiews_count.should == 0
|
252
253
|
|
253
254
|
review = Review.create :user_id => user.id, :product_id => product.id
|
254
|
-
|
255
|
+
|
255
256
|
product.reload
|
256
257
|
|
257
258
|
product.rexiews_count.should == 1
|
@@ -272,7 +273,7 @@ describe "CounterCulture" do
|
|
272
273
|
product2.rexiews_count.should == 0
|
273
274
|
|
274
275
|
review = Review.create :user_id => user.id, :product_id => product1.id
|
275
|
-
|
276
|
+
|
276
277
|
product1.reload
|
277
278
|
product2.reload
|
278
279
|
|
@@ -297,7 +298,7 @@ describe "CounterCulture" do
|
|
297
298
|
user.tried_count.should == 0
|
298
299
|
|
299
300
|
review = Review.create :user_id => user.id, :product_id => product.id, :review_type => nil
|
300
|
-
|
301
|
+
|
301
302
|
user.reload
|
302
303
|
|
303
304
|
user.using_count.should == 0
|
@@ -312,7 +313,7 @@ describe "CounterCulture" do
|
|
312
313
|
user.tried_count.should == 0
|
313
314
|
|
314
315
|
review = Review.create :user_id => user.id, :product_id => product.id, :review_type => nil
|
315
|
-
|
316
|
+
|
316
317
|
product.reload
|
317
318
|
|
318
319
|
user.using_count.should == 0
|
@@ -337,7 +338,7 @@ describe "CounterCulture" do
|
|
337
338
|
user2.tried_count.should == 0
|
338
339
|
|
339
340
|
review = Review.create :user_id => user1.id, :product_id => product.id, :review_type => nil
|
340
|
-
|
341
|
+
|
341
342
|
user1.reload
|
342
343
|
user2.reload
|
343
344
|
|
@@ -357,64 +358,64 @@ describe "CounterCulture" do
|
|
357
358
|
user2.using_count.should == 0
|
358
359
|
user2.tried_count.should == 0
|
359
360
|
end
|
360
|
-
|
361
|
+
|
361
362
|
describe "conditional counts on update" do
|
362
363
|
let(:product) {Product.create!}
|
363
364
|
let(:user) {User.create!}
|
364
|
-
|
365
|
+
|
365
366
|
it "should increment and decrement if changing column name" do
|
366
367
|
user.using_count.should == 0
|
367
368
|
user.tried_count.should == 0
|
368
|
-
|
369
|
+
|
369
370
|
review = Review.create :user_id => user.id, :product_id => product.id, :review_type => "using"
|
370
371
|
user.reload
|
371
|
-
|
372
|
+
|
372
373
|
user.using_count.should == 1
|
373
374
|
user.tried_count.should == 0
|
374
|
-
|
375
|
+
|
375
376
|
review.review_type = "tried"
|
376
377
|
review.save!
|
377
|
-
|
378
|
+
|
378
379
|
user.reload
|
379
|
-
|
380
|
+
|
380
381
|
user.using_count.should == 0
|
381
382
|
user.tried_count.should == 1
|
382
383
|
end
|
383
|
-
|
384
|
+
|
384
385
|
it "should increment if changing from a nil column name" do
|
385
386
|
user.using_count.should == 0
|
386
387
|
user.tried_count.should == 0
|
387
|
-
|
388
|
+
|
388
389
|
review = Review.create :user_id => user.id, :product_id => product.id, :review_type => nil
|
389
390
|
user.reload
|
390
|
-
|
391
|
+
|
391
392
|
user.using_count.should == 0
|
392
393
|
user.tried_count.should == 0
|
393
|
-
|
394
|
+
|
394
395
|
review.review_type = "tried"
|
395
396
|
review.save!
|
396
|
-
|
397
|
+
|
397
398
|
user.reload
|
398
|
-
|
399
|
+
|
399
400
|
user.using_count.should == 0
|
400
401
|
user.tried_count.should == 1
|
401
402
|
end
|
402
|
-
|
403
|
+
|
403
404
|
it "should decrement if changing column name to nil" do
|
404
405
|
user.using_count.should == 0
|
405
406
|
user.tried_count.should == 0
|
406
|
-
|
407
|
+
|
407
408
|
review = Review.create :user_id => user.id, :product_id => product.id, :review_type => "using"
|
408
409
|
user.reload
|
409
|
-
|
410
|
+
|
410
411
|
user.using_count.should == 1
|
411
412
|
user.tried_count.should == 0
|
412
|
-
|
413
|
+
|
413
414
|
review.review_type = nil
|
414
415
|
review.save!
|
415
|
-
|
416
|
+
|
416
417
|
user.reload
|
417
|
-
|
418
|
+
|
418
419
|
user.using_count.should == 0
|
419
420
|
user.tried_count.should == 0
|
420
421
|
end
|
@@ -433,7 +434,7 @@ describe "CounterCulture" do
|
|
433
434
|
product.reviews_count.should == 0
|
434
435
|
|
435
436
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 42
|
436
|
-
|
437
|
+
|
437
438
|
industry.reload
|
438
439
|
company.reload
|
439
440
|
user.reload
|
@@ -459,7 +460,7 @@ describe "CounterCulture" do
|
|
459
460
|
product.reviews_count.should == 0
|
460
461
|
|
461
462
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 42
|
462
|
-
|
463
|
+
|
463
464
|
industry.reload
|
464
465
|
company.reload
|
465
466
|
user.reload
|
@@ -504,7 +505,7 @@ describe "CounterCulture" do
|
|
504
505
|
industry2.review_approvals_count.should == 0
|
505
506
|
|
506
507
|
review = Review.create :user_id => user1.id, :product_id => product.id, :approvals => 42
|
507
|
-
|
508
|
+
|
508
509
|
industry1.reload
|
509
510
|
industry2.reload
|
510
511
|
company1.reload
|
@@ -553,7 +554,7 @@ describe "CounterCulture" do
|
|
553
554
|
industry.rexiews_count.should == 0
|
554
555
|
|
555
556
|
review = Review.create :user_id => user.id, :product_id => product.id
|
556
|
-
|
557
|
+
|
557
558
|
industry.reload
|
558
559
|
|
559
560
|
industry.rexiews_count.should == 1
|
@@ -568,7 +569,7 @@ describe "CounterCulture" do
|
|
568
569
|
industry.rexiews_count.should == 0
|
569
570
|
|
570
571
|
review = Review.create :user_id => user.id, :product_id => product.id
|
571
|
-
|
572
|
+
|
572
573
|
industry.reload
|
573
574
|
industry.rexiews_count.should == 1
|
574
575
|
|
@@ -591,7 +592,7 @@ describe "CounterCulture" do
|
|
591
592
|
industry2.rexiews_count.should == 0
|
592
593
|
|
593
594
|
review = Review.create :user_id => user1.id, :product_id => product.id
|
594
|
-
|
595
|
+
|
595
596
|
industry1.reload
|
596
597
|
industry1.rexiews_count.should == 1
|
597
598
|
industry2.reload
|
@@ -609,7 +610,7 @@ describe "CounterCulture" do
|
|
609
610
|
it "increments dynamic counter cache on create" do
|
610
611
|
user = User.create
|
611
612
|
product = Product.create
|
612
|
-
|
613
|
+
|
613
614
|
user.using_count.should == 0
|
614
615
|
user.tried_count.should == 0
|
615
616
|
|
@@ -631,7 +632,7 @@ describe "CounterCulture" do
|
|
631
632
|
it "decrements dynamic counter cache on destroy" do
|
632
633
|
user = User.create
|
633
634
|
product = Product.create
|
634
|
-
|
635
|
+
|
635
636
|
user.using_count.should == 0
|
636
637
|
user.tried_count.should == 0
|
637
638
|
|
@@ -674,14 +675,14 @@ describe "CounterCulture" do
|
|
674
675
|
industry.tried_count.should == 0
|
675
676
|
|
676
677
|
review_using = Review.create :user_id => user.id, :product_id => product.id, :review_type => 'using'
|
677
|
-
|
678
|
+
|
678
679
|
industry.reload
|
679
680
|
|
680
681
|
industry.using_count.should == 1
|
681
682
|
industry.tried_count.should == 0
|
682
683
|
|
683
684
|
review_tried = Review.create :user_id => user.id, :product_id => product.id, :review_type => 'tried'
|
684
|
-
|
685
|
+
|
685
686
|
industry.reload
|
686
687
|
|
687
688
|
industry.using_count.should == 1
|
@@ -698,14 +699,14 @@ describe "CounterCulture" do
|
|
698
699
|
industry.tried_count.should == 0
|
699
700
|
|
700
701
|
review_using = Review.create :user_id => user.id, :product_id => product.id, :review_type => 'using'
|
701
|
-
|
702
|
+
|
702
703
|
industry.reload
|
703
704
|
|
704
705
|
industry.using_count.should == 1
|
705
706
|
industry.tried_count.should == 0
|
706
707
|
|
707
708
|
review_tried = Review.create :user_id => user.id, :product_id => product.id, :review_type => 'tried'
|
708
|
-
|
709
|
+
|
709
710
|
industry.reload
|
710
711
|
|
711
712
|
industry.using_count.should == 1
|
@@ -741,7 +742,7 @@ describe "CounterCulture" do
|
|
741
742
|
industry2.tried_count.should == 0
|
742
743
|
|
743
744
|
review_using = Review.create :user_id => user1.id, :product_id => product.id, :review_type => 'using'
|
744
|
-
|
745
|
+
|
745
746
|
industry1.reload
|
746
747
|
industry2.reload
|
747
748
|
|
@@ -751,7 +752,7 @@ describe "CounterCulture" do
|
|
751
752
|
industry2.tried_count.should == 0
|
752
753
|
|
753
754
|
review_tried = Review.create :user_id => user1.id, :product_id => product.id, :review_type => 'tried'
|
754
|
-
|
755
|
+
|
755
756
|
industry1.reload
|
756
757
|
industry2.reload
|
757
758
|
|
@@ -786,7 +787,7 @@ describe "CounterCulture" do
|
|
786
787
|
it "should overwrite foreign-key values on create" do
|
787
788
|
3.times { Category.create }
|
788
789
|
Category.all {|category| category.products_count.should == 0 }
|
789
|
-
|
790
|
+
|
790
791
|
product = Product.create :category_id => Category.first.id
|
791
792
|
Category.all {|category| category.products_count.should == 1 }
|
792
793
|
end
|
@@ -794,7 +795,7 @@ describe "CounterCulture" do
|
|
794
795
|
it "should overwrite foreign-key values on destroy" do
|
795
796
|
3.times { Category.create }
|
796
797
|
Category.all {|category| category.products_count.should == 0 }
|
797
|
-
|
798
|
+
|
798
799
|
product = Product.create :category_id => Category.first.id
|
799
800
|
Category.all {|category| category.products_count.should == 1 }
|
800
801
|
|
@@ -805,7 +806,7 @@ describe "CounterCulture" do
|
|
805
806
|
it "should overwrite foreign-key values on destroy" do
|
806
807
|
3.times { Category.create }
|
807
808
|
Category.all {|category| category.products_count.should == 0 }
|
808
|
-
|
809
|
+
|
809
810
|
product = Product.create :category_id => Category.first.id
|
810
811
|
Category.all {|category| category.products_count.should == 1 }
|
811
812
|
|
@@ -824,7 +825,7 @@ describe "CounterCulture" do
|
|
824
825
|
user.review_approvals_count.should == 0
|
825
826
|
|
826
827
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 69
|
827
|
-
|
828
|
+
|
828
829
|
user.reload
|
829
830
|
product.reload
|
830
831
|
|
@@ -873,7 +874,7 @@ describe "CounterCulture" do
|
|
873
874
|
product = Product.create
|
874
875
|
|
875
876
|
product.twitter_reviews_count.should == 0
|
876
|
-
|
877
|
+
|
877
878
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 42
|
878
879
|
twitter_review = TwitterReview.create :user_id => user.id, :product_id => product.id, :approvals => 32
|
879
880
|
|
@@ -904,7 +905,7 @@ describe "CounterCulture" do
|
|
904
905
|
company.review_approvals_count.should == 0
|
905
906
|
|
906
907
|
review = Review.create :user_id => user.id, :product_id => product.id, :approvals => 42
|
907
|
-
|
908
|
+
|
908
909
|
company.reload
|
909
910
|
user.reload
|
910
911
|
product.reload
|
@@ -940,7 +941,7 @@ describe "CounterCulture" do
|
|
940
941
|
product.rexiews_count.should == 0
|
941
942
|
|
942
943
|
review = Review.create :user_id => user.id, :product_id => product.id
|
943
|
-
|
944
|
+
|
944
945
|
product.reload
|
945
946
|
|
946
947
|
product.rexiews_count.should == 1
|
@@ -957,7 +958,7 @@ describe "CounterCulture" do
|
|
957
958
|
it "should fix a dynamic counter cache correctly" do
|
958
959
|
user = User.create
|
959
960
|
product = Product.create
|
960
|
-
|
961
|
+
|
961
962
|
user.using_count.should == 0
|
962
963
|
user.tried_count.should == 0
|
963
964
|
|
@@ -1007,7 +1008,7 @@ describe "CounterCulture" do
|
|
1007
1008
|
string_id.users_count.should == 123
|
1008
1009
|
|
1009
1010
|
User.counter_culture_fix_counts
|
1010
|
-
|
1011
|
+
|
1011
1012
|
string_id.reload
|
1012
1013
|
string_id.users_count.should == 2
|
1013
1014
|
end
|
@@ -1080,7 +1081,7 @@ describe "CounterCulture" do
|
|
1080
1081
|
# first, clean up
|
1081
1082
|
SimpleDependent.delete_all
|
1082
1083
|
SimpleMain.delete_all
|
1083
|
-
|
1084
|
+
|
1084
1085
|
1000.times do |i|
|
1085
1086
|
main = SimpleMain.create
|
1086
1087
|
3.times { main.simple_dependents.create }
|
@@ -1215,18 +1216,31 @@ describe "CounterCulture" do
|
|
1215
1216
|
user.created_at.to_i.should == user.updated_at.to_i
|
1216
1217
|
product.created_at.to_i.should < product.updated_at.to_i
|
1217
1218
|
end
|
1218
|
-
|
1219
|
+
|
1220
|
+
it "should update counts correctly when creating using nested attributes" do
|
1221
|
+
user = User.create(:reviews_attributes => [{:some_text => 'abc'}, {:some_text => 'xyz'}])
|
1222
|
+
user.reload
|
1223
|
+
user.reviews_count.should == 2
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
it "should use relation primary_key correctly", :focus => true do
|
1227
|
+
category = Category.create!
|
1228
|
+
post = Post.create!(:category_id => category.id)
|
1229
|
+
category.reload
|
1230
|
+
category.posts_count.should == 1
|
1231
|
+
end
|
1232
|
+
|
1219
1233
|
describe "#previous_model" do
|
1220
1234
|
let(:user){User.create :name => "John Smith", :manages_company_id => 1}
|
1221
|
-
|
1235
|
+
|
1222
1236
|
it "should return a copy of the original model" do
|
1223
1237
|
user.name = "Joe Smith"
|
1224
1238
|
user.manages_company_id = 2
|
1225
1239
|
prev = user.send(:previous_model)
|
1226
|
-
|
1240
|
+
|
1227
1241
|
prev.name.should == "John Smith"
|
1228
1242
|
prev.manages_company_id.should == 1
|
1229
|
-
|
1243
|
+
|
1230
1244
|
user.name.should =="Joe Smith"
|
1231
1245
|
user.manages_company_id.should == 2
|
1232
1246
|
end
|
data/spec/models/post.rb
ADDED
data/spec/models/user.rb
CHANGED
data/spec/schema.rb
CHANGED
@@ -75,6 +75,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
75
75
|
create_table "categories", :force => true do |t|
|
76
76
|
t.string "name"
|
77
77
|
t.integer "products_count", :default => 0, :null => false
|
78
|
+
t.integer "posts_count", :default => 0, :null => false
|
78
79
|
t.datetime "created_at"
|
79
80
|
t.datetime "updated_at"
|
80
81
|
end
|
@@ -93,7 +94,7 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
93
94
|
t.datetime "created_at"
|
94
95
|
t.datetime "updated_at"
|
95
96
|
end
|
96
|
-
|
97
|
+
|
97
98
|
create_table "simple_dependents", :force => true do |t|
|
98
99
|
t.integer "simple_main_id"
|
99
100
|
t.datetime "created_at"
|
@@ -113,4 +114,10 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
|
|
113
114
|
t.datetime "updated_at"
|
114
115
|
end
|
115
116
|
|
117
|
+
create_table "posts", :primary_key => "post_id", :force => true do |t|
|
118
|
+
t.string "title"
|
119
|
+
t.integer "category_id", :default => nil
|
120
|
+
t.datetime "created_at", :null => false
|
121
|
+
t.datetime "updated_at", :null => false
|
122
|
+
end
|
116
123
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus von Koeller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- spec/models/conditional_main.rb
|
172
172
|
- spec/models/has_string_id.rb
|
173
173
|
- spec/models/industry.rb
|
174
|
+
- spec/models/post.rb
|
174
175
|
- spec/models/product.rb
|
175
176
|
- spec/models/review.rb
|
176
177
|
- spec/models/simple_dependent.rb
|