poly_belongs_to 0.2.8 → 0.2.9

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.
@@ -0,0 +1,8 @@
1
+ # Read about fixtures at
2
+ # http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
3
+
4
+ one:
5
+ work_order_id: 1
6
+
7
+ two:
8
+ work_order_id: 1
@@ -0,0 +1,12 @@
1
+ # Read about fixtures at
2
+ # http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
3
+
4
+ # This model initially had no columns defined. If you add columns to the
5
+ # model remove the '{}' from the fixture names and add the columns immediately
6
+ # below each fixture, per the syntax in the comments below
7
+ #
8
+ one: {}
9
+ # column: value
10
+ #
11
+ two: {}
12
+ # column: value
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class AddressBookTest < ActiveSupport::TestCase
4
+
5
+ def address_book
6
+ @address_book ||= AddressBook.new
7
+ end
8
+
9
+ def test_valid
10
+ assert address_book.valid?
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class EventTest < ActiveSupport::TestCase
4
+
5
+ def event
6
+ @event ||= Event.new
7
+ end
8
+
9
+ def test_valid
10
+ assert event.valid?
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class WorkOrderTest < ActiveSupport::TestCase
4
+
5
+ def work_order
6
+ @work_order ||= WorkOrder.new
7
+ end
8
+
9
+ def test_valid
10
+ assert work_order.valid?
11
+ end
12
+
13
+ end
@@ -35,6 +35,7 @@ class FakedCollectionTest < ActiveSupport::TestCase
35
35
  [nil, photos(:steve_photo).id].must_include steve_photos.id
36
36
  nil_steve.id.must_be_nil
37
37
  nil_photo.id.must_be_nil
38
+ null_object.id.must_be_nil
38
39
  end
39
40
 
40
41
  it "#all is an Array" do
@@ -105,16 +106,25 @@ class FakedCollectionTest < ActiveSupport::TestCase
105
106
  steve_photos.ancestors.must_include(ActiveRecord::Base)
106
107
  end
107
108
 
109
+ it "#ancestors has NilClass if empty" do
110
+ null_object.ancestors.must_include(NilClass)
111
+ nil_steve.ancestors.must_include(NilClass)
112
+ nil_photo.ancestors.must_include(NilClass)
113
+ end
114
+
108
115
  it "build #kind_of? FakedCollection object" do
109
116
  steve_photos.must_be_kind_of(PolyBelongsTo::FakedCollection)
117
+ null_object.must_be_kind_of(PolyBelongsTo::FakedCollection)
110
118
  end
111
119
 
112
120
  it "build #is_a? FakedCollection object" do
113
121
  steve_photos.is_a?(PolyBelongsTo::FakedCollection).must_be_same_as true
122
+ null_object.is_a?(PolyBelongsTo::FakedCollection).must_be_same_as true
114
123
  end
115
124
 
116
125
  it "build #instance_of? FakedCollection object" do
117
126
  steve_photos.must_be_instance_of(PolyBelongsTo::FakedCollection)
127
+ null_object.must_be_instance_of(PolyBelongsTo::FakedCollection)
118
128
  end
119
129
 
120
130
  it "#build builds appropriately" do
@@ -154,6 +164,7 @@ class FakedCollectionTest < ActiveSupport::TestCase
154
164
 
155
165
  it "has method_missing forward appropriate calls" do
156
166
  steve_photos.method_missing(:nil?).must_equal false
167
+ null_object.method_missing(:nil?).must_equal true
157
168
  end
158
169
 
159
170
  it "will not initialize on has_many" do
@@ -173,6 +184,12 @@ class FakedCollectionTest < ActiveSupport::TestCase
173
184
  nil_steve.must_be :empty?
174
185
  nil_steve.instance_eval {@instance}.must_be_nil
175
186
  nil_steve.wont_be :valid?
187
+
188
+ null_object.all.must_equal []
189
+ null_object.size.must_be_same_as 0
190
+ null_object.must_be :empty?
191
+ null_object.instance_eval {@instance}.must_be_nil
192
+ null_object.wont_be :valid?
176
193
  end
177
194
 
178
195
  end
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at
2
+ # http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
3
+
4
+ # This model initially had no columns defined. If you add columns to the
5
+ # model remove the '{}' from the fixture names and add the columns immediately
6
+ # below each fixture, per the syntax in the comments below
7
+ bob_address_book: {}
8
+ steve_address_book: {}
9
+ susan_address_book: {}
@@ -0,0 +1,18 @@
1
+ bob_contact:
2
+ user_id: <%= ActiveRecord::FixtureSet.identify(:bob) %>
3
+ contactable_id: <%= ActiveRecord::FixtureSet.identify(:bob_address_book) %>
4
+ contactable_type: AddressBook
5
+ content: <%= SecureRandom.hex %>
6
+
7
+ #steve_contact:
8
+ # user_id: <%= ActiveRecord::FixtureSet.identify(:steve) %>
9
+ # contactable_id: <%= ActiveRecord::FixtureSet.identify(:steve_address_book) %>
10
+ # contactable_type: AddressBook
11
+ # content: <%= SecureRandom.hex %>
12
+ #
13
+ #susan_contact:
14
+ # user_id: <%= ActiveRecord::FixtureSet.identify(:susan) %>
15
+ # contactable_id: <%= ActiveRecord::FixtureSet.identify(:susan_address_book) %>
16
+ # contactable_type: AddressBook
17
+ # content: <%= SecureRandom.hex %>
18
+ #
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+
4
+ class MajorVersionChangesTest < ActiveSupport::TestCase
5
+ fixtures :all
6
+
7
+ describe "Test breaking changes between major versions" do
8
+
9
+ let(:contact) { contacts(:bob_contact) }
10
+
11
+ case PolyBelongsTo::VERSION.split('.').take(3).join.to_i
12
+ when ->v{ v < 100 }
13
+ it "pre 1.0.0 first parent relation" do
14
+ contact.pbt.must_be_same_as :user
15
+ Contact.pbt.must_be_same_as :user
16
+
17
+ contact.pbts.must_include :user
18
+ contact.pbts.must_include :contactable
19
+ contact.pbts.first.must_be_same_as :user
20
+ Contact.pbts.must_include :user
21
+ Contact.pbts.must_include :contactable
22
+ Contact.pbts.first.must_be_same_as :user
23
+ end
24
+
25
+ it "pre 1.0.0 :poly? on dual ownership with non-polymorphic first" do
26
+ contact.poly?.must_be_same_as false
27
+ Contact.poly?.must_be_same_as false
28
+ end
29
+
30
+ it "pre 1.0.0 :pbt_type_sym on dual ownership with non-polymorphic first" do
31
+ contact.pbt_id_sym.must_be_same_as :user_id
32
+ Contact.pbt_id_sym.must_be_same_as :user_id
33
+ end
34
+
35
+ it "pre 1.0.0 :pbt_parent returns first parent" do
36
+ contact.pbt_parent.id.must_be_same_as users(:bob).id
37
+ end
38
+ when ->v { v >= 100 }
39
+ it "post 1.0.0 first polymorphic parent relation" do
40
+ contact.pbt.must_be_same_as :contactable
41
+ Contact.pbt.must_be_same_as :contactable
42
+
43
+ contact.pbts.must_include :user
44
+ contact.pbts.must_include :contactable
45
+ contact.pbts.first.must_be_same_as :contactable
46
+ Contact.pbts.must_include :user
47
+ Contact.pbts.must_include :contactable
48
+ Contact.pbts.first.must_be_same_as :contactable
49
+ end
50
+
51
+ it "post 1.0.0 :poly? on dual ownership with non-polymorphic first" do
52
+ contact.poly?.must_be_same_as true
53
+ Contact.poly?.must_be_same_as true
54
+ end
55
+
56
+ it "pre 1.0.0 :pbt_type_sym on dual ownership with non-polymorphic first" do
57
+ contact.pbt_id_sym.must_be_same_as :addressable_id
58
+ Contact.pbt_id_sym.must_be_same_as :addressable_id
59
+ end
60
+
61
+ it "post 1.0.0 :pbt_parent gives polymorphic parent precedence" do
62
+ contact.pbt_parent.id.wont_equal users(:bob).id
63
+ end
64
+ end
65
+ end
66
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
- require "codeclimate-test-reporter"
3
- CodeClimate::TestReporter.start
2
+ #require "codeclimate-test-reporter"
3
+ #CodeClimate::TestReporter.start
4
+ require 'simplecov'
5
+ SimpleCov.start
4
6
  require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
7
 
6
8
  ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
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.2.8
4
+ version: 0.2.9
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-05-13 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,7 @@ files:
108
108
  - test/dummy/app/controllers/application_controller.rb
109
109
  - test/dummy/app/helpers/application_helper.rb
110
110
  - test/dummy/app/models/address.rb
111
+ - test/dummy/app/models/address_book.rb
111
112
  - test/dummy/app/models/alpha.rb
112
113
  - test/dummy/app/models/beta.rb
113
114
  - test/dummy/app/models/capa.rb
@@ -115,6 +116,7 @@ files:
115
116
  - test/dummy/app/models/coffee.rb
116
117
  - test/dummy/app/models/contact.rb
117
118
  - test/dummy/app/models/delta.rb
119
+ - test/dummy/app/models/event.rb
118
120
  - test/dummy/app/models/geo_location.rb
119
121
  - test/dummy/app/models/phone.rb
120
122
  - test/dummy/app/models/photo.rb
@@ -124,6 +126,7 @@ files:
124
126
  - test/dummy/app/models/tag.rb
125
127
  - test/dummy/app/models/tire.rb
126
128
  - test/dummy/app/models/user.rb
129
+ - test/dummy/app/models/work_order.rb
127
130
  - test/dummy/app/views/layouts/application.html.erb
128
131
  - test/dummy/bin/bundle
129
132
  - test/dummy/bin/rails
@@ -165,17 +168,28 @@ files:
165
168
  - test/dummy/db/migrate/20150322233743_create_capas.rb
166
169
  - test/dummy/db/migrate/20150322233755_create_delta.rb
167
170
  - test/dummy/db/migrate/20150511161648_create_coffees.rb
171
+ - test/dummy/db/migrate/20160120224015_add_contactable_to_contacts.rb
172
+ - test/dummy/db/migrate/20160120231645_create_address_books.rb
173
+ - test/dummy/db/migrate/20161209115003_create_events.rb
174
+ - test/dummy/db/migrate/20161209115212_create_work_orders.rb
168
175
  - test/dummy/db/schema.rb
169
176
  - test/dummy/db/test.sqlite3
170
177
  - test/dummy/log/development.log
171
178
  - test/dummy/log/test.log
172
179
  - test/dummy/public/favicon.ico
173
180
  - test/dummy/test/fixtures/coffees.yml
181
+ - test/dummy/test/fixtures/events.yml
182
+ - test/dummy/test/fixtures/work_orders.yml
183
+ - test/dummy/test/models/address_book_test.rb
174
184
  - test/dummy/test/models/coffee_test.rb
185
+ - test/dummy/test/models/event_test.rb
186
+ - test/dummy/test/models/work_order_test.rb
175
187
  - test/dup_test.rb
176
188
  - test/faked_collection_test.rb
189
+ - test/fixtures/address_books.yml
177
190
  - test/fixtures/addresses.yml
178
191
  - test/fixtures/cars.yml
192
+ - test/fixtures/contacts.yml
179
193
  - test/fixtures/geo_locations.yml
180
194
  - test/fixtures/phones.yml
181
195
  - test/fixtures/photos.yml
@@ -185,6 +199,7 @@ files:
185
199
  - test/fixtures/tags.yml
186
200
  - test/fixtures/tires.yml
187
201
  - test/fixtures/users.yml
202
+ - test/major_version_changes_test.rb
188
203
  - test/pbt_test.rb
189
204
  - test/singleton_set_test.rb
190
205
  - test/test_helper.rb
@@ -208,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
223
  version: '0'
209
224
  requirements: []
210
225
  rubyforge_project:
211
- rubygems_version: 2.4.6
226
+ rubygems_version: 2.5.2
212
227
  signing_key:
213
228
  specification_version: 4
214
229
  summary: Uniform Omni-Relational ActiveRecord Tools
@@ -224,6 +239,8 @@ test_files:
224
239
  - test/fixtures/users.yml
225
240
  - test/fixtures/cars.yml
226
241
  - test/fixtures/tags.yml
242
+ - test/fixtures/contacts.yml
243
+ - test/fixtures/address_books.yml
227
244
  - test/fixtures/ssns.yml
228
245
  - test/singleton_set_test.rb
229
246
  - test/test_helper.rb
@@ -232,6 +249,8 @@ test_files:
232
249
  - test/dummy/db/test.sqlite3
233
250
  - test/dummy/db/schema.rb
234
251
  - test/dummy/db/migrate/20150220230146_create_squishies.rb
252
+ - test/dummy/db/migrate/20161209115003_create_events.rb
253
+ - test/dummy/db/migrate/20161209115212_create_work_orders.rb
235
254
  - test/dummy/db/migrate/20150322233755_create_delta.rb
236
255
  - test/dummy/db/migrate/20150322233743_create_capas.rb
237
256
  - test/dummy/db/migrate/20150216092449_create_contacts.rb
@@ -240,7 +259,9 @@ test_files:
240
259
  - test/dummy/db/migrate/20150322233720_create_alphas.rb
241
260
  - test/dummy/db/migrate/20150216092218_create_addresses.rb
242
261
  - test/dummy/db/migrate/20150211224225_create_phones.rb
262
+ - test/dummy/db/migrate/20160120224015_add_contactable_to_contacts.rb
243
263
  - test/dummy/db/migrate/20150220213422_create_geo_locations.rb
264
+ - test/dummy/db/migrate/20160120231645_create_address_books.rb
244
265
  - test/dummy/db/migrate/20150216092519_create_ssns.rb
245
266
  - test/dummy/db/migrate/20150211224157_create_tags.rb
246
267
  - test/dummy/db/migrate/20150211224139_create_users.rb
@@ -270,7 +291,10 @@ test_files:
270
291
  - test/dummy/app/helpers/application_helper.rb
271
292
  - test/dummy/app/models/coffee.rb
272
293
  - test/dummy/app/models/ssn.rb
294
+ - test/dummy/app/models/event.rb
273
295
  - test/dummy/app/models/capa.rb
296
+ - test/dummy/app/models/work_order.rb
297
+ - test/dummy/app/models/address_book.rb
274
298
  - test/dummy/app/models/contact.rb
275
299
  - test/dummy/app/models/alpha.rb
276
300
  - test/dummy/app/models/car.rb
@@ -295,6 +319,12 @@ test_files:
295
319
  - test/dummy/bin/rails
296
320
  - test/dummy/bin/bundle
297
321
  - test/dummy/bin/setup
322
+ - test/dummy/test/fixtures/work_orders.yml
323
+ - test/dummy/test/fixtures/events.yml
298
324
  - test/dummy/test/fixtures/coffees.yml
299
325
  - test/dummy/test/models/coffee_test.rb
326
+ - test/dummy/test/models/address_book_test.rb
327
+ - test/dummy/test/models/work_order_test.rb
328
+ - test/dummy/test/models/event_test.rb
300
329
  - test/pbt_test.rb
330
+ - test/major_version_changes_test.rb