polyamorous 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +18 -16
- data/Gemfile +13 -1
- data/README.md +8 -2
- data/lib/polyamorous.rb +13 -1
- data/lib/polyamorous/activerecord_3_and_4.0/join_dependency.rb +1 -1
- data/lib/polyamorous/activerecord_4.1/join_association.rb +3 -1
- data/lib/polyamorous/activerecord_4.1/join_dependency.rb +43 -4
- data/lib/polyamorous/activerecord_4.2/join_dependency.rb +12 -0
- data/lib/polyamorous/join.rb +11 -5
- data/lib/polyamorous/tree_node.rb +7 -0
- data/lib/polyamorous/version.rb +1 -1
- data/spec/helpers/polyamorous_helper.rb +2 -2
- data/spec/polyamorous/join_spec.rb +14 -1
- data/spec/support/shared_examples/join_association_3_and_4.0.rb +7 -7
- data/spec/support/shared_examples/join_association_4.1.rb +7 -7
- data/spec/support/shared_examples/join_dependency_3_and_4.0.rb +17 -17
- data/spec/support/shared_examples/join_dependency_4.1.rb +12 -12
- metadata +5 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a256aa59edc7952f875968b4de3aba8b9ae2ef1
|
4
|
+
data.tar.gz: 44fe6b2d97fde89c883db2b58d2fe847d8e70217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17b12b0d0ade5088d17bf164b03145b239ee184c5115d294cc7feda1d57e7085cceb1891b5a1640702fd1a182507277af155387732810d5719418f4bbb48cdea
|
7
|
+
data.tar.gz: 5090142ad7882a7efa7c3fa4ca72f74627d64d5537b1310c0f156325e4b54b004e2d09b0666b33cb981fad74bf3eca68ae6cf92538a13a39002571306576a64d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -9,24 +9,26 @@ rvm:
|
|
9
9
|
- 2.1.1
|
10
10
|
|
11
11
|
env:
|
12
|
-
- RAILS=
|
13
|
-
- RAILS=
|
14
|
-
- RAILS=
|
15
|
-
- RAILS=4-0-stable DB=sqlite
|
16
|
-
- RAILS=4-0-stable DB=mysql
|
17
|
-
- RAILS=4-0-stable DB=postgres
|
18
|
-
- RAILS=
|
19
|
-
- RAILS=
|
20
|
-
- RAILS=
|
21
|
-
- RAILS=3-
|
22
|
-
- RAILS=3-
|
23
|
-
- RAILS=3-
|
24
|
-
- RAILS=3-
|
25
|
-
- RAILS=3-
|
26
|
-
- RAILS=3-
|
12
|
+
- RAILS=master AREL=master DB=sqlite
|
13
|
+
- RAILS=master AREL=master DB=mysql
|
14
|
+
- RAILS=master AREL=master DB=postgres
|
15
|
+
- RAILS=4-1-stable AREL=5-0-stable DB=sqlite
|
16
|
+
- RAILS=4-1-stable AREL=5-0-stable DB=mysql
|
17
|
+
- RAILS=4-1-stable AREL=5-0-stable DB=postgres
|
18
|
+
- RAILS=4-0-stable AREL=4-0-stable DB=sqlite
|
19
|
+
- RAILS=4-0-stable AREL=4-0-stable DB=mysql
|
20
|
+
- RAILS=4-0-stable AREL=4-0-stable DB=postgres
|
21
|
+
- RAILS=3-2-stable AREL=3-0-stable DB=sqlite
|
22
|
+
- RAILS=3-2-stable AREL=3-0-stable DB=mysql
|
23
|
+
- RAILS=3-2-stable AREL=3-0-stable DB=postgres
|
24
|
+
- RAILS=3-1-stable AREL=2-2-stable DB=sqlite
|
25
|
+
- RAILS=3-1-stable AREL=2-2-stable DB=mysql
|
26
|
+
- RAILS=3-1-stable AREL=2-2-stable DB=postgres
|
27
|
+
- RAILS=3-0-stable AREL=2-0-stable DB=sqlite
|
28
|
+
- RAILS=3-0-stable AREL=2-0-stable DB=mysql
|
29
|
+
- RAILS=3-0-stable AREL=2-0-stable DB=postgres
|
27
30
|
|
28
31
|
before_script:
|
29
32
|
- mysql -e 'create database ransack collate utf8_general_ci;'
|
30
33
|
- mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";'
|
31
34
|
- psql -c 'create database ransack;' -U postgres
|
32
|
-
|
data/Gemfile
CHANGED
@@ -4,6 +4,18 @@ gemspec
|
|
4
4
|
gem 'rake'
|
5
5
|
|
6
6
|
rails = ENV['RAILS'] || 'master'
|
7
|
+
arel = ENV['AREL'] || 'master'
|
8
|
+
|
9
|
+
arel_opts = case arel
|
10
|
+
when /\// # A path
|
11
|
+
{:path => arel}
|
12
|
+
when /^v/ # A tagged version
|
13
|
+
{:git => 'git://github.com/rails/arel.git', :tag => arel}
|
14
|
+
else
|
15
|
+
{:git => 'git://github.com/rails/arel.git', :branch => arel}
|
16
|
+
end
|
17
|
+
|
18
|
+
gem 'arel', arel_opts
|
7
19
|
|
8
20
|
case rails
|
9
21
|
when /\// # A path
|
@@ -16,4 +28,4 @@ else
|
|
16
28
|
git 'git://github.com/rails/rails.git', :branch => rails do
|
17
29
|
gem 'activerecord'
|
18
30
|
end
|
19
|
-
end
|
31
|
+
end
|
data/README.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# Polyamorous
|
2
2
|
|
3
|
-
|
3
|
+
[]
|
4
|
+
(https://travis-ci.org/activerecord-hackery/polyamorous)
|
5
|
+
[]
|
6
|
+
(http://badge.fury.io/rb/polyamorous)
|
7
|
+
|
8
|
+
Polyamorous is an extraction from MetaSearch 1.1.x, Ransack, and Squeel by
|
9
|
+
[Ernie Miller](http://twitter.com/erniemiller).
|
4
10
|
|
5
11
|
## Copyright
|
6
12
|
|
7
|
-
Copyright © 2011-2014 [Ernie Miller](http://twitter.com/erniemiller)
|
13
|
+
Copyright © 2011-2014 [Ernie Miller](http://twitter.com/erniemiller)
|
data/lib/polyamorous.rb
CHANGED
@@ -2,6 +2,14 @@ require "polyamorous/version"
|
|
2
2
|
|
3
3
|
if defined?(::ActiveRecord)
|
4
4
|
module Polyamorous
|
5
|
+
if defined?(Arel::InnerJoin)
|
6
|
+
InnerJoin = Arel::InnerJoin
|
7
|
+
OuterJoin = Arel::OuterJoin
|
8
|
+
else
|
9
|
+
InnerJoin = Arel::Nodes::InnerJoin
|
10
|
+
OuterJoin = Arel::Nodes::OuterJoin
|
11
|
+
end
|
12
|
+
|
5
13
|
if defined?(::ActiveRecord::Associations::JoinDependency)
|
6
14
|
JoinDependency = ::ActiveRecord::Associations::JoinDependency
|
7
15
|
JoinAssociation = ::ActiveRecord::Associations::JoinDependency::JoinAssociation
|
@@ -13,9 +21,13 @@ if defined?(::ActiveRecord)
|
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
24
|
+
require 'polyamorous/tree_node'
|
16
25
|
require 'polyamorous/join'
|
17
26
|
|
18
|
-
if ActiveRecord::VERSION::STRING >= "4.
|
27
|
+
if ActiveRecord::VERSION::STRING >= "4.2"
|
28
|
+
require 'polyamorous/activerecord_4.1/join_association'
|
29
|
+
require 'polyamorous/activerecord_4.2/join_dependency'
|
30
|
+
elsif ActiveRecord::VERSION::STRING >= "4.1"
|
19
31
|
require 'polyamorous/activerecord_4.1/join_association'
|
20
32
|
require 'polyamorous/activerecord_4.1/join_dependency'
|
21
33
|
else
|
@@ -45,7 +45,7 @@ module Polyamorous
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def build_with_polymorphism(associations, parent = nil, join_type =
|
48
|
+
def build_with_polymorphism(associations, parent = nil, join_type = InnerJoin)
|
49
49
|
case associations
|
50
50
|
when Join
|
51
51
|
parent ||= _join_parts.last
|
@@ -2,6 +2,7 @@ module Polyamorous
|
|
2
2
|
module JoinAssociationExtensions
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
|
+
attr_reader :join_type
|
5
6
|
alias_method_chain :initialize, :polymorphism
|
6
7
|
if base.method_defined?(:active_record)
|
7
8
|
alias_method :base_klass, :active_record
|
@@ -15,7 +16,8 @@ module Polyamorous
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
def initialize_with_polymorphism(reflection, children, polymorphic_class = nil)
|
19
|
+
def initialize_with_polymorphism(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
|
20
|
+
@join_type = join_type
|
19
21
|
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
|
20
22
|
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
|
21
23
|
initialize_without_polymorphism(reflection, children)
|
@@ -9,6 +9,8 @@ module Polyamorous
|
|
9
9
|
end
|
10
10
|
|
11
11
|
alias_method_chain :build, :polymorphism
|
12
|
+
alias_method_chain :join_constraints, :polymorphism
|
13
|
+
|
12
14
|
if base.method_defined?(:active_record)
|
13
15
|
alias_method :base_klass, :active_record
|
14
16
|
end
|
@@ -22,9 +24,9 @@ module Polyamorous
|
|
22
24
|
reflection.check_validity!
|
23
25
|
|
24
26
|
if reflection.options[:polymorphic]
|
25
|
-
JoinAssociation.new reflection, build(right, name.klass || base_klass), name.klass
|
27
|
+
JoinAssociation.new reflection, build(right, name.klass || base_klass), name.klass, name.type
|
26
28
|
else
|
27
|
-
JoinAssociation.new reflection, build(right, reflection.klass), name.klass
|
29
|
+
JoinAssociation.new reflection, build(right, reflection.klass), name.klass, name.type
|
28
30
|
end
|
29
31
|
else
|
30
32
|
reflection = find_reflection base_klass, name
|
@@ -57,11 +59,48 @@ module Polyamorous
|
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
62
|
+
def join_constraints_with_polymorphism(outer_joins)
|
63
|
+
joins = join_root.children.flat_map { |child|
|
64
|
+
make_joins join_root, child
|
65
|
+
}
|
66
|
+
|
67
|
+
joins.concat outer_joins.flat_map { |oj|
|
68
|
+
if join_root.match? oj.join_root
|
69
|
+
walk join_root, oj.join_root
|
70
|
+
else
|
71
|
+
oj.join_root.children.flat_map { |child|
|
72
|
+
make_outer_joins oj.join_root, child
|
73
|
+
}
|
74
|
+
end
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def make_joins(parent, child)
|
79
|
+
tables = child.tables
|
80
|
+
joins = make_constraints parent, child, tables, child.join_type || Arel::Nodes::InnerJoin
|
81
|
+
|
82
|
+
joins.concat child.children.flat_map { |c| make_joins(child, c) }
|
83
|
+
end
|
84
|
+
|
85
|
+
private :make_joins
|
86
|
+
|
60
87
|
module ClassMethods
|
61
88
|
def walk_tree_with_polymorphism(associations, hash)
|
62
89
|
case associations
|
63
|
-
when
|
64
|
-
hash
|
90
|
+
when TreeNode
|
91
|
+
associations.add_to_tree(hash)
|
92
|
+
when Hash
|
93
|
+
associations.each do |k, v|
|
94
|
+
cache =
|
95
|
+
case k
|
96
|
+
when TreeNode
|
97
|
+
k.add_to_tree(hash)
|
98
|
+
else
|
99
|
+
hash[k] ||= {}
|
100
|
+
end
|
101
|
+
|
102
|
+
walk_tree(v, cache)
|
103
|
+
end
|
65
104
|
else
|
66
105
|
walk_tree_without_polymorphism(associations, hash)
|
67
106
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'polyamorous/activerecord_4.1/join_dependency'
|
2
|
+
|
3
|
+
module Polyamorous
|
4
|
+
module JoinDependencyExtensions
|
5
|
+
def make_joins(parent, child)
|
6
|
+
tables = child.tables
|
7
|
+
info = make_constraints parent, child, tables, child.join_type || Arel::Nodes::InnerJoin
|
8
|
+
|
9
|
+
[info] + child.children.flat_map { |c| make_joins(child, c) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/polyamorous/join.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Polyamorous
|
2
2
|
class Join
|
3
|
+
include TreeNode
|
4
|
+
|
3
5
|
attr_accessor :name
|
4
6
|
attr_reader :type, :klass
|
5
7
|
|
6
|
-
def initialize(name, type =
|
8
|
+
def initialize(name, type = InnerJoin, klass = nil)
|
7
9
|
@name = name
|
8
10
|
@type = convert_to_arel_join_type(type)
|
9
11
|
@klass = convert_to_class(klass) if klass
|
@@ -30,16 +32,20 @@ module Polyamorous
|
|
30
32
|
|
31
33
|
alias :== :eql?
|
32
34
|
|
35
|
+
def add_to_tree(hash)
|
36
|
+
hash[self] ||= {}
|
37
|
+
end
|
38
|
+
|
33
39
|
private
|
34
40
|
|
35
41
|
def convert_to_arel_join_type(type)
|
36
42
|
case type
|
37
43
|
when 'inner', :inner
|
38
|
-
|
44
|
+
InnerJoin
|
39
45
|
when 'outer', :outer
|
40
|
-
|
46
|
+
OuterJoin
|
41
47
|
when Class
|
42
|
-
if [
|
48
|
+
if [InnerJoin, OuterJoin].include? type
|
43
49
|
type
|
44
50
|
else
|
45
51
|
raise ArgumentError, "#{type} cannot be converted to an ARel join type"
|
@@ -61,4 +67,4 @@ module Polyamorous
|
|
61
67
|
end
|
62
68
|
|
63
69
|
end
|
64
|
-
end
|
70
|
+
end
|
data/lib/polyamorous/version.rb
CHANGED
@@ -13,8 +13,8 @@ module PolyamorousHelper
|
|
13
13
|
Polyamorous::JoinDependency.new klass, associations, []
|
14
14
|
end
|
15
15
|
|
16
|
-
def new_join(name, type =
|
16
|
+
def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
|
17
17
|
Polyamorous::Join.new name, type, klass
|
18
18
|
end
|
19
19
|
|
20
|
-
end
|
20
|
+
end
|
@@ -2,5 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Polyamorous
|
4
4
|
describe Join do
|
5
|
+
it "is a tree node" do
|
6
|
+
join = new_join(:articles, :outer)
|
7
|
+
expect(join).to be_kind_of(TreeNode)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can be add to a tree" do
|
11
|
+
join = new_join(:articles, :outer)
|
12
|
+
|
13
|
+
tree_hash = {}
|
14
|
+
join.add_to_tree(tree_hash)
|
15
|
+
|
16
|
+
expect(tree_hash[join]).to be {}
|
17
|
+
end
|
5
18
|
end
|
6
|
-
end
|
19
|
+
end
|
@@ -11,12 +11,12 @@ shared_examples "Join Association on ActiveRecord 3 and 4.0" do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
it 'respects polymorphism on equality test' do
|
14
|
-
subject.
|
14
|
+
expect(subject).to eq(
|
15
15
|
join_dependency.build_join_association_respecting_polymorphism(
|
16
16
|
reflection, parent, Person
|
17
17
|
)
|
18
18
|
)
|
19
|
-
subject.
|
19
|
+
expect(subject).not_to eq(
|
20
20
|
join_dependency.build_join_association_respecting_polymorphism(
|
21
21
|
reflection, parent, Article
|
22
22
|
)
|
@@ -26,14 +26,14 @@ shared_examples "Join Association on ActiveRecord 3 and 4.0" do
|
|
26
26
|
it 'leaves the orginal reflection intact for thread safety' do
|
27
27
|
reflection.instance_variable_set(:@klass, Article)
|
28
28
|
join_association.swapping_reflection_klass(reflection, Person) do |new_reflection|
|
29
|
-
new_reflection.options.
|
30
|
-
new_reflection.options.
|
31
|
-
new_reflection.klass.
|
32
|
-
reflection.klass.
|
29
|
+
expect(new_reflection.options).not_to equal reflection.options
|
30
|
+
expect(new_reflection.options).not_to have_key(:polymorphic)
|
31
|
+
expect(new_reflection.klass).to eq(Person)
|
32
|
+
expect(reflection.klass).to eq(Article)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'sets the polmorphic option to true after initializing' do
|
37
|
-
join_association.options[:polymorphic].
|
37
|
+
expect(join_association.options[:polymorphic]).to be_true
|
38
38
|
end
|
39
39
|
end
|
@@ -11,10 +11,10 @@ shared_examples "Join Association on ActiveRecord 4.1" do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
it 'respects polymorphism on equality test' do
|
14
|
-
subject.
|
14
|
+
expect(subject).to eq(
|
15
15
|
join_dependency.build_join_association_respecting_polymorphism(reflection, parent, Person)
|
16
16
|
)
|
17
|
-
subject.
|
17
|
+
expect(subject).not_to eq(
|
18
18
|
join_dependency.build_join_association_respecting_polymorphism(
|
19
19
|
reflection, parent, Article
|
20
20
|
)
|
@@ -24,14 +24,14 @@ shared_examples "Join Association on ActiveRecord 4.1" do
|
|
24
24
|
it 'leaves the orginal reflection intact for thread safety' do
|
25
25
|
reflection.instance_variable_set(:@klass, Article)
|
26
26
|
join_association.swapping_reflection_klass(reflection, Person) do |new_reflection|
|
27
|
-
new_reflection.options.
|
28
|
-
new_reflection.options.
|
29
|
-
new_reflection.klass.
|
30
|
-
reflection.klass.
|
27
|
+
expect(new_reflection.options).not_to equal reflection.options
|
28
|
+
expect(new_reflection.options).not_to have_key(:polymorphic)
|
29
|
+
expect(new_reflection.klass).to eq(Person)
|
30
|
+
expect(reflection.klass).to eq(Article)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'sets the polmorphic option to true after initializing' do
|
35
|
-
join_association.reflection.options[:polymorphic].
|
35
|
+
expect(join_association.reflection.options[:polymorphic]).to be_true
|
36
36
|
end
|
37
37
|
end
|
@@ -2,53 +2,53 @@ shared_examples "Join Dependency on ActiveRecord 3 and 4.0" do
|
|
2
2
|
context 'with symbol joins' do
|
3
3
|
subject { new_join_dependency Person, :articles => :comments }
|
4
4
|
|
5
|
-
specify { subject.join_associations.
|
6
|
-
specify { subject.join_associations.
|
5
|
+
specify { expect(subject.join_associations.size).to eq(2) }
|
6
|
+
specify { expect(subject.join_associations).to be_all { |a| a.join_type == Polyamorous::InnerJoin } }
|
7
7
|
end
|
8
8
|
|
9
9
|
context 'with has_many :through association' do
|
10
10
|
subject { new_join_dependency Person, :authored_article_comments }
|
11
11
|
|
12
|
-
specify { subject.join_associations.
|
13
|
-
specify { subject.join_associations.first.table_name.
|
12
|
+
specify { expect(subject.join_associations.size).to eq(1) }
|
13
|
+
specify { expect(subject.join_associations.first.table_name).to eq 'comments' }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with outer join' do
|
17
17
|
subject { new_join_dependency Person, new_join(:articles, :outer) }
|
18
18
|
|
19
|
-
specify { subject.join_associations.
|
20
|
-
specify { subject.join_associations.
|
19
|
+
specify { expect(subject.join_associations.size).to eq(1) }
|
20
|
+
specify { expect(subject.join_associations).to be_all { |a| a.join_type == Polyamorous::OuterJoin } }
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'with nested outer joins' do
|
24
24
|
subject { new_join_dependency Person, new_join(:articles, :outer) => new_join(:comments, :outer) }
|
25
25
|
|
26
|
-
specify { subject.join_associations.
|
27
|
-
specify { subject.join_associations.
|
26
|
+
specify { expect(subject.join_associations.size).to eq(2) }
|
27
|
+
specify { expect(subject.join_associations).to be_all { |a| a.join_type == Polyamorous::OuterJoin } }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'with polymorphic belongs_to join' do
|
31
31
|
subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
|
32
32
|
|
33
|
-
specify { subject.join_associations.
|
34
|
-
specify { subject.join_associations.
|
35
|
-
specify { subject.join_associations.first.table_name.
|
33
|
+
specify { expect(subject.join_associations.size).to eq(1) }
|
34
|
+
specify { expect(subject.join_associations).to be_all { |a| a.join_type == Polyamorous::InnerJoin } }
|
35
|
+
specify { expect(subject.join_associations.first.table_name).to eq 'people' }
|
36
36
|
|
37
37
|
it 'finds a join association respecting polymorphism' do
|
38
38
|
parent = subject.join_base
|
39
39
|
reflection = Note.reflect_on_association(:notable)
|
40
|
-
subject.find_join_association_respecting_polymorphism(
|
40
|
+
expect(subject.find_join_association_respecting_polymorphism(
|
41
41
|
reflection, parent, Person
|
42
|
-
).
|
42
|
+
)).to eq subject.join_associations.first
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with polymorphic belongs_to join and nested symbol join' do
|
47
47
|
subject { new_join_dependency Note, new_join(:notable, :inner, Person) => :comments }
|
48
48
|
|
49
|
-
specify { subject.join_associations.
|
50
|
-
specify { subject.join_associations.
|
51
|
-
specify { subject.join_associations.first.table_name.
|
52
|
-
specify { subject.join_associations[1].table_name.
|
49
|
+
specify { expect(subject.join_associations.size).to eq(2) }
|
50
|
+
specify { expect(subject.join_associations).to be_all { |a| a.join_type == Polyamorous::InnerJoin } }
|
51
|
+
specify { expect(subject.join_associations.first.table_name).to eq 'people' }
|
52
|
+
specify { expect(subject.join_associations[1].table_name).to eq 'comments' }
|
53
53
|
end
|
54
54
|
end
|
@@ -1,46 +1,46 @@
|
|
1
1
|
shared_examples "Join Dependency on ActiveRecord 4.1" do
|
2
2
|
context 'with symbol joins' do
|
3
3
|
subject { new_join_dependency Person, :articles => :comments }
|
4
|
-
specify { subject.join_root.drop(1).
|
4
|
+
specify { expect(subject.join_root.drop(1).size).to eq(2) }
|
5
5
|
end
|
6
6
|
|
7
7
|
context 'with has_many :through association' do
|
8
8
|
subject { new_join_dependency Person, :authored_article_comments }
|
9
9
|
|
10
|
-
specify { subject.join_root.drop(1).
|
11
|
-
specify { subject.join_root.drop(1).first.table_name.
|
10
|
+
specify { expect(subject.join_root.drop(1).size).to eq(1) }
|
11
|
+
specify { expect(subject.join_root.drop(1).first.table_name).to eq 'comments' }
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'with outer join' do
|
15
15
|
subject { new_join_dependency Person, new_join(:articles, :outer) }
|
16
|
-
specify { subject.join_root.drop(1).
|
16
|
+
specify { expect(subject.join_root.drop(1).size).to eq(1) }
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'with nested outer joins' do
|
20
20
|
subject { new_join_dependency Person, new_join(:articles, :outer) => new_join(:comments, :outer) }
|
21
|
-
specify { subject.join_root.drop(1).
|
21
|
+
specify { expect(subject.join_root.drop(1).size).to eq(2) }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'with polymorphic belongs_to join' do
|
25
25
|
subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
|
26
26
|
|
27
|
-
specify { subject.join_root.drop(1).
|
28
|
-
specify { subject.join_root.drop(1).first.table_name.
|
27
|
+
specify { expect(subject.join_root.drop(1).size).to eq(1) }
|
28
|
+
specify { expect(subject.join_root.drop(1).first.table_name).to eq 'people' }
|
29
29
|
|
30
30
|
it 'finds a join association respecting polymorphism' do
|
31
31
|
parent = subject.join_root
|
32
32
|
reflection = Note.reflect_on_association(:notable)
|
33
|
-
subject.find_join_association_respecting_polymorphism(
|
33
|
+
expect(subject.find_join_association_respecting_polymorphism(
|
34
34
|
reflection, parent, Person
|
35
|
-
).
|
35
|
+
)).to eq subject.join_root.drop(1).first
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'with polymorphic belongs_to join and nested symbol join' do
|
40
40
|
subject { new_join_dependency Note, new_join(:notable, :inner, Person) => :comments }
|
41
41
|
|
42
|
-
specify { subject.join_root.drop(1).
|
43
|
-
specify { subject.join_root.drop(1).first.table_name.
|
44
|
-
specify { subject.join_root.drop(1)[1].table_name.
|
42
|
+
specify { expect(subject.join_root.drop(1).size).to eq(2) }
|
43
|
+
specify { expect(subject.join_root.drop(1).first.table_name).to eq 'people' }
|
44
|
+
specify { expect(subject.join_root.drop(1)[1].table_name).to eq 'comments' }
|
45
45
|
end
|
46
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyamorous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -100,7 +100,9 @@ files:
|
|
100
100
|
- lib/polyamorous/activerecord_3_and_4.0/join_dependency.rb
|
101
101
|
- lib/polyamorous/activerecord_4.1/join_association.rb
|
102
102
|
- lib/polyamorous/activerecord_4.1/join_dependency.rb
|
103
|
+
- lib/polyamorous/activerecord_4.2/join_dependency.rb
|
103
104
|
- lib/polyamorous/join.rb
|
105
|
+
- lib/polyamorous/tree_node.rb
|
104
106
|
- lib/polyamorous/version.rb
|
105
107
|
- polyamorous.gemspec
|
106
108
|
- spec/blueprints/articles.rb
|
@@ -141,19 +143,4 @@ rubygems_version: 2.2.2
|
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...
|
144
|
-
test_files:
|
145
|
-
- spec/blueprints/articles.rb
|
146
|
-
- spec/blueprints/comments.rb
|
147
|
-
- spec/blueprints/notes.rb
|
148
|
-
- spec/blueprints/people.rb
|
149
|
-
- spec/blueprints/tags.rb
|
150
|
-
- spec/helpers/polyamorous_helper.rb
|
151
|
-
- spec/polyamorous/join_association_spec.rb
|
152
|
-
- spec/polyamorous/join_dependency_spec.rb
|
153
|
-
- spec/polyamorous/join_spec.rb
|
154
|
-
- spec/spec_helper.rb
|
155
|
-
- spec/support/schema.rb
|
156
|
-
- spec/support/shared_examples/join_association_3_and_4.0.rb
|
157
|
-
- spec/support/shared_examples/join_association_4.1.rb
|
158
|
-
- spec/support/shared_examples/join_dependency_3_and_4.0.rb
|
159
|
-
- spec/support/shared_examples/join_dependency_4.1.rb
|
146
|
+
test_files: []
|