Sha256: 154423e39197547294a8ce46b2b069a12ed3dc1413fe31f681bacc65cb87cb41

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Virtus::Attribute::EmbeddedValue, '.build' do
  subject { described_class.build(type) }

  context 'when type is a Virtus.model' do
    let(:type) { Class.new { include Virtus.model } }

    it { is_expected.to be_frozen }

    it { is_expected.to be_instance_of(Virtus::Attribute::EmbeddedValue) }

    describe '#coercer' do
      subject { super().coercer }
      it { is_expected.to be_instance_of(described_class::FromOpenStruct) }
    end
  end

  context 'when type includes Virtus' do
    let(:type) { Class.new { include Virtus } }

    it { is_expected.to be_frozen }

    it { is_expected.to be_instance_of(Virtus::Attribute::EmbeddedValue) }

    describe '#coercer' do
      subject { super().coercer }
      it { is_expected.to be_instance_of(described_class::FromOpenStruct) }
    end
  end

  context 'when type is an OpenStruct subclass' do
    let(:type) { Class.new(OpenStruct) }

    it { is_expected.to be_frozen }

    it { is_expected.to be_instance_of(Virtus::Attribute::EmbeddedValue) }

    describe '#coercer' do
      subject { super().coercer }
      it { is_expected.to be_instance_of(described_class::FromOpenStruct) }
    end
  end

  context 'when type is OpenStruct' do
    let(:type) { OpenStruct }

    it { is_expected.to be_frozen }

    it { is_expected.to be_instance_of(Virtus::Attribute::EmbeddedValue) }

    describe '#coercer' do
      subject { super().coercer }
      it { is_expected.to be_instance_of(described_class::FromOpenStruct) }
    end
  end

  context 'when type is Struct' do
    let(:type) { Struct.new(:test) }

    it { is_expected.to be_frozen }

    it { is_expected.to be_instance_of(Virtus::Attribute::EmbeddedValue) }

    describe '#coercer' do
      subject { super().coercer }
      it { is_expected.to be_instance_of(described_class::FromStruct) }
    end
  end
end

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus2-2.1.0 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus2-2.0.2 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus2-2.0.1 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus-2.0.0 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus-1.0.5 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
virtus-1.0.4 spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb