aub-record_filter 0.9.2 → 0.9.3
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.
- data/VERSION.yml +1 -1
- data/lib/record_filter/table.rb +1 -1
- data/spec/active_record_spec.rb +14 -0
- data/spec/models.rb +14 -1
- data/spec/test.db +0 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/record_filter/table.rb
CHANGED
@@ -80,7 +80,7 @@ module RecordFilter
|
|
80
80
|
join_predicate =
|
81
81
|
case association.macro
|
82
82
|
when :belongs_to
|
83
|
-
[{ association.options[:foreign_key] || association.
|
83
|
+
[{ association.options[:foreign_key] || association.primary_key_name.to_sym => @model_class.primary_key }]
|
84
84
|
when :has_many, :has_one
|
85
85
|
[{ association.options[:primary_key] || @model_class.primary_key => association.primary_key_name.to_sym }]
|
86
86
|
end
|
data/spec/active_record_spec.rb
CHANGED
@@ -105,6 +105,20 @@ describe 'active record options' do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
describe 'using class_name when the association has a different name than the class name' do
|
109
|
+
before do
|
110
|
+
AssetAttachment.filter { having(:from).with(:id).gt(1) }.inspect
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should create the correct condition' do
|
114
|
+
AssetAttachment.last_find[:conditions].should == [%q(asset_attachments__from.id > ?), 1]
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should create the correct join' do
|
118
|
+
AssetAttachment.last_find[:joins].should == [%q(INNER JOIN "assets" AS asset_attachments__from ON "asset_attachments".from_id = asset_attachments__from.id)]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
108
122
|
describe 'using foreign_key' do
|
109
123
|
before do
|
110
124
|
Post.filter do
|
data/spec/models.rb
CHANGED
@@ -10,6 +10,19 @@ class Article < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
+
class Asset < ActiveRecord::Base
|
14
|
+
extend TestModel
|
15
|
+
has_many :asset_attachments
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class AssetAttachment < ActiveRecord::Base
|
20
|
+
extend TestModel
|
21
|
+
belongs_to :to, :polymorphic => true
|
22
|
+
belongs_to :from, :class_name => 'Asset'
|
23
|
+
end
|
24
|
+
|
25
|
+
|
13
26
|
class Author < ActiveRecord::Base
|
14
27
|
extend TestModel
|
15
28
|
belongs_to :user
|
@@ -56,7 +69,7 @@ end
|
|
56
69
|
class Post < ActiveRecord::Base
|
57
70
|
extend TestModel
|
58
71
|
belongs_to :blog
|
59
|
-
belongs_to :publication, :class_name => 'Blog'
|
72
|
+
belongs_to :publication, :class_name => 'Blog', :foreign_key => 'blog_id'
|
60
73
|
belongs_to :special_blog, :class_name => 'Blog', :foreign_key => :special_blog_id
|
61
74
|
has_many :comments
|
62
75
|
has_many :bad_comments, :conditions => { :offensive => true }, :class_name => 'Comment'
|
data/spec/test.db
CHANGED
Binary file
|