Sha256: c036302baa8287d8c5242704645d0c1bb31e2b7f39a57af94f344ae7c1a3ccaa

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

module Polyamorous
  describe JoinAssociation do

    let(:join_dependency) { new_join_dependency Note, {} }
    let(:reflection) { Note.reflect_on_association(:notable) }
    let(:parent) { join_dependency.send(:join_root) }
    let(:join_association) {
      new_join_association(reflection, parent.children, Article)
    }

    subject { new_join_association(reflection, parent.children, Person) }

    it 'respects polymorphism on equality test' do
      expect(subject).to eq new_join_association(reflection, parent.children, Person)
      expect(subject).not_to eq new_join_association(reflection, parent.children, Article)
    end

    it 'leaves the orginal reflection intact for thread safety' do
      reflection.instance_variable_set(:@klass, Article)
      join_association
      .swapping_reflection_klass(reflection, Person) do |new_reflection|
        expect(new_reflection.options).not_to equal reflection.options
        expect(new_reflection.options).not_to have_key(:polymorphic)
        expect(new_reflection.klass).to eq(Person)
        expect(reflection.klass).to eq(Article)
      end
    end

    it 'sets the polymorphic option to true after initializing' do
      expect(join_association.reflection.options[:polymorphic]).to be true
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/spec/polyamorous/join_association_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/spec/polyamorous/join_association_spec.rb
ransack-2.4.2 spec/polyamorous/join_association_spec.rb
ransack-2.4.1 spec/polyamorous/join_association_spec.rb
ransack-2.4.0 spec/polyamorous/join_association_spec.rb