Methods
- S
- T
-
- test_charset,
- test_collation,
- test_create_record_with_pk_as_zero,
- test_current_database,
- test_data_source_exists?,
- test_data_sources,
- test_disable_referential_integrity,
- test_foreign_key_violations_are_translated_to_specific_exception,
- test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false,
- test_indexes,
- test_log_invalid_encoding,
- test_not_specifying_database_name_for_cross_database_selects,
- test_passing_arguments_to_tables_is_deprecated,
- test_remove_index_when_name_and_wrong_column_name_specified,
- test_reset_empty_table_with_custom_pk,
- test_reset_table_with_non_integer_pk,
- test_select_all_always_return_activerecord_result,
- test_select_methods_passing_a_association_relation,
- test_select_methods_passing_a_relation,
- test_show_nonexistent_variable_returns_nil,
- test_table_alias,
- test_table_exists?,
- test_table_exists_checking_both_tables_and_views_is_deprecated,
- test_tables,
- test_tables_returning_both_tables_and_views_is_deprecated,
- test_uniqueness_violations_are_translated_to_specific_exception,
- test_update_prepared_statement,
- test_value_limit_violations_are_translated_to_specific_exception
Instance Public methods
setup()
Link
test_charset()
Link
test_collation()
Link
test_create_record_with_pk_as_zero()
Link
test_current_database()
Link
test_data_source_exists?()
Link
# File activerecord/test/cases/adapter_test.rb, line 62 def test_data_source_exists? assert @connection.data_source_exists?("accounts") assert @connection.data_source_exists?(:accounts) assert_not @connection.data_source_exists?("nonexistingtable") assert_not @connection.data_source_exists?(nil) end
test_data_sources()
Link
# File activerecord/test/cases/adapter_test.rb, line 54 def test_data_sources data_sources = @connection.data_sources assert data_sources.include?("accounts") assert data_sources.include?("authors") assert data_sources.include?("tasks") assert data_sources.include?("topics") end
test_disable_referential_integrity()
Link
# File activerecord/test/cases/adapter_test.rb, line 225 def test_disable_referential_integrity assert_nothing_raised do @connection.disable_referential_integrity do # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method if @connection.prefetch_primary_key? id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id")) @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)" else @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)" end # should delete created record as otherwise disable_referential_integrity will try to enable constraints after executed block # and will fail (at least on Oracle) @connection.execute "DELETE FROM fk_test_has_fk" end end end
test_foreign_key_violations_are_translated_to_specific_exception()
Link
# File activerecord/test/cases/adapter_test.rb, line 188 def test_foreign_key_violations_are_translated_to_specific_exception error = assert_raises(ActiveRecord::InvalidForeignKey) do # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method if @connection.prefetch_primary_key? id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id")) @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)" else @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)" end end assert_not_nil error.cause end
test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false()
Link
# File activerecord/test/cases/adapter_test.rb, line 202 def test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false klass_has_fk = Class.new(ActiveRecord::Base) do self.table_name = 'fk_test_has_fk' end error = assert_raises(ActiveRecord::InvalidForeignKey) do has_fk = klass_has_fk.new has_fk.fk_id = 1231231231 has_fk.save(validate: false) end assert_not_nil error.cause end
test_indexes()
Link
# File activerecord/test/cases/adapter_test.rb, line 69 def test_indexes idx_name = "accounts_idx" if @connection.respond_to?(:indexes) indexes = @connection.indexes("accounts") assert indexes.empty? @connection.add_index :accounts, :firm_id, :name => idx_name indexes = @connection.indexes("accounts") assert_equal "accounts", indexes.first.table assert_equal idx_name, indexes.first.name assert !indexes.first.unique assert_equal ["firm_id"], indexes.first.columns else warn "#{@connection.class} does not respond to #indexes" end ensure @connection.remove_index(:accounts, :name => idx_name) rescue nil end
test_log_invalid_encoding()
Link
# File activerecord/test/cases/adapter_test.rb, line 273 def test_log_invalid_encoding error = assert_raise ActiveRecord::StatementInvalid do @connection.send :log, "SELECT 'ы' FROM DUAL" do raise 'ы'.force_encoding(Encoding::ASCII_8BIT) end end assert_not_nil error.cause end
test_not_specifying_database_name_for_cross_database_selects()
Link
# File activerecord/test/cases/adapter_test.rb, line 124 def test_not_specifying_database_name_for_cross_database_selects begin assert_nothing_raised do ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database)) config = ARTest.connection_config ActiveRecord::Base.connection.execute( "SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " "FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses" ) end ensure ActiveRecord::Base.establish_connection :arunit end end
test_passing_arguments_to_tables_is_deprecated()
Link
test_remove_index_when_name_and_wrong_column_name_specified()
Link
# File activerecord/test/cases/adapter_test.rb, line 90 def test_remove_index_when_name_and_wrong_column_name_specified index_name = "accounts_idx" @connection.add_index :accounts, :firm_id, :name => index_name assert_raises ArgumentError do @connection.remove_index :accounts, :name => index_name, :column => :wrong_column_name end ensure @connection.remove_index(:accounts, :name => index_name) end
test_reset_empty_table_with_custom_pk()
Link
test_reset_table_with_non_integer_pk()
Link
# File activerecord/test/cases/adapter_test.rb, line 169 def test_reset_table_with_non_integer_pk Subscriber.delete_all Subscriber.connection.reset_pk_sequence! 'subscribers' sub = Subscriber.new(:name => 'robert drake') sub.id = 'bob drake' assert_nothing_raised { sub.save! } end
test_select_all_always_return_activerecord_result()
Link
test_select_methods_passing_a_association_relation()
Link
# File activerecord/test/cases/adapter_test.rb, line 247 def test_select_methods_passing_a_association_relation author = Author.create!(name: 'john') Post.create!(author: author, title: 'foo', body: 'bar') query = author.posts.where(title: 'foo').select(:title) assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes)) assert_equal({"title" => "foo"}, @connection.select_one(query)) assert @connection.select_all(query).is_a?(ActiveRecord::Result) assert_equal "foo", @connection.select_value(query) assert_equal ["foo"], @connection.select_values(query) end
test_select_methods_passing_a_relation()
Link
# File activerecord/test/cases/adapter_test.rb, line 258 def test_select_methods_passing_a_relation Post.create!(title: 'foo', body: 'bar') query = Post.where(title: 'foo').select(:title) assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes)) assert_equal({"title" => "foo"}, @connection.select_one(query)) assert @connection.select_all(query).is_a?(ActiveRecord::Result) assert_equal "foo", @connection.select_value(query) assert_equal ["foo"], @connection.select_values(query) end
test_show_nonexistent_variable_returns_nil()
Link
test_table_alias()
Link
# File activerecord/test/cases/adapter_test.rb, line 141 def test_table_alias def @connection.test_table_alias_length() 10; end class << @connection alias_method :old_table_alias_length, :table_alias_length alias_method :table_alias_length, :test_table_alias_length end assert_equal 'posts', @connection.table_alias_for('posts') assert_equal 'posts_comm', @connection.table_alias_for('posts_comments') assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts') class << @connection remove_method :table_alias_length alias_method :table_alias_length, :old_table_alias_length end end
test_table_exists?()
Link
test_table_exists_checking_both_tables_and_views_is_deprecated()
Link
test_tables()
Link
# File activerecord/test/cases/adapter_test.rb, line 33 def test_tables tables = nil ActiveSupport::Deprecation.silence { tables = @connection.tables } assert tables.include?("accounts") assert tables.include?("authors") assert tables.include?("tasks") assert tables.include?("topics") end
test_tables_returning_both_tables_and_views_is_deprecated()
Link
test_uniqueness_violations_are_translated_to_specific_exception()
Link
# File activerecord/test/cases/adapter_test.rb, line 178 def test_uniqueness_violations_are_translated_to_specific_exception @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" error = assert_raises(ActiveRecord::RecordNotUnique) do @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" end assert_not_nil error.cause end
test_update_prepared_statement()
Link
# File activerecord/test/cases/adapter_test.rb, line 17 def test_update_prepared_statement b = Book.create(name: "my \x00 book") b.reload assert_equal "my \x00 book", b.name b.update_attributes(name: "my other \x00 book") b.reload assert_equal "my other \x00 book", b.name end
test_value_limit_violations_are_translated_to_specific_exception()
Link