aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/schema
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix `bigint?` for Enum columns in MySQLRyuta Kamizono2016-01-311-1/+1
| | | | Follow up to #22896.
* Add missing source_type if provided on hmt which belongs to an sti recordVipul A M2016-01-241-0/+2
| | | | Fixes #23209
* Use the database type to deserialize enumSean Griffin2016-01-231-0/+1
| | | | | | | | | | | | This fixes incorrect assumptions made by e991c7b that we can assume the DB is already casting the value for us. The enum type needs additional information to perform casting, and needs a subtype. I've opted not to call `super` in `cast`, as we have a known set of types which we accept there, and the subtype likely doesn't accept them (symbol -> integer doesn't make sense) Close #23190
* Merge pull request #20005 from kamipo/default_expression_supportRafael França2016-01-162-20/+24
|\ | | | | Add `:expression` option support on the schema default
| * Fix extract default with CURRENT_TIMESTUMPRyuta Kamizono2016-01-131-0/+7
| |
| * Add expression support on the schema defaultRyuta Kamizono2016-01-131-20/+17
| | | | | | | | | | | | | | | | Example: create_table :posts do |t| t.datetime :published_at, default: -> { 'NOW()' } end
* | Revert "Merge pull request #20835 from ↵Kasper Timm Hansen2016-01-141-1/+0
|/ | | | | | | | | | | | | glittershark/if-and-unless-in-secure-token" This reverts commit 224eddfc0eeff6555ae88691306e61c7a9e8b758, reversing changes made to 9d681fc74c6251d5f2b93fa9576c9b2113116680. When merging the pull request, I misunderstood `has_secure_token` as declaring a model has a token from birth and through the rest of its lifetime. Therefore, supporting conditional creation doesn't make sense. You should never mark a model as having a secure token if there's a time when it shouldn't have it on creation.
* Add conditional_token to users.Kasper Timm Hansen2016-01-091-0/+1
| | | | | | Fix the NoMethodErrors introduced in 224eddf, when adding conditional token creation. The model declarations but the column wasn't added to the schema.
* Add short-hand methods for text and blob types in MySQLRyuta Kamizono2016-01-051-10/+10
| | | | | | | | | | | | | | | | | In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length. But in MySQL, these have limited length for each types (ref #21591, #21619). This change adds short-hand methods for each text and blob types. Example: create_table :foos do |t| t.tinyblob :tiny_blob t.mediumblob :medium_blob t.longblob :long_blob t.tinytext :tiny_text t.mediumtext :medium_text t.longtext :long_text end
* Fix `unsigned?` and `blob_or_text_column?` for Enum columns in MySQLRyuta Kamizono2016-01-041-1/+1
|
* Remove unused `test/schema/mysql_specific_schema.rb`Ryuta Kamizono2015-12-191-62/+0
| | | | Follow up to #22642.
* tests, pluralize singular table name.Yves Senn2015-12-021-1/+1
| | | | | | | | | | This solves the following error: ActiveRecord::StatementInvalid: Could not find table 'guitars' It seems that the table structure of the `Guitar` model has not been necessary until now. Due to the wrong table name the model was not correctly linked to the table.
* Except keys of `build_record`'s argument from `create_scope` in ↵yui-knk2015-11-161-1/+1
| | | | | | | | | | | | | | initialize_attributes If argument of `build_record` has key and value which is same as default value of database, we should also except the key from `create_scope` in `initialize_attributes`. Because at first `build_record` initialize record object with argument of `build_record`, then assign attributes derived from Association's scope. In this case `record.changed` does not include the key, which value is same as default value of database, so we should add the key to except list. Fix #21893.
* Merge pull request #18548 from ↵Sean Griffin2015-10-281-0/+8
|\ | | | | | | | | | | sebjacobs/support-bidirectional-destroy-dependencies Add support for bidirectional destroy dependencies
| * Add support for bidirectional destroy dependenciesSeb Jacobs2015-01-161-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit if you defined a bidirectional relationship between two models with destroy dependencies on both sides, a call to `destroy` would result in an infinite callback loop. Take the following relationship. class Content < ActiveRecord::Base has_one :content_position, dependent: :destroy end class ContentPosition < ActiveRecord::Base belongs_to :content, dependent: :destroy end Calling `Content#destroy` or `ContentPosition#destroy` would result in an infinite callback loop. This commit changes the behaviour of `ActiveRecord::Callbacks#destroy` so that it guards against subsequent callbacks. Thanks to @zetter for demonstrating the issue with failing tests[1]. [1] rails#13609
* | Merge pull request #19686 from tsun1215/index_errorsSean Griffin2015-10-261-0/+9
|\ \ | | | | | | | | | | | | | | | Errors can be indexed with nested attributes Close #8638
| * | Errors can be indexed with nested attributesMichael Probber2015-04-171-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `has_many` can now take `index_errors: true` as an option. When this is enabled, errors for nested models will be returned alongside an index, as opposed to just the nested model name. This option can also be enabled (or disabled) globally through `ActiveRecord::Base.index_nested_attribute_errors` E.X. ```ruby class Guitar < ActiveRecord::Base has_many :tuning_pegs accepts_nested_attributes_for :tuning_pegs end class TuningPeg < ActiveRecord::Base belongs_to :guitar validates_numericality_of :pitch end ``` - Old style - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - New style (if defined globally, or set in has_many_relationship) - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` [Michael Probber, Terence Sun]
* | | Fix merge conflicts for #19938Sean Griffin2015-10-201-0/+6
|\ \ \ | | | | | | | | | | | | | | | | This is a separate commit, as it is not just a changelog conflict. Want to point out the changes in the code
| * | | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-041-0/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems
* | | Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2Sean Griffin2015-10-202-2/+13
|\ \ \ | | | | | | | | Add stored procedure test in mysql2
| * | | Add stored procedure test in mysql2Ryuta Kamizono2015-10-152-2/+13
| | | |
* | | | Fix to correctly schema dump the `tinyblob`Ryuta Kamizono2015-10-152-2/+2
|/ / / | | | | | | | | | | | | | | | Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`. But `t.binary ... limit: 255` is generating SQL to `varchar(255)`. It is incorrect. This commit fixes this problem.
* | | Fix regression in inverse_of on through associationseileencodes2015-09-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `inverse_of` on through associations was accidently removed/caused to stop working in commit f8d2899 which was part of a refactoring on `ThroughReflection`. To fix we moved `inverse_of` and `check_validity_of_inverse!` to the `AbstractReflection` so it's available to the `ThroughReflection` without having to dup any methods. We then need to delegate `inverse_name` method in `ThroughReflection`. `inverse_name` can't be moved to `AbstractReflection` without moving methods that set the instance variable `@automatic_inverse_of`. This adds a test that ensures that `inverse_of` on a `ThroughReflection` returns the correct class name, and the correct record for the inverse relationship. Fixes #21692
* | | Implement ActiveRecord::Base.ignored_columnsJean Boussier2015-09-241-0/+1
| | |
* | | 0 precision is not the same as no precisionSean Griffin2015-09-231-8/+28
| | | | | | | | | | | | | | | | | | | | | And we are passing them as separate types in the query, which means 0 precision is still not supported by older versions of MySQL. I also missed a handful of other cases where they need to be conditionally applied.
* | | Don't attempt to specify datetime precision unless supportedSean Griffin2015-09-231-8/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, versions of MySQL prior to 5.6 do not support this, which is what's used on Travis by default. The method `mysql_56?` appeared to only ever be used to conditionally apply subsecond precision, so I've generalized it and used it more liberally. This should fix the test failures caused by #20317
* | | Fixed taking precision into count when assigning a value to timestamp attributeBogdan Gusiev2015-09-231-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Timestamp column can have less precision than ruby timestamp In result in how big a fraction of a second can be stored in the database. m = Model.create! m.created_at.usec == m.reload.created_at.usec # => false # due to different seconds precision in Time.now and database column If the precision is low enough, (mysql default is 0, so it is always low enough by default) the value changes when model is reloaded from the database. This patch fixes that issue ensuring that any timestamp assigned as an attribute is converted to column precision under the attribute.
* | | Ensure aliased attributes passed to `select` are quoted if using `from`Sean Griffin2015-09-211-0/+4
| | | | | | | | | | | | | | | | | | Fixes #21488 [Sean Griffin & johanlunds]
* | | :scissors: empty line at the top of filesAkira Matsuda2015-09-211-1/+0
| | |
* | | Only nullify persisted has_one target associationsAgis-2015-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since after 87d1aba3c `dependent: :destroy` callbacks on has_one assocations run *after* destroy, it is possible that a nullification is attempted on an already destroyed target: class Car < ActiveRecord::Base has_one :engine, dependent: :nullify end class Engine < ActiveRecord::Base belongs_to :car, dependent: :destroy end > car = Car.create! > engine = Engine.create!(car: car) > engine.destroy! # => ActiveRecord::ActiveRecordError: cannot update a > destroyed record In the above case, `engine.destroy!` deletes `engine` and *then* triggers the deletion of `car`, which in turn triggers a nullification of `engine.car_id`. However, `engine` is already destroyed at that point. Fixes #21223.
* | | Merge pull request #19683 from tristang/require-option-for-counter-cacheRafael Mendonça França2015-08-131-0/+2
|\ \ \ | | | | | | | | | | | | Require explicit counter_cache option for has_many
| * | | Add tests for associations without counter_cacheTristan Gamilis2015-04-091-0/+2
| | | | | | | | | | | | | | | | | | | | Assert that counter_cache behaviour is not used on belongs_to or has_many associations if the option is not given explicitly.
* | | | Skip statement cache on through association readerRafael Mendonça França2015-08-121-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If the through class has default scopes we should skip the statement cache. Closes #20745.
* | | | use correct DB connection for generated HABTM tableMatt Hanlon2015-08-071-0/+9
| | | |
* | | | Fix counter_cache for polymorphic associationsStefan Kanev2015-07-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* | | | Ensure cyclic associations w/ autosave don't cause duplicate errorsSean Griffin2015-07-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code is so fucked. Things that cause this bug not to replicate: - Defining the validation before the association (we end up calling `uniq!` on the errors in the autosave validation) - Adding `accepts_nested_attributes_for` (I have no clue why. The only thing it does that should affect this is adds `autosave: true` to the inverse reflection, and doing that manually doesn't fix this). This solution is a hack, and I'm almost certain there's a better way to go about it, but this shouldn't cause a huge hit on validation times, and is the simplest way to get it done. Fixes #20874.
* | | | Add pending test for the great-grandparent touching bug from #19324David Heinemeier Hansson2015-06-251-0/+11
| | | |
* | | | Add enum prefix/suffix option to enum definitionIgor Kapkov2015-06-121-0/+4
| | | | | | | | | | | | | | | | Fixes #17511 and #17415
* | | | Correctly handle array columns with defaults in the schema dumperSean Griffin2015-06-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the subtype provides custom schema dumping behavior, we need to defer to it. We purposely choose not to handle any values other than an array (which technically should only ever be `nil`, but I'd rather code defensively here). Fixes #20515.
* | | | Fix crash when loading fixture with belongs_to association defined in ↵Victor Costan2015-06-041-0/+5
| | | | | | | | | | | | | | | | abstract base class.
* | | | Move PostgreSQL specific schema to postgresql_specific_schema.rbRyuta Kamizono2015-05-032-14/+11
| |/ / |/| |
* | | Merge pull request #17574 from kamipo/charset_collation_optionsJeremy Kemper2015-04-072-18/+10
|\ \ \ | |/ / |/| | | | | Add charset and collation options support for MySQL string and text columns.
| * | Add `:charset` and `:collation` options support for MySQL string and text ↵Ryuta Kamizono2015-03-062-18/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | columns Example: create_table :foos do |t| t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin' t.text :text_ascii, charset: 'ascii' end
* | | Delegate limit to subtypewallerjake2015-03-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described here https://github.com/rails/rails/issues/19420. When using the Postgres BigInt[] field type the big int value was not being translated into schema.rb. This caused the field to become just a regular integer field when building off of schema.rb. This fix will address this by delegating the limit from the subtype to the Array type. https://github.com/rails/rails/issues/19420
* | | Fix leaky chain on polymorphic associationeileencodes2015-03-151-0/+4
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If there was a polymorphic hm:t association with a scope AND second non-scoped hm:t association on a model the polymorphic scope would leak through into the call for the non-polymorhic hm:t association. This would only break if `hotel.drink_designers` was called before `hotel.recipes`. If `hotel.recipes` was called first there would be no problem with the SQL. Before (employable_type should not be here): ``` SELECT COUNT(*) FROM "drink_designers" INNER JOIN "chefs" ON "drink_designers"."id" = "chefs"."employable_id" INNER JOIN "departments" ON "chefs"."department_id" = "departments"."id" WHERE "departments"."hotel_id" = ? AND "chefs"."employable_type" = ? [["hotel_id", 1], ["employable_type", "DrinkDesigner"]] ``` After: ``` SELECT COUNT(*) FROM "recipes" INNER JOIN "chefs" ON "recipes"."chef_id" = "chefs"."id" INNER JOIN "departments" ON "chefs"."department_id" = "departments"."id" WHERE "departments"."hotel_id" = ? [["hotel_id", 1]] ``` From the SQL you can see that `employable_type` was leaking through when calling recipes. The solution is to dup the chain of the polymorphic association so it doesn't get cached. Additionally, this follows `scope_chain` which dup's the `source_reflection`'s `scope_chain`. This required another model/table/relationship because the leak only happens on a hm:t polymorphic that's called before another hm:t on the same model. I am specifically testing the SQL here instead of the number of records becasue the test could pass if there was 1 drink designer recipe for the drink designer chef even though the `employable_type` was leaking through. This needs to specifically check that `employable_type` is not in the SQL statement.
* | tests, favor `drop_table` and `:if_exists` over raw SQL.Yves Senn2015-03-022-12/+4
| | | | | | | | | | We've replaced most querues using DROP TABLE in our tests already. This patch replaces the last couple calls.
* | Merge pull request #17297 from ↵Rafael Mendonça França2015-02-251-0/+1
|\ \ | | | | | | | | | | | | rebyn/fix/17161-remove-objs-from-has_many-updates-fields Add specs for adding-to/clear has_many collections’s behavior on `updated_at`
| * | Add specs for adding-to/clear has_many collections’s behavior on `updated_at`Tu Hoang2014-10-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are behaviors mentioned in #17161 that: 1. are not documented properly, and 2. don't have specs This commit addresses the spec absence. For has_many collections, 1. addition (<<) should update the associated object's updated_at (if any) 2. .clear, depending on options[:dependent], calls delete_all, destroy_all, or nullifies the associated object(s)' foreign key.
* | | Remove unused tableRyuta Kamizono2015-02-251-10/+0
| | | | | | | | | | | | `postgresql_xml_data_type` table is used from nowhere.
* | | Add `ActiveRecord::Base.suppress`Michael Ryan2015-02-181-0/+4
| | |