aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Change for `ActiveRecord::Migration.[]` to raise `ArgumentError` instead of ↵yui-knk2016-03-241-0/+3
| | | | | | | | | `RuntimeError` The error is raised because user passed invalid version number to a public api of `ActiveRecord`, so `ArgumentError` is more suitable. And add a test case checking if an error is raised when unknown migration version is passed, because these test cases are not implemented.
* Ensure `drop_table` even if tests failure or interruptedRyuta Kamizono2016-02-241-7/+5
| | | | | | I was encountered remaining `:binary_testings` table by tests failure. When remaining `:binary_testings` table, never reach `drop_table` due to `create_table` in the test always fails.
* `drop_table :test_text_limits` as wellRyuta Kamizono2016-02-241-9/+13
| | | | Follow up to 3b01785.
* Merge pull request #23789 from ↵Rafael França2016-02-231-1/+1
|\ | | | | | | | | wisetara/wisetara/deprecate-args-ActiveSupport__TestCase#assert_nothing_raised-for-pr Wisetara/deprecate args active support test case#assert nothing raised for pr
| * remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-1/+1
| |
* | Make sure we don't change the global state in the testsRafael Mendonça França2016-02-231-0/+4
| | | | | | | | We are creating the table but not deleting after the test.
* | Remove needless `drop_table :test_limits`Ryuta Kamizono2016-02-231-3/+0
|/ | | | A `:test_limits` table has not been created.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-02-071-2/+0
|\
| * [ci skip] Good bye SQLite2yui-knk2016-02-061-2/+0
| | | | | | | | Follow up of https://github.com/rails/rails/commit/c9feea6c9ab4494b0cb0b8cf4316847854f65af6
* | Rename `active_record_internal_metadatas` to `ar_internal_metadata`Yasuo Honda2016-02-011-0/+15
| | | | | | | | for those who already migrated to Rails 5.0.0 beta
* | Shorten ActiveRecord::InternalMetadata.table_name to ar_internal_metadataYasuo Honda2016-02-011-5/+5
|/ | | | to support Oracle database which only supports 30 byte identifier length
* Fix intermittent test failuresschneems2016-01-141-0/+1
| | | 😳
* Revert "Revert "Set environment even when no migration runs""schneems2016-01-141-1/+28
| | | | This reverts commit 11e85b91731ca6125ee1db33553f984549a3bc2b.
* Revert "Set environment even when no migration runs"Sean Griffin2016-01-141-28/+1
|
* Set environment even when no migration runsschneems2016-01-111-0/+27
| | | | | This PR addresses the issue described in https://github.com/rails/rails/pull/22967#issuecomment-170251635. If the database is non empty and has no new migrations than `db:migrate` will not set the environment. This PR works by always setting the environment value on successful `up` migration regardless of whether or not a migration was actually executed.
* Clean up duplicate migration logicschneems2016-01-111-1/+1
|
* Merge pull request #22967 from schneems/schneems/generic-metadataSean Griffin2016-01-081-0/+44
|\ | | | | Prevent destructive action on production database
| * Use hash like syntax for InternalMetadataschneems2016-01-081-2/+2
| | | | | | | | Discussion: https://github.com/rails/rails/pull/22967#discussion_r49137035
| * Prevent destructive action on production databaseschneems2016-01-071-0/+44
| | | | | | | | | | | | | | This PR introduces a key/value type store to Active Record that can be used for storing internal values. It is an alternative implementation to #21237 cc @sgrif @matthewd. It is possible to run your tests against your production database by accident right now. While infrequently, but as an anecdotal data point, Heroku receives a non-trivial number of requests for a database restore due to this happening. In these cases the loss can be large. To prevent against running tests against production we can store the "environment" version that was used when migrating the database in a new internal table. Before executing tests we can see if the database is a listed in `protected_environments` and abort. There is a manual escape valve to force this check from happening with environment variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`.
* | Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
| |
* | Don't over-specify types in our testsSean Griffin2015-12-161-1/+0
|/ | | | | | | This test was failing when run on Windows using PostgreSQL. Depending on the OS (and 32 vs 64 bit), this type could be a `BigNum`. We could loosen the assertion to `Numeric`, but if the value is equal to the expected, and responds to `bitlength` properly, who cares?
* Internal test migrations use the private 'Current' versionMatthew Draper2015-12-151-10/+10
| | | | | | | | Apart from specific versioning support, our tests should focus on the behaviour of whatever version they're accompanying, regardless of when they were written. Application code should *not* do this.
* Revert "Allow specifying the default table options for mysql adapters"Sean Griffin2015-11-191-19/+0
| | | | | | | This reverts commit 8246b593bff71f2cebf274c133bb8917f1e094c8. There was concern about this modifying the behavior of past migrations. We're going to add an way to modify the migration generator instead.
* Allow specifying the default table options for mysql adaptersSean Griffin2015-11-191-0/+19
| | | | | | | | | | | | | It's often the case that you want to have an option that you cannot specify at the database level, but want applied to *all* tables that you create. For example, you might want to specify `ROW_FORMAT=DYNAMIC` to not have to limit text columns to length 171 for indexing when using utf8mb4. This allows an easy way to specify this in your database configuration. While this change affects both MySQL and MySQL2, the test only covers MySQL2, as the legacy mysql adapter appears to always return ASCII strings, and is tangential to what we're actually doing.
* Rename 'key' to 'lock_id' or 'lock_name' for advisory lockingSam Davies2015-11-181-19/+19
| | | | | | | | | - key was a poor choice of name. A key implies something that will unlock a lock. The concept is actually more like a 'lock identifier' - mysql documentation calls this a 'lock name' - postgres documentation calls it a 'lock_id' - Updated variable names to reflect the preferred terminology for the database in question
* Require the count_down_latchRafael Mendonça França2015-11-051-2/+3
|
* don't sleep in testsAaron Patterson2015-10-301-10/+6
| | | | | we should be using a countdown latch instead of rolling our own busy-loop.
* Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-0/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #22092 - Works on Postgres and MySQL - Uses advisory locks because of two important properties: 1. The can be obtained outside of the context of a transaction 2. They are automatically released when the session ends, so if a migration process crashed for whatever reason the lock is not left open perpetually - Adds get_advisory_lock and release_advisory_lock methods to database adapters - Attempting to run a migration while another one is in process will raise a ConcurrentMigrationError instead of attempting to run in parallel with undefined behavior. This could be rescued and the migration could exit cleanly instead. Perhaps as a configuration option? Technical Notes ============== The Migrator uses generate_migrator_advisory_lock_key to build the key for the lock. In order to be compatible across multiple adapters there are some constraints on this key. - Postgres limits us to 64 bit signed integers - MySQL advisory locks are server-wide so we have to scope to the database - To fulfil these requirements we use a Migrator salt (a randomly chosen signed integer with max length of 31 bits) that identifies the Rails migration process as the owner of the lock. We multiply this salt with a CRC32 unsigned integer hash of the database name to get a signed 64 bit integer that can also be converted to a string to act as a lock key in MySQL databases. - It is important for subsequent versions of the Migrator to use the same salt, otherwise different versions of the Migrator will not see each other's locks.
* remove dead code.Yves Senn2015-09-091-3/+1
| | | | | | The last call site of `last_version` was removed with: 838e18321118ee3ec6669217e5ea0216f79c969a
* Merge pull request #21342 from yui-knk/test/add_assert_methodRafael Mendonça França2015-08-241-1/+1
|\ | | | | Add `assert_nothing_raised` to make clear test case perpose
| * Add `assert_nothing_raised` to make clear test case perposeyui-knk2015-08-231-1/+1
| |
* | Remove test helper method to inside test methodyui-knk2015-08-231-5/+1
|/ | | | | | Remove `MigrationTest#connection` and write `ActiveRecord::Base.connection` directly to test, because `MigrationTest#connection` is only used in `test_migration_instance_has_connection`.
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* Error message testing fixFranky W2015-02-201-1/+3
| | | | | | | | | The testing of error messages have been implemented wrongly a few times. This is an attempt to fix it. For example, some of these test should have failed with the new code. The reason they are not failling with the new string is the fact they were not being tested beforehand.
* pg tests, be clear about the missing type that causes a test skip.Yves Senn2015-02-121-8/+2
| | | | Also removed some cruft in the `setup` and `teardown` methods.
* tests, remove unused requires.Yves Senn2015-02-121-1/+0
| | | | | | "active_support/testing/stream" is already required in `test_case.rb`. Furthermore the test "test/cases/migration_test.rb" could no longer be executed directly.
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-2/+2
| | | | | | | | | | | | | | | | | | The same is not true of `define_attribute`, which is meant to be the low level no-magic API that sits underneath. The differences between the two APIs are: - `attribute` - Lazy (the attribute will be defined after the schema has loaded) - Allows either a type object or a symbol - `define_attribute` - Runs immediately (might get trampled by schema loading) - Requires a type object This was the last blocker in terms of public interface requirements originally discussed for this feature back in May. All the implementation blockers have been cleared, so this feature is probably ready for release (pending one more look-over by me).
* Merge pull request #18526 from vipulnsward/add-silence-streamRafael Mendonça França2015-02-051-19/+3
|\ | | | | Extracted silence_stream method to new module in activesupport/testing
| * - Extracted silence_stream method to new module in activesupport/testing.Vipul A M2015-01-201-19/+3
| | | | | | | | | | | | | | | | | | | | | | | | - Added include for the same in ActiveSupport::Test. - Removed occurrences of silence_stream being used elsewhere. - Reordered activesupport testcase requires alphabetically. - Removed require of silence stream from test_case - Moved quietly method to stream helper - Moved capture output to stream helper module and setup requires for the same elsewhere
* | Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's finally finished!!!!!!! The reason the Attributes API was kept private in 4.2 was due to some publicly visible implementation details. It was previously implemented by overloading `columns` and `columns_hash`, to make them return column objects which were modified with the attribute information. This meant that those methods LIED! We didn't change the database schema. We changed the attribute information on the class. That is wrong! It should be the other way around, where schema loading just calls the attributes API for you. And now it does! Yes, this means that there is nothing that happens in automatic schema loading that you couldn't manually do yourself. (There's still some funky cases where we hit the connection adapter that I need to handle, before we can turn off automatic schema detection entirely.) There were a few weird test failures caused by this that had to be fixed. The main source came from the fact that the attribute methods are now defined in terms of `attribute_names`, which has a clause like `return [] unless table_exists?`. I don't *think* this is an issue, since the only place this caused failures were in a fake adapter which didn't override `table_exists?`. Additionally, there were a few cases where tests were failing because a migration was run, but the model was not reloaded. I'm not sure why these started failing from this change, I might need to clear an additional cache in `reload_schema_from_cache`. Again, since this is not normal usage, and it's expected that `reset_column_information` will be called after the table is modified, I don't think it's a problem. Still, test failures that were unrelated to the change are worrying, and I need to dig into them further. Finally, I spent a lot of time debugging issues with the mutex used in `define_attribute_methods`. I think we can just remove that method entirely, and define the attribute methods *manually* in the call to `define_attribute`, which would simplify the code *tremendously*. Ok. now to make this damn thing public, and work on moving it up to Active Model.
* | tests, use `drop_table if_exists: true` in our test suite.Yves Senn2015-01-201-1/+1
|/
* Use IO::NULL alwaysNobuyoshi Nakada2015-01-101-1/+1
|
* Remove deprecated methods at `Kernel`.Rafael Mendonça França2015-01-041-0/+10
| | | | `silence_stderr`, `silence_stream`, `capture` and `quietly`.
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Load test schema even if there are no migrationsSean Griffin2014-10-311-0/+13
| | | | Fixes #17170
* Treat strings greater than int max value as out of rangeSean Griffin2014-10-311-1/+0
| | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* MySQL: skip GTID-unsafe statement tests when enforce_gtid_consistency is enabledJeremy Kemper2014-09-011-17/+19
|
* MigrationTest doesn't need to be verbose anymoreAkira Matsuda2014-08-291-1/+1
|
* No tests are dealing with ActiveRecord::Migration.message_count here anymoreAkira Matsuda2014-08-291-1/+0
|
* Reset ActiveRecord::Migration.verbose to the value beforeAkira Matsuda2014-08-291-1/+3
|