Sha256: 038f46b7167df1cf29eede3771c01a6d7f47185b0cf931e9a3324a6cb65ab4fa

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe ActiveEncode::GlobalID do
  before do
    class CustomEncode < ActiveEncode::Base
    end
  end

  after do
    Object.send(:remove_const, :CustomEncode)
  end

  describe '#to_global_id' do
    subject { encode.to_global_id }
    let(:encode_class) { ActiveEncode::Base }
    let(:encode) { encode_class.create(nil) }

    it { is_expected.to be_a GlobalID }
    it { expect(subject.model_class).to eq encode_class }
    it { expect(subject.model_id).to eq encode.id }
    it { expect(subject.app).to eq 'ActiveEncode' }

    context 'with an ActiveEncode::Base subclass' do
      let(:encode_class) { CustomEncode }

      it { is_expected.to be_a GlobalID }
      it { expect(subject.model_class).to eq encode_class }
      it { expect(subject.model_id).to eq encode.id }
      it { expect(subject.app).to eq 'ActiveEncode' }
    end
  end

  describe 'GlobalID::Locator#locate' do
    subject { GlobalID::Locator.locate(global_id) }
    let(:encode_class) { ActiveEncode::Base }
    let(:encode) { encode_class.create(nil) }
    let(:global_id) { encode.to_global_id }

    it { is_expected.to be_a encode_class }
    it { expect(subject.id).to eq encode.id }

    context 'with an ActiveEncode::Base subclass' do
      let(:encode_class) { CustomEncode }

      it { is_expected.to be_a encode_class }
      it { expect(subject.id).to eq encode.id }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_encode-1.2.0 spec/units/global_id_spec.rb
active_encode-1.1.3 spec/units/global_id_spec.rb
active_encode-1.1.2 spec/units/global_id_spec.rb
active_encode-1.1.1 spec/units/global_id_spec.rb
active_encode-1.1.0 spec/units/global_id_spec.rb
active_encode-1.0.0 spec/units/global_id_spec.rb
active_encode-0.8.2 spec/units/global_id_spec.rb
active_encode-0.8.1 spec/units/global_id_spec.rb
active_encode-0.8.0 spec/units/global_id_spec.rb