poly_belongs_to 0.1.7 → 0.1.8
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/README.md +24 -9
- data/lib/poly_belongs_to/faked_collection.rb +4 -0
- data/lib/poly_belongs_to/version.rb +1 -1
- data/lib/poly_belongs_to.rb +18 -0
- data/test/dummy/app/models/car.rb +4 -0
- data/test/dummy/app/models/tire.rb +4 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/db/migrate/20150301100658_create_tires.rb +11 -0
- data/test/dummy/db/migrate/20150301100722_create_cars.rb +10 -0
- data/test/dummy/db/schema.rb +21 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +23983 -0
- data/test/faked_collection_test.rb +17 -1
- data/test/fixtures/cars.yml +6 -0
- data/test/fixtures/tires.yml +22 -0
- data/test/fixtures/users.yml +1 -0
- data/test/poly_belongs_to_test.rb +32 -0
- metadata +14 -2
@@ -9,6 +9,14 @@ class FakedCollectionTest < ActiveSupport::TestCase
|
|
9
9
|
PolyBelongsTo::FakedCollection.new(steve_prof, Photo)
|
10
10
|
}
|
11
11
|
|
12
|
+
it "is named correctly" do
|
13
|
+
photos.class.name.must_equal "PolyBelongsTo::FakedCollection"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "knows its superclass" do
|
17
|
+
PolyBelongsTo::FakedCollection.superclass.must_equal Object
|
18
|
+
end
|
19
|
+
|
12
20
|
it ".all is an Array" do
|
13
21
|
photos.all.is_a?(Array).must_be_same_as true
|
14
22
|
photos.all.kind_of?(Array).must_be_same_as true
|
@@ -31,10 +39,18 @@ class FakedCollectionTest < ActiveSupport::TestCase
|
|
31
39
|
photos.ancestors.include?(Object).must_be_same_as true
|
32
40
|
end
|
33
41
|
|
34
|
-
it "build
|
42
|
+
it "build kind of FakedCollection object" do
|
35
43
|
photos.kind_of?(PolyBelongsTo::FakedCollection).must_be_same_as true
|
36
44
|
end
|
37
45
|
|
46
|
+
it "build is a FakedCollection object" do
|
47
|
+
photos.is_a?(PolyBelongsTo::FakedCollection).must_be_same_as true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "build instance of FakedCollection object" do
|
51
|
+
photos.instance_of?(PolyBelongsTo::FakedCollection).must_be_same_as true
|
52
|
+
end
|
53
|
+
|
38
54
|
it "builds appropriately" do
|
39
55
|
photos.build({content: "cheese"})
|
40
56
|
photos.first.content.must_equal "cheese"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Read about fixtures at
|
2
|
+
# http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
3
|
+
|
4
|
+
low_profile1:
|
5
|
+
user: <%= ActiveRecord::FixtureSet.identify(:bob) %>
|
6
|
+
car: <%= ActiveRecord::FixtureSet.identify(:honda_civic) %>
|
7
|
+
content: MyString
|
8
|
+
|
9
|
+
low_profile2:
|
10
|
+
user: <%= ActiveRecord::FixtureSet.identify(:bob) %>
|
11
|
+
car: <%= ActiveRecord::FixtureSet.identify(:honda_civic) %>
|
12
|
+
content: MyString
|
13
|
+
|
14
|
+
low_profile3:
|
15
|
+
user: <%= ActiveRecord::FixtureSet.identify(:bob) %>
|
16
|
+
car: <%= ActiveRecord::FixtureSet.identify(:honda_civic) %>
|
17
|
+
content: MyString
|
18
|
+
|
19
|
+
low_profile4:
|
20
|
+
user: <%= ActiveRecord::FixtureSet.identify(:bob) %>
|
21
|
+
car: <%= ActiveRecord::FixtureSet.identify(:honda_civic) %>
|
22
|
+
content: MyString
|
data/test/fixtures/users.yml
CHANGED
@@ -38,6 +38,18 @@ class PolyBelongsToTest < ActiveSupport::TestCase
|
|
38
38
|
Tag.pbt.must_be_same_as :user
|
39
39
|
end
|
40
40
|
|
41
|
+
it "Tags of multiple parents" do
|
42
|
+
tire = tires(:low_profile1)
|
43
|
+
parents = tire.class.pbts
|
44
|
+
parents.must_be_kind_of Array
|
45
|
+
parents.must_include :user
|
46
|
+
parents.must_include :car
|
47
|
+
parents = tire.pbts
|
48
|
+
parents.must_be_kind_of Array
|
49
|
+
parents.must_include :user
|
50
|
+
parents.must_include :car
|
51
|
+
end
|
52
|
+
|
41
53
|
it "Phone belongs to table as :phoneable" do
|
42
54
|
phone = phones(:bob_phone)
|
43
55
|
phone.pbt.must_be_same_as :phoneable
|
@@ -165,4 +177,24 @@ class PolyBelongsToTest < ActiveSupport::TestCase
|
|
165
177
|
profile.pbt_parent.id.must_be_same_as user.id
|
166
178
|
end
|
167
179
|
|
180
|
+
it "pbt_parents: can show multiple parents" do
|
181
|
+
user = User.new(id: 1)
|
182
|
+
user.cars.build
|
183
|
+
user.cars.first.tires.build(user_id: user.id)
|
184
|
+
user.save
|
185
|
+
parents = user.cars.first.tires.first.pbt_parents
|
186
|
+
parents.must_be_kind_of Array
|
187
|
+
parents.must_include user
|
188
|
+
parents.must_include user.cars.first
|
189
|
+
user.destroy
|
190
|
+
end
|
191
|
+
|
192
|
+
it "pbt_parents: one parent for polymorphic" do
|
193
|
+
bob_address = addresses(:bob_address)
|
194
|
+
parents = bob_address.pbt_parents
|
195
|
+
parents.must_be_kind_of Array
|
196
|
+
parents.size.must_equal 1
|
197
|
+
parents.first.must_equal profiles(:bob_prof)
|
198
|
+
end
|
199
|
+
|
168
200
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poly_belongs_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- test/dummy/app/controllers/application_controller.rb
|
105
105
|
- test/dummy/app/helpers/application_helper.rb
|
106
106
|
- test/dummy/app/models/address.rb
|
107
|
+
- test/dummy/app/models/car.rb
|
107
108
|
- test/dummy/app/models/contact.rb
|
108
109
|
- test/dummy/app/models/geo_location.rb
|
109
110
|
- test/dummy/app/models/phone.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- test/dummy/app/models/squishy.rb
|
113
114
|
- test/dummy/app/models/ssn.rb
|
114
115
|
- test/dummy/app/models/tag.rb
|
116
|
+
- test/dummy/app/models/tire.rb
|
115
117
|
- test/dummy/app/models/user.rb
|
116
118
|
- test/dummy/app/views/layouts/application.html.erb
|
117
119
|
- test/dummy/bin/bundle
|
@@ -147,6 +149,8 @@ files:
|
|
147
149
|
- test/dummy/db/migrate/20150216092519_create_ssns.rb
|
148
150
|
- test/dummy/db/migrate/20150220213422_create_geo_locations.rb
|
149
151
|
- test/dummy/db/migrate/20150220230146_create_squishies.rb
|
152
|
+
- test/dummy/db/migrate/20150301100658_create_tires.rb
|
153
|
+
- test/dummy/db/migrate/20150301100722_create_cars.rb
|
150
154
|
- test/dummy/db/schema.rb
|
151
155
|
- test/dummy/db/test.sqlite3
|
152
156
|
- test/dummy/log/development.log
|
@@ -155,6 +159,7 @@ files:
|
|
155
159
|
- test/dup_test.rb
|
156
160
|
- test/faked_collection_test.rb
|
157
161
|
- test/fixtures/addresses.yml
|
162
|
+
- test/fixtures/cars.yml
|
158
163
|
- test/fixtures/geo_locations.yml
|
159
164
|
- test/fixtures/phones.yml
|
160
165
|
- test/fixtures/photos.yml
|
@@ -162,6 +167,7 @@ files:
|
|
162
167
|
- test/fixtures/squishies.yml
|
163
168
|
- test/fixtures/ssns.yml
|
164
169
|
- test/fixtures/tags.yml
|
170
|
+
- test/fixtures/tires.yml
|
165
171
|
- test/fixtures/users.yml
|
166
172
|
- test/pbt_test.rb
|
167
173
|
- test/poly_belongs_to_test.rb
|
@@ -197,9 +203,11 @@ test_files:
|
|
197
203
|
- test/fixtures/addresses.yml
|
198
204
|
- test/fixtures/photos.yml
|
199
205
|
- test/fixtures/profiles.yml
|
206
|
+
- test/fixtures/tires.yml
|
200
207
|
- test/fixtures/geo_locations.yml
|
201
208
|
- test/fixtures/phones.yml
|
202
209
|
- test/fixtures/users.yml
|
210
|
+
- test/fixtures/cars.yml
|
203
211
|
- test/fixtures/tags.yml
|
204
212
|
- test/fixtures/ssns.yml
|
205
213
|
- test/test_helper.rb
|
@@ -208,6 +216,7 @@ test_files:
|
|
208
216
|
- test/dummy/db/schema.rb
|
209
217
|
- test/dummy/db/migrate/20150220230146_create_squishies.rb
|
210
218
|
- test/dummy/db/migrate/20150216092449_create_contacts.rb
|
219
|
+
- test/dummy/db/migrate/20150301100658_create_tires.rb
|
211
220
|
- test/dummy/db/migrate/20150216092218_create_addresses.rb
|
212
221
|
- test/dummy/db/migrate/20150211224225_create_phones.rb
|
213
222
|
- test/dummy/db/migrate/20150220213422_create_geo_locations.rb
|
@@ -215,6 +224,7 @@ test_files:
|
|
215
224
|
- test/dummy/db/migrate/20150211224157_create_tags.rb
|
216
225
|
- test/dummy/db/migrate/20150211224139_create_users.rb
|
217
226
|
- test/dummy/db/migrate/20150216092338_create_profiles.rb
|
227
|
+
- test/dummy/db/migrate/20150301100722_create_cars.rb
|
218
228
|
- test/dummy/db/migrate/20150216092411_create_photos.rb
|
219
229
|
- test/dummy/config/initializers/mime_types.rb
|
220
230
|
- test/dummy/config/initializers/session_store.rb
|
@@ -238,6 +248,8 @@ test_files:
|
|
238
248
|
- test/dummy/app/helpers/application_helper.rb
|
239
249
|
- test/dummy/app/models/ssn.rb
|
240
250
|
- test/dummy/app/models/contact.rb
|
251
|
+
- test/dummy/app/models/car.rb
|
252
|
+
- test/dummy/app/models/tire.rb
|
241
253
|
- test/dummy/app/models/user.rb
|
242
254
|
- test/dummy/app/models/geo_location.rb
|
243
255
|
- test/dummy/app/models/address.rb
|