johnsbrn-has_many_polymorphs 2.13.3 → 2.13.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/generators/tagging/templates/tag_test.rb +1 -1
- data/generators/tagging/templates/tagging_extensions.rb +3 -3
- data/generators/tagging/templates/tagging_test.rb +5 -5
- data/lib/has_many_polymorphs/association.rb +7 -6
- data/lib/has_many_polymorphs/class_methods.rb +1 -1
- data/lib/has_many_polymorphs/support_methods.rb +7 -3
- data/test/generator/tagging_generator_test.rb +1 -1
- data/test/integration/app/generators/commenting_generator_test.rb +1 -1
- data/test/integration/app/test/functional/addresses_controller_test.rb +1 -1
- data/test/integration/app/test/functional/sellers_controller_test.rb +1 -1
- data/test/integration/app/test/functional/states_controller_test.rb +1 -1
- data/test/integration/app/test/functional/users_controller_test.rb +1 -1
- data/test/integration/app/test/test_helper.rb +1 -1
- data/test/integration/app/test/unit/bone_test.rb +1 -1
- data/test/integration/app/test/unit/double_sti_parent_relationship_test.rb +1 -1
- data/test/integration/app/test/unit/double_sti_parent_test.rb +1 -1
- data/test/integration/app/test/unit/organic_substance_test.rb +1 -1
- data/test/integration/app/test/unit/single_sti_parent_relationship_test.rb +1 -1
- data/test/integration/app/test/unit/single_sti_parent_test.rb +1 -1
- data/test/integration/app/test/unit/stick_test.rb +1 -1
- data/test/integration/app/test/unit/stone_test.rb +1 -1
- data/test/integration/server_test.rb +2 -2
- data/test/models/eaters_foodstuff.rb +1 -3
- data/test/test_helper.rb +4 -3
- data/test/unit/has_many_polymorphs_test.rb +63 -64
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -154,7 +154,7 @@ class ActiveRecord::Base #:nodoc:
|
|
154
154
|
|
155
155
|
scope = scope(:find)
|
156
156
|
options[:select] ||= "#{table_name}.*"
|
157
|
-
options[:from] ||= "#{table_name},
|
157
|
+
options[:from] ||= "#{table_name}, tags, taggings"
|
158
158
|
|
159
159
|
sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
|
160
160
|
sql << "FROM #{(scope && scope[:from]) || options[:from]} "
|
@@ -163,12 +163,12 @@ class ActiveRecord::Base #:nodoc:
|
|
163
163
|
|
164
164
|
sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
|
165
165
|
sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
|
166
|
-
sql << "AND taggings.
|
166
|
+
sql << "AND taggings.tag_id = tags.id "
|
167
167
|
|
168
168
|
sql << "AND ("
|
169
169
|
or_options = []
|
170
170
|
tag_list.each do |name|
|
171
|
-
or_options << "
|
171
|
+
or_options << "tags.name = '#{name}'"
|
172
172
|
end
|
173
173
|
or_options_joined = or_options.join(" OR ")
|
174
174
|
sql << "#{or_options_joined}) "
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class TaggingTest <
|
3
|
+
class TaggingTest < ActiveSupport::TestCase
|
4
4
|
fixtures :tags, :taggings, <%= taggable_models[0..1].join(", ") -%>
|
5
5
|
|
6
6
|
def setup
|
@@ -45,15 +45,15 @@ class TaggingTest < Test::Unit::TestCase
|
|
45
45
|
<% if options[:self_referential] -%>
|
46
46
|
def test_self_referential_tag_with
|
47
47
|
@tag1.tag_with [1, 2]
|
48
|
-
assert @tag1.tags.
|
49
|
-
assert !@tag2.tags.
|
48
|
+
assert @tag1.tags.any? {|obj| obj == @tag1}
|
49
|
+
assert !@tag2.tags.any? {|obj| obj == @tag1}
|
50
50
|
end
|
51
51
|
|
52
52
|
<% end -%>
|
53
53
|
def test__add_tags
|
54
54
|
@obj1._add_tags "porter longneck"
|
55
|
-
assert Tag.find_by_name("porter").taggables.
|
56
|
-
assert Tag.find_by_name("longneck").taggables.
|
55
|
+
assert Tag.find_by_name("porter").taggables.any? {|obj| obj == @obj1}
|
56
|
+
assert Tag.find_by_name("longneck").taggables.any? {|obj| obj == @obj1}
|
57
57
|
assert_equal "longneck pale porter", @obj1.tag_list
|
58
58
|
|
59
59
|
@obj1._add_tags [2]
|
@@ -88,18 +88,19 @@ module ActiveRecord #:nodoc:
|
|
88
88
|
def construct_quoted_owner_attributes(*args) #:nodoc:
|
89
89
|
# no access to returning() here? why not?
|
90
90
|
type_key = @reflection.options[:foreign_type_key]
|
91
|
-
{@reflection.primary_key_name => @owner.id
|
92
|
-
|
91
|
+
h = {@reflection.primary_key_name => @owner.id}
|
92
|
+
h[type_key] = @owner.class.base_class.name if type_key
|
93
|
+
h
|
93
94
|
end
|
94
95
|
|
95
96
|
def construct_from #:nodoc:
|
96
97
|
# build the FROM part of the query, in this case, the polymorphic join table
|
97
|
-
@reflection.klass.
|
98
|
+
@reflection.klass.quoted_table_name
|
98
99
|
end
|
99
100
|
|
100
101
|
def construct_owner #:nodoc:
|
101
102
|
# the table name for the owner object's class
|
102
|
-
@owner.class.
|
103
|
+
@owner.class.quoted_table_name
|
103
104
|
end
|
104
105
|
|
105
106
|
def construct_owner_key #:nodoc:
|
@@ -114,10 +115,10 @@ module ActiveRecord #:nodoc:
|
|
114
115
|
|
115
116
|
def construct_joins(custom_joins = nil) #:nodoc:
|
116
117
|
# build the string of default joins
|
117
|
-
"JOIN #{construct_owner} polymorphic_parent ON #{construct_from}.#{@reflection.options[:foreign_key]} = polymorphic_parent.#{construct_owner_key} " +
|
118
|
+
"JOIN #{construct_owner} AS polymorphic_parent ON #{construct_from}.#{@reflection.options[:foreign_key]} = polymorphic_parent.#{construct_owner_key} " +
|
118
119
|
@reflection.options[:from].map do |plural|
|
119
120
|
klass = plural._as_class
|
120
|
-
"LEFT JOIN #{klass.
|
121
|
+
"LEFT JOIN #{klass.quoted_table_name} ON #{construct_from}.#{@reflection.options[:polymorphic_key]} = #{klass.quoted_table_name}.#{klass.primary_key} AND #{construct_from}.#{@reflection.options[:polymorphic_type_key]} = #{@reflection.klass.quote_value(klass.base_class.name)}"
|
121
122
|
end.uniq.join(" ") + " #{custom_joins}"
|
122
123
|
end
|
123
124
|
|
@@ -398,7 +398,7 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
|
|
398
398
|
}
|
399
399
|
|
400
400
|
if reflection.options[:foreign_type_key]
|
401
|
-
type_check = "#{reflection.options[:foreign_type_key]} = #{quote_value(self.base_class.name)}"
|
401
|
+
type_check = "#{reflection.options[:join_class_name].constantize.quoted_table_name}.#{reflection.options[:foreign_type_key]} = #{quote_value(self.base_class.name)}"
|
402
402
|
conjunction = options[:conditions] ? " AND " : nil
|
403
403
|
options[:conditions] = "#{options[:conditions]}#{conjunction}#{type_check}"
|
404
404
|
options[:as] = reflection.options[:as]
|
@@ -45,9 +45,13 @@ class Hash
|
|
45
45
|
|
46
46
|
# An implementation of select that returns a Hash.
|
47
47
|
def _select
|
48
|
-
|
49
|
-
yield
|
50
|
-
|
48
|
+
if RUBY_VERSION >= "1.9"
|
49
|
+
Hash[*self.select {|k, v| yield k, v }.flatten]
|
50
|
+
else
|
51
|
+
Hash[*self.select do |key, value|
|
52
|
+
yield key, value
|
53
|
+
end._flatten_once]
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
class CommentingGeneratorTest <
|
4
|
+
class CommentingGeneratorTest < ActiveSupport::TestCase
|
5
5
|
|
6
6
|
def test_ensure_comments_dont_exist
|
7
7
|
# make sure the comments are already defined
|
@@ -4,7 +4,7 @@ require 'addresses_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class AddressesController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class AddressesControllerTest <
|
7
|
+
class AddressesControllerTest < ActiveSupport::TestCase
|
8
8
|
fixtures :addresses
|
9
9
|
|
10
10
|
def setup
|
@@ -4,7 +4,7 @@ require 'sellers_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class SellersController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class SellersControllerTest <
|
7
|
+
class SellersControllerTest < ActiveSupport::TestCase
|
8
8
|
fixtures :sellers
|
9
9
|
|
10
10
|
def setup
|
@@ -4,7 +4,7 @@ require 'states_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class StatesController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class StatesControllerTest <
|
7
|
+
class StatesControllerTest < ActiveSupport::TestCase
|
8
8
|
fixtures :states
|
9
9
|
|
10
10
|
def setup
|
@@ -4,7 +4,7 @@ require 'users_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class UsersController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class UsersControllerTest <
|
7
|
+
class UsersControllerTest < ActiveSupport::TestCase
|
8
8
|
fixtures :users
|
9
9
|
|
10
10
|
def setup
|
@@ -2,7 +2,7 @@ ENV["RAILS_ENV"] = "development"
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
3
|
require 'test_help'
|
4
4
|
|
5
|
-
class
|
5
|
+
class ActiveSupport::TestCase
|
6
6
|
self.use_transactional_fixtures = true
|
7
7
|
self.use_instantiated_fixtures = false
|
8
8
|
end
|
@@ -4,7 +4,7 @@ require 'open-uri'
|
|
4
4
|
|
5
5
|
# Start the server
|
6
6
|
|
7
|
-
class ServerTest <
|
7
|
+
class ServerTest < ActiveSupport::TestCase
|
8
8
|
|
9
9
|
PORT = 43040
|
10
10
|
URL = "http://localhost:#{PORT}/"
|
@@ -40,4 +40,4 @@ class ServerTest < Test::Unit::TestCase
|
|
40
40
|
# XXX Probably can use script/runner to test this
|
41
41
|
end
|
42
42
|
|
43
|
-
end
|
43
|
+
end
|
@@ -3,8 +3,6 @@ class EatersFoodstuff < ActiveRecord::Base
|
|
3
3
|
belongs_to :foodstuff, :class_name => "Petfood", :foreign_key => "foodstuff_id"
|
4
4
|
belongs_to :eater, :polymorphic => true
|
5
5
|
|
6
|
-
|
7
|
-
self.some_attribute = 3
|
8
|
-
end
|
6
|
+
before_save { |record| record.some_attribute = 3 }
|
9
7
|
end
|
10
8
|
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
|
2
2
|
$VERBOSE = nil
|
3
3
|
require 'rubygems'
|
4
|
+
require 'rake' # echoe relies on Rake being present but doesn't require it itself
|
4
5
|
require 'echoe'
|
5
6
|
require 'test/unit'
|
6
7
|
require 'multi_rails_init'
|
7
|
-
require 'ruby-debug'
|
8
|
+
#require 'ruby-debug' # uncomment if needed (for Ruby >= 1.9 use require 'debug' where needed)
|
8
9
|
|
9
10
|
if defined? ENV['MULTIRAILS_RAILS_VERSION']
|
10
11
|
ENV['RAILS_GEM_VERSION'] = ENV['MULTIRAILS_RAILS_VERSION']
|
@@ -25,11 +26,11 @@ require 'test_help'
|
|
25
26
|
|
26
27
|
ActiveSupport::Inflector.inflections {|i| i.irregular 'fish', 'fish' }
|
27
28
|
|
28
|
-
$LOAD_PATH.unshift(
|
29
|
+
$LOAD_PATH.unshift(ActiveSupport::TestCase.fixture_path = HERE + "/fixtures")
|
29
30
|
$LOAD_PATH.unshift(HERE + "/models")
|
30
31
|
$LOAD_PATH.unshift(HERE + "/modules")
|
31
32
|
|
32
|
-
class
|
33
|
+
class ActiveSupport::TestCase
|
33
34
|
self.use_transactional_fixtures = !(ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false)
|
34
35
|
self.use_instantiated_fixtures = false
|
35
36
|
end
|
@@ -10,7 +10,7 @@ require 'aquatic/fish'
|
|
10
10
|
require 'aquatic/pupils_whale'
|
11
11
|
require 'beautiful_fight_relationship'
|
12
12
|
|
13
|
-
class PolymorphTest <
|
13
|
+
class PolymorphTest < ActiveSupport::TestCase
|
14
14
|
|
15
15
|
set_fixture_class :bow_wows => Dog
|
16
16
|
set_fixture_class :keep_your_enemies_close => BeautifulFightRelationship
|
@@ -76,7 +76,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
76
76
|
def test_duplicate_assignment
|
77
77
|
# try to add a duplicate item when :ignore_duplicates is false
|
78
78
|
@kibbles.eaters.push(@alice)
|
79
|
-
assert @kibbles.eaters.
|
79
|
+
assert @kibbles.eaters.any? {|obj| obj == @alice}
|
80
80
|
@kibbles.eaters.push(@alice)
|
81
81
|
assert_equal @kibbles_eaters_count + 2, @kibbles.eaters.count
|
82
82
|
assert_equal @join_count + 2, EatersFoodstuff.count
|
@@ -114,7 +114,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
114
114
|
|
115
115
|
# reload; is the new association there?
|
116
116
|
assert @bits.eaters.reload
|
117
|
-
assert @bits.eaters.
|
117
|
+
assert @bits.eaters.any? {|obj| obj == @chloe}
|
118
118
|
end
|
119
119
|
|
120
120
|
def test_build_join_record_on_association
|
@@ -126,7 +126,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
126
126
|
assert_equal @join_count + 1, EatersFoodstuff.count
|
127
127
|
|
128
128
|
assert @bits.eaters.reload
|
129
|
-
assert @bits.eaters.
|
129
|
+
assert @bits.eaters.any? {|obj| obj == @chloe}
|
130
130
|
end
|
131
131
|
|
132
132
|
# not supporting this, since has_many :through doesn't support it either
|
@@ -145,12 +145,12 @@ class PolymorphTest < Test::Unit::TestCase
|
|
145
145
|
def test_self_reference
|
146
146
|
assert @kibbles.eaters << @bits
|
147
147
|
assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count
|
148
|
-
assert @kibbles.eaters.
|
148
|
+
assert @kibbles.eaters.any? {|obj| obj == @bits}
|
149
149
|
@kibbles.reload
|
150
150
|
assert @kibbles.foodstuffs_of_eaters.blank?
|
151
151
|
|
152
152
|
@bits.reload
|
153
|
-
assert @bits.foodstuffs_of_eaters.
|
153
|
+
assert @bits.foodstuffs_of_eaters.any? {|obj| obj == @kibbles}
|
154
154
|
assert_equal [@kibbles], @bits.foodstuffs_of_eaters
|
155
155
|
end
|
156
156
|
|
@@ -190,9 +190,9 @@ class PolymorphTest < Test::Unit::TestCase
|
|
190
190
|
def test_individual_collections_push
|
191
191
|
assert_equal [@chloe], (@kibbles.eater_kittens << @chloe)
|
192
192
|
@kibbles.reload
|
193
|
-
assert @kibbles.eaters.
|
194
|
-
assert @kibbles.eater_kittens.
|
195
|
-
assert !@kibbles.eater_dogs.
|
193
|
+
assert @kibbles.eaters.any? {|obj| obj == @chloe}
|
194
|
+
assert @kibbles.eater_kittens.any? {|obj| obj == @chloe}
|
195
|
+
assert !@kibbles.eater_dogs.any? {|obj| obj == @chloe}
|
196
196
|
end
|
197
197
|
|
198
198
|
def test_individual_collections_delete
|
@@ -204,7 +204,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
204
204
|
|
205
205
|
@kibbles.reload
|
206
206
|
assert @kibbles.eater_kittens.empty?
|
207
|
-
assert @kibbles.eater_dogs.
|
207
|
+
assert @kibbles.eater_dogs.any? {|obj| obj == @spot}
|
208
208
|
end
|
209
209
|
|
210
210
|
def test_individual_collections_clear
|
@@ -217,14 +217,14 @@ class PolymorphTest < Test::Unit::TestCase
|
|
217
217
|
|
218
218
|
assert @kibbles.eater_kittens.empty?
|
219
219
|
assert_equal 2, @kibbles.eaters.size
|
220
|
-
assert !@kibbles.eater_kittens.
|
221
|
-
assert !@kibbles.eaters.
|
220
|
+
assert !@kibbles.eater_kittens.any? {|obj| obj == @chloe}
|
221
|
+
assert !@kibbles.eaters.any? {|obj| obj == @chloe}
|
222
222
|
|
223
223
|
@kibbles.reload
|
224
224
|
assert @kibbles.eater_kittens.empty?
|
225
225
|
assert_equal 2, @kibbles.eaters.size
|
226
|
-
assert !@kibbles.eater_kittens.
|
227
|
-
assert !@kibbles.eaters.
|
226
|
+
assert !@kibbles.eater_kittens.any? {|obj| obj == @chloe}
|
227
|
+
assert !@kibbles.eaters.any? {|obj| obj == @chloe}
|
228
228
|
end
|
229
229
|
|
230
230
|
def test_childrens_individual_collections
|
@@ -316,13 +316,13 @@ class PolymorphTest < Test::Unit::TestCase
|
|
316
316
|
|
317
317
|
def test_namespaced_polymorphic_collection
|
318
318
|
@shamu.aquatic_pupils << @swimmy
|
319
|
-
assert @shamu.aquatic_pupils.
|
319
|
+
assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
|
320
320
|
@shamu.reload
|
321
|
-
assert @shamu.aquatic_pupils.
|
321
|
+
assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
|
322
322
|
|
323
323
|
@shamu.aquatic_pupils << @spot
|
324
|
-
assert @shamu.dogs.
|
325
|
-
assert @shamu.aquatic_pupils.
|
324
|
+
assert @shamu.dogs.any? {|obj| obj == @spot}
|
325
|
+
assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
|
326
326
|
assert_equal @swimmy, @shamu.aquatic_fish.first
|
327
327
|
assert_equal 10, @shamu.aquatic_fish.first.speed
|
328
328
|
end
|
@@ -333,8 +333,8 @@ class PolymorphTest < Test::Unit::TestCase
|
|
333
333
|
|
334
334
|
@shamu.reload
|
335
335
|
@shamu.aquatic_pupils.delete @spot
|
336
|
-
assert !@shamu.dogs.
|
337
|
-
assert !@shamu.aquatic_pupils.
|
336
|
+
assert !@shamu.dogs.any? {|obj| obj == @spot}
|
337
|
+
assert !@shamu.aquatic_pupils.any? {|obj| obj == @spot}
|
338
338
|
assert_equal 1, @shamu.aquatic_pupils.length
|
339
339
|
end
|
340
340
|
|
@@ -357,9 +357,9 @@ class PolymorphTest < Test::Unit::TestCase
|
|
357
357
|
@alice.enemies << @spot
|
358
358
|
@alice.reload
|
359
359
|
@spot.reload
|
360
|
-
assert @spot.protectors.
|
361
|
-
assert @alice.enemies.
|
362
|
-
assert !@alice.protectors.
|
360
|
+
assert @spot.protectors.any? {|obj| obj == @alice}
|
361
|
+
assert @alice.enemies.any? {|obj| obj == @spot}
|
362
|
+
assert !@alice.protectors.any? {|obj| obj == @alice}
|
363
363
|
assert_equal 1, @alice.beautiful_fight_relationships_as_protector.size
|
364
364
|
assert_equal 0, @alice.beautiful_fight_relationships_as_enemy.size
|
365
365
|
assert_equal 1, @alice.beautiful_fight_relationships.size
|
@@ -367,7 +367,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
367
367
|
# self reference
|
368
368
|
assert_equal 1, @alice.enemies.length
|
369
369
|
@alice.enemies.push @alice
|
370
|
-
assert @alice.enemies.
|
370
|
+
assert @alice.enemies.any? {|obj| obj == @alice}
|
371
371
|
assert_equal 2, @alice.enemies.length
|
372
372
|
@alice.reload
|
373
373
|
assert_equal 2, @alice.beautiful_fight_relationships_as_protector.size
|
@@ -386,7 +386,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
386
386
|
assert_equal @double_join_count + 1, BeautifulFightRelationship.count
|
387
387
|
|
388
388
|
assert @alice.enemies.reload
|
389
|
-
assert @alice.enemies.
|
389
|
+
assert @alice.enemies.any? {|obj| obj == @spot}
|
390
390
|
end
|
391
391
|
|
392
392
|
def test_double_dependency_injection
|
@@ -396,12 +396,12 @@ class PolymorphTest < Test::Unit::TestCase
|
|
396
396
|
def test_double_collection_deletion
|
397
397
|
@alice.enemies << @spot
|
398
398
|
@alice.reload
|
399
|
-
assert @alice.enemies.
|
399
|
+
assert @alice.enemies.any? {|obj| obj == @spot}
|
400
400
|
@alice.enemies.delete(@spot)
|
401
|
-
assert !@alice.enemies.
|
401
|
+
assert !@alice.enemies.any? {|obj| obj == @spot}
|
402
402
|
assert @alice.enemies.empty?
|
403
403
|
@alice.reload
|
404
|
-
assert !@alice.enemies.
|
404
|
+
assert !@alice.enemies.any? {|obj| obj == @spot}
|
405
405
|
assert @alice.enemies.empty?
|
406
406
|
assert_equal 0, @alice.beautiful_fight_relationships.size
|
407
407
|
end
|
@@ -409,12 +409,12 @@ class PolymorphTest < Test::Unit::TestCase
|
|
409
409
|
def test_double_collection_deletion_from_opposite_side
|
410
410
|
@alice.protectors << @puma
|
411
411
|
@alice.reload
|
412
|
-
assert @alice.protectors.
|
412
|
+
assert @alice.protectors.any? {|obj| obj == @puma}
|
413
413
|
@alice.protectors.delete(@puma)
|
414
|
-
assert !@alice.protectors.
|
414
|
+
assert !@alice.protectors.any? {|obj| obj == @puma}
|
415
415
|
assert @alice.protectors.empty?
|
416
416
|
@alice.reload
|
417
|
-
assert !@alice.protectors.
|
417
|
+
assert !@alice.protectors.any? {|obj| obj == @puma}
|
418
418
|
assert @alice.protectors.empty?
|
419
419
|
assert_equal 0, @alice.beautiful_fight_relationships.size
|
420
420
|
end
|
@@ -423,59 +423,58 @@ class PolymorphTest < Test::Unit::TestCase
|
|
423
423
|
assert @alice.dogs.empty?
|
424
424
|
@alice.enemies << @spot
|
425
425
|
|
426
|
-
assert @alice.enemies.
|
427
|
-
assert !@alice.kittens.
|
426
|
+
assert @alice.enemies.any? {|obj| obj == @spot}
|
427
|
+
assert !@alice.kittens.any? {|obj| obj == @alice}
|
428
428
|
|
429
|
-
assert !@alice.dogs.
|
429
|
+
assert !@alice.dogs.any? {|obj| obj == @spot}
|
430
430
|
@alice.reload
|
431
|
-
assert @alice.dogs.
|
432
|
-
assert !WildBoar.find(@alice.id).dogs.
|
431
|
+
assert @alice.dogs.any? {|obj| obj == @spot}
|
432
|
+
assert !WildBoar.find(@alice.id).dogs.any? {|obj| obj == @spot} # make sure the parent type is checked
|
433
433
|
end
|
434
434
|
|
435
435
|
def test_individual_collections_created_for_double_relationship_from_opposite_side
|
436
436
|
assert @alice.wild_boars.empty?
|
437
437
|
@alice.protectors << @puma
|
438
|
-
|
439
|
-
assert @alice.protectors.include?(@puma)
|
440
|
-
assert !@alice.wild_boars.include?(@puma)
|
441
438
|
@alice.reload
|
442
|
-
|
439
|
+
|
440
|
+
assert @alice.protectors.any? {|obj| obj == @puma}
|
441
|
+
assert @alice.wild_boars.any? {|obj| obj == @puma}
|
443
442
|
|
444
|
-
assert !Dog.find(@alice.id).wild_boars.
|
443
|
+
assert !Dog.find(@alice.id).wild_boars.any? {|obj| obj == @puma} # make sure the parent type is checked
|
445
444
|
end
|
446
445
|
|
447
446
|
def test_self_referential_individual_collections_created_for_double_relationship
|
448
447
|
@alice.enemies << @alice
|
449
448
|
@alice.reload
|
450
|
-
assert @alice.enemy_kittens.
|
451
|
-
assert @alice.protector_kittens.
|
452
|
-
assert @alice.kittens.
|
449
|
+
assert @alice.enemy_kittens.any? {|obj| obj == @alice}
|
450
|
+
assert @alice.protector_kittens.any? {|obj| obj == @alice}
|
451
|
+
assert @alice.kittens.any? {|obj| obj == @alice}
|
453
452
|
assert_equal 2, @alice.kittens.size
|
454
453
|
|
455
454
|
@alice.enemies << (@chloe = Kitten.find_by_name('Chloe'))
|
456
455
|
@alice.reload
|
457
|
-
assert @alice.enemy_kittens.
|
458
|
-
assert !@alice.protector_kittens.
|
459
|
-
assert @alice.kittens.
|
456
|
+
assert @alice.enemy_kittens.any? {|obj| obj == @chloe}
|
457
|
+
assert !@alice.protector_kittens.any? {|obj| obj == @chloe}
|
458
|
+
assert @alice.kittens.any? {|obj| obj == @chloe}
|
460
459
|
assert_equal 3, @alice.kittens.size
|
461
460
|
end
|
462
461
|
|
463
462
|
def test_child_of_polymorphic_join_can_reach_parent
|
464
463
|
@alice.enemies << @spot
|
465
464
|
@alice.reload
|
466
|
-
assert @spot.protectors.
|
465
|
+
assert @spot.protectors.any? {|obj| obj == @alice}
|
467
466
|
end
|
468
467
|
|
469
468
|
def test_double_collection_deletion_from_child_polymorphic_join
|
470
469
|
@alice.enemies << @spot
|
471
470
|
@spot.protectors.delete(@alice)
|
472
|
-
assert !@spot.protectors.
|
471
|
+
assert !@spot.protectors.any? {|obj| obj == @alice}
|
473
472
|
@alice.reload
|
474
|
-
assert !@alice.enemies.
|
473
|
+
assert !@alice.enemies.any? {|obj| obj == @spot}
|
475
474
|
BeautifulFightRelationship.create(:protector_id => 2, :protector_type => "Dog", :enemy_id => @spot.id, :enemy_type => @spot.class.name)
|
476
475
|
@alice.enemies << @spot
|
477
476
|
@spot.protectors.delete(@alice)
|
478
|
-
assert !@spot.protectors.
|
477
|
+
assert !@spot.protectors.any? {|obj| obj == @alice}
|
479
478
|
end
|
480
479
|
|
481
480
|
def test_collection_query_on_unsaved_record
|
@@ -486,15 +485,15 @@ class PolymorphTest < Test::Unit::TestCase
|
|
486
485
|
def test_double_individual_collections_push
|
487
486
|
assert_equal [@chloe], (@spot.protector_kittens << @chloe)
|
488
487
|
@spot.reload
|
489
|
-
assert @spot.protectors.
|
490
|
-
assert @spot.protector_kittens.
|
491
|
-
assert !@spot.protector_dogs.
|
488
|
+
assert @spot.protectors.any? {|obj| obj == @chloe}
|
489
|
+
assert @spot.protector_kittens.any? {|obj| obj == @chloe}
|
490
|
+
assert !@spot.protector_dogs.any? {|obj| obj == @chloe}
|
492
491
|
|
493
492
|
assert_equal [@froggy], (@spot.frogs << @froggy)
|
494
493
|
@spot.reload
|
495
|
-
assert @spot.enemies.
|
496
|
-
assert @spot.frogs.
|
497
|
-
assert !@spot.enemy_dogs.
|
494
|
+
assert @spot.enemies.any? {|obj| obj == @froggy}
|
495
|
+
assert @spot.frogs.any? {|obj| obj == @froggy}
|
496
|
+
assert !@spot.enemy_dogs.any? {|obj| obj == @froggy}
|
498
497
|
end
|
499
498
|
|
500
499
|
def test_double_individual_collections_delete
|
@@ -506,7 +505,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
506
505
|
|
507
506
|
@spot.reload
|
508
507
|
assert @spot.protector_kittens.empty?
|
509
|
-
assert @spot.wild_boars.
|
508
|
+
assert @spot.wild_boars.any? {|obj| obj == @puma}
|
510
509
|
end
|
511
510
|
|
512
511
|
def test_double_individual_collections_clear
|
@@ -518,12 +517,12 @@ class PolymorphTest < Test::Unit::TestCase
|
|
518
517
|
@spot.reload
|
519
518
|
assert @spot.protector_kittens.empty?
|
520
519
|
assert_equal 1, @spot.protectors.size
|
521
|
-
assert !@spot.protector_kittens.
|
522
|
-
assert !@spot.protectors.
|
523
|
-
assert !@spot.protector_kittens.
|
524
|
-
assert !@spot.protectors.
|
525
|
-
assert @spot.protectors.
|
526
|
-
assert @spot.wild_boars.
|
520
|
+
assert !@spot.protector_kittens.any? {|obj| obj == @chloe}
|
521
|
+
assert !@spot.protectors.any? {|obj| obj == @chloe}
|
522
|
+
assert !@spot.protector_kittens.any? {|obj| obj == @alice}
|
523
|
+
assert !@spot.protectors.any? {|obj| obj == @alice}
|
524
|
+
assert @spot.protectors.any? {|obj| obj == @puma}
|
525
|
+
assert @spot.wild_boars.any? {|obj| obj == @puma}
|
527
526
|
end
|
528
527
|
|
529
528
|
def test_single_extensions
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: johnsbrn-has_many_polymorphs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.13.
|
4
|
+
version: 2.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Weaver
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|