Sha256: 3e408704abd546773a3ce35a78fb17cf7a2f3da66a531d156d28472578d816cc

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'
require 'granite/form/base'

describe Granite::Form::Model::Associations::Reflections::EmbedsAny do
  describe '#build' do
    subject { described_class.build(User, User, :projects) {}.klass.new }

    before do
      stub_model(:project) do
        include Granite::Form::Model::Lifecycle
        attribute :title, String
      end
      stub_model(:user) do
        include Granite::Form::Model::Associations

        attribute :name, String
        embeds_many :projects
      end
    end

    it { is_expected.to be_a(Granite::Form::Model) }
    it { is_expected.to be_a(Granite::Form::Model::Primary) }
    it { is_expected.to be_a(Granite::Form::Model::Lifecycle) }
    it { is_expected.to be_a(Granite::Form::Model::Associations) }

    context 'when Granite::Form.base_concern is defined' do
      before do
        stub_const('MyModule', Module.new)

        allow(Granite::Form).to receive(:base_concern).and_return(MyModule)

        stub_model(:user) do
          include Granite::Form::Model::Associations

          embeds_many :projects
        end
      end

      it { is_expected.to be_a(MyModule) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
granite-form-0.2.0 spec/granite/form/model/associations/reflections/embeds_any_spec.rb
granite-form-0.1.1 spec/lib/granite/form/model/associations/reflections/embeds_any_spec.rb
granite-form-0.1.0 spec/lib/granite/form/model/associations/reflections/embeds_any_spec.rb