提交 1e8d5e62 编写于 作者: A Akira Matsuda

Merge branch 'isolating_tests'

Now we're almost ready to remove this: https://github.com/rails/rails/blob/5294ad8/activesupport/lib/active_support/test_case.rb#L29
......@@ -751,13 +751,17 @@ def app
assert_equal "http://bar.com/foo", foos_url
end
test "test can override default url options" do
def test_can_override_default_url_options
original_host = default_url_options.dup
default_url_options[:host] = "foobar.com"
assert_equal "http://foobar.com/foo", foos_url
get "/bar"
assert_response :success
assert_equal "http://foobar.com/foo", foos_url
ensure
ActionDispatch::Integration::Session.default_url_options = self.default_url_options = original_host
end
test "current request path parameters are recalled" do
......
......@@ -9,14 +9,20 @@ class LocalizedTemplatesTest < ActionController::TestCase
tests LocalizedController
def test_localized_template_is_used
old_locale = I18n.locale
I18n.locale = :de
get :hello_world
assert_equal "Gutten Tag", @response.body
ensure
I18n.locale = old_locale
end
def test_default_locale_template_is_used_when_locale_is_missing
old_locale = I18n.locale
I18n.locale = :dk
get :hello_world
assert_equal "Hello World", @response.body
ensure
I18n.locale = old_locale
end
end
\ No newline at end of file
end
......@@ -60,16 +60,17 @@ def clear_log; self.log = []; self.log_all = []; end
self.clear_log
self.ignored_sql = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/, /^BEGIN/, /^COMMIT/]
self.ignored_sql = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/, /^BEGIN/, /^COMMIT/]
# FIXME: this needs to be refactored so specific database can add their own
# ignored SQL, or better yet, use a different notification for the queries
# instead examining the SQL content.
oracle_ignored = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im]
mysql_ignored = [/^SHOW TABLES/i, /^SHOW FULL FIELDS/]
postgresql_ignored = [/^\s*select\b.*\bfrom\b.*pg_namespace\b/im, /^\s*select\b.*\battname\b.*\bfrom\b.*\bpg_attribute\b/im]
postgresql_ignored = [/^\s*select\b.*\bfrom\b.*pg_namespace\b/im, /^\s*select\b.*\battname\b.*\bfrom\b.*\bpg_attribute\b/im, /^SHOW search_path/i]
sqlite3_ignored = [/^\s*SELECT name\b.*\bFROM sqlite_master/im]
[oracle_ignored, mysql_ignored, postgresql_ignored].each do |db_ignored_sql|
[oracle_ignored, mysql_ignored, postgresql_ignored, sqlite3_ignored].each do |db_ignored_sql|
ignored_sql.concat db_ignored_sql
end
......
......@@ -12,6 +12,7 @@ def setup
def teardown
@connection.drop_table :fruits rescue nil
ActiveRecord::SchemaMigration.delete_all rescue nil
end
def test_schema_define
......
......@@ -221,6 +221,9 @@ def test_has_many_through_has_many_with_has_and_belongs_to_many_source_reflectio
end
def test_has_many_through_has_many_with_has_and_belongs_to_many_source_reflection_preload_via_joins
# preload table schemas
Author.joins(:post_categories).first
assert_includes_and_joins_equal(
Author.where('categories.id' => categories(:cooking).id),
[authors(:bob)], :post_categories
......@@ -246,6 +249,9 @@ def test_has_many_through_has_and_belongs_to_many_with_has_many_source_reflectio
end
def test_has_many_through_has_and_belongs_to_many_with_has_many_source_reflection_preload_via_joins
# preload table schemas
Category.joins(:post_comments).first
assert_includes_and_joins_equal(
Category.where('comments.id' => comments(:more_greetings).id).order('categories.id'),
[categories(:general), categories(:technology)], :post_comments
......@@ -271,6 +277,9 @@ def test_has_many_through_has_many_with_has_many_through_habtm_source_reflection
end
def test_has_many_through_has_many_with_has_many_through_habtm_source_reflection_preload_via_joins
# preload table schemas
Author.joins(:category_post_comments).first
assert_includes_and_joins_equal(
Author.where('comments.id' => comments(:does_it_hurt).id).order('authors.id'),
[authors(:david), authors(:mary)], :category_post_comments
......
......@@ -108,18 +108,20 @@ def test_dup_after_initialize_callbacks
end
def test_dup_validity_is_independent
Topic.validates_presence_of :title
topic = Topic.new("title" => "Litterature")
topic.valid?
duped = topic.dup
duped.title = nil
assert duped.invalid?
topic.title = nil
duped.title = 'Mathematics'
assert topic.invalid?
assert duped.valid?
repair_validations(Topic) do
Topic.validates_presence_of :title
topic = Topic.new("title" => "Litterature")
topic.valid?
duped = topic.dup
duped.title = nil
assert duped.invalid?
topic.title = nil
duped.title = 'Mathematics'
assert topic.invalid?
assert duped.valid?
end
end
end
end
......@@ -30,9 +30,13 @@ def setup
Reminder.reset_column_information
ActiveRecord::Migration.verbose = true
ActiveRecord::Migration.message_count = 0
ActiveRecord::Base.connection.schema_cache.clear!
end
def teardown
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
ActiveRecord::Base.connection.initialize_schema_migrations_table
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
......@@ -44,6 +48,7 @@ def teardown
%w(reminders people_reminders prefix_reminders_suffix).each do |table|
Reminder.connection.drop_table(table) rescue nil
end
Reminder.reset_table_name
Reminder.reset_column_information
%w(last_name key bio age height wealth birthday favorite_day
......@@ -257,9 +262,6 @@ def test_schema_migrations_table_name
ActiveRecord::Base.table_name_suffix = ""
Reminder.reset_table_name
assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
ensure
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
end
def test_proper_table_name
......@@ -286,9 +288,6 @@ def test_proper_table_name
Reminder.reset_table_name
assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name('table')
assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name(:table)
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
Reminder.reset_table_name
end
def test_rename_table_with_prefix_and_suffix
......@@ -307,8 +306,6 @@ def test_rename_table_with_prefix_and_suffix
assert_equal "hello world", Thing.first.content
ensure
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
Thing.reset_table_name
Thing.reset_sequence_name
end
......@@ -326,9 +323,6 @@ def test_add_drop_table_with_prefix_and_suffix
WeNeedReminders.down
assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
ensure
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
Reminder.reset_table_name
Reminder.reset_sequence_name
end
......@@ -437,6 +431,8 @@ class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
def setup
@connection = Person.connection
@connection.create_table(:delete_me, :force => true) {|t| }
Person.reset_column_information
Person.reset_sequence_name
end
def teardown
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册