mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
port some mocha to minitest/mock
This commit is contained in:
parent
f491c6ac2a
commit
476ef2df74
4 changed files with 223 additions and 222 deletions
1
Gemfile
1
Gemfile
|
@ -11,6 +11,7 @@ end
|
||||||
gem 'rack-test', github: "brynary/rack-test"
|
gem 'rack-test', github: "brynary/rack-test"
|
||||||
gem 'bcrypt-ruby', '~> 3.0.0'
|
gem 'bcrypt-ruby', '~> 3.0.0'
|
||||||
gem 'jquery-rails'
|
gem 'jquery-rails'
|
||||||
|
gem 'minitest', '~> 3.0.0'
|
||||||
|
|
||||||
if ENV['JOURNEY']
|
if ENV['JOURNEY']
|
||||||
gem 'journey', path: ENV['JOURNEY']
|
gem 'journey', path: ENV['JOURNEY']
|
||||||
|
|
|
@ -2,6 +2,7 @@ require File.expand_path('../../../../load_paths', __FILE__)
|
||||||
|
|
||||||
require 'config'
|
require 'config'
|
||||||
|
|
||||||
|
gem 'minitest'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'mocha'
|
require 'mocha'
|
||||||
|
|
221
activerecord/test/cases/migration/change_table_test.rb
Normal file
221
activerecord/test/cases/migration/change_table_test.rb
Normal file
|
@ -0,0 +1,221 @@
|
||||||
|
require "cases/migration/helper"
|
||||||
|
|
||||||
|
module ActiveRecord
|
||||||
|
class Migration
|
||||||
|
class TableTest < ActiveRecord::TestCase
|
||||||
|
class MockConnection < MiniTest::Mock
|
||||||
|
def native_database_types
|
||||||
|
{
|
||||||
|
:string => 'varchar(255)',
|
||||||
|
:integer => 'integer',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def type_to_sql(type, limit, precision, scale)
|
||||||
|
native_database_types[type]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@connection = MockConnection.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
assert @connection.verify
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_change_table
|
||||||
|
yield ConnectionAdapters::Table.new(:delete_me, @connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_references_column_type_adds_id
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'customer_id', :integer, {}]
|
||||||
|
t.references :customer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_references_column_type_removes_id
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'customer_id']
|
||||||
|
t.remove_references :customer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_add_belongs_to_works_like_add_references
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'customer_id', :integer, {}]
|
||||||
|
t.belongs_to :customer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_belongs_to_works_like_remove_references
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'customer_id']
|
||||||
|
t.remove_belongs_to :customer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_references_column_type_with_polymorphic_adds_type
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'taggable_id', :integer, {}]
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'taggable_type', :string, {}]
|
||||||
|
t.references :taggable, :polymorphic => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_references_column_type_with_polymorphic_removes_type
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'taggable_id']
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'taggable_type']
|
||||||
|
t.remove_references :taggable, :polymorphic => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'taggable_id', :integer, {:null => false}]
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, 'taggable_type', :string, {:null => false}]
|
||||||
|
t.references :taggable, :polymorphic => true, :null => false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'taggable_id']
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, 'taggable_type']
|
||||||
|
t.remove_references :taggable, :polymorphic => true, :null => false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_timestamps_creates_updated_at_and_created_at
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_timestamps, nil, [:delete_me]
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_timestamps_creates_updated_at_and_created_at
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_timestamps, nil, [:delete_me]
|
||||||
|
t.remove_timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def string_column
|
||||||
|
@connection.native_database_types[:string]
|
||||||
|
end
|
||||||
|
|
||||||
|
def integer_column
|
||||||
|
@connection.native_database_types[:integer]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_integer_creates_integer_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :foo, integer_column, {}]
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :bar, integer_column, {}]
|
||||||
|
t.integer :foo, :bar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_string_creates_string_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :foo, string_column, {}]
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :bar, string_column, {}]
|
||||||
|
t.string :foo, :bar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_column_creates_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :bar, :integer, {}]
|
||||||
|
t.column :bar, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_column_creates_column_with_options
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_column, nil, [:delete_me, :bar, :integer, {:null => false}]
|
||||||
|
t.column :bar, :integer, :null => false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_creates_index
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_index, nil, [:delete_me, :bar, {}]
|
||||||
|
t.index :bar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_creates_index_with_options
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :add_index, nil, [:delete_me, :bar, {:unique => true}]
|
||||||
|
t.index :bar, :unique => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_exists
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :index_exists?, nil, [:delete_me, :bar, {}]
|
||||||
|
t.index_exists?(:bar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_exists_with_options
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :index_exists?, nil, [:delete_me, :bar, {:unique => true}]
|
||||||
|
t.index_exists?(:bar, :unique => true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_change_changes_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :change_column, nil, [:delete_me, :bar, :string, {}]
|
||||||
|
t.change :bar, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_change_changes_column_with_options
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :change_column, nil, [:delete_me, :bar, :string, {:null => true}]
|
||||||
|
t.change :bar, :string, :null => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_change_default_changes_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :change_column_default, nil, [:delete_me, :bar, :string]
|
||||||
|
t.change_default :bar, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_drops_single_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, :bar]
|
||||||
|
t.remove :bar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_drops_multiple_columns
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_column, nil, [:delete_me, :bar, :baz]
|
||||||
|
t.remove :bar, :baz
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_index_removes_index_with_options
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :remove_index, nil, [:delete_me, {:unique => true}]
|
||||||
|
t.remove_index :unique => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rename_renames_column
|
||||||
|
with_change_table do |t|
|
||||||
|
@connection.expect :rename_column, nil, [:delete_me, :bar, :baz]
|
||||||
|
t.rename :bar, :baz
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -421,228 +421,6 @@ class ReservedWordsMigrationTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
class ChangeTableMigrationsTest < ActiveRecord::TestCase
|
|
||||||
def setup
|
|
||||||
@connection = Person.connection
|
|
||||||
@connection.stubs(:add_index)
|
|
||||||
@connection.create_table :delete_me, :force => true do |t|
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
Person.connection.drop_table :delete_me rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_references_column_type_adds_id
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
|
|
||||||
t.references :customer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_references_column_type_removes_id
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'customer_id')
|
|
||||||
t.remove_references :customer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_add_belongs_to_works_like_add_references
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
|
|
||||||
t.belongs_to :customer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_belongs_to_works_like_remove_references
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'customer_id')
|
|
||||||
t.remove_belongs_to :customer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_references_column_type_with_polymorphic_adds_type
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {})
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {})
|
|
||||||
t.references :taggable, :polymorphic => true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_references_column_type_with_polymorphic_removes_type
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'taggable_type')
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'taggable_id')
|
|
||||||
t.remove_references :taggable, :polymorphic => true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {:null => false})
|
|
||||||
@connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {:null => false})
|
|
||||||
t.references :taggable, :polymorphic => true, :null => false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'taggable_type')
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, 'taggable_id')
|
|
||||||
t.remove_references :taggable, :polymorphic => true, :null => false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_timestamps_creates_updated_at_and_created_at
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_timestamps).with(:delete_me)
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_timestamps_creates_updated_at_and_created_at
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_timestamps).with(:delete_me)
|
|
||||||
t.remove_timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def string_column
|
|
||||||
if current_adapter?(:PostgreSQLAdapter)
|
|
||||||
"character varying(255)"
|
|
||||||
elsif current_adapter?(:OracleAdapter)
|
|
||||||
'VARCHAR2(255)'
|
|
||||||
else
|
|
||||||
'varchar(255)'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def integer_column
|
|
||||||
if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
|
||||||
'int(11)'
|
|
||||||
elsif current_adapter?(:OracleAdapter)
|
|
||||||
'NUMBER(38)'
|
|
||||||
else
|
|
||||||
'integer'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_integer_creates_integer_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :foo, integer_column, {})
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :bar, integer_column, {})
|
|
||||||
t.integer :foo, :bar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_string_creates_string_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :foo, string_column, {})
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :bar, string_column, {})
|
|
||||||
t.string :foo, :bar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_column_creates_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :bar, :integer, {})
|
|
||||||
t.column :bar, :integer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_column_creates_column_with_options
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_column).with(:delete_me, :bar, :integer, {:null => false})
|
|
||||||
t.column :bar, :integer, :null => false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_creates_index
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_index).with(:delete_me, :bar, {})
|
|
||||||
t.index :bar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_creates_index_with_options
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:add_index).with(:delete_me, :bar, {:unique => true})
|
|
||||||
t.index :bar, :unique => true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_exists
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:index_exists?).with(:delete_me, :bar, {})
|
|
||||||
t.index_exists?(:bar)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_exists_with_options
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:index_exists?).with(:delete_me, :bar, {:unique => true})
|
|
||||||
t.index_exists?(:bar, :unique => true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_change_changes_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:change_column).with(:delete_me, :bar, :string, {})
|
|
||||||
t.change :bar, :string
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_change_changes_column_with_options
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:change_column).with(:delete_me, :bar, :string, {:null => true})
|
|
||||||
t.change :bar, :string, :null => true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_change_default_changes_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:change_column_default).with(:delete_me, :bar, :string)
|
|
||||||
t.change_default :bar, :string
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_drops_single_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, :bar)
|
|
||||||
t.remove :bar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_drops_multiple_columns
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_column).with(:delete_me, :bar, :baz)
|
|
||||||
t.remove :bar, :baz
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_remove_index_removes_index_with_options
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:remove_index).with(:delete_me, {:unique => true})
|
|
||||||
t.remove_index :unique => true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rename_renames_column
|
|
||||||
with_change_table do |t|
|
|
||||||
@connection.expects(:rename_column).with(:delete_me, :bar, :baz)
|
|
||||||
t.rename :bar, :baz
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
def with_change_table
|
|
||||||
Person.connection.change_table :delete_me do |t|
|
|
||||||
yield t
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ActiveRecord::Base.connection.supports_bulk_alter?
|
if ActiveRecord::Base.connection.supports_bulk_alter?
|
||||||
class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
|
class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
|
||||||
def setup
|
def setup
|
||||||
|
|
Loading…
Reference in a new issue