passive_record 0.4.12 → 0.4.13
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/lib/passive_record/associations/has_many_through.rb +8 -2
- data/lib/passive_record/version.rb +1 -1
- data/spec/passive_record_spec.rb +10 -1
- data/spec/spec_helper.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d211fdab7ab67cfa36f0eb20919b98f334b1f52a
|
4
|
+
data.tar.gz: 3b222ff303400e4b17b8bb776fd621c0d4b06ffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 127ac6578c9583d0a9d24819818c92a9b01fab3b7c9a00507d3c422bede8055135c62aff00c81155281f5276aca747d787a8819646f0a3d8206a2dbb006ef974
|
7
|
+
data.tar.gz: a6ceaf8115ed8e8dd11c1cc1333eef38f5f66cb0a9f1d3a86988758b60f9b6de6dde2b819ed925f97316b57bef15c41fd3b1638af5316af7188b318c04c35380
|
@@ -31,6 +31,7 @@ module PassiveRecord
|
|
31
31
|
)
|
32
32
|
end
|
33
33
|
else
|
34
|
+
# binding.pry
|
34
35
|
intermediary_model = intermediary_relation.
|
35
36
|
where(
|
36
37
|
association.target_name_symbol.to_s.singularize + "_id" => child.id).
|
@@ -95,7 +96,7 @@ module PassiveRecord
|
|
95
96
|
if intermediary_relation.is_a?(HasManyThroughRelation)
|
96
97
|
conds = intermediary_relation.intermediary_conditions
|
97
98
|
|
98
|
-
if nested_association.habtm
|
99
|
+
if nested_association.habtm || nested_association.is_a?(HasManyThroughAssociation)
|
99
100
|
{ association.through_class => conds }
|
100
101
|
else
|
101
102
|
{ association.through_class.to_s.singularize.to_sym => conds }
|
@@ -132,10 +133,13 @@ module PassiveRecord
|
|
132
133
|
|
133
134
|
until !n.is_a?(HasManyThroughAssociation)
|
134
135
|
key = n.through_class.to_s.singularize.to_sym
|
136
|
+
p [ :n_class, n.class, key ]
|
135
137
|
hash = {key => hash}
|
136
138
|
n = n.nested_association
|
137
139
|
end
|
138
140
|
|
141
|
+
# binding.pry
|
142
|
+
|
139
143
|
hash
|
140
144
|
else
|
141
145
|
nested_conds
|
@@ -144,7 +148,9 @@ module PassiveRecord
|
|
144
148
|
end
|
145
149
|
|
146
150
|
def where(conditions={})
|
147
|
-
|
151
|
+
merged_conditions = conditions.merge(intermediary_conditions)
|
152
|
+
# binding.pry
|
153
|
+
child_class.where(merged_conditions)
|
148
154
|
end
|
149
155
|
end
|
150
156
|
end
|
data/spec/passive_record_spec.rb
CHANGED
@@ -352,6 +352,16 @@ describe "passive record models" do
|
|
352
352
|
expect(network.tags.promoted).not_to include(unpromoted_tag)
|
353
353
|
end
|
354
354
|
end
|
355
|
+
|
356
|
+
describe 'should find related nested models through a manual habtm' do
|
357
|
+
let!(:special_category) { Post.first.create_category(special: true) }
|
358
|
+
let!(:unspecial_category) { Post.last.create_category(special: false) }
|
359
|
+
|
360
|
+
it 'should refine and restrict' do
|
361
|
+
expect(network.categories.special).to include(special_category)
|
362
|
+
expect(network.categories.special).not_to include(unspecial_category)
|
363
|
+
end
|
364
|
+
end
|
355
365
|
end
|
356
366
|
end
|
357
367
|
end
|
@@ -578,7 +588,6 @@ describe "passive record models" do
|
|
578
588
|
|
579
589
|
it 'should permit querying' do
|
580
590
|
ResourceAllocation.create(user: user, resource: resource)
|
581
|
-
# binding.pry
|
582
591
|
expect(user.resources.where.all).to include(resource)
|
583
592
|
end
|
584
593
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -122,6 +122,7 @@ class Network < Model
|
|
122
122
|
has_many :posts, :through => :streams
|
123
123
|
has_many :comments, :through => :posts
|
124
124
|
has_many :tags, :through => :posts
|
125
|
+
has_many :categories, :through => :posts
|
125
126
|
end
|
126
127
|
|
127
128
|
class Stream < Model
|
@@ -153,6 +154,19 @@ class Tag < Model
|
|
153
154
|
def self.promoted; where(promoted: true) end
|
154
155
|
end
|
155
156
|
|
157
|
+
class Category < Model
|
158
|
+
attr_accessor :special
|
159
|
+
has_many :post_categories
|
160
|
+
has_many :posts, :through => :post_categories
|
161
|
+
|
162
|
+
def self.special; where(special: true) end
|
163
|
+
end
|
164
|
+
|
165
|
+
class PostCategory < Model
|
166
|
+
belongs_to :post
|
167
|
+
belongs_to :category
|
168
|
+
end
|
169
|
+
|
156
170
|
class Post < Model
|
157
171
|
belongs_to :author
|
158
172
|
belongs_to :blog
|
@@ -160,6 +174,9 @@ class Post < Model
|
|
160
174
|
has_many :commenters, :through => :comments, :class_name => "Author"
|
161
175
|
has_and_belongs_to_many :tags
|
162
176
|
|
177
|
+
has_many :post_categories
|
178
|
+
has_many :categories, :through => :post_categories
|
179
|
+
|
163
180
|
attr_accessor :active, :published_at
|
164
181
|
before_create { @published_at = Time.now }
|
165
182
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passive_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Weissman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|