ibm_db 2.5.6-x86-mingw32 → 2.5.7-x86-mingw32
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.
- data/CHANGES +6 -0
- data/README +1 -1
- data/ext/Makefile.nt32 +3 -3
- data/ext/Makefile.nt32.191 +212 -0
- data/ext/ibm_db.c +30 -5
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +300 -108
- data/lib/active_record/connection_adapters/ibm_db_pstmt.rb +1 -1
- data/lib/mswin32/rb18x/ibm_db.so +0 -0
- data/lib/mswin32/rb19x/ibm_db.so +0 -0
- data/test/cases/adapter_test.rb +25 -22
- data/test/cases/associations/belongs_to_associations_test.rb +245 -43
- data/test/cases/associations/cascaded_eager_loading_test.rb +28 -26
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +60 -156
- data/test/cases/associations/join_model_test.rb +96 -146
- data/test/cases/attribute_methods_test.rb +98 -33
- data/test/cases/base_test.rb +525 -103
- data/test/cases/calculations_test.rb +92 -8
- data/test/cases/migration_test.rb +533 -207
- data/test/cases/persistence_test.rb +636 -0
- data/test/cases/query_cache_test.rb +242 -0
- data/test/cases/relations_test.rb +1019 -0
- data/test/cases/schema_dumper_test.rb +37 -17
- data/test/cases/transaction_callbacks_test.rb +300 -0
- data/test/cases/validations/uniqueness_validation_test.rb +38 -22
- data/test/cases/xml_serialization_test.rb +276 -0
- data/test/config.yml +154 -0
- data/test/connections/native_ibm_db/connection.rb +2 -0
- data/test/models/warehouse_thing.rb +4 -4
- data/test/schema/i5/ibm_db_specific_schema.rb +3 -1
- data/test/schema/ids/ibm_db_specific_schema.rb +3 -1
- data/test/schema/luw/ibm_db_specific_schema.rb +2 -0
- data/test/schema/schema.rb +174 -89
- data/test/schema/zOS/ibm_db_specific_schema.rb +3 -1
- metadata +10 -7
- data/test/cases/associations/eager_test.rb +0 -862
- data/test/cases/associations/has_many_through_associations_test.rb +0 -461
- data/test/cases/finder_test.rb +0 -1088
- data/test/cases/fixtures_test.rb +0 -684
@@ -177,7 +177,7 @@ module ActiveRecord
|
|
177
177
|
end
|
178
178
|
|
179
179
|
pstmt = connection.prepare(statement, "#{self.class.name} Create")
|
180
|
-
self.id = connection.prepared_insert(pstmt, quoted_attributes.values)
|
180
|
+
self.id = connection.prepared_insert(pstmt, quoted_attributes.values, self.id)
|
181
181
|
|
182
182
|
@new_record = false
|
183
183
|
id
|
data/lib/mswin32/rb18x/ibm_db.so
CHANGED
Binary file
|
data/lib/mswin32/rb19x/ibm_db.so
CHANGED
Binary file
|
data/test/cases/adapter_test.rb
CHANGED
@@ -18,28 +18,28 @@ class AdapterTest < ActiveRecord::TestCase
|
|
18
18
|
else
|
19
19
|
warn "#{@connection.class} does not support client connection attribute schema_name"
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
if @connection.respond_to?(:app_user)
|
23
23
|
ActiveRecord::Base.connection.app_user = 'new_user'
|
24
24
|
assert_equal 'new_user', ActiveRecord::Base.connection.app_user
|
25
25
|
else
|
26
26
|
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_USER"
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
if @connection.respond_to?(:account)
|
30
30
|
ActiveRecord::Base.connection.account = 'new_acct'
|
31
31
|
assert_equal 'new_acct', ActiveRecord::Base.connection.account
|
32
32
|
else
|
33
33
|
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_ACCTSTR"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
if @connection.respond_to?(:application)
|
37
37
|
ActiveRecord::Base.connection.application = 'new_app'
|
38
38
|
assert_equal 'new_app', ActiveRecord::Base.connection.application
|
39
39
|
else
|
40
40
|
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
if @connection.respond_to?(:workstation)
|
44
44
|
ActiveRecord::Base.connection.workstation = 'new_wrkst'
|
45
45
|
assert_equal 'new_wrkst', ActiveRecord::Base.connection.workstation
|
@@ -48,7 +48,7 @@ class AdapterTest < ActiveRecord::TestCase
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def test_tables
|
53
53
|
tables = @connection.tables
|
54
54
|
assert tables.include?("accounts")
|
@@ -87,7 +87,7 @@ class AdapterTest < ActiveRecord::TestCase
|
|
87
87
|
|
88
88
|
def test_current_database
|
89
89
|
if @connection.respond_to?(:current_database)
|
90
|
-
assert_equal
|
90
|
+
assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -112,7 +112,12 @@ class AdapterTest < ActiveRecord::TestCase
|
|
112
112
|
begin
|
113
113
|
assert_nothing_raised do
|
114
114
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
|
115
|
-
|
115
|
+
|
116
|
+
config = ARTest.connection_config
|
117
|
+
ActiveRecord::Base.connection.execute(
|
118
|
+
"SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
|
119
|
+
"FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
|
120
|
+
)
|
116
121
|
end
|
117
122
|
ensure
|
118
123
|
ActiveRecord::Base.establish_connection 'arunit'
|
@@ -166,14 +171,16 @@ class AdapterTest < ActiveRecord::TestCase
|
|
166
171
|
end
|
167
172
|
|
168
173
|
def test_uniqueness_violations_are_translated_to_specific_exception
|
169
|
-
@connection.
|
170
|
-
assert_raises(ActiveRecord::RecordNotUnique) do
|
174
|
+
unless @connection.adapter_name == 'IBM_DB'
|
171
175
|
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
176
|
+
assert_raises(ActiveRecord::RecordNotUnique) do
|
177
|
+
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
178
|
+
end
|
172
179
|
end
|
173
180
|
end
|
174
181
|
|
175
182
|
def test_foreign_key_violations_are_translated_to_specific_exception
|
176
|
-
unless @connection.adapter_name == 'SQLite'
|
183
|
+
unless @connection.adapter_name == 'SQLite' || @connection.adapter_name == 'IBM_DB'
|
177
184
|
assert_raises(ActiveRecord::InvalidForeignKey) do
|
178
185
|
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
|
179
186
|
if @connection.prefetch_primary_key?
|
@@ -186,17 +193,13 @@ class AdapterTest < ActiveRecord::TestCase
|
|
186
193
|
end
|
187
194
|
end
|
188
195
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
sql_inject = "1, 7 procedure help()"
|
198
|
-
assert_no_match(/procedure/, @connection.add_limit_offset!("", :limit=>sql_inject))
|
199
|
-
assert_no_match(/procedure/, @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7))
|
200
|
-
end
|
196
|
+
def test_deprecated_visitor_for
|
197
|
+
visitor_klass = Class.new(Arel::Visitors::ToSql)
|
198
|
+
Arel::Visitors::VISITORS['fuuu'] = visitor_klass
|
199
|
+
pool = stub(:spec => stub(:config => { :adapter => 'fuuu' }))
|
200
|
+
visitor = assert_deprecated {
|
201
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.visitor_for(pool)
|
202
|
+
}
|
203
|
+
assert visitor.is_a?(visitor_klass)
|
201
204
|
end
|
202
205
|
end
|
@@ -17,7 +17,7 @@ require 'models/essay'
|
|
17
17
|
class BelongsToAssociationsTest < ActiveRecord::TestCase
|
18
18
|
fixtures :accounts, :companies, :developers, :projects, :topics,
|
19
19
|
:developers_projects, :computers, :authors, :author_addresses,
|
20
|
-
:posts, :tags, :taggings, :comments
|
20
|
+
:posts, :tags, :taggings, :comments, :sponsors, :members
|
21
21
|
|
22
22
|
def test_belongs_to
|
23
23
|
Client.find(3).firm.name
|
@@ -54,11 +54,6 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
54
54
|
assert_nothing_raised { account.firm = account.firm }
|
55
55
|
end
|
56
56
|
|
57
|
-
def test_triple_equality
|
58
|
-
assert Client.find(3).firm === Firm
|
59
|
-
assert Firm === Client.find(3).firm
|
60
|
-
end
|
61
|
-
|
62
57
|
def test_type_mismatch
|
63
58
|
assert_raise(ActiveRecord::AssociationTypeMismatch) { Account.find(1).firm = 1 }
|
64
59
|
assert_raise(ActiveRecord::AssociationTypeMismatch) { Account.find(1).firm = Project.find(1) }
|
@@ -79,23 +74,17 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
79
74
|
end
|
80
75
|
|
81
76
|
def test_eager_loading_with_primary_key
|
82
|
-
|
83
|
-
|
77
|
+
Firm.create("name" => "Apple")
|
78
|
+
Client.create("name" => "Citibank", :firm_name => "Apple")
|
84
79
|
citibank_result = Client.find(:first, :conditions => {:name => "Citibank"}, :include => :firm_with_primary_key)
|
85
|
-
|
80
|
+
assert citibank_result.association_cache.key?(:firm_with_primary_key)
|
86
81
|
end
|
87
82
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
citibank.firm = first_firm
|
94
|
-
original_proxy = citibank.firm
|
95
|
-
citibank.firm = another_firm
|
96
|
-
|
97
|
-
assert_equal first_firm.object_id, original_proxy.target.object_id
|
98
|
-
assert_equal another_firm.object_id, citibank.firm.target.object_id
|
83
|
+
def test_eager_loading_with_primary_key_as_symbol
|
84
|
+
Firm.create("name" => "Apple")
|
85
|
+
Client.create("name" => "Citibank", :firm_name => "Apple")
|
86
|
+
citibank_result = Client.find(:first, :conditions => {:name => "Citibank"}, :include => :firm_with_primary_key_symbols)
|
87
|
+
assert citibank_result.association_cache.key?(:firm_with_primary_key_symbols)
|
99
88
|
end
|
100
89
|
|
101
90
|
def test_creating_the_belonging_object
|
@@ -130,6 +119,23 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
130
119
|
assert_equal apple.name, client.firm_name
|
131
120
|
end
|
132
121
|
|
122
|
+
def test_create!
|
123
|
+
client = Client.create!(:name => "Jimmy")
|
124
|
+
account = client.create_account!(:credit_limit => 10)
|
125
|
+
assert_equal account, client.account
|
126
|
+
assert account.persisted?
|
127
|
+
client.save
|
128
|
+
client.reload
|
129
|
+
assert_equal account, client.account
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_failing_create!
|
133
|
+
client = Client.create!(:name => "Jimmy")
|
134
|
+
assert_raise(ActiveRecord::RecordInvalid) { client.create_account! }
|
135
|
+
assert_not_nil client.account
|
136
|
+
assert client.account.new_record?
|
137
|
+
end
|
138
|
+
|
133
139
|
def test_natural_assignment_to_nil
|
134
140
|
client = Client.find(3)
|
135
141
|
client.firm = nil
|
@@ -156,6 +162,26 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
156
162
|
assert_not_nil Company.find(3).firm_with_condition, "Microsoft should have a firm"
|
157
163
|
end
|
158
164
|
|
165
|
+
def test_polymorphic_association_class
|
166
|
+
sponsor = Sponsor.new
|
167
|
+
assert_nil sponsor.association(:sponsorable).send(:klass)
|
168
|
+
|
169
|
+
sponsor.sponsorable_type = '' # the column doesn't have to be declared NOT NULL
|
170
|
+
assert_nil sponsor.association(:sponsorable).send(:klass)
|
171
|
+
|
172
|
+
sponsor.sponsorable = Member.new :name => "Bert"
|
173
|
+
assert_equal Member, sponsor.association(:sponsorable).send(:klass)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_with_polymorphic_and_condition
|
177
|
+
sponsor = Sponsor.create
|
178
|
+
member = Member.create :name => "Bert"
|
179
|
+
sponsor.sponsorable = member
|
180
|
+
|
181
|
+
assert_equal member, sponsor.sponsorable
|
182
|
+
assert_nil sponsor.sponsorable_with_conditions
|
183
|
+
end
|
184
|
+
|
159
185
|
def test_with_select
|
160
186
|
assert_equal Company.find(2).firm_with_select.attributes.size, 1
|
161
187
|
assert_equal Company.find(2, :include => :firm_with_select ).firm_with_select.attributes.size, 1
|
@@ -172,17 +198,6 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
172
198
|
assert_equal 0, Topic.find(debate.id).send(:read_attribute, "replies_count"), "First reply deleted"
|
173
199
|
end
|
174
200
|
|
175
|
-
def test_belongs_to_with_primary_key_counter
|
176
|
-
debate = Topic.create("title" => "debate")
|
177
|
-
assert_equal 0, debate.send(:read_attribute, "replies_count"), "No replies yet"
|
178
|
-
|
179
|
-
trash = debate.replies_with_primary_key.create("title" => "blah!", "content" => "world around!")
|
180
|
-
assert_equal 1, Topic.find(debate.id).send(:read_attribute, "replies_count"), "First reply created"
|
181
|
-
|
182
|
-
trash.destroy
|
183
|
-
assert_equal 0, Topic.find(debate.id).send(:read_attribute, "replies_count"), "First reply deleted"
|
184
|
-
end
|
185
|
-
|
186
201
|
def test_belongs_to_counter_with_assigning_nil
|
187
202
|
p = Post.find(1)
|
188
203
|
c = Comment.find(1)
|
@@ -195,16 +210,23 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
195
210
|
assert_equal 1, Post.find(p.id).comments.size
|
196
211
|
end
|
197
212
|
|
198
|
-
def
|
199
|
-
debate
|
200
|
-
|
213
|
+
def test_belongs_to_with_primary_key_counter
|
214
|
+
debate = Topic.create("title" => "debate")
|
215
|
+
debate2 = Topic.create("title" => "debate2")
|
216
|
+
reply = Reply.create("title" => "blah!", "content" => "world around!", "parent_title" => "debate")
|
217
|
+
|
218
|
+
assert_equal 1, debate.reload.replies_count
|
219
|
+
assert_equal 0, debate2.reload.replies_count
|
201
220
|
|
202
|
-
|
203
|
-
|
221
|
+
reply.topic_with_primary_key = debate2
|
222
|
+
|
223
|
+
assert_equal 0, debate.reload.replies_count
|
224
|
+
assert_equal 1, debate2.reload.replies_count
|
204
225
|
|
205
226
|
reply.topic_with_primary_key = nil
|
206
227
|
|
207
|
-
assert_equal 0,
|
228
|
+
assert_equal 0, debate.reload.replies_count
|
229
|
+
assert_equal 0, debate2.reload.replies_count
|
208
230
|
end
|
209
231
|
|
210
232
|
def test_belongs_to_counter_with_reassigning
|
@@ -308,13 +330,21 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
308
330
|
assert_equal Firm.find(:first, :order => "id"), c.firm_with_basic_id
|
309
331
|
end
|
310
332
|
|
311
|
-
def
|
312
|
-
|
313
|
-
|
333
|
+
def test_setting_foreign_key_after_nil_target_loaded
|
334
|
+
client = Client.new
|
335
|
+
client.firm_with_basic_id
|
336
|
+
client.firm_id = 1
|
314
337
|
|
315
|
-
|
316
|
-
|
317
|
-
|
338
|
+
assert_equal companies(:first_firm), client.firm_with_basic_id
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_polymorphic_setting_foreign_key_after_nil_target_loaded
|
342
|
+
sponsor = Sponsor.new
|
343
|
+
sponsor.sponsorable
|
344
|
+
sponsor.sponsorable_id = 1
|
345
|
+
sponsor.sponsorable_type = "Member"
|
346
|
+
|
347
|
+
assert_equal members(:groucho), sponsor.sponsorable
|
318
348
|
end
|
319
349
|
|
320
350
|
def test_field_name_same_as_foreign_key
|
@@ -416,6 +446,18 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
416
446
|
assert_nil sponsor.sponsorable_id
|
417
447
|
end
|
418
448
|
|
449
|
+
def test_assignment_updates_foreign_id_field_for_new_and_saved_records
|
450
|
+
client = Client.new
|
451
|
+
saved_firm = Firm.create :name => "Saved"
|
452
|
+
new_firm = Firm.new
|
453
|
+
|
454
|
+
client.firm = saved_firm
|
455
|
+
assert_equal saved_firm.id, client.client_of
|
456
|
+
|
457
|
+
client.firm = new_firm
|
458
|
+
assert_nil client.client_of
|
459
|
+
end
|
460
|
+
|
419
461
|
def test_polymorphic_assignment_with_primary_key_updates_foreign_id_field_for_new_and_saved_records
|
420
462
|
essay = Essay.new
|
421
463
|
saved_writer = Author.create(:name => "David")
|
@@ -483,4 +525,164 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
483
525
|
new_firm = accounts(:signals37).build_firm(:name => 'Apple')
|
484
526
|
assert_equal new_firm.name, "Apple"
|
485
527
|
end
|
528
|
+
|
529
|
+
def test_reassigning_the_parent_id_updates_the_object
|
530
|
+
client = companies(:second_client)
|
531
|
+
|
532
|
+
client.firm
|
533
|
+
client.firm_with_condition
|
534
|
+
firm_proxy = client.send(:association_instance_get, :firm)
|
535
|
+
firm_with_condition_proxy = client.send(:association_instance_get, :firm_with_condition)
|
536
|
+
|
537
|
+
assert !firm_proxy.stale_target?
|
538
|
+
assert !firm_with_condition_proxy.stale_target?
|
539
|
+
assert_equal companies(:first_firm), client.firm
|
540
|
+
assert_equal companies(:first_firm), client.firm_with_condition
|
541
|
+
|
542
|
+
client.client_of = companies(:another_firm).id
|
543
|
+
|
544
|
+
assert firm_proxy.stale_target?
|
545
|
+
assert firm_with_condition_proxy.stale_target?
|
546
|
+
assert_equal companies(:another_firm), client.firm
|
547
|
+
assert_equal companies(:another_firm), client.firm_with_condition
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_polymorphic_reassignment_of_associated_id_updates_the_object
|
551
|
+
sponsor = sponsors(:moustache_club_sponsor_for_groucho)
|
552
|
+
|
553
|
+
sponsor.sponsorable
|
554
|
+
proxy = sponsor.send(:association_instance_get, :sponsorable)
|
555
|
+
|
556
|
+
assert !proxy.stale_target?
|
557
|
+
assert_equal members(:groucho), sponsor.sponsorable
|
558
|
+
|
559
|
+
sponsor.sponsorable_id = members(:some_other_guy).id
|
560
|
+
|
561
|
+
assert proxy.stale_target?
|
562
|
+
assert_equal members(:some_other_guy), sponsor.sponsorable
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_polymorphic_reassignment_of_associated_type_updates_the_object
|
566
|
+
sponsor = sponsors(:moustache_club_sponsor_for_groucho)
|
567
|
+
|
568
|
+
sponsor.sponsorable
|
569
|
+
proxy = sponsor.send(:association_instance_get, :sponsorable)
|
570
|
+
|
571
|
+
assert !proxy.stale_target?
|
572
|
+
assert_equal members(:groucho), sponsor.sponsorable
|
573
|
+
|
574
|
+
sponsor.sponsorable_type = 'Firm'
|
575
|
+
|
576
|
+
assert proxy.stale_target?
|
577
|
+
assert_equal companies(:first_firm), sponsor.sponsorable
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_reloading_association_with_key_change
|
581
|
+
client = companies(:second_client)
|
582
|
+
firm = client.association(:firm)
|
583
|
+
|
584
|
+
client.firm = companies(:another_firm)
|
585
|
+
firm.reload
|
586
|
+
assert_equal companies(:another_firm), firm.target
|
587
|
+
|
588
|
+
client.client_of = companies(:first_firm).id
|
589
|
+
firm.reload
|
590
|
+
assert_equal companies(:first_firm), firm.target
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_polymorphic_counter_cache
|
594
|
+
tagging = taggings(:welcome_general)
|
595
|
+
post = posts(:welcome)
|
596
|
+
comment = comments(:greetings)
|
597
|
+
|
598
|
+
assert_difference lambda { post.reload.taggings_count }, -1 do
|
599
|
+
assert_difference 'comment.reload.taggings_count', +1 do
|
600
|
+
tagging.taggable = comment
|
601
|
+
end
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_polymorphic_with_custom_foreign_type
|
606
|
+
sponsor = sponsors(:moustache_club_sponsor_for_groucho)
|
607
|
+
groucho = members(:groucho)
|
608
|
+
other = members(:some_other_guy)
|
609
|
+
|
610
|
+
assert_equal groucho, sponsor.sponsorable
|
611
|
+
assert_equal groucho, sponsor.thing
|
612
|
+
|
613
|
+
sponsor.thing = other
|
614
|
+
|
615
|
+
assert_equal other, sponsor.sponsorable
|
616
|
+
assert_equal other, sponsor.thing
|
617
|
+
|
618
|
+
sponsor.sponsorable = groucho
|
619
|
+
|
620
|
+
assert_equal groucho, sponsor.sponsorable
|
621
|
+
assert_equal groucho, sponsor.thing
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_build_with_conditions
|
625
|
+
client = companies(:second_client)
|
626
|
+
firm = client.build_bob_firm
|
627
|
+
|
628
|
+
assert_equal "Bob", firm.name
|
629
|
+
end
|
630
|
+
|
631
|
+
def test_create_with_conditions
|
632
|
+
client = companies(:second_client)
|
633
|
+
firm = client.create_bob_firm
|
634
|
+
|
635
|
+
assert_equal "Bob", firm.name
|
636
|
+
end
|
637
|
+
|
638
|
+
def test_create_bang_with_conditions
|
639
|
+
client = companies(:second_client)
|
640
|
+
firm = client.create_bob_firm!
|
641
|
+
|
642
|
+
assert_equal "Bob", firm.name
|
643
|
+
end
|
644
|
+
|
645
|
+
def test_build_with_block
|
646
|
+
client = Client.create(:name => 'Client Company')
|
647
|
+
|
648
|
+
firm = client.build_firm{ |f| f.name = 'Agency Company' }
|
649
|
+
assert_equal 'Agency Company', firm.name
|
650
|
+
end
|
651
|
+
|
652
|
+
def test_create_with_block
|
653
|
+
client = Client.create(:name => 'Client Company')
|
654
|
+
|
655
|
+
firm = client.create_firm{ |f| f.name = 'Agency Company' }
|
656
|
+
assert_equal 'Agency Company', firm.name
|
657
|
+
end
|
658
|
+
|
659
|
+
def test_create_bang_with_block
|
660
|
+
client = Client.create(:name => 'Client Company')
|
661
|
+
|
662
|
+
firm = client.create_firm!{ |f| f.name = 'Agency Company' }
|
663
|
+
assert_equal 'Agency Company', firm.name
|
664
|
+
end
|
665
|
+
|
666
|
+
def test_should_set_foreign_key_on_create_association
|
667
|
+
client = Client.create! :name => "fuu"
|
668
|
+
|
669
|
+
firm = client.create_firm :name => "baa"
|
670
|
+
assert_equal firm.id, client.client_of
|
671
|
+
end
|
672
|
+
|
673
|
+
def test_should_set_foreign_key_on_create_association!
|
674
|
+
client = Client.create! :name => "fuu"
|
675
|
+
|
676
|
+
firm = client.create_firm! :name => "baa"
|
677
|
+
assert_equal firm.id, client.client_of
|
678
|
+
end
|
679
|
+
|
680
|
+
def test_self_referential_belongs_to_with_counter_cache_assigning_nil
|
681
|
+
comment = Comment.create! :post => posts(:thinking), :body => "fuu"
|
682
|
+
comment.parent = nil
|
683
|
+
comment.save!
|
684
|
+
|
685
|
+
assert_equal nil, comment.reload.parent
|
686
|
+
assert_equal 0, comments(:greetings).reload.children_count
|
687
|
+
end
|
486
688
|
end
|