aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/schema
Commit message (Collapse)AuthorAgeFilesLines
* Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-081-0/+5
| | | | | | | To be possible to use a custom column name to save/read the polymorphic associated type in a has_many or has_one polymorphic association, now users can use the option :foreign_type to inform in what column the associated object type will be saved.
* pg tests, get rid of global schema `schema_1`.Yves Senn2014-12-021-7/+0
|
* pg tests, move uniqueness validation test to array tests.Yves Senn2014-12-021-10/+1
|
* tests, extract pg number tests into separate file.Yves Senn2014-12-021-9/+1
|
* tests, move schema shorthand assertions into pg specific tests.Yves Senn2014-12-021-55/+3
|
* tests, move pg geometric tests out of `base_test`.Yves Senn2014-12-021-13/+0
|
* tests, favor public API over inspecting columns where possible.Yves Senn2014-12-012-7/+1
| | | | | This is a follow up to https://github.com/rails/rails/commit/07786c5e75a7b0afdf318063510af6b475e3e04c and https://github.com/rails/rails/commit/cd2596f55e88fe659592612a793c4f4aa723c9be
* Ensure HABTM relationships produce valid class names (Fixes #17119)Sammy Larbi2014-11-091-0/+5
|
* Added SchemaDumper support for tables with jsonb columns.Ted O'Meara2014-11-041-11/+4
|
* Use bind values for joined tables in where statementsSean Griffin2014-11-011-0/+5
| | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* đź’ŁSean Griffin2014-10-281-1/+1
| | | | We were relying on hash inequality in tests
* Dynamically modified schema and association would not be correctly resetAkira Matsuda2014-09-061-0/+6
| | | | | This fixes <"SQLite3::SQLException: no such column: legacy_things.person_id: SELECT \"legacy_things\".* FROM \"legacy_things\" WHERE \"legacy_things\".\"person_id\" = ?"> in OptimisticLockingTest#test_lock_destroy
* Added enable_extension! to helperAbdelkader Boudih2014-09-051-1/+1
|
* Only merge scopes with zero arity in has_many throughAgis-2014-08-201-0/+1
| | | | | | | | | | | | | | | with dynamic conditions. Fixes #16128 This bug was introduced in https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d so it's present from 4.1.2-rc1 and after. https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d merges any relation scopes passed as proc objects to the relation, but does *not* take into account the arity of the lambda. To reproduce: https://gist.github.com/Agis-/5f1f0d664d2cd08dfb9b
* Change the default `null` value for timestampsSean Griffin2014-08-121-5/+5
| | | | | | | As per discussion, this changes the model generators to specify `null: false` for timestamp columns. A warning is now emitted if `timestamps` is called without a `null` option specified, so we can safely change the behavior when no option is specified in Rails 5.
* use foreign key DSL in our tests.Yves Senn2014-07-161-3/+2
|
* Address ORA-00972: identifier is too long when tested with OracleYasuo Honda2014-07-141-2/+2
| | | | by using shorter attribute names.
* Re-enable foriegn key tests on MySQLGodfrey Chan2014-07-051-3/+1
| | | | This reverts commit e84799d, e31104c and e6ca8e2
* MySQL doesn't work with foreign keysPhilippe Creux2014-06-271-1/+4
| | | | | | This was previously fixed in e84799d but broken in 3f596f8. This commit reintroduced the conditional that prevents the foreign keys from being added to MySQL databases.
* Fix test with add_foreign_key DSL in 9d21ef9Philippe Creux2014-06-271-1/+1
|
* Do not change the global state of the test suiteRafael Mendonça França2014-06-271-0/+1
|
* fk: use random digest namesYves Senn2014-06-262-5/+5
| | | | | | The name of the foreign key is not relevant from a users perspective. Using random names resolves the urge to rename the foreign key when the respective table or column is renamed.
* Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-2/+1
| | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* Fix has_and_belongs_to_many in a namespaced model pointing to a non ↵Rafael Mendonça França2014-06-191-0/+5
| | | | | | | | | | | | | | | namespaced model Now the following case will work fine class Tag < ActiveRecord::Base end class Publisher::Article < ActiveRecord::Base has_and_belongs_to_many :tags end Fixes #15761
* Merge pull request #15343 from dontfidget/fix_polymorphic_automatic_inverse_ofRafael Mendonça França2014-06-131-0/+2
|\ | | | | prevent bad automatic inverse_of association
| * use name specified by 'as' for automatic inverse association to avoid ↵Andrew S. Brown2014-06-101-0/+2
| | | | | | | | reflecting on wrong association
* | Timestamp values should be present on callbacksRafael Mendonça França2014-06-091-0/+1
| | | | | | | | | | | | | | This reverts commit dd3ea17191e316aeebddaa7b176f6cfeee7a6365 and add a regression test. Fixes #15418
* | pg, preserve money type when dumping schema and extract money default.Yves Senn2014-06-031-8/+1
| |
* | test pg, move bit string type tests into `bit_string_test.rb`.Yves Senn2014-06-031-8/+0
| |
* | Allow specifying a default value in overloaded propertiesSean Griffin2014-05-301-0/+1
| |
* | Add a public API to allow users to specify column typesSean Griffin2014-05-261-0/+6
|/ | | | | | | | | | | | | | | | | | | | | | | | As a result of all of the refactoring that's been done, it's now possible for us to define a public API to allow users to specify behavior. This is an initial implementation so that I can work off of it in smaller pieces for additional features/refactorings. The current behavior will continue to stay the same, though I'd like to refactor towards the automatic schema detection being built off of this API, and add the ability to opt out of automatic schema detection. Use cases: - We can deprecate a lot of the edge cases around types, now that there is an alternate path for users who wish to maintain the same behavior. - I intend to refactor serialized columns to be built on top of this API. - Gem and library maintainers are able to interact with `ActiveRecord` at a slightly lower level in a more stable way. - Interesting ability to reverse the work flow of adding to the schema. Model can become the single source of truth for the structure. We can compare that to what the database says the schema is, diff them, and generate a migration.
* Fixed serialization for records with an attribute named `format`.Godfrey Chan2014-05-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * * * This bug can be triggered when serializing record R (the instance) of type C (the class), provided that the following conditions are met: 1. The name of one or more columns/attributes on C/R matches an existing private method on C (e.g. those defined by `Kernel`, such as `format`). 2. The attribute methods have not yet been generated on C. In this case, the matching private methods will be called by the serialization code (with no arguments) and their return values will be serialized instead. If the method requires one or more arguments, it will result in an `ArgumentError`. This regression is introduced in d1316bb. * * * Attribute methods (e.g. `#name` and `#format`, assuming the class has columns named `name` and `format` in its database table) are lazily defined. Instead of defining them when a the class is defined (e.g. in the `inherited` hook on `ActiveRecord::Base`), this operation is deferred until they are first accessed. The reason behind this is that is defining those methods requires knowing what columns are defined on the database table, which usually requires a round-trip to the database. Deferring their definition until the last-possible moment helps reducing unnessary work, especially in development mode where classes are redefined and throw away between requests. Typically, when an attribute is first accessed (e.g. `a_book.format`), it will fire the `method_missing` hook on the class, which triggers the definition of the attribute methods. This even works for methods like `format`, because calling a private method with an explicit receiver will also trigger that hook. Unfortunately, `read_attribute_for_serialization` is simply an alias to `send`, which does not respect method visibility. As a result, when serializing a record with those conflicting attributes, the `method_missing` is not fired, and as a result the attribute methods are not defined one would expected. Before d1316bb, this is negated by the fact that calling the `run_callbacks` method will also trigger a call to `respond_to?`, which is another trigger point for the class to define its attribute methods. Therefore, when Active Record tries to run the `after_find` callbacks, it will also define all the attribute methods thus masking the problem. * * * The proper fix for this problem is probably to restrict `read_attribute_for_serialization` to call public methods only (i.e. alias `read_attribute_for_serialization` to `public_send` instead of `send`). This however would be quite risky to change in a patch release and would probably require a full deprecation cycle. Another approach would be to override `read_attribute_for_serialization` inside Active Record to force the definition of attribute methods: def read_attribute_for_serialization(attribute) self.class.define_attribute_methods send(attribute) end Unfortunately, this is quite likely going to cause a performance degradation. This patch therefore restores the behaviour from the 4-0-stable branch by explicitly forcing the class to define its attribute methods in a similar spot (when records are initialized). This should not cause any extra roundtrips to the database because the `@columns` should already be cached on the class. Fixes #15188.
* Revert "Merge pull request #14544 from jefflai2/named_scope_sti"Rafael Mendonça França2014-05-211-2/+0
| | | | | | | | | | | | This reverts commit 9a1abedcdeecd9464668695d4f9c1d55a2fd9332, reversing changes made to c72d6c91a7c0c2dc81cc857a1d6db496e84e0065. Conflicts: activerecord/CHANGELOG.md activerecord/test/models/comment.rb This change break integration with activerecord-deprecated_finders so I'm reverting until we find a way to make it work with this gem.
* Fix polymorphic eager load with foreign_key as String.Lauro Caetano2014-05-201-0/+3
| | | | | | | | | The foreign_key could be `String` and just doing `owners_map[owner_key]` could return `nil`. To prevent this bug, we should `to_s` both keys if their types are different. Fixes #14734.
* Merge pull request #14544 from jefflai2/named_scope_stiRafael Mendonça França2014-05-201-0/+2
|\ | | | | | | | | | | | | Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
| * Fixes Issue #13466.Jefferson Lai2014-04-231-0/+2
| | | | | | | | | | | | Changed the call to a scope block to be evaluated with instance_eval. The result is that ScopeRegistry can use the actual class instead of base_class when caching scopes so queries made by classes with a common ancestor won't leak scopes.
* | Remove dead test code for unsupported adaptersSean Griffin2014-05-171-8/+0
| |
* | Fix how to compute class name on habtm namespaced.Kassio Borges2014-05-131-0/+11
| | | | | | | | | | | | Thank's for @laurocaetano for the help with tests. :smiley: Fixes #14709
* | Merge branch 'master' into rm-uuid-fixturesRafael Mendonça França2014-04-101-1/+7
|\ \ | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG.md activesupport/CHANGELOG.md
| * \ Merge pull request #14579 from senny/pg/remove_string_limitRafael Mendonça França2014-04-041-1/+1
| |\ \ | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL, remove varchar limit. Conflicts: activerecord/CHANGELOG.md
| | * | PostgreSQL and SQLite, remove varchar limit. [Vladimir Sazhin & Toms Mikoss ↵Yves Senn2014-04-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | & Yves Senn] There is no reason for the PG adapter to have a default limit of 255 on :string columns. See this snippet from the PG docs: Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.
| * | | Fix the test defining the models in the right placeRafael Mendonça França2014-04-041-0/+6
| |/ /
* | | Merge pull request #12016 from roderickvd/uuid_fixesRafael Mendonça França2014-04-041-0/+9
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | | | | | | | Auto-generate stable fixture UUIDs on PostgreSQL Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/fixtures.rb activerecord/test/cases/adapters/postgresql/uuid_test.rb activesupport/CHANGELOG.md
| * | Auto-generate stable fixture UUIDs on PostgreSQL.Roderick van Domburg2014-01-071-0/+9
| | | | | | | | | | | | Fixes: #11524
* | | Fix error when using `with_options` with lambda.Lauro Caetano2014-04-031-0/+2
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was causing error when using `with_options` passing a lambda as its last argument. class User < ActiveRecord::Base with_options dependent: :destroy do |assoc| assoc.has_many :profiles, -> { where(active: true) } end end It was happening because the `option_merger` was taking the last argument and checking if it was a Hash. This breaks the HasMany usage, because its last argument can be a Hash or a Proc. As the behavior described in this test: https://github.com/rails/rails/blob/master/activesupport/test/option_merger_test.rb#L69 the method will only accept the lambda, this way it will keep the expected behavior. See 9eaa0a34
* | Test microsecond on mysql 5.6Arthur Neves2014-03-121-1/+5
| |
* | register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester]lsylvester2014-03-111-1/+10
| | | | | | | | citext makes it possible to use AR Hash finders for case-insensitive matching as sql UPPER/LOWER functions are not needed.
* | Fixed STI classes not defining an attribute method if there is aGodfrey Chan2014-02-231-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | conflicting private method defined on its ancestors. The problem is that `method_defined_within?(name, klass, superklass)` only works correclty when `klass` and `superklass` are both `Class`es. If both `klass` and `superklass` are both `Class`es, they share the same inheritance chain, so if a method is defined on `klass` but not `superklass`, this method must be introduced at some point between `klass` and `superklass`. This does not work when `superklass` is a `Module`. A `Module`'s inheritance chain contains just itself. So if a method is defined on `klass` but not on `superklass`, the method could still be defined somewhere upstream, e.g. in `Object`. This fix works by avoiding calling `method_defined_within?` with a module while still fufilling the requirement (checking that the method is defined withing `superclass` but not is not a generated attribute method). 4d8ee288 is likely an attempted partial fix for this problem. This unrolls that fix and properly check the `superclass` as intended. Fixes #11569.
* | Add more tests for the dirty feature for enumsRafael Mendonça França2014-01-211-0/+1
| |
* | Don't try to get the subclass if the inheritance column doesn't existUjjwal Thaakar2014-01-141-0/+5
|/ | | | | | | The `subclass_from_attrs` method is called even if the column specified by the `inheritance_column` setting doesn't exist. This prevents setting associations via the attributes hash if the association name clashes with the value of the setting, typically `:type`. This worked previously in Rails 3.2.