Sha256: 4ee558742b55e4ce9ff388d149d7241cec6944c3bb18f6cee474797c5e409dd4

Contents?: true

Size: 1.34 KB

Versions: 23

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

describe Impression do
  fixtures :widgets

  let(:widget) { Widget.find(1) }

  before(:each) do
    Impression.destroy_all
  end

  describe "self#impressionist_counter_caching?" do
    it "should know when counter caching is enabled" do
      Widget.should be_impressionist_counter_caching
    end

    it "should know when counter caching is disabled" do
      Article.should_not be_impressionist_counter_caching
    end
  end

  describe "self#counter_caching?" do
    it "should know when counter caching is enabled" do
      ActiveSupport::Deprecation.should_receive(:warn)
      Widget.should be_counter_caching
    end

    it "should know when counter caching is disabled" do
      ActiveSupport::Deprecation.should_receive(:warn)
      Article.should_not be_counter_caching
    end

  end

  describe "#update_impressionist_counter_cache" do
    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)
    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
  end

end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
impressionist-2.0.0 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.6.1 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.6.0 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.5.2 tests/test_app/spec/models/counter_caching_spec.rb
impressionist2-1.5.5 tests/test_app/spec/models/counter_caching_spec.rb
impressionist2-1.5.4 tests/test_app/spec/models/counter_caching_spec.rb
impressionist2-1.5.3 tests/test_app/spec/models/counter_caching_spec.rb
impressionist2-1.5.1 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.5.1 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.13 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.12 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.11 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.10 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.9 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.8 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.7 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.6 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.5 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.4 tests/test_app/spec/models/counter_caching_spec.rb
impressionist-1.4.3 tests/test_app/spec/models/counter_caching_spec.rb