ibm_db 2.5.26-universal-darwin-14 → 2.6.1-universal-darwin-14

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +11 -0
  3. data/MANIFEST +14 -14
  4. data/README +225 -225
  5. data/ext/Makefile.nt32 +181 -181
  6. data/ext/Makefile.nt32.191 +212 -212
  7. data/ext/extconf.rb +264 -261
  8. data/ext/extconf_MacOS.rb +269 -0
  9. data/ext/ibm_db.c +11879 -11793
  10. data/ext/ruby_ibm_db.h +241 -240
  11. data/ext/ruby_ibm_db_cli.c +851 -845
  12. data/ext/ruby_ibm_db_cli.h +500 -489
  13. data/init.rb +41 -41
  14. data/lib/IBM_DB.rb +27 -19
  15. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +3339 -3289
  16. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +1 -1
  17. data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -328
  18. data/test/cases/adapter_test.rb +207 -207
  19. data/test/cases/associations/belongs_to_associations_test.rb +711 -711
  20. data/test/cases/associations/cascaded_eager_loading_test.rb +181 -181
  21. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +851 -851
  22. data/test/cases/associations/join_model_test.rb +743 -743
  23. data/test/cases/attribute_methods_test.rb +822 -822
  24. data/test/cases/base_test.rb +2133 -2133
  25. data/test/cases/calculations_test.rb +482 -482
  26. data/test/cases/migration_test.rb +2408 -2408
  27. data/test/cases/persistence_test.rb +642 -642
  28. data/test/cases/query_cache_test.rb +257 -257
  29. data/test/cases/relations_test.rb +1182 -1182
  30. data/test/cases/schema_dumper_test.rb +256 -256
  31. data/test/cases/transaction_callbacks_test.rb +300 -300
  32. data/test/cases/validations/uniqueness_validation_test.rb +299 -299
  33. data/test/cases/xml_serialization_test.rb +408 -408
  34. data/test/config.yml +154 -154
  35. data/test/connections/native_ibm_db/connection.rb +43 -43
  36. data/test/ibm_db_test.rb +24 -24
  37. data/test/models/warehouse_thing.rb +4 -4
  38. data/test/schema/schema.rb +751 -751
  39. metadata +6 -8
  40. data/lib/linux/rb18x/ibm_db.bundle +0 -0
  41. data/lib/linux/rb19x/ibm_db.bundle +0 -0
  42. data/lib/linux/rb20x/ibm_db.bundle +0 -0
  43. data/lib/linux/rb21x/ibm_db.bundle +0 -0
@@ -1,299 +1,299 @@
1
- # encoding: utf-8
2
- require "cases/helper"
3
- require 'models/topic'
4
- require 'models/reply'
5
- require 'models/warehouse_thing'
6
- require 'models/guid'
7
- require 'models/event'
8
-
9
- class Wizard < ActiveRecord::Base
10
- self.abstract_class = true
11
-
12
- validates_uniqueness_of :name
13
- end
14
-
15
- class IneptWizard < Wizard
16
- validates_uniqueness_of :city
17
- end
18
-
19
- class Conjurer < IneptWizard
20
- end
21
-
22
- class Thaumaturgist < IneptWizard
23
- end
24
-
25
- class UniquenessValidationTest < ActiveRecord::TestCase
26
- fixtures :topics, 'warehouse_things', :developers
27
-
28
- repair_validations(Topic, Reply)
29
-
30
- def test_validate_uniqueness
31
- Topic.validates_uniqueness_of(:title)
32
-
33
- t = Topic.new("title" => "I'm uniqué!")
34
- assert t.save, "Should save t as unique"
35
-
36
- t.content = "Remaining unique"
37
- assert t.save, "Should still save t as unique"
38
-
39
- t2 = Topic.new("title" => "I'm uniqué!")
40
- assert !t2.valid?, "Shouldn't be valid"
41
- assert !t2.save, "Shouldn't save t2 as unique"
42
- assert_equal ["has already been taken"], t2.errors[:title]
43
-
44
- t2.title = "Now Im really also unique"
45
- assert t2.save, "Should now save t2 as unique"
46
- end
47
-
48
- def test_validates_uniqueness_with_validates
49
- Topic.validates :title, :uniqueness => true
50
- Topic.create!('title' => 'abc')
51
-
52
- t2 = Topic.new('title' => 'abc')
53
- assert !t2.valid?
54
- assert t2.errors[:title]
55
- end
56
-
57
- def test_validates_uniqueness_with_newline_chars
58
- Topic.validates_uniqueness_of(:title, :case_sensitive => false)
59
-
60
- t = Topic.new("title" => "new\nline")
61
- assert t.save, "Should save t as unique"
62
- end
63
-
64
- def test_validate_uniqueness_with_scope
65
- Reply.validates_uniqueness_of(:content, :scope => "parent_id")
66
-
67
- t = Topic.create("title" => "I'm unique!")
68
-
69
- r1 = t.replies.create "title" => "r1", "content" => "hello world"
70
- assert r1.valid?, "Saving r1"
71
-
72
- r2 = t.replies.create "title" => "r2", "content" => "hello world"
73
- assert !r2.valid?, "Saving r2 first time"
74
-
75
- r2.content = "something else"
76
- assert r2.save, "Saving r2 second time"
77
-
78
- t2 = Topic.create("title" => "I'm unique too!")
79
- r3 = t2.replies.create "title" => "r3", "content" => "hello world"
80
- assert r3.valid?, "Saving r3"
81
- end
82
-
83
- def test_validate_uniqueness_scoped_to_defining_class
84
- t = Topic.create("title" => "What, me worry?")
85
-
86
- r1 = t.unique_replies.create "title" => "r1", "content" => "a barrel of fun"
87
- assert r1.valid?, "Saving r1"
88
-
89
- r2 = t.silly_unique_replies.create "title" => "r2", "content" => "a barrel of fun"
90
- assert !r2.valid?, "Saving r2"
91
-
92
- # Should succeed as validates_uniqueness_of only applies to
93
- # UniqueReply and its subclasses
94
- r3 = t.replies.create "title" => "r2", "content" => "a barrel of fun"
95
- assert r3.valid?, "Saving r3"
96
- end
97
-
98
- def test_validate_uniqueness_with_scope_array
99
- Reply.validates_uniqueness_of(:author_name, :scope => [:author_email_address, :parent_id])
100
-
101
- t = Topic.create("title" => "The earth is actually flat!")
102
-
103
- r1 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply"
104
- assert r1.valid?, "Saving r1"
105
-
106
- r2 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply again..."
107
- assert !r2.valid?, "Saving r2. Double reply by same author."
108
-
109
- r2.author_email_address = "jeremy_alt_email@rubyonrails.com"
110
- assert r2.save, "Saving r2 the second time."
111
-
112
- r3 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy_alt_email@rubyonrails.com", "title" => "You're wrong", "content" => "It's cubic"
113
- assert !r3.valid?, "Saving r3"
114
-
115
- r3.author_name = "jj"
116
- assert r3.save, "Saving r3 the second time."
117
-
118
- r3.author_name = "jeremy"
119
- assert !r3.save, "Saving r3 the third time."
120
- end
121
-
122
- def test_validate_case_insensitive_uniqueness
123
- Topic.validates_uniqueness_of(:title, :parent_id, :case_sensitive => false, :allow_nil => true)
124
-
125
- t = Topic.new("title" => "I'm unique!", :parent_id => 2)
126
- assert t.save, "Should save t as unique"
127
-
128
- t.content = "Remaining unique"
129
- assert t.save, "Should still save t as unique"
130
-
131
- t2 = Topic.new("title" => "I'm UNIQUE!", :parent_id => 1)
132
- assert !t2.valid?, "Shouldn't be valid"
133
- assert !t2.save, "Shouldn't save t2 as unique"
134
- assert t2.errors[:title].any?
135
- assert t2.errors[:parent_id].any?
136
- assert_equal ["has already been taken"], t2.errors[:title]
137
-
138
- t2.title = "I'm truly UNIQUE!"
139
- assert !t2.valid?, "Shouldn't be valid"
140
- assert !t2.save, "Shouldn't save t2 as unique"
141
- assert t2.errors[:title].empty?
142
- assert t2.errors[:parent_id].any?
143
-
144
- t2.parent_id = 4
145
- assert t2.save, "Should now save t2 as unique"
146
-
147
- t2.parent_id = nil
148
- t2.title = nil
149
- assert t2.valid?, "should validate with nil"
150
- assert t2.save, "should save with nil"
151
-
152
- with_kcode('UTF8') do
153
- t_utf8 = Topic.new("title" => "Я тоже уникальный!")
154
- assert t_utf8.save, "Should save t_utf8 as unique"
155
-
156
- # If database hasn't UTF-8 character set, this test fails
157
- if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
158
- t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
159
- assert !t2_utf8.valid?, "Shouldn't be valid"
160
- assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
161
- end
162
- end
163
- end
164
-
165
- def test_validate_case_sensitive_uniqueness_with_special_sql_like_chars
166
- Topic.validates_uniqueness_of(:title, :case_sensitive => true)
167
-
168
- t = Topic.new("title" => "I'm unique!")
169
- assert t.save, "Should save t as unique"
170
-
171
- t2 = Topic.new("title" => "I'm %")
172
- assert t2.save, "Should save t2 as unique"
173
-
174
- t3 = Topic.new("title" => "I'm uniqu_!")
175
- assert t3.save, "Should save t3 as unique"
176
- end
177
-
178
- def test_validate_case_insensitive_uniqueness_with_special_sql_like_chars
179
- Topic.validates_uniqueness_of(:title, :case_sensitive => false)
180
-
181
- t = Topic.new("title" => "I'm unique!")
182
- assert t.save, "Should save t as unique"
183
-
184
- t2 = Topic.new("title" => "I'm %")
185
- assert t2.save, "Should save t2 as unique"
186
-
187
- t3 = Topic.new("title" => "I'm uniqu_!")
188
- assert t3.save, "Should save t3 as unique"
189
- end
190
-
191
- def test_validate_case_sensitive_uniqueness
192
- Topic.validates_uniqueness_of(:title, :case_sensitive => true, :allow_nil => true)
193
-
194
- t = Topic.new("title" => "I'm unique!")
195
- assert t.save, "Should save t as unique"
196
-
197
- t.content = "Remaining unique"
198
- assert t.save, "Should still save t as unique"
199
-
200
- t2 = Topic.new("title" => "I'M UNIQUE!")
201
- assert t2.valid?, "Should be valid"
202
- assert t2.save, "Should save t2 as unique"
203
- assert t2.errors[:title].empty?
204
- assert t2.errors[:parent_id].empty?
205
- assert_not_equal ["has already been taken"], t2.errors[:title]
206
-
207
- t3 = Topic.new("title" => "I'M uNiQUe!")
208
- assert t3.valid?, "Should be valid"
209
- assert t3.save, "Should save t2 as unique"
210
- assert t3.errors[:title].empty?
211
- assert t3.errors[:parent_id].empty?
212
- assert_not_equal ["has already been taken"], t3.errors[:title]
213
- end
214
-
215
- def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
216
- Topic.validates_uniqueness_of(:title, :case_sensitve => true)
217
- Topic.create!('title' => 101)
218
-
219
- t2 = Topic.new('title' => 101)
220
- assert !t2.valid?
221
- assert t2.errors[:title]
222
- end
223
-
224
- def test_validate_uniqueness_with_non_standard_table_names
225
- i1 = WarehouseThing.create(:value => 1000)
226
- assert !i1.valid?, "i1 should not be valid"
227
- assert i1.errors[:value].any?, "Should not be empty"
228
- end
229
-
230
- def test_validates_uniqueness_inside_with_scope
231
- Topic.validates_uniqueness_of(:title)
232
-
233
- Topic.send(:with_scope, :find => { :conditions => { :author_name => "David" } }) do
234
- t1 = Topic.new("title" => "I'm unique!", "author_name" => "Mary")
235
- assert t1.save
236
- t2 = Topic.new("title" => "I'm unique!", "author_name" => "David")
237
- assert !t2.valid?
238
- end
239
- end
240
-
241
- def test_validate_uniqueness_with_columns_which_are_sql_keywords
242
- repair_validations(Guid) do
243
- Guid.validates_uniqueness_of :key
244
- g = Guid.new
245
- g.key = "foo"
246
- assert_nothing_raised { !g.valid? }
247
- end
248
- end
249
-
250
- def test_validate_uniqueness_with_limit
251
- # Event.title is limited to 5 characters
252
- e1 = Event.create(:title => "abcde")
253
- assert e1.valid?, "Could not create an event with a unique, 5 character title"
254
- e2 = Event.create(:title => "abcdefgh")
255
- assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
256
- end
257
-
258
- def test_validate_uniqueness_with_limit_and_utf8
259
- unless current_adapter?(:IBM_DBAdapter)
260
- # Limit for the varchar field is number of bytes and not characters for DB2. Hence the below test cases is expected to fail.
261
- with_kcode('UTF8') do
262
- # Event.title is limited to 5 characters
263
- e1 = Event.create(:title => "一二三四五")
264
- assert e1.valid?, "Could not create an event with a unique, 5 character title"
265
- e2 = Event.create(:title => "一二三四五六七八")
266
- assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
267
- end
268
- end
269
- end
270
-
271
- def test_validate_straight_inheritance_uniqueness
272
- w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
273
- assert w1.valid?, "Saving w1"
274
-
275
- # Should use validation from base class (which is abstract)
276
- w2 = IneptWizard.new(:name => "Rincewind", :city => "Quirm")
277
- assert !w2.valid?, "w2 shouldn't be valid"
278
- assert w2.errors[:name].any?, "Should have errors for name"
279
- assert_equal ["has already been taken"], w2.errors[:name], "Should have uniqueness message for name"
280
-
281
- w3 = Conjurer.new(:name => "Rincewind", :city => "Quirm")
282
- assert !w3.valid?, "w3 shouldn't be valid"
283
- assert w3.errors[:name].any?, "Should have errors for name"
284
- assert_equal ["has already been taken"], w3.errors[:name], "Should have uniqueness message for name"
285
-
286
- w4 = Conjurer.create(:name => "The Amazing Bonko", :city => "Quirm")
287
- assert w4.valid?, "Saving w4"
288
-
289
- w5 = Thaumaturgist.new(:name => "The Amazing Bonko", :city => "Lancre")
290
- assert !w5.valid?, "w5 shouldn't be valid"
291
- assert w5.errors[:name].any?, "Should have errors for name"
292
- assert_equal ["has already been taken"], w5.errors[:name], "Should have uniqueness message for name"
293
-
294
- w6 = Thaumaturgist.new(:name => "Mustrum Ridcully", :city => "Quirm")
295
- assert !w6.valid?, "w6 shouldn't be valid"
296
- assert w6.errors[:city].any?, "Should have errors for city"
297
- assert_equal ["has already been taken"], w6.errors[:city], "Should have uniqueness message for city"
298
- end
299
- end
1
+ # encoding: utf-8
2
+ require "cases/helper"
3
+ require 'models/topic'
4
+ require 'models/reply'
5
+ require 'models/warehouse_thing'
6
+ require 'models/guid'
7
+ require 'models/event'
8
+
9
+ class Wizard < ActiveRecord::Base
10
+ self.abstract_class = true
11
+
12
+ validates_uniqueness_of :name
13
+ end
14
+
15
+ class IneptWizard < Wizard
16
+ validates_uniqueness_of :city
17
+ end
18
+
19
+ class Conjurer < IneptWizard
20
+ end
21
+
22
+ class Thaumaturgist < IneptWizard
23
+ end
24
+
25
+ class UniquenessValidationTest < ActiveRecord::TestCase
26
+ fixtures :topics, 'warehouse_things', :developers
27
+
28
+ repair_validations(Topic, Reply)
29
+
30
+ def test_validate_uniqueness
31
+ Topic.validates_uniqueness_of(:title)
32
+
33
+ t = Topic.new("title" => "I'm uniqué!")
34
+ assert t.save, "Should save t as unique"
35
+
36
+ t.content = "Remaining unique"
37
+ assert t.save, "Should still save t as unique"
38
+
39
+ t2 = Topic.new("title" => "I'm uniqué!")
40
+ assert !t2.valid?, "Shouldn't be valid"
41
+ assert !t2.save, "Shouldn't save t2 as unique"
42
+ assert_equal ["has already been taken"], t2.errors[:title]
43
+
44
+ t2.title = "Now Im really also unique"
45
+ assert t2.save, "Should now save t2 as unique"
46
+ end
47
+
48
+ def test_validates_uniqueness_with_validates
49
+ Topic.validates :title, :uniqueness => true
50
+ Topic.create!('title' => 'abc')
51
+
52
+ t2 = Topic.new('title' => 'abc')
53
+ assert !t2.valid?
54
+ assert t2.errors[:title]
55
+ end
56
+
57
+ def test_validates_uniqueness_with_newline_chars
58
+ Topic.validates_uniqueness_of(:title, :case_sensitive => false)
59
+
60
+ t = Topic.new("title" => "new\nline")
61
+ assert t.save, "Should save t as unique"
62
+ end
63
+
64
+ def test_validate_uniqueness_with_scope
65
+ Reply.validates_uniqueness_of(:content, :scope => "parent_id")
66
+
67
+ t = Topic.create("title" => "I'm unique!")
68
+
69
+ r1 = t.replies.create "title" => "r1", "content" => "hello world"
70
+ assert r1.valid?, "Saving r1"
71
+
72
+ r2 = t.replies.create "title" => "r2", "content" => "hello world"
73
+ assert !r2.valid?, "Saving r2 first time"
74
+
75
+ r2.content = "something else"
76
+ assert r2.save, "Saving r2 second time"
77
+
78
+ t2 = Topic.create("title" => "I'm unique too!")
79
+ r3 = t2.replies.create "title" => "r3", "content" => "hello world"
80
+ assert r3.valid?, "Saving r3"
81
+ end
82
+
83
+ def test_validate_uniqueness_scoped_to_defining_class
84
+ t = Topic.create("title" => "What, me worry?")
85
+
86
+ r1 = t.unique_replies.create "title" => "r1", "content" => "a barrel of fun"
87
+ assert r1.valid?, "Saving r1"
88
+
89
+ r2 = t.silly_unique_replies.create "title" => "r2", "content" => "a barrel of fun"
90
+ assert !r2.valid?, "Saving r2"
91
+
92
+ # Should succeed as validates_uniqueness_of only applies to
93
+ # UniqueReply and its subclasses
94
+ r3 = t.replies.create "title" => "r2", "content" => "a barrel of fun"
95
+ assert r3.valid?, "Saving r3"
96
+ end
97
+
98
+ def test_validate_uniqueness_with_scope_array
99
+ Reply.validates_uniqueness_of(:author_name, :scope => [:author_email_address, :parent_id])
100
+
101
+ t = Topic.create("title" => "The earth is actually flat!")
102
+
103
+ r1 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply"
104
+ assert r1.valid?, "Saving r1"
105
+
106
+ r2 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're crazy!", "content" => "Crazy reply again..."
107
+ assert !r2.valid?, "Saving r2. Double reply by same author."
108
+
109
+ r2.author_email_address = "jeremy_alt_email@rubyonrails.com"
110
+ assert r2.save, "Saving r2 the second time."
111
+
112
+ r3 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy_alt_email@rubyonrails.com", "title" => "You're wrong", "content" => "It's cubic"
113
+ assert !r3.valid?, "Saving r3"
114
+
115
+ r3.author_name = "jj"
116
+ assert r3.save, "Saving r3 the second time."
117
+
118
+ r3.author_name = "jeremy"
119
+ assert !r3.save, "Saving r3 the third time."
120
+ end
121
+
122
+ def test_validate_case_insensitive_uniqueness
123
+ Topic.validates_uniqueness_of(:title, :parent_id, :case_sensitive => false, :allow_nil => true)
124
+
125
+ t = Topic.new("title" => "I'm unique!", :parent_id => 2)
126
+ assert t.save, "Should save t as unique"
127
+
128
+ t.content = "Remaining unique"
129
+ assert t.save, "Should still save t as unique"
130
+
131
+ t2 = Topic.new("title" => "I'm UNIQUE!", :parent_id => 1)
132
+ assert !t2.valid?, "Shouldn't be valid"
133
+ assert !t2.save, "Shouldn't save t2 as unique"
134
+ assert t2.errors[:title].any?
135
+ assert t2.errors[:parent_id].any?
136
+ assert_equal ["has already been taken"], t2.errors[:title]
137
+
138
+ t2.title = "I'm truly UNIQUE!"
139
+ assert !t2.valid?, "Shouldn't be valid"
140
+ assert !t2.save, "Shouldn't save t2 as unique"
141
+ assert t2.errors[:title].empty?
142
+ assert t2.errors[:parent_id].any?
143
+
144
+ t2.parent_id = 4
145
+ assert t2.save, "Should now save t2 as unique"
146
+
147
+ t2.parent_id = nil
148
+ t2.title = nil
149
+ assert t2.valid?, "should validate with nil"
150
+ assert t2.save, "should save with nil"
151
+
152
+ with_kcode('UTF8') do
153
+ t_utf8 = Topic.new("title" => "Я тоже уникальный!")
154
+ assert t_utf8.save, "Should save t_utf8 as unique"
155
+
156
+ # If database hasn't UTF-8 character set, this test fails
157
+ if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
158
+ t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
159
+ assert !t2_utf8.valid?, "Shouldn't be valid"
160
+ assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
161
+ end
162
+ end
163
+ end
164
+
165
+ def test_validate_case_sensitive_uniqueness_with_special_sql_like_chars
166
+ Topic.validates_uniqueness_of(:title, :case_sensitive => true)
167
+
168
+ t = Topic.new("title" => "I'm unique!")
169
+ assert t.save, "Should save t as unique"
170
+
171
+ t2 = Topic.new("title" => "I'm %")
172
+ assert t2.save, "Should save t2 as unique"
173
+
174
+ t3 = Topic.new("title" => "I'm uniqu_!")
175
+ assert t3.save, "Should save t3 as unique"
176
+ end
177
+
178
+ def test_validate_case_insensitive_uniqueness_with_special_sql_like_chars
179
+ Topic.validates_uniqueness_of(:title, :case_sensitive => false)
180
+
181
+ t = Topic.new("title" => "I'm unique!")
182
+ assert t.save, "Should save t as unique"
183
+
184
+ t2 = Topic.new("title" => "I'm %")
185
+ assert t2.save, "Should save t2 as unique"
186
+
187
+ t3 = Topic.new("title" => "I'm uniqu_!")
188
+ assert t3.save, "Should save t3 as unique"
189
+ end
190
+
191
+ def test_validate_case_sensitive_uniqueness
192
+ Topic.validates_uniqueness_of(:title, :case_sensitive => true, :allow_nil => true)
193
+
194
+ t = Topic.new("title" => "I'm unique!")
195
+ assert t.save, "Should save t as unique"
196
+
197
+ t.content = "Remaining unique"
198
+ assert t.save, "Should still save t as unique"
199
+
200
+ t2 = Topic.new("title" => "I'M UNIQUE!")
201
+ assert t2.valid?, "Should be valid"
202
+ assert t2.save, "Should save t2 as unique"
203
+ assert t2.errors[:title].empty?
204
+ assert t2.errors[:parent_id].empty?
205
+ assert_not_equal ["has already been taken"], t2.errors[:title]
206
+
207
+ t3 = Topic.new("title" => "I'M uNiQUe!")
208
+ assert t3.valid?, "Should be valid"
209
+ assert t3.save, "Should save t2 as unique"
210
+ assert t3.errors[:title].empty?
211
+ assert t3.errors[:parent_id].empty?
212
+ assert_not_equal ["has already been taken"], t3.errors[:title]
213
+ end
214
+
215
+ def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
216
+ Topic.validates_uniqueness_of(:title, :case_sensitve => true)
217
+ Topic.create!('title' => 101)
218
+
219
+ t2 = Topic.new('title' => 101)
220
+ assert !t2.valid?
221
+ assert t2.errors[:title]
222
+ end
223
+
224
+ def test_validate_uniqueness_with_non_standard_table_names
225
+ i1 = WarehouseThing.create(:value => 1000)
226
+ assert !i1.valid?, "i1 should not be valid"
227
+ assert i1.errors[:value].any?, "Should not be empty"
228
+ end
229
+
230
+ def test_validates_uniqueness_inside_with_scope
231
+ Topic.validates_uniqueness_of(:title)
232
+
233
+ Topic.send(:with_scope, :find => { :conditions => { :author_name => "David" } }) do
234
+ t1 = Topic.new("title" => "I'm unique!", "author_name" => "Mary")
235
+ assert t1.save
236
+ t2 = Topic.new("title" => "I'm unique!", "author_name" => "David")
237
+ assert !t2.valid?
238
+ end
239
+ end
240
+
241
+ def test_validate_uniqueness_with_columns_which_are_sql_keywords
242
+ repair_validations(Guid) do
243
+ Guid.validates_uniqueness_of :key
244
+ g = Guid.new
245
+ g.key = "foo"
246
+ assert_nothing_raised { !g.valid? }
247
+ end
248
+ end
249
+
250
+ def test_validate_uniqueness_with_limit
251
+ # Event.title is limited to 5 characters
252
+ e1 = Event.create(:title => "abcde")
253
+ assert e1.valid?, "Could not create an event with a unique, 5 character title"
254
+ e2 = Event.create(:title => "abcdefgh")
255
+ assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
256
+ end
257
+
258
+ def test_validate_uniqueness_with_limit_and_utf8
259
+ unless current_adapter?(:IBM_DBAdapter)
260
+ # Limit for the varchar field is number of bytes and not characters for DB2. Hence the below test cases is expected to fail.
261
+ with_kcode('UTF8') do
262
+ # Event.title is limited to 5 characters
263
+ e1 = Event.create(:title => "一二三四五")
264
+ assert e1.valid?, "Could not create an event with a unique, 5 character title"
265
+ e2 = Event.create(:title => "一二三四五六七八")
266
+ assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
267
+ end
268
+ end
269
+ end
270
+
271
+ def test_validate_straight_inheritance_uniqueness
272
+ w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
273
+ assert w1.valid?, "Saving w1"
274
+
275
+ # Should use validation from base class (which is abstract)
276
+ w2 = IneptWizard.new(:name => "Rincewind", :city => "Quirm")
277
+ assert !w2.valid?, "w2 shouldn't be valid"
278
+ assert w2.errors[:name].any?, "Should have errors for name"
279
+ assert_equal ["has already been taken"], w2.errors[:name], "Should have uniqueness message for name"
280
+
281
+ w3 = Conjurer.new(:name => "Rincewind", :city => "Quirm")
282
+ assert !w3.valid?, "w3 shouldn't be valid"
283
+ assert w3.errors[:name].any?, "Should have errors for name"
284
+ assert_equal ["has already been taken"], w3.errors[:name], "Should have uniqueness message for name"
285
+
286
+ w4 = Conjurer.create(:name => "The Amazing Bonko", :city => "Quirm")
287
+ assert w4.valid?, "Saving w4"
288
+
289
+ w5 = Thaumaturgist.new(:name => "The Amazing Bonko", :city => "Lancre")
290
+ assert !w5.valid?, "w5 shouldn't be valid"
291
+ assert w5.errors[:name].any?, "Should have errors for name"
292
+ assert_equal ["has already been taken"], w5.errors[:name], "Should have uniqueness message for name"
293
+
294
+ w6 = Thaumaturgist.new(:name => "Mustrum Ridcully", :city => "Quirm")
295
+ assert !w6.valid?, "w6 shouldn't be valid"
296
+ assert w6.errors[:city].any?, "Should have errors for city"
297
+ assert_equal ["has already been taken"], w6.errors[:city], "Should have uniqueness message for city"
298
+ end
299
+ end