Sha256: 4c8b652cc0360b3f6c2fdca51aa7504a1e663afdc246c19ab9562392c25f76f6

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

require 'helper'

describe Twitter::Identity do

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

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

    after do
      Twitter.identity_map = false
    end

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

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

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

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
twitter-4.8.1 spec/twitter/identifiable_spec.rb
twitter-4.8.0 spec/twitter/identifiable_spec.rb
twitter-4.7.0 spec/twitter/identifiable_spec.rb
twitter-4.6.2 spec/twitter/identifiable_spec.rb
twitter-4.6.1 spec/twitter/identifiable_spec.rb
twitter-4.6.0 spec/twitter/identifiable_spec.rb
twitter-4.5.0 spec/twitter/identifiable_spec.rb
twitter-4.4.4 spec/twitter/identifiable_spec.rb
twitter-4.4.3 spec/twitter/identifiable_spec.rb
twitter-4.4.2 spec/twitter/identifiable_spec.rb
twitter-4.4.1 spec/twitter/identifiable_spec.rb
twitter-4.4.0 spec/twitter/identifiable_spec.rb