aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_one_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Follow-up to #10776Robin Dupret2015-02-261-1/+1
| | | | | | | | | | The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
* `WhereClause#predicates` does not need to be publicSean Griffin2015-01-271-4/+4
| | | | | | | | | | | The only place it was accessed was in tests. Many of them have another way that they can test their behavior, that doesn't involve reaching into internals as far as they did. `AssociationScopeTest` is testing a situation where the where clause would have one bind param per predicate, so it can just ignore the predicates entirely. The where chain test was primarly duplicating the logic tested on `WhereClause` directly, so I instead just make sure it calls the appropriate method which is fully tested in isolation.
* Remove all references to `where_values` in testsSean Griffin2015-01-251-4/+4
|
* Extracted `ActiveRecord::AttributeAssignment` to ↵Bogdan Gusiev2015-01-231-1/+1
| | | | | | `ActiveModel::AttributesAssignment` Allows to use it for any object as an includable module.
* Fix warning: assigned but unused variable - postRyuta Kamizono2014-12-311-1/+1
|
* Fix error message when trying to create an associated recordRafael Mendonça França2014-12-301-0/+8
| | | | | | | | | | | | This error only happens when the foreign key is missing. Before this fix the following exception was being raised: NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218> Now the message is: ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
* Share foreign_key_present? implementation in _has_ associationsbrainopia2014-12-311-0/+6
|
* Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-081-0/+11
| | | | | | | 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.
* Fix a bug where AR::RecordNotSaved loses error messagesYuki Nishijima2014-11-271-3/+10
| | | | | | Since 3e30c5d, it started ignoring the given error message. This commit changes the behavior of AR::RecordNotSaved#initialize so that it no longer loses the given error message.
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Ignore SCHEMA queries when asserting no queriesAkira Matsuda2014-08-281-1/+1
|
* Associations now raise `ArgumentError` on name conflicts.Lauro Caetano2014-01-311-0/+10
| | | | | Dangerous association names conflicts include instance or class methods already defined by `ActiveRecord::Base`.
* `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.Rafael Mendonça França2014-01-211-0/+7
| | | | | | | | | | Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results among different database engines. But for singular associations this behavior is not needed since we will have one record to return. As this ORDER BY option can lead some performance issues we are removing it for singular associations accessors. Fixes #12623.
* Raise `ArgumentError` when `has_one` is used with `counter_cache`Godfrey Chan2013-11-291-0/+8
| | | | | | | | | Previously, the `has_one` macro incorrectly accepts the `counter_cache` option due to a bug, although that options was never supported nor functional on `has_one` and `has_one ... through` relationships. It now correctly raises an `ArgumentError` when passed that option. For reference, this bug was introduced in 52f8e4b9.
* Fix test name [ci skip]Carlos Antonio da Silva2013-11-141-1/+1
|
* Fixes problem with replacing has_one association record with itselfDenis Redozubov2013-11-111-2/+16
|
* Save association when primary key is manually setlaurocaetano2013-10-241-0/+11
|
* Avoid empty transaction from setting has_one association on new record.Dylan Thacker-Smith2013-09-111-0/+2
|
* Dropped deprecated option `:restrict` for `:dependent` in associationsNeeraj Singh2013-07-031-16/+0
|
* Fix #8856 Ensure has_one association=(associate) triggers save.Chris Thompson2013-04-301-0/+16
| | | | | | | | | | | | | | | | | | | | | | | activerecord/lib/active_record/associations.rb states: # [association=(associate)] # Assigns the associate object, extracts the primary key, sets it as the foreign key, # and saves the associate object. Since commit 42dd5d9f2976677a4bf22347f2dde1a8135dfbb4 to fix #7191, this is no longer the case if the associate has changed, but is the same object. For example: # Pirate has_one :ship pirate = Pirate.create!(catchphrase: "A Pirate") ship = pirate.build_ship(name: 'old name') ship.save! ship.name = 'new name' pirate.ship = ship That last line should trigger a save. Although we are not changing the association, the associate (ship) has changed.
* Revert "Merge pull request #8989 from robertomiranda/use-rails-4-find-by"Guillermo Iguaran2013-01-181-2/+2
| | | | | This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
* User Rails 4 find_byrobertomiranda2013-01-181-2/+2
|
* User assert_kind_of, invert assert_equal expectationsCarlos Antonio da Silva2012-11-291-3/+3
|
* Added STI support to init and building associationsJason Rush2012-11-291-0/+30
| | | | | | | | Allows you to do BaseClass.new(:type => "SubClass") as well as parent.children.build(:type => "SubClass") or parent.build_child to initialize an STI subclass. Ensures that the class name is a valid class and that it is in the ancestors of the super class that the association is expecting.
* Do not create useless database transaction when building `has_one` association.Bogdan Gusiev2012-11-101-0/+6
|
* Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-161-16/+0
|
* Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-16/+0
|
* Remove the dependent_restrict_raises option.Jon Leighton2012-08-101-43/+13
| | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* Fix #7191. Remove unnecessary transaction when assigning has_one associations.kennyj2012-08-081-0/+13
|
* s/scoped/scope/Jon Leighton2012-08-011-1/+1
|
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-4/+4
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-1/+1
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* remove deprecated callsJon Leighton2012-04-271-3/+3
|
* find and replace deprecated keysJon Leighton2012-04-271-1/+1
|
* %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other ↵Jon Leighton2012-04-271-1/+1
| | | | things
* remove calls to find(:first), find(:last) and find(:all)Jon Leighton2012-04-261-2/+2
|
* Fix #5069 - Protect foreign key from mass assignment throught association ↵Jean Boussier2012-03-051-0/+16
| | | | builder
* Fix typoRafael Mendonça França2012-02-011-2/+2
|
* Use human attribute name to show the dependent destroy messageRafael Mendonça França2012-02-011-1/+25
|
* fix has_one, has_many restrict error messageManoj2012-02-011-1/+1
|
* Remove deprecation warnings from testsRafael Mendonça França2012-01-311-6/+12
|
* suggested fixes for :dependent => :restrict deprecation.Manoj2012-01-311-16/+5
|
* has_many/has_one, :dependent => :restrict, deprecation added.Manoj2012-01-291-2/+46
|
* Only call set_owner_attributes for has_one association if target exists.Dieter Komendera2011-07-041-0/+11
|
* Assign the association attributes to the associated record before the ↵Jon Leighton2011-06-301-0/+7
| | | | before_initialize callback of the record runs. Fixes #1842.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* removed deprecated methods, and related tests, from ActiveRecordJosh Kalderimis2011-05-251-9/+0
|
* Add block setting of attributes to singular associationsAndrew White2011-05-171-0/+21
|