Skip to content

Commit

Permalink
Add a test case where no dependent record exists for some of main rec…
Browse files Browse the repository at this point in the history
…ords
  • Loading branch information
luvtechno committed Oct 9, 2013
1 parent 589b4f5 commit 6234e1a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/counter_culture_spec.rb
Expand Up @@ -1065,6 +1065,24 @@
SimpleMain.find_each { |main| main.simple_dependents_count.should == 3 }
end

it "should correctly fix the counter caches when no dependent record exists for some of main records" do
# first, clean up
SimpleDependent.delete_all
SimpleMain.delete_all

1000.times do |i|
main = SimpleMain.create
(main.id % 4).times { main.simple_dependents.create }
end

SimpleMain.find_each { |main| main.simple_dependents_count.should == main.id % 4 }

SimpleMain.order('random()').limit(50).update_all simple_dependents_count: 1
SimpleDependent.counter_culture_fix_counts :batch_size => 100

SimpleMain.find_each { |main| main.simple_dependents_count.should == main.id % 4 }
end

it "should correctly sum up flaot values" do
user = User.create

Expand Down

0 comments on commit 6234e1a

Please sign in to comment.