ibm_db 0.10.0 → 1.0.0

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,186 @@
1
+ require "cases/helper"
2
+ require 'active_record/schema_dumper'
3
+ require 'stringio'
4
+
5
+
6
+ class SchemaDumperTest < ActiveRecord::TestCase
7
+ def standard_dump
8
+ stream = StringIO.new
9
+ ActiveRecord::SchemaDumper.ignore_tables = []
10
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
11
+ stream.string
12
+ end
13
+
14
+ def test_schema_dump
15
+ output = standard_dump
16
+ assert_match %r{create_table "accounts"}, output
17
+ assert_match %r{create_table "authors"}, output
18
+ assert_no_match %r{create_table "schema_migrations"}, output
19
+ end
20
+
21
+ def test_schema_dump_excludes_sqlite_sequence
22
+ output = standard_dump
23
+ assert_no_match %r{create_table "sqlite_sequence"}, output
24
+ end
25
+
26
+ def assert_line_up(lines, pattern, required = false)
27
+ return assert(true) if lines.empty?
28
+ matches = lines.map { |line| line.match(pattern) }
29
+ assert matches.all? if required
30
+ matches.compact!
31
+ return assert(true) if matches.empty?
32
+ assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length
33
+ end
34
+
35
+ def column_definition_lines(output = standard_dump)
36
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }
37
+ end
38
+
39
+ def test_types_line_up
40
+ column_definition_lines.each do |column_set|
41
+ next if column_set.empty?
42
+
43
+ lengths = column_set.map do |column|
44
+ if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/)
45
+ match[0].length
46
+ end
47
+ end
48
+
49
+ assert_equal 1, lengths.uniq.length
50
+ end
51
+ end
52
+
53
+ def test_arguments_line_up
54
+ column_definition_lines.each do |column_set|
55
+ assert_line_up(column_set, /:default => /)
56
+ assert_line_up(column_set, /:limit => /)
57
+ assert_line_up(column_set, /:null => /)
58
+ end
59
+ end
60
+
61
+ def test_no_dump_errors
62
+ output = standard_dump
63
+ assert_no_match %r{\# Could not dump table}, output
64
+ end
65
+
66
+ def test_schema_dump_includes_not_null_columns
67
+ stream = StringIO.new
68
+
69
+ ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/]
70
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
71
+ output = stream.string
72
+ assert_match %r{:null => false}, output
73
+ end
74
+
75
+ def test_schema_dump_includes_limit_constraint_for_integer_columns
76
+ stream = StringIO.new
77
+
78
+ ActiveRecord::SchemaDumper.ignore_tables = [/^(?!integer_limits)/]
79
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
80
+ output = stream.string
81
+
82
+ if current_adapter?(:PostgreSQLAdapter)
83
+ assert_match %r{c_int_1.*:limit => 2}, output
84
+ assert_match %r{c_int_2.*:limit => 2}, output
85
+
86
+ # int 3 is 4 bytes in postgresql
87
+ assert_match %r{c_int_3.*}, output
88
+ assert_no_match %r{c_int_3.*:limit}, output
89
+
90
+ assert_match %r{c_int_4.*}, output
91
+ assert_no_match %r{c_int_4.*:limit}, output
92
+ elsif current_adapter?(:MysqlAdapter)
93
+ assert_match %r{c_int_1.*:limit => 1}, output
94
+ assert_match %r{c_int_2.*:limit => 2}, output
95
+ assert_match %r{c_int_3.*:limit => 3}, output
96
+
97
+ assert_match %r{c_int_4.*}, output
98
+ assert_no_match %r{c_int_4.*:limit}, output
99
+ elsif current_adapter?(:SQLiteAdapter)
100
+ assert_match %r{c_int_1.*:limit => 1}, output
101
+ assert_match %r{c_int_2.*:limit => 2}, output
102
+ assert_match %r{c_int_3.*:limit => 3}, output
103
+ assert_match %r{c_int_4.*:limit => 4}, output
104
+ end
105
+ assert_match %r{c_int_without_limit.*}, output
106
+ assert_no_match %r{c_int_without_limit.*:limit}, output
107
+
108
+ if current_adapter?(:SQLiteAdapter)
109
+ assert_match %r{c_int_5.*:limit => 5}, output
110
+ assert_match %r{c_int_6.*:limit => 6}, output
111
+ assert_match %r{c_int_7.*:limit => 7}, output
112
+ assert_match %r{c_int_8.*:limit => 8}, output
113
+ else
114
+ unless current_adapter?(:IBM_DBAdapter) #IBM data servers do not support limits on integer datatype
115
+ assert_match %r{c_int_5.*:limit => 8}, output
116
+ assert_match %r{c_int_6.*:limit => 8}, output
117
+ assert_match %r{c_int_7.*:limit => 8}, output
118
+ assert_match %r{c_int_8.*:limit => 8}, output
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_schema_dump_with_string_ignored_table
124
+ stream = StringIO.new
125
+
126
+ ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
127
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
128
+ output = stream.string
129
+ assert_no_match %r{create_table "accounts"}, output
130
+ assert_match %r{create_table "authors"}, output
131
+ assert_no_match %r{create_table "schema_migrations"}, output
132
+ end
133
+
134
+ def test_schema_dump_with_regexp_ignored_table
135
+ stream = StringIO.new
136
+
137
+ ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
138
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
139
+ output = stream.string
140
+ assert_no_match %r{create_table "accounts"}, output
141
+ assert_match %r{create_table "authors"}, output
142
+ assert_no_match %r{create_table "schema_migrations"}, output
143
+ end
144
+
145
+ def test_schema_dump_illegal_ignored_table_value
146
+ stream = StringIO.new
147
+ ActiveRecord::SchemaDumper.ignore_tables = [5]
148
+ assert_raise(StandardError) do
149
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
150
+ end
151
+ end
152
+
153
+ if current_adapter?(:MysqlAdapter)
154
+ def test_schema_dump_should_not_add_default_value_for_mysql_text_field
155
+ output = standard_dump
156
+ assert_match %r{t.text\s+"body",\s+:null => false$}, output
157
+ end
158
+
159
+ def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
160
+ output = standard_dump
161
+ match = output.match(%r{create_table "movies"(.*)do})
162
+ assert_not_nil(match, "nonstandardpk table not found")
163
+ assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
164
+ end
165
+
166
+ def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
167
+ output = standard_dump
168
+ assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
169
+ assert_match %r{t.binary\s+"normal_blob"$}, output
170
+ assert_match %r{t.binary\s+"medium_blob",\s+:limit => 16777215$}, output
171
+ assert_match %r{t.binary\s+"long_blob",\s+:limit => 2147483647$}, output
172
+ assert_match %r{t.text\s+"tiny_text",\s+:limit => 255$}, output
173
+ assert_match %r{t.text\s+"normal_text"$}, output
174
+ assert_match %r{t.text\s+"medium_text",\s+:limit => 16777215$}, output
175
+ assert_match %r{t.text\s+"long_text",\s+:limit => 2147483647$}, output
176
+ end
177
+ end
178
+
179
+ def test_schema_dump_includes_decimal_options
180
+ stream = StringIO.new
181
+ ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]
182
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
183
+ output = stream.string
184
+ assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output
185
+ end
186
+ end
@@ -364,6 +364,13 @@ class ValidationsTest < ActiveRecord::TestCase
364
364
  assert t2.save, "Should now save t2 as unique"
365
365
  end
366
366
 
367
+ def test_validates_uniquness_with_newline_chars
368
+ Topic.validates_uniqueness_of(:title, :case_sensitive => false)
369
+
370
+ t = Topic.new("title" => "new\nline")
371
+ assert t.save, "Should save t as unique"
372
+ end
373
+
367
374
  def test_validate_uniqueness_with_scope
368
375
  Reply.validates_uniqueness_of(:content, :scope => "parent_id")
369
376
 
@@ -451,6 +458,18 @@ class ValidationsTest < ActiveRecord::TestCase
451
458
  t2.title = nil
452
459
  assert t2.valid?, "should validate with nil"
453
460
  assert t2.save, "should save with nil"
461
+
462
+ with_kcode('UTF8') do
463
+ t_utf8 = Topic.new("title" => "Я тоже уникальный!")
464
+ assert t_utf8.save, "Should save t_utf8 as unique"
465
+
466
+ # If database hasn't UTF-8 character set, this test fails
467
+ if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
468
+ t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
469
+ assert !t2_utf8.valid?, "Shouldn't be valid"
470
+ assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
471
+ end
472
+ end
454
473
  end
455
474
 
456
475
  def test_validate_case_sensitive_uniqueness
@@ -1059,6 +1078,18 @@ class ValidationsTest < ActiveRecord::TestCase
1059
1078
  end
1060
1079
  end
1061
1080
 
1081
+ def test_validates_length_of_with_block
1082
+ Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least %d words.",
1083
+ :tokenizer => lambda {|str| str.scan(/\w+/) }
1084
+ t = Topic.create!(:content => "this content should be long enough")
1085
+ assert t.valid?
1086
+
1087
+ t.content = "not long enough"
1088
+ assert !t.valid?
1089
+ assert t.errors.on(:content)
1090
+ assert_equal "Your essay must be at least 5 words.", t.errors[:content]
1091
+ end
1092
+
1062
1093
  def test_validates_size_of_association_utf8
1063
1094
  with_kcode('UTF8') do
1064
1095
  assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 }
@@ -1379,6 +1410,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1379
1410
  INTEGERS = [0, 10, -10] + INTEGER_STRINGS
1380
1411
  BIGDECIMAL = BIGDECIMAL_STRINGS.collect! { |bd| BigDecimal.new(bd) }
1381
1412
  JUNK = ["not a number", "42 not a number", "0xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"]
1413
+ INFINITY = [1.0/0.0]
1382
1414
 
1383
1415
  def setup
1384
1416
  Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
@@ -1390,27 +1422,27 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1390
1422
  Topic.validates_numericality_of :approved
1391
1423
 
1392
1424
  invalid!(NIL + BLANK + JUNK)
1393
- valid!(FLOATS + INTEGERS + BIGDECIMAL)
1425
+ valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
1394
1426
  end
1395
1427
 
1396
1428
  def test_validates_numericality_of_with_nil_allowed
1397
1429
  Topic.validates_numericality_of :approved, :allow_nil => true
1398
1430
 
1399
1431
  invalid!(BLANK + JUNK)
1400
- valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL)
1432
+ valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
1401
1433
  end
1402
1434
 
1403
1435
  def test_validates_numericality_of_with_integer_only
1404
1436
  Topic.validates_numericality_of :approved, :only_integer => true
1405
1437
 
1406
- invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL)
1438
+ invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
1407
1439
  valid!(INTEGERS)
1408
1440
  end
1409
1441
 
1410
1442
  def test_validates_numericality_of_with_integer_only_and_nil_allowed
1411
1443
  Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
1412
1444
 
1413
- invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL)
1445
+ invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
1414
1446
  valid!(NIL + INTEGERS)
1415
1447
  end
1416
1448
 
@@ -1431,7 +1463,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1431
1463
  def test_validates_numericality_with_equal_to
1432
1464
  Topic.validates_numericality_of :approved, :equal_to => 10
1433
1465
 
1434
- invalid!([-10, 11], 'must be equal to 10')
1466
+ invalid!([-10, 11] + INFINITY, 'must be equal to 10')
1435
1467
  valid!([10])
1436
1468
  end
1437
1469
 
@@ -66,6 +66,7 @@ ActiveRecord::Schema.define do
66
66
  create_table :categories, :force => true do |t|
67
67
  t.string :name, :null => false
68
68
  t.string :type
69
+ t.integer :categorizations_count
69
70
  end
70
71
 
71
72
  create_table :categories_posts, :force => true, :id => false do |t|
@@ -418,6 +419,13 @@ ActiveRecord::Schema.define do
418
419
  t.column :key, :string
419
420
  end
420
421
 
422
+ create_table :integer_limits, :force => true do |t|
423
+ t.integer :"c_int_without_limit"
424
+ (1..8).each do |i|
425
+ t.integer :"c_int_#{i}", :limit => i
426
+ end
427
+ end
428
+
421
429
  except ['SQLite','IBM_DB'] do
422
430
  # fk_test_has_fk should be before fk_test_has_pk
423
431
  create_table :fk_test_has_fk, :force => true do |t|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IBM
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-03 00:00:00 -07:00
12
+ date: 2008-11-05 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -32,54 +33,56 @@ extra_rdoc_files:
32
33
  - README
33
34
  - MANIFEST
34
35
  files:
36
+ - README
37
+ - lib
38
+ - lib/active_record
39
+ - lib/active_record/connection_adapters
40
+ - lib/active_record/connection_adapters/ibm_db_adapter.rb
41
+ - lib/active_record/vendor
42
+ - lib/active_record/vendor/db2-i5-zOS.yaml
43
+ - lib/IBM_DB.rb
35
44
  - test
36
- - test/ibm_db_test.rb
45
+ - test/connections
46
+ - test/connections/native_ibm_db
47
+ - test/connections/native_ibm_db/connection.rb
48
+ - test/models
49
+ - test/models/warehouse_thing.rb
37
50
  - test/cases
38
- - test/cases/adapter_test.rb
39
- - test/cases/calculations_test.rb
40
- - test/cases/query_cache_test.rb
41
51
  - test/cases/finder_test.rb
52
+ - test/cases/schema_dumper_test.rb
42
53
  - test/cases/validations_test.rb
43
- - test/cases/associations
44
- - test/cases/associations/join_model_test.rb
45
- - test/cases/associations/cascaded_eager_loading_test.rb
46
- - test/cases/associations/eager_test.rb
47
- - test/cases/associations/has_and_belongs_to_many_associations_test.rb
48
- - test/cases/base_test.rb
49
54
  - test/cases/fixtures_test.rb
55
+ - test/cases/calculations_test.rb
56
+ - test/cases/query_cache_test.rb
50
57
  - test/cases/migration_test.rb
51
- - test/models
52
- - test/models/warehouse_thing.rb
58
+ - test/cases/base_test.rb
59
+ - test/cases/associations
60
+ - test/cases/associations/has_many_through_associations_test.rb
61
+ - test/cases/associations/has_and_belongs_to_many_associations_test.rb
62
+ - test/cases/associations/eager_test.rb
63
+ - test/cases/associations/cascaded_eager_loading_test.rb
64
+ - test/cases/associations/join_model_test.rb
65
+ - test/cases/adapter_test.rb
53
66
  - test/schema
67
+ - test/schema/zOS
68
+ - test/schema/zOS/ibm_db_specific_schema.rb
54
69
  - test/schema/ids
55
70
  - test/schema/ids/ibm_db_specific_schema.rb
56
71
  - test/schema/i5
57
72
  - test/schema/i5/ibm_db_specific_schema.rb
58
- - test/schema/zOS
59
- - test/schema/zOS/ibm_db_specific_schema.rb
60
73
  - test/schema/schema.rb
61
74
  - test/schema/luw
62
75
  - test/schema/luw/ibm_db_specific_schema.rb
63
- - test/connections
64
- - test/connections/native_ibm_db
65
- - test/connections/native_ibm_db/connection.rb
66
- - README
67
- - CHANGES
68
- - lib
69
- - lib/IBM_DB.rb
70
- - lib/active_record
71
- - lib/active_record/connection_adapters
72
- - lib/active_record/connection_adapters/ibm_db_adapter.rb
73
- - lib/active_record/vendor
74
- - lib/active_record/vendor/db2-i5-zOS.yaml
75
- - init.rb
76
- - MANIFEST
77
- - LICENSE
76
+ - test/ibm_db_test.rb
78
77
  - ext
79
78
  - ext/ruby_ibm_db.h
80
79
  - ext/Makefile.nt32
81
80
  - ext/extconf.rb
82
81
  - ext/ibm_db.c
82
+ - LICENSE
83
+ - init.rb
84
+ - CHANGES
85
+ - MANIFEST
83
86
  has_rdoc: true
84
87
  homepage: http://rubyforge.org/projects/rubyibm/
85
88
  post_install_message:
@@ -102,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
105
  requirements:
103
106
  - ActiveRecord, at least 1.15.1
104
107
  rubyforge_project: rubyibm
105
- rubygems_version: 1.0.0
108
+ rubygems_version: 1.3.0
106
109
  signing_key:
107
110
  specification_version: 2
108
111
  summary: "Rails Driver and Adapter for IBM Data Servers: {DB2 on Linux/Unix/Windows, DB2 on zOS, DB2 on i5/OS, Informix (IDS)}"