2012-03-12 23:09:21 +00:00
|
|
|
require 'spec_helper'
|
2011-10-31 18:18:46 +00:00
|
|
|
|
|
|
|
describe Impression do
|
|
|
|
fixtures :widgets
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@widget = Widget.find(1)
|
|
|
|
Impression.destroy_all
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "self#counter_caching?" do
|
|
|
|
it "should know when counter caching is enabled" do
|
|
|
|
Widget.should be_counter_caching
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should know when counter caching is disabled" do
|
|
|
|
Article.should_not be_counter_caching
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update_counter_cache" do
|
|
|
|
it "should update the counter cache column to reflect the correct number of impressions" do
|
|
|
|
lambda {
|
|
|
|
Impression.create(:impressionable_type => @widget.class.name, :impressionable_id => @widget.id)
|
|
|
|
@widget.reload
|
|
|
|
}.should change(@widget, :impressions_count).from(0).to(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-06 21:42:28 +00:00
|
|
|
end
|