aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/fixtures.rb
Commit message (Collapse)AuthorAgeFilesLines
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-2/+2
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Use tt in doc for ActiveRecord [ci skip]Yoshiyuki Hirano2017-08-271-1/+1
|
* Add `binary` helper method to fixtures.yalab2017-08-121-0/+4
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* [Active Record] require => require_relativeAkira Matsuda2017-07-011-2/+2
|
* Use bulk INSERT to insert fixturesKir Shatrov2017-06-201-3/+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.
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-2/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-14/+6
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Passing in no arguments to the dynamic fixture accessor method returns all ↵Kevin McPhillips2017-04-071-4/+25
| | | | fixtures, not an empty array.
* Ensure test threads share a DB connectioneileencodes2017-02-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Remove deprecated #use_transactional_fixtures configurationRafael Mendonça França2016-12-291-13/+1
|
* fix #create_fixtures when equal table names in different databasesJulia Lopez2016-12-211-3/+3
|
* Fix spelling in API docsDave Powers2016-11-121-2/+2
| | | | [ci skip]
* 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
| |