Sha256: 9f8760f0b1fa37e610cc617f6df3a0da1e90e96d5735b13b426cf532bed2335c

Contents?: true

Size: 1.43 KB

Versions: 24

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

describe ::ActiveRemote::Integration do
  let(:guid) { "GUID-derp" }
  subject { Tag.new(:guid => guid) }

  context "#to_param" do
    # API
    specify { expect(subject).to respond_to(:to_param) }

    it "returns the guid if the guid is present (by default)" do
      expect(subject.to_param).to eq(guid)
    end
  end

  context "#cache_key" do
    # API
    specify { expect(subject).to respond_to(:cache_key) }

    it "sets 'new' as the identifier when the record has not been persisted" do
      expect(subject).to receive(:new_record?).and_return(true)
      expect(subject.cache_key).to match(/tag\/new/)
    end

    it "sets the cache_key to the class/guid as a default" do
      expect(subject).to receive(:new_record?).and_return(false)
      expect(subject.cache_key).to eq("tag/#{guid}")
    end

    it "adds the 'updated_at' attribute to the cache_key if updated_at is present" do
      ::ActiveRemote.config.default_cache_key_updated_at = true
      twenty_o_one_one = subject[:updated_at] = DateTime.new(2001, 01, 01)
      expect(subject).to receive(:new_record?).and_return(false)
      expect(subject.cache_key).to eq("tag/#{guid}-#{twenty_o_one_one.to_s(:number)}")
      subject[:updated_at] = nil
      ::ActiveRemote.config.default_cache_key_updated_at = false
    end

    it "defaults the cache updated_at to false" do
      expect(::ActiveRemote.config.default_cache_key_updated_at?).to be_falsey
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
active_remote-3.3.3 spec/lib/active_remote/integration_spec.rb
active_remote-3.3.2 spec/lib/active_remote/integration_spec.rb
active_remote-3.3.1 spec/lib/active_remote/integration_spec.rb
active_remote-3.3.0 spec/lib/active_remote/integration_spec.rb
active_remote-3.2.2 spec/lib/active_remote/integration_spec.rb
active_remote-3.2.1 spec/lib/active_remote/integration_spec.rb
active_remote-3.2.0 spec/lib/active_remote/integration_spec.rb
active_remote-3.2.0.pre spec/lib/active_remote/integration_spec.rb
active_remote-3.1.3 spec/lib/active_remote/integration_spec.rb
active_remote-3.1.2 spec/lib/active_remote/integration_spec.rb
active_remote-3.1.2.pre spec/lib/active_remote/integration_spec.rb
active_remote-3.1.1 spec/lib/active_remote/integration_spec.rb
active_remote-3.1.0 spec/lib/active_remote/integration_spec.rb
active_remote-3.0.0 spec/lib/active_remote/integration_spec.rb
active_remote-3.0.0.pre1 spec/lib/active_remote/integration_spec.rb
active_remote-2.4.0 spec/lib/active_remote/integration_spec.rb
active_remote-2.3.5 spec/lib/active_remote/integration_spec.rb
active_remote-2.3.4 spec/lib/active_remote/integration_spec.rb
active_remote-2.3.3 spec/lib/active_remote/integration_spec.rb
active_remote-2.3.3.pre spec/lib/active_remote/integration_spec.rb