Sha256: fff8f435a139dd4842906d39b8891d8643a5747d04a522e2d94e28674373d3db

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

require "spec_helper"

describe ActiveRemote::PrimaryKey do
  let(:tag) { Tag.new(:id => "1234", :guid => "TAG-123", :user_guid => "USR-123") }

  after { Tag.instance_variable_set :@primary_key, nil }

  describe ".default_primary_key" do
    it "returns array of :guid" do
      expect(Tag.default_primary_key).to eq(:guid)
    end
  end

  describe "primary_key" do
    context "when no arguments are passed" do
      it "returns default primary key" do
        expect(Tag.primary_key).to eq(:guid)
      end
    end

    context "when arguments are passed" do
      let(:specified_primary_key) { :name }

      it "returns the given primary key" do
        expect(Tag.primary_key(specified_primary_key)).to eq(specified_primary_key)
      end
    end
  end

  describe "#primary_key" do
    it "returns the primary key for the class" do
      expect(Tag.new.primary_key).to eq Tag.primary_key
    end
  end

  describe "#to_key" do
    context "when no primary key is specified and default of guid does not exist" do
      it "returns nil" do
        expect(NoAttributes.new.to_key).to eq nil
      end
    end

    context "when no primary key is specified, but default of guid exists" do
      it "returns guid in array" do
        expect(Tag.new(:guid => "TAG-123").to_key).to eq ["TAG-123"]
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_remote-6.0.3 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.1.2 spec/lib/active_remote/primary_key_spec.rb
active_remote-7.0.0 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.1.1 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.1.0 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.0.2 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.0.1 spec/lib/active_remote/primary_key_spec.rb
active_remote-6.0.0.beta spec/lib/active_remote/primary_key_spec.rb
active_remote-5.2.0 spec/lib/active_remote/primary_key_spec.rb
active_remote-5.2.0.beta spec/lib/active_remote/primary_key_spec.rb