aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/fixtures
Commit message (Collapse)AuthorAgeFilesLines
* Add `binary` helper method to fixtures.yalab2017-08-121-0/+4
|
* Use bulk INSERT to insert fixturesKir Shatrov2017-06-201-0/+1
| | | | | | | | Improves the performance from O(n) to O(1). Previously it would require 50 queries to insert 50 fixtures. Now it takes only one query. Disabled on sqlite which doesn't support multiple inserts.
* Refactor enum to use `value` instead of `label` in the scopeRyuta Kamizono2017-05-071-0/+1
|
* Correct spellingBenjamin Fleischer2017-02-051-1/+1
| | | | | | | ``` go get -u github.com/client9/misspell/cmd/misspell misspell -w -error -source=text . ```
* fix #create_fixtures when equal table names in different databasesJulia Lopez2016-12-211-0/+2
|
* Throw friendly error message when fixture is not a hashKir Shatrov2016-12-151-0/+3
| | | | | | Right now, when fixture is not a Hash we throw an error message saying "fixture is not a hash". This is not very user friendly because it's not saying which fixture is invalid.
* Merge pull request #26466 from y-yagi/remove_duplicated_fixture_set_namesArthur Nogueira Neves2016-09-131-0/+2
|\ | | | | remove duplicated fixture set names
| * remove duplicated fixture set namesyuuji.yaginuma2016-09-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | If using namespaced fixtures, get following Ruby warning. ``` activerecord/lib/active_record/fixtures.rb:922: warning: method redefined; discarding old admin_foos activerecord/lib/active_record/fixtures.rb:922: warning: previous definition of admin_foos was here ``` This is happening because of the multiple set the same path when setting the fixture name. Fix to remove the duplicate path.
* | Add tests for ActiveRecord::Enum#enum when suffix specifiedYosuke Kabuto2016-09-121-0/+1
|/ | | | Make name of attribute medium instead of normal
* Fixed `where` for polymorphic associations when passed an array containing ↵Philippe Huibonhoa2016-02-161-1/+10
| | | | | | | | | | | | | | | | | different types. When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array. PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2)) This is fixed to properly look for any records matching both type and id: PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1) OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
* fix regression when loading fixture files with symbol keys.Yves Senn2016-01-131-0/+3
| | | | Closes #22584.
* Fix ↵Ryuta Kamizono2015-12-192-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct` to NULL-agnostic way The sort order of NULL depends on the RDBS implementation. This commit is to fix the test to NULL-agnostic way. Example: ``` activerecord_unittest=# SELECT DISTINCT "posts"."id", author_addresses_authors.id AS alias_0 FROM "posts" LEFT OUTER JOIN "authors" ON "authors"."id" = "posts"."author_id" LEFT OUTER JOIN "author_addresses" ON "author_addresses"."id" = "authors"."author_address_id" LEFT OUTER JOIN "categorizations" ON "categorizations"."category_id" = "posts"."id" LEFT OUTER JOIN "authors" "authors_posts" ON "authors_posts"."id" = "categorizations"."author_id" LEFT OUTER JOIN "author_addresses" "author_addresses_authors" ON "author_addresses_authors"."id" = "authors_posts"."author_address_id" ORDER BY author_addresses_authors.id DESC; id | alias_0 ----+--------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 1 | 1 (12 rows) ``` ``` root@localhost [activerecord_unittest] > SELECT DISTINCT `posts`.`id`, author_addresses_authors.id AS alias_0 FROM `posts` LEFT OUTER JOIN `authors` ON `authors`.`id` = `posts`.`author_id` LEFT OUTER JOIN `author_addresses` ON `author_addresses`.`id` = `authors`.`author_address_id` LEFT OUTER JOIN `categorizations` ON `categorizations`.`category_id` = `posts`.`id` LEFT OUTER JOIN `authors` `authors_posts` ON `authors_posts`.`id` = `categorizations`.`author_id` LEFT OUTER JOIN `author_addresses` `author_addresses_authors` ON `author_addresses_authors`.`id` = `authors_posts`.`author_address_id` ORDER BY author_addresses_authors.id DESC; +----+---------+ | id | alias_0 | +----+---------+ | 1 | 1 | | 3 | NULL | | 1 | NULL | | 2 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | | 7 | NULL | | 8 | NULL | | 9 | NULL | | 10 | NULL | | 11 | NULL | +----+---------+ 12 rows in set (0.00 sec) ```
* Merge pull request #18548 from ↵Sean Griffin2015-10-282-0/+6
|\ | | | | | | | | | | sebjacobs/support-bidirectional-destroy-dependencies Add support for bidirectional destroy dependencies
| * Add support for bidirectional destroy dependenciesSeb Jacobs2015-01-162-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 #20574 from repinel/fix-db-fixtures-loadYves Senn2015-09-303-0/+22
|\ \ | | | | | | | | | | | | | | | | | | Allow fixtures YAML files to set the model class in the file itself Conflicts: activerecord/CHANGELOG.md
| * | Allow fixtures YAML files to set the model class in the file itselfRoque Pinel2015-09-114-0/+25
|/ / | | | | | | | | | | | | | | Currently, `set_fixture_class` is only available using the `TestFixtures` concern and it is ignored for `rake db:fixtures:load`. Using the correct model class, it is possible for the fixture load to also load the associations from the YAML files (e.g., `:belongs_to` and `:has_many`).
* | descriptive error message when fixtures contian a missing column.Yves Senn2015-08-131-0/+2
| | | | | | | | Closes #21201.
* | Fix spelling of `Thoughtleadering`eileencodes2015-07-021-1/+1
| | | | | | | | Not much of a thought leader if I can't spell it correctly :wink:
* | Use default model enum in fixtures if not definedeileencodes2015-07-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | After 908cfef was introduced fixtures that did not set an enum would return nil instead of the default enum value. The fixtures should assume the default if a different enum is not defined. The change checks first if the enum is defined in the fixture before setting it based on the fixture.
* | Add pending test for the great-grandparent touching bug from #19324David Heinemeier Hansson2015-06-252-0/+32
| |
* | Add enum prefix/suffix option to enum definitionIgor Kapkov2015-06-121-0/+4
| | | | | | | | Fixes #17511 and #17415
* | Fix crash when loading fixture with belongs_to association defined in ↵Victor Costan2015-06-041-0/+3
| | | | | | | | abstract base class.
* | Resolve enums in test fixturesGeorge Claghorn2015-05-271-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, values for columns backing Active Record enums must be specified as integers in test fixtures: awdr: title: "Agile Web Development with Rails" status: 2 rfr: title: "Ruby for Rails" status: <%= Book.statuses[:proposed] %> This is potentially confusing, since enum values are typically specified as symbols or strings in application code. To resolve the confusion, this change permits the use of symbols or strings to specify enum values: awdr: status: :published It is compatible with fixtures that specify enum values as integers.
* | Fixes #18492Vipul A M2015-01-142-0/+9
|/ | | | | | | - Add check for not deleting previously created fixtures, to overcome sti fixtures from multiple files - Added fixtures and fixtures test to verify the same - Fixed wrong fixtures duplicating data insertion in same table
* Fix lookup of fixtures with non-string labelPrathamesh Sonpatki2015-01-061-0/+3
| | | | | | | | | | | - Fixtures with non-string labels such as integers should be accessed using integer label as key. For eg. pirates(1) or pirates(42). - But this results in NotFound error because the label is converted into string before looking up into the fixtures hash. - After this commit, the label is converted into string only if its a symbol. - This issue was fount out while adding a test case for https://github.com/rails/rails/commit/7b910917.
* Unused csv fixture fileAkira Matsuda2014-12-091-1/+0
|
* make it possible to access fixtures excluded by a `default_scope`.Yves Senn2014-11-211-0/+5
| | | | | | | | Prior to this patch you'd end up with an error like: ``` ActiveRecord::RecordNotFound: Couldn't find <Model> with 'id'=<id> [WHERE (<default_scope condition>)] ```
* Ensure HABTM relationships produce valid class names (Fixes #17119)Sammy Larbi2014-11-092-0/+6
|
* Fix query with nested array in Active RecordCristian Bica2014-09-061-1/+1
| | | | | | | | `User.where(id: [[1,2],3])` was equal to `User.where(id:[1, 2, 3])` in Rails 4.1.x but because of some refactoring in Arel this stopped working in 4.2.0. This fixes it in Rails. [Dan Olson & Cristian Bica]
* fk: use random digest namesYves Senn2014-06-261-1/+1
| | | | | | 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/+0
| | | | | | | | | | | 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.
* Update test data which doesn't reflect expected usageSean Griffin2014-06-121-5/+5
| | | | | | Topics call `serialize :content`, which means that the values in the database should be YAML encoded, and we would only expect to receive YAML strings to `update_column` and `update_columns`.
* Fixed serialization for records with an attribute named `format`.Godfrey Chan2014-05-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * * * 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-10/+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.
* Merge pull request #14544 from jefflai2/named_scope_stiRafael Mendonça França2014-05-201-0/+10
|\ | | | | | | | | | | | | Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
| * Fixes Issue #13466.Jefferson Lai2014-04-231-0/+10
| | | | | | | | | | | | 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.
* | Merge pull request #12016 from roderickvd/uuid_fixesRafael Mendonça França2014-04-042-0/+5
|\ \ | |/ |/| | | | | | | | | | | | | | | 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-072-0/+5
| | | | | | | | Fixes: #11524
* | Extend fixture label replacement to allow string interpolationEric Steele2014-03-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Allows fixtures to use their $LABEL as part of a string instead of limiting use to the entire value. mark: first_name: $LABEL username: $LABEL1973 email: $LABEL@$LABELmail.com users(:mark).first_name # => mark users(:mark).username # => mark1973 users(:mark).email # => mark@markmail.com
* | 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.
* | Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* | Ensure #second acts like #first AR finderJason Meller2014-01-201-0/+7
|/ | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* Extend ActiveRecord::Base#cache_key to take an optional list of timestamp ↵David Heinemeier Hansson2013-11-021-0/+1
| | | | attributes of which the highest will be used.
* we should have unique sponsorable ids in the fixtures at leastAaron Patterson2013-10-141-1/+1
|
* Fix broken link to Fixtures documentation on guidesDavid Padilla2013-08-291-1/+1
| | | | | | and activerecord tests [ci skip]
* load fixtures from linked foldersKassio Borges2013-08-053-0/+13
|
* has_many through obeys order on through associationNeeraj Singh2013-04-042-0/+11
| | | | fixes #10016
* Merge pull request #9141 from adamgamble/issue-9091David Heinemeier Hansson2013-04-031-0/+4
|\ | | | | belongs_to :touch should touch old record when transitioning.
| * + Add test for auto timestamps update of both old & new parent recordsPikachuEXE2013-03-141-0/+4
| |
* | Update other counter caches on destroyIan Young2013-03-202-0/+4
| |