impressionist/tests/test_app/spec/models/counter_caching_spec.rb

52 lines
1.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2011-10-31 18:18:46 +00:00
describe Impression do
fixtures :widgets
let(:widget) { Widget.find(1) }
2011-10-31 18:18:46 +00:00
before(:each) do
Impression.destroy_all
end
describe "self#impressionist_counter_caching?" do
2011-10-31 18:18:46 +00:00
it "should know when counter caching is enabled" do
Widget.should be_impressionist_counter_caching
2011-10-31 18:18:46 +00:00
end
it "should know when counter caching is disabled" do
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
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
ActiveSupport::Deprecation.should_receive(:warn)
2011-10-31 18:18:46 +00:00
Article.should_not be_counter_caching
end
2011-10-31 18:18:46 +00:00
end
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
expect {
widget.impressions.create(:request_hash => 'abcd1234')
widget.reload
}.to change(widget, :impressions_count).from(0).to(1)
2011-10-31 18:18:46 +00:00
end
it "should not update the timestamp on the impressable" do
expect {
widget.impressions.create(:request_hash => 'abcd1234')
widget.reload
}.to_not change(widget, :updated_at)
end
2011-10-31 18:18:46 +00:00
end
end