activerecord-hackery--ransack/spec/polyamorous/join_dependency_spec.rb

82 lines
3.1 KiB
Ruby
Raw Permalink Normal View History

2018-06-23 17:00:21 +00:00
require 'spec_helper'
module Polyamorous
describe JoinDependency do
context 'with symbol joins' do
subject { new_join_dependency Person, articles: :comments }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq(2) }
2019-04-14 15:17:56 +00:00
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
.to eq [Polyamorous::InnerJoin] }
2018-06-23 17:00:21 +00:00
end
context 'with has_many :through association' do
subject { new_join_dependency Person, :authored_article_comments }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq 1 }
specify { expect(subject.send(:join_root).drop(1).first.table_name)
2018-06-23 17:00:21 +00:00
.to eq 'comments' }
end
context 'with outer join' do
subject { new_join_dependency Person, new_join(:articles, :outer) }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq 1 }
specify { expect(subject.send(:join_root).drop(1).first.join_type)
2018-06-23 17:00:21 +00:00
.to eq Polyamorous::OuterJoin }
end
context 'with nested outer joins' do
subject { new_join_dependency Person,
new_join(:articles, :outer) => new_join(:comments, :outer) }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq 2 }
specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
2018-06-23 17:00:21 +00:00
.to eq [Polyamorous::OuterJoin, Polyamorous::OuterJoin] }
2019-04-14 15:17:56 +00:00
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
.to eq [Polyamorous::OuterJoin] }
2018-06-23 17:00:21 +00:00
end
context 'with polymorphic belongs_to join' do
subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq 1 }
specify { expect(subject.send(:join_root).drop(1).first.join_type)
2018-06-23 17:00:21 +00:00
.to eq Polyamorous::InnerJoin }
specify { expect(subject.send(:join_root).drop(1).first.table_name)
2018-06-23 17:00:21 +00:00
.to eq 'people' }
end
context 'with polymorphic belongs_to join and nested symbol join' do
subject { new_join_dependency Note,
new_join(:notable, :inner, Person) => :comments }
specify { expect(subject.send(:join_root).drop(1).size)
2018-06-23 17:00:21 +00:00
.to eq 2 }
2019-04-14 15:17:56 +00:00
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
.to eq [Polyamorous::InnerJoin] }
specify { expect(subject.send(:join_root).drop(1).first.table_name)
.to eq 'people' }
specify { expect(subject.send(:join_root).drop(1)[1].table_name)
.to eq 'comments' }
end
context 'with polymorphic belongs_to join and nested join' do
subject { new_join_dependency Note,
new_join(:notable, :outer, Person) => :comments }
specify { expect(subject.send(:join_root).drop(1).size).to eq 2 }
specify { expect(subject.send(:join_root).drop(1).map(&:join_type)).to eq [Polyamorous::OuterJoin, Polyamorous::InnerJoin] }
specify { expect(subject.send(:join_root).drop(1).first.table_name)
2018-06-23 17:00:21 +00:00
.to eq 'people' }
specify { expect(subject.send(:join_root).drop(1)[1].table_name)
2018-06-23 17:00:21 +00:00
.to eq 'comments' }
end
end
end