poly_belongs_to 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+
4
+ class DupTest < ActiveSupport::TestCase
5
+ fixtures :all
6
+
7
+ describe PolyBelongsTo::SingletonSet do
8
+ let (:example) { users(:bob) }
9
+ let (:the_set) { PolyBelongsTo::SingletonSet.new }
10
+
11
+ it "formats name with #formatted_name" do
12
+ the_set.formatted_name(example).must_equal "#{example.class.name}-#{example.id}"
13
+ end
14
+
15
+ it "adds with :add?" do
16
+ the_set.add?(example)
17
+ the_set.to_a.must_equal ["#{example.class.name}-#{example.id}"]
18
+ end
19
+ it "adds with :add" do
20
+ the_set.add(example)
21
+ the_set.to_a.must_equal ["#{example.class.name}-#{example.id}"]
22
+ end
23
+ it "adds with :<<" do
24
+ the_set.<<(example)
25
+ the_set.to_a.must_equal ["#{example.class.name}-#{example.id}"]
26
+ end
27
+
28
+ it "can tell you what's included" do
29
+ the_set.<<(example)
30
+ the_set.include?(example).must_be_same_as true
31
+ end
32
+
33
+ it "flags a duplicate" do
34
+ the_set.<<(example)
35
+ the_set.<<(example).must_be_nil
36
+ the_set.flagged?(example).must_be_same_as true
37
+ the_set.instance_eval {@flagged}.to_a.must_equal ["#{example.class.name}-#{example.id}"]
38
+ end
39
+
40
+ it "says false for unflagged items" do
41
+ the_set.flagged?(example).must_be_same_as false
42
+ end
43
+ end
44
+ end
data/test/test_helper.rb CHANGED
@@ -7,6 +7,7 @@ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db
7
7
  require 'rails/test_help'
8
8
  require 'minitest/rails'
9
9
  require 'minitest/reporters'
10
+ require 'color_pound_spec_reporter'
10
11
  require 'securerandom'
11
12
 
12
13
  unless Rails.version =~ /^4.[2-9]/
@@ -20,9 +21,8 @@ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
20
21
  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
21
22
  end
22
23
 
23
- Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
24
+ Minitest::Reporters.use! [ColorPoundSpecReporter.new]
24
25
 
25
26
  class ActiveSupport::TestCase
26
- ActiveRecord::Base.send(:include, PolyBelongsTo::Dup)
27
27
  CleanAttrs = PolyBelongsTo::Pbt::AttrSanitizer
28
28
  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.8
4
+ version: 0.1.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-03-01 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,17 +95,24 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - lib/poly_belongs_to.rb
98
+ - lib/poly_belongs_to/core.rb
98
99
  - lib/poly_belongs_to/dup.rb
99
100
  - lib/poly_belongs_to/faked_collection.rb
100
- - lib/poly_belongs_to/poly_belongs_to.rb
101
+ - lib/poly_belongs_to/pbt.rb
102
+ - lib/poly_belongs_to/singleton_set.rb
101
103
  - lib/poly_belongs_to/version.rb
102
104
  - lib/tasks/poly_belongs_to_tasks.rake
105
+ - test/core_test.rb
103
106
  - test/dummy/Rakefile
104
107
  - test/dummy/app/controllers/application_controller.rb
105
108
  - test/dummy/app/helpers/application_helper.rb
106
109
  - test/dummy/app/models/address.rb
110
+ - test/dummy/app/models/alpha.rb
111
+ - test/dummy/app/models/beta.rb
112
+ - test/dummy/app/models/capa.rb
107
113
  - test/dummy/app/models/car.rb
108
114
  - test/dummy/app/models/contact.rb
115
+ - test/dummy/app/models/delta.rb
109
116
  - test/dummy/app/models/geo_location.rb
110
117
  - test/dummy/app/models/phone.rb
111
118
  - test/dummy/app/models/photo.rb
@@ -151,6 +158,10 @@ files:
151
158
  - test/dummy/db/migrate/20150220230146_create_squishies.rb
152
159
  - test/dummy/db/migrate/20150301100658_create_tires.rb
153
160
  - test/dummy/db/migrate/20150301100722_create_cars.rb
161
+ - test/dummy/db/migrate/20150322233720_create_alphas.rb
162
+ - test/dummy/db/migrate/20150322233733_create_beta.rb
163
+ - test/dummy/db/migrate/20150322233743_create_capas.rb
164
+ - test/dummy/db/migrate/20150322233755_create_delta.rb
154
165
  - test/dummy/db/schema.rb
155
166
  - test/dummy/db/test.sqlite3
156
167
  - test/dummy/log/development.log
@@ -170,7 +181,7 @@ files:
170
181
  - test/fixtures/tires.yml
171
182
  - test/fixtures/users.yml
172
183
  - test/pbt_test.rb
173
- - test/poly_belongs_to_test.rb
184
+ - test/singleton_set_test.rb
174
185
  - test/test_helper.rb
175
186
  homepage: https://github.com/danielpclark/PolyBelongsTo
176
187
  licenses:
@@ -192,12 +203,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
203
  version: '0'
193
204
  requirements: []
194
205
  rubyforge_project:
195
- rubygems_version: 2.4.5
206
+ rubygems_version: 2.4.6
196
207
  signing_key:
197
208
  specification_version: 4
198
209
  summary: Shorthand belongs_to testing and universal identifiers.
199
210
  test_files:
200
- - test/poly_belongs_to_test.rb
201
211
  - test/dup_test.rb
202
212
  - test/fixtures/squishies.yml
203
213
  - test/fixtures/addresses.yml
@@ -210,13 +220,19 @@ test_files:
210
220
  - test/fixtures/cars.yml
211
221
  - test/fixtures/tags.yml
212
222
  - test/fixtures/ssns.yml
223
+ - test/singleton_set_test.rb
213
224
  - test/test_helper.rb
214
225
  - test/faked_collection_test.rb
226
+ - test/core_test.rb
215
227
  - test/dummy/db/test.sqlite3
216
228
  - test/dummy/db/schema.rb
217
229
  - test/dummy/db/migrate/20150220230146_create_squishies.rb
230
+ - test/dummy/db/migrate/20150322233755_create_delta.rb
231
+ - test/dummy/db/migrate/20150322233743_create_capas.rb
218
232
  - test/dummy/db/migrate/20150216092449_create_contacts.rb
219
233
  - test/dummy/db/migrate/20150301100658_create_tires.rb
234
+ - test/dummy/db/migrate/20150322233733_create_beta.rb
235
+ - test/dummy/db/migrate/20150322233720_create_alphas.rb
220
236
  - test/dummy/db/migrate/20150216092218_create_addresses.rb
221
237
  - test/dummy/db/migrate/20150211224225_create_phones.rb
222
238
  - test/dummy/db/migrate/20150220213422_create_geo_locations.rb
@@ -247,17 +263,21 @@ test_files:
247
263
  - test/dummy/app/controllers/application_controller.rb
248
264
  - test/dummy/app/helpers/application_helper.rb
249
265
  - test/dummy/app/models/ssn.rb
266
+ - test/dummy/app/models/capa.rb
250
267
  - test/dummy/app/models/contact.rb
268
+ - test/dummy/app/models/alpha.rb
251
269
  - test/dummy/app/models/car.rb
252
270
  - test/dummy/app/models/tire.rb
253
271
  - test/dummy/app/models/user.rb
254
272
  - test/dummy/app/models/geo_location.rb
255
273
  - test/dummy/app/models/address.rb
274
+ - test/dummy/app/models/delta.rb
256
275
  - test/dummy/app/models/phone.rb
257
276
  - test/dummy/app/models/profile.rb
258
277
  - test/dummy/app/models/squishy.rb
259
278
  - test/dummy/app/models/tag.rb
260
279
  - test/dummy/app/models/photo.rb
280
+ - test/dummy/app/models/beta.rb
261
281
  - test/dummy/app/views/layouts/application.html.erb
262
282
  - test/dummy/public/favicon.ico
263
283
  - test/dummy/Rakefile
@@ -1,200 +0,0 @@
1
- require 'test_helper'
2
- require 'minitest/autorun'
3
-
4
- class PolyBelongsToTest < ActiveSupport::TestCase
5
- fixtures :all
6
-
7
- it "is a module" do
8
- PolyBelongsTo::Core.must_be_kind_of Module
9
- end
10
-
11
- it "User as not polymorphic" do
12
- user = users(:bob)
13
- user.poly?.must_be_same_as false
14
- User.poly?.must_be_same_as false
15
- end
16
-
17
- it "Tag as not polymorphic" do
18
- tag = tags(:bob_tag)
19
- tag.poly?.must_be_same_as false
20
- Tag.poly?.must_be_same_as false
21
- end
22
-
23
- it "Phone as polymorphic" do
24
- phone = phones(:bob_phone)
25
- phone.poly?.must_be_same_as true
26
- Phone.poly?.must_be_same_as true
27
- end
28
-
29
- it "User belongs to table as nil" do
30
- user = users(:bob)
31
- user.pbt.must_be_nil
32
- User.pbt.must_be_nil
33
- end
34
-
35
- it "Tag belongs to table as :user" do
36
- tag = tags(:bob_tag)
37
- tag.pbt.must_be_same_as :user
38
- Tag.pbt.must_be_same_as :user
39
- end
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
-
53
- it "Phone belongs to table as :phoneable" do
54
- phone = phones(:bob_phone)
55
- phone.pbt.must_be_same_as :phoneable
56
- Phone.pbt.must_be_same_as :phoneable
57
- end
58
-
59
- it "User params name as :user" do
60
- user = users(:bob)
61
- user.pbt_params_name.must_be_same_as :user
62
- User.pbt_params_name.must_be_same_as :user
63
- User.pbt_params_name(true).must_be_same_as :user
64
- User.pbt_params_name(false).must_be_same_as :user
65
- end
66
-
67
- it "Tag params name as :tag" do
68
- tag = tags(:bob_tag)
69
- tag.pbt_params_name.must_be_same_as :tag
70
- Tag.pbt_params_name.must_be_same_as :tag
71
- Tag.pbt_params_name(true).must_be_same_as :tag
72
- Tag.pbt_params_name(false).must_be_same_as :tag
73
- end
74
-
75
- it "Phone params name as :phones_attributes" do
76
- phone = phones(:bob_phone)
77
- phone.pbt_params_name.must_be_same_as :phones_attributes
78
- Phone.pbt_params_name.must_be_same_as :phones_attributes
79
- Phone.pbt_params_name(true).must_be_same_as :phones_attributes
80
- end
81
-
82
- it "Phone params name with false as :phone" do
83
- phone = phones(:bob_phone)
84
- phone.pbt_params_name(false).must_be_same_as :phone
85
- Phone.pbt_params_name(false).must_be_same_as :phone
86
- end
87
-
88
- it "User belongs to field id symbol as nil" do
89
- user = users(:bob)
90
- user.pbt_id_sym.must_be_nil
91
- User.pbt_id_sym.must_be_nil
92
- end
93
-
94
- it "Tag belongs to field id symbol as :tag_id" do
95
- tag = tags(:bob_tag)
96
- tag.pbt_id_sym.must_be_same_as :user_id
97
- Tag.pbt_id_sym.must_be_same_as :user_id
98
- end
99
-
100
- it "Phone belongs to field id symbol as :phoneable_id" do
101
- phone = phones(:bob_phone)
102
- phone.pbt_id_sym.must_be_same_as :phoneable_id
103
- Phone.pbt_id_sym.must_be_same_as :phoneable_id
104
- end
105
-
106
- it "User belongs to field type symbol as nil" do
107
- user = users(:bob)
108
- user.pbt_type_sym.must_be_nil
109
- User.pbt_type_sym.must_be_nil
110
- end
111
-
112
- it "Tag belongs to field type symbol as nil" do
113
- tag = tags(:bob_tag)
114
- tag.pbt_type_sym.must_be_nil
115
- Tag.pbt_type_sym.must_be_nil
116
- end
117
-
118
- it "Phone belongs to field type symbol as :phoneable_type" do
119
- phone = phones(:bob_phone)
120
- phone.pbt_type_sym.must_be_same_as :phoneable_type
121
- Phone.pbt_type_sym.must_be_same_as :phoneable_type
122
- end
123
-
124
- it "User belongs to id as nil" do
125
- user = users(:bob)
126
- user.pbt_id.must_be_nil
127
- end
128
-
129
- it "Tag belongs to id as user's id" do
130
- tag = tags(:bob_tag)
131
- tag.pbt_id.must_be_same_as ActiveRecord::FixtureSet.identify(:bob)
132
- end
133
-
134
- it "Phone belongs to id as user's profile id" do
135
- phone = phones(:bob_phone)
136
- phone.pbt_id.must_be_same_as ActiveRecord::FixtureSet.identify(:bob_prof)
137
- end
138
-
139
- it "User belongs to type as nil" do
140
- user = users(:bob)
141
- user.pbt_type.must_be_nil
142
- end
143
-
144
- it "Tag belongs to type as nil" do
145
- tag = tags(:bob_tag)
146
- tag.pbt_type.must_be_nil
147
- end
148
-
149
- it "Phone belongs to type as 'Profile'" do
150
- phone = phones(:bob_phone)
151
- phone.pbt_type.must_equal "Profile"
152
- end
153
-
154
- it "User parent returns nil" do
155
- user = users(:bob)
156
- user.pbt_parent.must_be_nil
157
- end
158
-
159
- it "Tag parent returns user instance" do
160
- user = users(:bob)
161
- tag = user.tags.build
162
- tag.pbt_parent.id.must_be_same_as user.id
163
- end
164
-
165
- it "Phone parent returns profile" do
166
- user = users(:bob)
167
- profile = user.profiles.build
168
- phone = profile.phones.build
169
- profile.save
170
- phone.pbt_parent.id.must_be_same_as profile.id
171
- end
172
-
173
- it "Profile parent returns user" do
174
- user = users(:bob)
175
- profile = user.profiles.build
176
- profile.save
177
- profile.pbt_parent.id.must_be_same_as user.id
178
- end
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
-
200
- end