polyamorous 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,9 @@ module Polyamorous
6
6
  alias_method_chain :initialize, :polymorphism
7
7
  alias_method :equality_without_polymorphism, :==
8
8
  alias_method :==, :equality_with_polymorphism
9
+ if base.method_defined?(:active_record)
10
+ alias_method :base_klass, :active_record
11
+ end
9
12
 
10
13
  if ActiveRecord::VERSION::STRING =~ /^3\.0\./
11
14
  alias_method_chain :association_join, :polymorphism
@@ -35,7 +38,7 @@ module Polyamorous
35
38
  end
36
39
 
37
40
  def equality_with_polymorphism(other)
38
- equality_without_polymorphism(other) && active_record == other.active_record
41
+ equality_without_polymorphism(other) && base_klass == other.base_klass
39
42
  end
40
43
 
41
44
  def build_constraint_with_polymorphism(reflection, table, key, foreign_table, foreign_key)
@@ -60,7 +63,7 @@ module Polyamorous
60
63
 
61
64
  parent_table = Arel::Table.new(parent.table_name, :as => parent.aliased_table_name,
62
65
  :engine => arel_engine,
63
- :columns => parent.active_record.columns)
66
+ :columns => parent.base_klass.columns)
64
67
 
65
68
  @join << parent_table[reflection.options[:foreign_type]].eq(reflection.klass.name)
66
69
  end
@@ -69,4 +72,4 @@ module Polyamorous
69
72
  end
70
73
 
71
74
  end
72
- end
75
+ end
@@ -5,6 +5,9 @@ module Polyamorous
5
5
  base.class_eval do
6
6
  alias_method_chain :build, :polymorphism
7
7
  alias_method_chain :graft, :polymorphism
8
+ if base.method_defined?(:active_record)
9
+ alias_method :base_klass, :active_record
10
+ end
8
11
  end
9
12
  end
10
13
 
@@ -58,7 +61,7 @@ module Polyamorous
58
61
  unless reflection.options[:polymorphic]
59
62
  association
60
63
  else
61
- association if association.active_record == klass
64
+ association if association.base_klass == klass
62
65
  end
63
66
  end
64
67
  end
@@ -72,4 +75,4 @@ module Polyamorous
72
75
  end
73
76
 
74
77
  end
75
- end
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Polyamorous
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -2,5 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  module Polyamorous
4
4
  describe JoinAssociation do
5
+ let(:join_dependency) { new_join_dependency Note, {} }
6
+ let(:parent) { join_dependency.join_base }
7
+ let(:reflection) { Note.reflect_on_association(:notable) }
8
+ subject {
9
+ join_dependency.build_join_association_respecting_polymorphism(
10
+ reflection, parent, Person
11
+ )
12
+ }
13
+
14
+ it 'respects polymorphism on equality test' do
15
+ subject.should eq(
16
+ join_dependency.build_join_association_respecting_polymorphism(
17
+ reflection, parent, Person
18
+ )
19
+ )
20
+ subject.should_not eq(
21
+ join_dependency.build_join_association_respecting_polymorphism(
22
+ reflection, parent, Article
23
+ )
24
+ )
25
+ end
5
26
  end
6
- end
27
+ end
@@ -37,6 +37,14 @@ module Polyamorous
37
37
  specify { subject.join_associations.should have(1).association }
38
38
  specify { subject.join_associations.should be_all { |a| a.join_type == Arel::InnerJoin } }
39
39
  specify { subject.join_associations.first.table_name.should eq 'people' }
40
+
41
+ it 'finds a join association respecting polymorphism' do
42
+ parent = subject.join_base
43
+ reflection = Note.reflect_on_association(:notable)
44
+ subject.find_join_association_respecting_polymorphism(
45
+ reflection, parent, Person
46
+ ).should eq subject.join_associations.first
47
+ end
40
48
  end
41
49
 
42
50
  context 'with polymorphic belongs_to join and nested symbol join' do
@@ -49,4 +57,4 @@ module Polyamorous
49
57
  end
50
58
 
51
59
  end
52
- end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyamorous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 1064198230970801175
139
+ hash: 2316863332699379483
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
@@ -145,10 +145,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 1064198230970801175
148
+ hash: 2316863332699379483
149
149
  requirements: []
150
150
  rubyforge_project: polyamorous
151
- rubygems_version: 1.8.24
151
+ rubygems_version: 1.8.25
152
152
  signing_key:
153
153
  specification_version: 3
154
154
  summary: Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...