ibm_db 2.5.27-x86-mingw32 → 2.6.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +5 -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 -264
  8. data/ext/extconf_MacOS.rb +269 -0
  9. data/ext/ibm_db.c +1 -1
  10. data/ext/ruby_ibm_db.h +241 -241
  11. data/init.rb +41 -41
  12. data/lib/IBM_DB.rb +27 -3
  13. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +3290 -3290
  14. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +1 -1
  15. data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -328
  16. data/lib/mswin32/ibm_db.rb +104 -20
  17. data/lib/mswin32/rb19x/ibm_db.so +0 -0
  18. data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
  19. data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
  20. data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
  21. data/test/cases/adapter_test.rb +207 -207
  22. data/test/cases/associations/belongs_to_associations_test.rb +711 -711
  23. data/test/cases/associations/cascaded_eager_loading_test.rb +181 -181
  24. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +851 -851
  25. data/test/cases/associations/join_model_test.rb +743 -743
  26. data/test/cases/attribute_methods_test.rb +822 -822
  27. data/test/cases/base_test.rb +2133 -2133
  28. data/test/cases/calculations_test.rb +482 -482
  29. data/test/cases/migration_test.rb +2408 -2408
  30. data/test/cases/persistence_test.rb +642 -642
  31. data/test/cases/query_cache_test.rb +257 -257
  32. data/test/cases/relations_test.rb +1182 -1182
  33. data/test/cases/schema_dumper_test.rb +256 -256
  34. data/test/cases/transaction_callbacks_test.rb +300 -300
  35. data/test/cases/validations/uniqueness_validation_test.rb +299 -299
  36. data/test/cases/xml_serialization_test.rb +408 -408
  37. data/test/config.yml +154 -154
  38. data/test/connections/native_ibm_db/connection.rb +43 -43
  39. data/test/ibm_db_test.rb +24 -24
  40. data/test/models/warehouse_thing.rb +4 -4
  41. data/test/schema/schema.rb +751 -751
  42. metadata +31 -16
@@ -1,32 +1,116 @@
1
+ needToDownloadedCLIPackage = false
2
+ IBM_DB_HOME = ENV['IBM_DB_HOME']
3
+ cliPackagePath = File.dirname(__FILE__) + '/../clidriver'
4
+
5
+ if ((IBM_DB_HOME == nil || IBM_DB_HOME == '') && (!Dir.exists?(cliPackagePath)))
6
+ needToDownloadedCLIPackage = true
7
+ end
8
+
9
+ def downloadCLIPackage(destination, link = nil)
10
+ if(link.nil?)
11
+ downloadLink = DOWNLOADLINK
12
+ else
13
+ downloadLink = link
14
+ end
15
+
16
+ uri = URI.parse(downloadLink)
17
+
18
+ filename = "#{destination}/clidriver.zip"
19
+
20
+ headers = { 'Accept-Encoding' => 'identity', }
21
+
22
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
23
+ http = Net::HTTP.new(uri.host, uri.port)
24
+ response = http.request(request)
25
+
26
+ f = open(filename, 'wb')
27
+ f.write(response.body)
28
+ f.close()
29
+
30
+ filename
31
+ end
32
+
33
+ def unzipCLIPackage(archive, destination)
34
+ if (RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/)
35
+ Archive::Zip.extract(archive, destination)
36
+ end
37
+ end
38
+
39
+
40
+ # Download CLI package
41
+ if(needToDownloadedCLIPackage == true)
42
+ require 'net/http'
43
+ require 'open-uri'
44
+ require 'rubygems/package'
45
+ require 'fileutils'
46
+ require 'archive/zip'
47
+
48
+ TAR_LONGLINK = '././@LongLink'
49
+
50
+ machine_bits = ['ibm'].pack('p').size * 8
51
+
52
+ is64Bit = true
53
+
54
+ if machine_bits == 64
55
+ is64Bit = true
56
+ else
57
+ is64Bit = false
58
+ end
59
+
60
+ if (RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/)
61
+ if(is64Bit)
62
+ DOWNLOADLINK = "http://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/ntx64_odbc_cli.zip"
63
+ else
64
+ DOWNLOADLINK = "http://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/nt32_odbc_cli.zip"
65
+ end
66
+ end
67
+
68
+ destination = "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}"
69
+ archive = downloadCLIPackage(destination)
70
+ unzipCLIPackage(archive,destination)
71
+ end
72
+
73
+
74
+ if(IBM_DB_HOME !=nil && IBM_DB_HOME != '')
75
+ bin_path = IBM_DB_HOME+'/bin'
76
+ ENV['PATH'] = ENV['PATH'] + ';.;' + bin_path
77
+ end
78
+
79
+ if (RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/)
80
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
81
+ ENV['PATH'] = ENV['PATH'] + ';.;' + File.expand_path(File.dirname(__FILE__) + '/../clidriver/bin')
82
+ end
83
+
84
+
1
85
  if (RUBY_VERSION =~ /1.9./ )
2
- require 'mswin32/rb19x/ibm_db.so'
86
+ require 'rb19x/ibm_db.so'
3
87
  elsif (RUBY_VERSION =~ /2.0./)
4
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
5
- machine_bits = ['ibm'].pack('p').size * 8
88
+ #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
89
+ machine_bits = ['ibm'].pack('p').size * 8
6
90
  if machine_bits == 64
7
- #require 'mswin32/rb2x/x64/ibm_db.so'
8
- raise NotImplementedError, "ibm_db with Ruby 2.0 64-bit on Windows platform is not supported. Refer to README for more details"
91
+ #require 'rb2x/x64/ibm_db.so'
92
+ raise NotImplementedError, "ibm_db with Ruby 2.0 64-bit on Windows platform is not supported. Refer to README for more details"
9
93
  else
10
- require 'mswin32/rb2x/i386/ibm_db.so'
94
+ require 'rb2x/i386/ibm_db.so'
11
95
  end
12
96
  elsif (RUBY_VERSION =~ /2.1./)
13
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
14
- machine_bits = ['ibm'].pack('p').size * 8
97
+ #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
98
+ machine_bits = ['ibm'].pack('p').size * 8
15
99
  if machine_bits == 64
16
- #require 'mswin32/rb21x/x64/ibm_db.so'
17
- raise NotImplementedError, "ibm_db with Ruby 2.1 64-bit on Windows platform is not supported. Refer to README for more details"
100
+ #require 'rb21x/x64/ibm_db.so'
101
+ raise NotImplementedError, "ibm_db with Ruby 2.1 64-bit on Windows platform is not supported. Refer to README for more details"
18
102
  else
19
- require 'mswin32/rb21x/i386/ibm_db.so'
103
+ require 'rb21x/i386/ibm_db.so'
20
104
  end
21
105
  elsif (RUBY_VERSION =~ /2.2./ )
22
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
23
- machine_bits = ['ibm'].pack('p').size * 8
24
- if machine_bits == 64
25
- #require 'mswin32/rb22x/x64/ibm_db.so'
26
- raise NotImplementedError, "ibm_db with Ruby 2.2 64-bit on Windows platform is not supported. Refer to README for more details"
27
- else
28
- require 'mswin32/rb22x/i386/ibm_db.so'
29
- end
106
+ #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
107
+ machine_bits = ['ibm'].pack('p').size * 8
108
+ if machine_bits == 64
109
+ #require 'rb22x/x64/ibm_db.so'
110
+ raise NotImplementedError, "ibm_db with Ruby 2.2 64-bit on Windows platform is not supported. Refer to README for more details"
111
+ else
112
+ require 'rb22x/i386/ibm_db.so'
113
+ end
30
114
  else
31
- require 'mswin32/rb18x/ibm_db.so'
115
+ require 'rb18x/ibm_db.so'
32
116
  end
Binary file
Binary file
Binary file
Binary file
@@ -1,207 +1,207 @@
1
- require "cases/helper"
2
-
3
- module ActiveRecord
4
- class AdapterTest < ActiveRecord::TestCase
5
- def setup
6
- @connection = ActiveRecord::Base.connection
7
- end
8
-
9
- if current_adapter?(:IBM_DBAdapter)
10
- def test_a_connection_attributes
11
- if @connection.servertype.class.name.include?('::IBM_IDS')
12
- return
13
- end
14
- if @connection.respond_to?(:schema)
15
- previous_schema = ActiveRecord::Base.connection.schema
16
- ActiveRecord::Base.connection.schema = 'SYSCAT'
17
- assert_equal 'SYSCAT', ActiveRecord::Base.connection.schema
18
- ActiveRecord::Base.connection.schema = previous_schema
19
- else
20
- warn "#{@connection.class} does not support client connection attribute schema_name"
21
- end
22
-
23
- if @connection.respond_to?(:app_user)
24
- ActiveRecord::Base.connection.app_user = 'new_user'
25
- assert_equal 'new_user', ActiveRecord::Base.connection.app_user
26
- else
27
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_USER"
28
- end
29
-
30
- if @connection.respond_to?(:account)
31
- ActiveRecord::Base.connection.account = 'new_acct'
32
- assert_equal 'new_acct', ActiveRecord::Base.connection.account
33
- else
34
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_ACCTSTR"
35
- end
36
-
37
- if @connection.respond_to?(:application)
38
- ActiveRecord::Base.connection.application = 'new_app'
39
- assert_equal 'new_app', ActiveRecord::Base.connection.application
40
- else
41
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
42
- end
43
-
44
- if @connection.respond_to?(:workstation)
45
- ActiveRecord::Base.connection.workstation = 'new_wrkst'
46
- assert_equal 'new_wrkst', ActiveRecord::Base.connection.workstation
47
- else
48
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_WRKSTNNAME"
49
- end
50
- end
51
- end
52
-
53
- def test_tables
54
- tables = @connection.tables
55
- assert tables.include?("accounts")
56
- assert tables.include?("authors")
57
- assert tables.include?("tasks")
58
- assert tables.include?("topics")
59
- end
60
-
61
- def test_table_exists?
62
- assert @connection.table_exists?("accounts")
63
- assert !@connection.table_exists?("nonexistingtable")
64
- assert !@connection.table_exists?(nil)
65
- end
66
-
67
- def test_indexes
68
- idx_name = "accounts_idx"
69
-
70
- if @connection.respond_to?(:indexes)
71
- indexes = @connection.indexes("accounts")
72
- assert indexes.empty?
73
-
74
- @connection.add_index :accounts, :firm_id, :name => idx_name
75
- indexes = @connection.indexes("accounts")
76
- assert_equal "accounts", indexes.first.table
77
- # OpenBase does not have the concept of a named index
78
- # Indexes are merely properties of columns.
79
- assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
80
- assert !indexes.first.unique
81
- assert_equal ["firm_id"], indexes.first.columns
82
- else
83
- warn "#{@connection.class} does not respond to #indexes"
84
- end
85
-
86
- ensure
87
- @connection.remove_index(:accounts, :name => idx_name) rescue nil
88
- end
89
-
90
- def test_current_database
91
- if @connection.respond_to?(:current_database)
92
- assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
93
- end
94
- end
95
-
96
- if current_adapter?(:MysqlAdapter)
97
- def test_charset
98
- assert_not_nil @connection.charset
99
- assert_not_equal 'character_set_database', @connection.charset
100
- assert_equal @connection.show_variable('character_set_database'), @connection.charset
101
- end
102
-
103
- def test_collation
104
- assert_not_nil @connection.collation
105
- assert_not_equal 'collation_database', @connection.collation
106
- assert_equal @connection.show_variable('collation_database'), @connection.collation
107
- end
108
-
109
- def test_show_nonexistent_variable_returns_nil
110
- assert_nil @connection.show_variable('foo_bar_baz')
111
- end
112
-
113
- def test_not_specifying_database_name_for_cross_database_selects
114
- begin
115
- assert_nothing_raised do
116
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
117
-
118
- config = ARTest.connection_config
119
- ActiveRecord::Base.connection.execute(
120
- "SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
121
- "FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
122
- )
123
- end
124
- ensure
125
- ActiveRecord::Base.establish_connection 'arunit'
126
- end
127
- end
128
- end
129
-
130
- def test_table_alias
131
- def @connection.test_table_alias_length() 10; end
132
- class << @connection
133
- alias_method :old_table_alias_length, :table_alias_length
134
- alias_method :table_alias_length, :test_table_alias_length
135
- end
136
-
137
- assert_equal 'posts', @connection.table_alias_for('posts')
138
- assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
139
- assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
140
-
141
- class << @connection
142
- remove_method :table_alias_length
143
- alias_method :table_alias_length, :old_table_alias_length
144
- end
145
- end
146
-
147
- # test resetting sequences in odd tables in postgreSQL
148
- if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
149
- require 'models/movie'
150
- require 'models/subscriber'
151
-
152
- def test_reset_empty_table_with_custom_pk
153
- Movie.delete_all
154
- Movie.connection.reset_pk_sequence! 'movies'
155
- assert_equal 1, Movie.create(:name => 'fight club').id
156
- end
157
-
158
- if ActiveRecord::Base.connection.adapter_name != "FrontBase"
159
- def test_reset_table_with_non_integer_pk
160
- Subscriber.delete_all
161
- Subscriber.connection.reset_pk_sequence! 'subscribers'
162
- sub = Subscriber.new(:name => 'robert drake')
163
- sub.id = 'bob drake'
164
- assert_nothing_raised { sub.save! }
165
- end
166
- end
167
- end
168
-
169
- def test_uniqueness_violations_are_translated_to_specific_exception
170
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
171
- assert_raises(ActiveRecord::RecordNotUnique) do
172
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
173
- end
174
- end
175
-
176
- def test_foreign_key_violations_are_translated_to_specific_exception
177
- unless @connection.adapter_name == 'SQLite'
178
- assert_raises(ActiveRecord::InvalidForeignKey) do
179
- # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
180
- if @connection.prefetch_primary_key?
181
- id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
182
- @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
183
- else
184
- @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
185
- end
186
- end
187
- end
188
- end
189
-
190
- def test_disable_referential_integrity
191
- assert_nothing_raised do
192
- @connection.disable_referential_integrity do
193
- # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
194
- if @connection.prefetch_primary_key?
195
- id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
196
- @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
197
- else
198
- @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
199
- end
200
- # should deleted created record as otherwise disable_referential_integrity will try to enable contraints after executed block
201
- # and will fail (at least on Oracle)
202
- @connection.execute "DELETE FROM fk_test_has_fk"
203
- end
204
- end
205
- end
206
- end
207
- end
1
+ require "cases/helper"
2
+
3
+ module ActiveRecord
4
+ class AdapterTest < ActiveRecord::TestCase
5
+ def setup
6
+ @connection = ActiveRecord::Base.connection
7
+ end
8
+
9
+ if current_adapter?(:IBM_DBAdapter)
10
+ def test_a_connection_attributes
11
+ if @connection.servertype.class.name.include?('::IBM_IDS')
12
+ return
13
+ end
14
+ if @connection.respond_to?(:schema)
15
+ previous_schema = ActiveRecord::Base.connection.schema
16
+ ActiveRecord::Base.connection.schema = 'SYSCAT'
17
+ assert_equal 'SYSCAT', ActiveRecord::Base.connection.schema
18
+ ActiveRecord::Base.connection.schema = previous_schema
19
+ else
20
+ warn "#{@connection.class} does not support client connection attribute schema_name"
21
+ end
22
+
23
+ if @connection.respond_to?(:app_user)
24
+ ActiveRecord::Base.connection.app_user = 'new_user'
25
+ assert_equal 'new_user', ActiveRecord::Base.connection.app_user
26
+ else
27
+ warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_USER"
28
+ end
29
+
30
+ if @connection.respond_to?(:account)
31
+ ActiveRecord::Base.connection.account = 'new_acct'
32
+ assert_equal 'new_acct', ActiveRecord::Base.connection.account
33
+ else
34
+ warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_ACCTSTR"
35
+ end
36
+
37
+ if @connection.respond_to?(:application)
38
+ ActiveRecord::Base.connection.application = 'new_app'
39
+ assert_equal 'new_app', ActiveRecord::Base.connection.application
40
+ else
41
+ warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
42
+ end
43
+
44
+ if @connection.respond_to?(:workstation)
45
+ ActiveRecord::Base.connection.workstation = 'new_wrkst'
46
+ assert_equal 'new_wrkst', ActiveRecord::Base.connection.workstation
47
+ else
48
+ warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_WRKSTNNAME"
49
+ end
50
+ end
51
+ end
52
+
53
+ def test_tables
54
+ tables = @connection.tables
55
+ assert tables.include?("accounts")
56
+ assert tables.include?("authors")
57
+ assert tables.include?("tasks")
58
+ assert tables.include?("topics")
59
+ end
60
+
61
+ def test_table_exists?
62
+ assert @connection.table_exists?("accounts")
63
+ assert !@connection.table_exists?("nonexistingtable")
64
+ assert !@connection.table_exists?(nil)
65
+ end
66
+
67
+ def test_indexes
68
+ idx_name = "accounts_idx"
69
+
70
+ if @connection.respond_to?(:indexes)
71
+ indexes = @connection.indexes("accounts")
72
+ assert indexes.empty?
73
+
74
+ @connection.add_index :accounts, :firm_id, :name => idx_name
75
+ indexes = @connection.indexes("accounts")
76
+ assert_equal "accounts", indexes.first.table
77
+ # OpenBase does not have the concept of a named index
78
+ # Indexes are merely properties of columns.
79
+ assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
80
+ assert !indexes.first.unique
81
+ assert_equal ["firm_id"], indexes.first.columns
82
+ else
83
+ warn "#{@connection.class} does not respond to #indexes"
84
+ end
85
+
86
+ ensure
87
+ @connection.remove_index(:accounts, :name => idx_name) rescue nil
88
+ end
89
+
90
+ def test_current_database
91
+ if @connection.respond_to?(:current_database)
92
+ assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
93
+ end
94
+ end
95
+
96
+ if current_adapter?(:MysqlAdapter)
97
+ def test_charset
98
+ assert_not_nil @connection.charset
99
+ assert_not_equal 'character_set_database', @connection.charset
100
+ assert_equal @connection.show_variable('character_set_database'), @connection.charset
101
+ end
102
+
103
+ def test_collation
104
+ assert_not_nil @connection.collation
105
+ assert_not_equal 'collation_database', @connection.collation
106
+ assert_equal @connection.show_variable('collation_database'), @connection.collation
107
+ end
108
+
109
+ def test_show_nonexistent_variable_returns_nil
110
+ assert_nil @connection.show_variable('foo_bar_baz')
111
+ end
112
+
113
+ def test_not_specifying_database_name_for_cross_database_selects
114
+ begin
115
+ assert_nothing_raised do
116
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
117
+
118
+ config = ARTest.connection_config
119
+ ActiveRecord::Base.connection.execute(
120
+ "SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
121
+ "FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
122
+ )
123
+ end
124
+ ensure
125
+ ActiveRecord::Base.establish_connection 'arunit'
126
+ end
127
+ end
128
+ end
129
+
130
+ def test_table_alias
131
+ def @connection.test_table_alias_length() 10; end
132
+ class << @connection
133
+ alias_method :old_table_alias_length, :table_alias_length
134
+ alias_method :table_alias_length, :test_table_alias_length
135
+ end
136
+
137
+ assert_equal 'posts', @connection.table_alias_for('posts')
138
+ assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
139
+ assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
140
+
141
+ class << @connection
142
+ remove_method :table_alias_length
143
+ alias_method :table_alias_length, :old_table_alias_length
144
+ end
145
+ end
146
+
147
+ # test resetting sequences in odd tables in postgreSQL
148
+ if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
149
+ require 'models/movie'
150
+ require 'models/subscriber'
151
+
152
+ def test_reset_empty_table_with_custom_pk
153
+ Movie.delete_all
154
+ Movie.connection.reset_pk_sequence! 'movies'
155
+ assert_equal 1, Movie.create(:name => 'fight club').id
156
+ end
157
+
158
+ if ActiveRecord::Base.connection.adapter_name != "FrontBase"
159
+ def test_reset_table_with_non_integer_pk
160
+ Subscriber.delete_all
161
+ Subscriber.connection.reset_pk_sequence! 'subscribers'
162
+ sub = Subscriber.new(:name => 'robert drake')
163
+ sub.id = 'bob drake'
164
+ assert_nothing_raised { sub.save! }
165
+ end
166
+ end
167
+ end
168
+
169
+ def test_uniqueness_violations_are_translated_to_specific_exception
170
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
171
+ assert_raises(ActiveRecord::RecordNotUnique) do
172
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
173
+ end
174
+ end
175
+
176
+ def test_foreign_key_violations_are_translated_to_specific_exception
177
+ unless @connection.adapter_name == 'SQLite'
178
+ assert_raises(ActiveRecord::InvalidForeignKey) do
179
+ # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
180
+ if @connection.prefetch_primary_key?
181
+ id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
182
+ @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
183
+ else
184
+ @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ def test_disable_referential_integrity
191
+ assert_nothing_raised do
192
+ @connection.disable_referential_integrity do
193
+ # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
194
+ if @connection.prefetch_primary_key?
195
+ id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
196
+ @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
197
+ else
198
+ @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
199
+ end
200
+ # should deleted created record as otherwise disable_referential_integrity will try to enable contraints after executed block
201
+ # and will fail (at least on Oracle)
202
+ @connection.execute "DELETE FROM fk_test_has_fk"
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end