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
|
|
|
|
|
2012-03-19 18:31:05 +00:00
|
|
|
describe "self#impressionist_counter_caching?" do
|
2011-10-31 18:18:46 +00:00
|
|
|
it "should know when counter caching is enabled" do
|
2012-03-19 18:31:05 +00:00
|
|
|
Widget.should be_impressionist_counter_caching
|
2011-10-31 18:18:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should know when counter caching is disabled" do
|
2012-03-19 18:31:05 +00:00
|
|
|
Article.should_not be_impressionist_counter_caching
|
2011-10-31 18:18:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "self#counter_caching?" do
|
|
|
|
it "should know when counter caching is enabled" do
|
2012-03-19 19:56:42 +00:00
|
|
|
ActiveSupport::Deprecation.should_receive(:warn)
|
2011-10-31 18:18:46 +00:00
|
|
|
Widget.should be_counter_caching
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should know when counter caching is disabled" do
|
2012-03-19 19:56:42 +00:00
|
|
|
ActiveSupport::Deprecation.should_receive(:warn)
|
2011-10-31 18:18:46 +00:00
|
|
|
Article.should_not be_counter_caching
|
|
|
|
end
|
2012-03-19 19:56:42 +00:00
|
|
|
|
2011-10-31 18:18:46 +00:00
|
|
|
end
|
|
|
|
|
2012-03-19 18:33:19 +00:00
|
|
|
describe "#update_impressionist_counter_cache" do
|
2011-10-31 18:18:46 +00:00
|
|
|
it "should update the counter cache column to reflect the correct number of impressions" do
|
|
|
|
lambda {
|
2012-03-19 22:24:40 +00:00
|
|
|
@widget.impressions.create(:request_hash => 'abcd1234')
|
2011-10-31 18:18:46 +00:00
|
|
|
@widget.reload
|
|
|
|
}.should change(@widget, :impressions_count).from(0).to(1)
|
|
|
|
end
|
2012-07-04 14:23:25 +00:00
|
|
|
|
|
|
|
it "should not update the timestamp on the impressable" do
|
|
|
|
lambda {
|
|
|
|
@widget.impressions.create(:request_hash => 'abcd1234')
|
|
|
|
@widget.reload
|
|
|
|
}.should_not change(@widget, :updated_at)
|
|
|
|
end
|
2011-10-31 18:18:46 +00:00
|
|
|
end
|
|
|
|
|
2012-03-06 21:42:28 +00:00
|
|
|
end
|