Sha256: 210203ed5532bc76ee49d6d5caa9a237750e46066d5bd1b3f7bc0d2c13e9d246

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'helper'

describe Wayback::Identity do

  describe "#initialize" do
    it "raises an ArgumentError when type is not specified" do
      expect{Wayback::Identity.new}.to raise_error ArgumentError
    end
  end

  context "identity map enabled" do
    before do
      Wayback.identity_map = Wayback::IdentityMap
    end

    after do
      Wayback.identity_map = false
    end

    describe ".fetch" do
      it "returns existing objects" do
        Wayback::Identity.store(Wayback::Identity.new(:id => 1))
        expect(Wayback::Identity.fetch(:id => 1)).to be
      end

      it "raises an error on objects that don't exist" do
        expect{Wayback::Identity.fetch(:id => 6)}.to raise_error Wayback::Error::IdentityMapKeyError
      end
    end
  end

  describe "#==" do
    it "returns true when objects IDs are the same" do
      one = Wayback::Identity.new(:id => 1, :screen_name => "gleuch")
      two = Wayback::Identity.new(:id => 1, :screen_name => "ohjia")
      expect(one == two).to be_true
    end
    it "returns false when objects IDs are different" do
      one = Wayback::Identity.new(:id => 1)
      two = Wayback::Identity.new(:id => 2)
      expect(one == two).to be_false
    end
    it "returns false when classes are different" do
      one = Wayback::Identity.new(:id => 1)
      two = Wayback::Base.new(:id => 1)
      expect(one == two).to be_false
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wayback-0.3.1 spec/wayback/identifiable_spec.rb
wayback-0.2.1 spec/wayback/identifiable_spec.rb
wayback-0.2.0 spec/wayback/identifiable_spec.rb
wayback-0.1.0 spec/wayback/identifiable_spec.rb