Sha256: 9f3b784a519536f8a36f6e8b7714b1a785464d7d955d32dcf1f8b96b5a0bef21

Contents?: true

Size: 1.4 KB

Versions: 24

Compression:

Stored size: 1.4 KB

Contents

require 'helper'

describe Toy::Caching do
  uses_constants('User')

  context "new" do
    before do
      @user = User.new
    end

    it "should be class:new" do
      @user.cache_key.should == 'User:new'
    end

    it "should work with suffix" do
      @user.cache_key(:foo).should == 'User:new:foo'

      @user.cache_key(:foo, :bar).should == 'User:new:foo:bar'
    end
  end

  context "not new" do
    context "with updated_at" do
      before do
        User.timestamps
        @now = Time.now.utc
        Timecop.freeze(@now) do
          @user = User.create
        end
      end

      it "should be class:id-timestamp" do
        @user.cache_key.should == "User:#{@user.id}-#{@now.to_s(:number)}"
      end

      it "should work with suffix" do
        @user.cache_key(:foo).should == "User:#{@user.id}-#{@now.to_s(:number)}:foo"

        @user.cache_key(:foo, :bar).should == "User:#{@user.id}-#{@now.to_s(:number)}:foo:bar"
      end
    end

    context "without updated_at" do
      before do
        @now = Time.now.utc
        Timecop.freeze(@now) do
          @user = User.create
        end
      end

      it "should be class:id" do
        @user.cache_key.should == "User:#{@user.id}"
      end

      it "should work with suffix" do
        @user.cache_key(:foo).should == "User:#{@user.id}:foo"

        @user.cache_key(:foo, :bar, :baz). should == "User:#{@user.id}:foo:bar:baz"
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
toystore-0.13.2 spec/toy/caching_spec.rb
toystore-0.13.1 spec/toy/caching_spec.rb
toystore-0.13.0 spec/toy/caching_spec.rb
toystore-0.12.0 spec/toy/caching_spec.rb
toystore-0.11.0 spec/toy/caching_spec.rb
toystore-0.10.4 spec/toy/caching_spec.rb
toystore-0.10.3 spec/toy/caching_spec.rb
toystore-0.10.2 spec/toy/caching_spec.rb
toystore-0.10.1 spec/toy/caching_spec.rb
toystore-0.10.0 spec/toy/caching_spec.rb
toystore-0.9.0 spec/toy/caching_spec.rb
toystore-0.8.3 spec/toy/caching_spec.rb
toystore-0.8.2 spec/toy/caching_spec.rb
toystore-0.8.1 spec/toy/caching_spec.rb
toystore-0.8.0 spec/toy/caching_spec.rb
toystore-0.7.0 spec/toy/caching_spec.rb
toystore-0.6.6 spec/toy/caching_spec.rb
toystore-0.6.5 spec/toy/caching_spec.rb
toystore-0.6.4 spec/toy/caching_spec.rb
toystore-0.6.3 spec/toy/caching_spec.rb