aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/fixtures.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-7/+7
|
* remove duplicated fixture set namesyuuji.yaginuma2016-09-121-1/+1
| | | | | | | | | | | | 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.
* Fix `ActiveRecord::FixtureSet` docs [ci skip]Ryuta Kamizono2016-08-151-4/+4
| | | | | | | `ActiveSupport::TestCase` was replaced `ActiveRecord::TestCase` in #26150. But this docs is for rails apps per se, it should be `ActiveSupport::TestCase`. See https://github.com/rails/rails/pull/26150#discussion_r74710989.
* Consolidate `ActiveRecord::TestCase` and `ActiveSupport::TestCase` in AR ↵Ryuta Kamizono2016-08-141-4/+4
| | | | test cases
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-13/+13
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-16/+16
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix `payload[:class_name]` to `payload[:spec_name]`Ryuta Kamizono2016-07-171-8/+3
| | | | | | Follow up to #20818. `retrieve_connection` is passed `spec_name` instead of `klass` since #24844.
* Create connection.active_record notification and use that to ensure that lazy-Jeremy Wadsack2016-07-121-0/+28
| | | | | | | | | | | | | | | | | | | loaded model classes have their connections wrapped in transactions. See #17776 In Rails 4 config.eager_load was changed to false in the test environment. This means that model classes that connect to alternate databases with establish_connection are not loaded at start up. If use_transactional_fixtures is enabled, transactions are wrapped around the connections that have been established only at the start of the test suite. So model classes loaded later don't have transactions causing data created in the alternate database not to be removed. This change resolves that by creating a new connection.active_record notification that gets fired whenever a connection is established. I then added a subscriber after we set up transactions in the test environment to listen for additional connections and wrap those in transactions as well.
* Fix typoFrancesco Rodriguez2016-06-121-1/+1
| | | [ci skip]
* Refer to rails command instead of rake in a bunch of placesDavid Heinemeier Hansson2015-12-181-1/+1
| | | | Still more to do. Please assist!
* FixtureSet.fixture_class_names should have no default valueJamis Buck2015-10-291-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Look at `TestFixtures.set_fixture_class`. As documented, it accepts a mapping of fixture identifiers (string or symbol) to Classes (the model classes that implement the named fixture). Look now at the initialization of `TestFixtures.fixture_class_names`. It defines a Hash, which will return a string by default (where the string is the estimated class name of the given fixture identifier). Now look at TestFixtures.load_fixtures. It calls `FixtureSet.create_fixtures`, passing in the mapping of `fixture_class_names`. Following this on to `FixtureSet.create_fixtures`, this instantiates a `FixtureSet::ClassCache`, passing in the map of class names. `ClassCache`, in turn, calls `insert_class` for each value in the cache. (Recall that `set_fixture_class` puts Class objects in there, while the default proc for the mapping puts String objects.) Look finally at `insert_class`. If the value is present, it checks to see if the value is a subclass of `AR::Base`. Fair enough...but wait! What if the value is a String? You get an exception, because a String instance cannot be compared with a Class. Judging from the implementation, it seems like the expected behavior here is for `fixture_class_names` to have no default proc. Look-ups are supposed to happen via `ClassCache`, with `fixture_class_names` existing solely as a repository for explicitly-registered class mappings. That is what this change does.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-2/+2
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Merge pull request #20574 from repinel/fix-db-fixtures-loadYves Senn2015-09-301-9/+30
|\ | | | | | | | | | | | | 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-111-9/+33
|/ | | | | | | | 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`).
* Add `:nodoc:` for internal testing methods [ci skip]Robin Dupret2015-07-281-2/+2
|
* Use default model enum in fixtures if not definedeileencodes2015-07-021-1/+3
| | | | | | | | | | | 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.
* [ci skip] Fix the dynamic fixtures exampleJeremy Baker2015-06-131-1/+1
| | | | | My impression of the code sample is that the intent is to assign guy_1, guy_2, etc. The code as it stood would have assigned guy_1, guy_1, etc. This simply replaces the 1 with the iterator variable i.
* Merge pull request #20437 from pwnall/abstract_fixturesRafael Mendonça França2015-06-091-1/+1
|\ | | | | Fix crash when loading fixture with belongs_to association defined in abstract base class
| * Fix crash when loading fixture with belongs_to association defined in ↵Victor Costan2015-06-041-1/+1
| | | | | | | | abstract base class.
* | Stop `to_s(:db)` for fixture's timestampFumiaki MATSUSHIMA2015-06-071-1/+0
|/ | | | Time instance will be casted so we don't have to do `to_s(:db)`.
* Resolve enums in test fixturesGeorge Claghorn2015-05-271-0/+5
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-8/+20
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #19177 from gregmolnar/fixturesRafael Mendonça França2015-03-021-5/+3
|\ | | | | Added testcase for #18742
| * Use the correct connection for reset_pk_sequenceMontana Low2015-03-011-5/+3
| | | | | | | | When a fs.model_class.connection uses a different database than connection, connection.reset_pk_sequence will fail with an exception causing fixture load to rollback. This is reproducible for any ActiveRecord::Base class that calls establish_connection with a different database.
* | Merge pull request #17426 from jpcody/fixture_associations_fixAaron Patterson2015-02-241-0/+4
|\ \ | |/ |/| Rely on through table name in has_many fixtures
| * Rely on through table name in has_many fixturesJoshua Cody2014-10-291-0/+4
| | | | | | | | | | | | | | Rather than using the association's join_table method, which constructs a table name from conventions, this should rely on the through reflection's table_name to be resilient to tables that were not automatically named.
* | Use Module#include instead of send :include, since now is a public method ↵robertomiranda2015-01-311-2/+2
| | | | | | | | | | | | [ci skip] ref https://bugs.ruby-lang.org/issues/8846
* | changed deleted_tables list to setHyonjee Joo2015-01-311-1/+2
| |
* | Merge pull request #18512 from vipulnsward/18492-fixtures-with-stiAaron Patterson2015-01-311-1/+5
|\ \ | | | | | | Fix STI for fixtures from multi-files
| * | Fixes #18492Vipul A M2015-01-141-1/+5
| | | | | | | | | | | | | | | | | | | | | - 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
* | | Remove most type related predicates from `Column`Sean Griffin2015-01-301-3/+3
|/ / | | | | | | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* | Fix lookup of fixtures with non-string labelPrathamesh Sonpatki2015-01-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | - 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.
* | Fix TypeError in Fixture creationMatt Hogan2015-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ruby 4.2 started doing `value.gsub('$LABEL', label)` for fixture label interpolation, but you can have have valid YAML where `label` isn't a String. For example: ```YAML 0: name: John email: johndoe@gmail.com 1: name: Jane email: janedoe@gmail.com ``` This YAML will create a label that is a Fixnum, causing `TypeError: no implicit conversion of Fixnum into String.`
* | Remove deprecated `ActiveRecord::Fixtures` constantRafael Mendonça França2015-01-041-6/+0
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-3/+3
| |
* | Fix build failuresSean Griffin2014-11-221-1/+3
| | | | | | | | | | | | | | | | | | | | For some reason changing `.find` to `.unscoped.find` in https://github.com/rails/rails/commit/f766abd4cf3eb75469d3646cfb6d85e668c619f3 caused `scoping` to leak in some tests when run in isolation (looks like a concurrency issue?). `relation_scoping_test.rb` is a case that failed. From what I can tell it should not be possible, but changing to the block form fixes it. There is a deeper issue that I can't seem to find. /cc @senny
* | make it possible to access fixtures excluded by a `default_scope`.Yves Senn2014-11-211-1/+1
| | | | | | | | | | | | | | | | 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>)] ```
* | Avoid unnecessary allocations/callsPablo Herrero2014-11-021-1/+1
|/
* Merge pull request #17014 from grosser/grosser/fast-fixturesAaron Patterson2014-10-101-34/+2
|\ | | | | speed up fixtures by not loading all their classes
| * speed up fixtures by not loading all their classesgrosser2014-10-061-34/+2
| |
* | Use Hash#each_key instead of Hash#keys.eachErik Michaels-Ober2014-09-291-1/+1
|/ | | | | | Hash#keys.each allocates an array of keys; Hash#each_key iterates through the keys without allocating a new array. This is the reason why Hash#each_key exists.
* fix fixtures not loading if a belongs_to association is defined with a ↵Will Bryant2014-09-221-1/+1
| | | | :foreign_key option that's a symbol
* Updated comment about features of fixturesPrathamesh Sonpatki2014-09-191-0/+3
| | | | | | - Added a note about some features which are not dependent on auto-generated ID's. - [ci skip]
* extract updating all fixture cache to a method so we can lock laterAaron Patterson2014-09-031-1/+5
|
* [ci skip] Fix example code of ActiveRecord::FixtureSet.context_classyuuji.yaginuma2014-08-291-1/+1
|
* don't log errors when all is finePeter Schröder2014-07-171-5/+5
|
* Move uuid_v5 and uuid_v3 to Digest::UUIDRafael Mendonça França2014-07-151-2/+2
| | | | | These methods are not random so they should not belings to SecureRandom module.
* Revert code changes at "Copy edits and code font wrap for Active Record [ci ↵Rafael Mendonça França2014-06-131-1/+7
| | | | | | | | skip]" This partially reverts commit 1a203d5e07f639332880099fab610b886b1742fc. Reason: It was committed by accident