aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Fixes #33610Darwin D Wu2018-09-111-0/+12
| | | | | | | | | | | | In order to avoid double assignments of nested_attributes for `has_many` relations during record initialization, nested_attributes in `create_with` should not be passed into `klass.new` and have them populate during `initialize_internals_callback` with scope attributes. However, `create_with` keys should always have precedence over where clauses, so if there are same keys in both `create_with` and `where_values_hash`, the value in `create_with` should be the one that's used.
* Call build when extend with nested attributes definedAlireza Bashiri2018-08-021-0/+12
| | | | | | | | What? From now on when `accepts_nested_attributes_for` defined and `extend` option added the overwritten `build` method being called. [Alireza Bashiri, Martins Polakovs]
* Enable `Layout/EmptyLinesAroundBlockBody` to reduce review cost in the futureRyuta Kamizono2018-07-121-1/+0
| | | | | | | We sometimes ask "✂️ extra blank lines" to a contributor in reviews like https://github.com/rails/rails/pull/33337#discussion_r201509738. It is preferable to deal automatically without depending on manpower.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-2/+2
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Remove extra whitespaceDaniel Colson2018-01-251-2/+2
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-3/+3
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-18/+18
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Raise on create for singular association when parent is unpersistedAlex Kitchens2017-06-081-1/+1
| | | | | | A collection association will raise on `#create_association` when the parent is unpersisted. A singular association should do the same. This addresses issue #29219.
* More friendly exception in nested attributesKir Shatrov2017-05-221-1/+1
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-25/+25
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-1/+2
| | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
* applies remaining conventions across the projectXavier Noria2016-08-061-2/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-6/+6
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-12/+10
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-131/+131
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-190/+190
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* `load_target` is a public methodRyuta Kamizono2016-07-231-4/+4
| | | | `send` is unnecessary.
* remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-9/+9
|
* Addresses #23568Ryan T. Hosford2016-02-091-0/+14
| | | | | | | - Corrects an incorrect exception message when using accepts_nested_attributes_for - Removes rescue/reraise behavior introduced in #19077 - Adds has_many & has_one, nested_attributes test case specifying the message that should be conveyed with an exception raised because one of the nested attributes provided is unknown
* Don't short-circuit reject_if procAndrew White2016-01-221-0/+13
| | | | | | | | | | | | | When updating an associated record via nested attribute hashes the reject_if proc could be bypassed if the _destroy flag was set in the attribute hash and allow_destroy was set to false. The fix is to only short-circuit if the _destroy flag is set and the option allow_destroy is set to true. It also fixes an issue where a new record wasn't created if _destroy was set and the option allow_destroy was set to false. CVE-2015-7577
* Update and fix forbidden attributes testsThomas Walpole2015-11-031-35/+0
| | | | Add AC::Parameters tests for WhereChain#not
* Removed mocha from Active Record Part 2Ronak Jangir2015-09-161-16/+20
|
* Ensure that 'ActionController::Parameters' can still be passed to AR for ↵Thomas Walpole2015-07-181-1/+13
| | | | collection associations
* Ensure that `ActionController::Parameters` can still be passed to ARSean Griffin2015-07-181-0/+23
| | | | | | | | | | | | | | | | | | | | | Since nested hashes are also instances of `ActionController::Parameters`, and we're explicitly looking to work with a hash for nested attributes, this caused breakage in several points. This is the minimum viable fix for the issue (and one that I'm not terribly fond of). I can't think of a better place to handle this at the moment. I'd prefer to use some sort of solution that doesn't special case AC::Parameters, but we can't use something like `to_h` or `to_a` since `Enumerable` adds both. While I've added a trivial test case for verifying this fix in isolation, we really need better integration coverage to prevent regressions like this in the future. We don't actually have a lot of great places for integration coverage at the moment, so I'm deferring it for now. Fixes #20922.
* Add test proving that accepts_nested_attributes_for is secure against ID ↵Victor Costan2015-07-071-0/+10
| | | | tampering attacks.
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Always perform validations on nested attribute associationsSean Griffin2015-01-301-0/+7
| | | | | | | Collection associations would have already been validated, but singular associations were not. Fixes #18735.
* Don't redefine autosave association callbacks in nested attrsSean Griffin2015-01-281-0/+10
| | | | | | | | These callbacks will already have been defined when the association was built. The check against `reflection.autosave` happens at call time, not at define time, so simply modifying the reflection is sufficient. Fixes #18704
* Extracted `ActiveRecord::AttributeAssignment` to ↵Bogdan Gusiev2015-01-231-1/+1
| | | | | | `ActiveModel::AttributesAssignment` Allows to use it for any object as an includable module.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-6/+6
|
* Remove extra indirection for testing exceptions and messagesCarlos Antonio da Silva2014-03-201-28/+12
| | | | | | assert_raise + assert_equal on the returned exception message work just fine, there is no need for extra work, specially like this overly complicated helper.
* Use teardown helper method.Guo Xiang Tan2014-03-141-1/+1
| | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* This test does not test anything that happens in the real world. If youAaron Patterson2013-06-131-20/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | recreate the models without mucking with internal caches of the relation objects, then the test fails. For example: class Man < ActiveRecord::Base has_many :interests end class Interest < ActiveRecord::Base belongs_to :man end Then do this test: def test_validate_presence_of_parent_fails_without_inverse_of repair_validations(Interest) do Interest.validates_presence_of(:man) assert_no_difference ['Man.count', 'Interest.count'] do man = Man.create(:name => 'John', :interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}]) assert_not_predicate man.errors[:"interests.man"], :empty? end end end The test will fail. This is a bad test, so I am removing it.
* refute the predicate for better failure messagesAaron Patterson2013-06-131-1/+1
|
* Created a method to automatically find inverse associations and cachewangjohn2013-05-071-0/+2
| | | | | | the results. Added tests to check to make sure that inverse associations are automatically found when has_many, has_one, or belongs_to associations are defined.
* Do not overwrite manually built records during one-to-one nested attribute ↵Olek Janiszewski2013-05-031-0/+14
| | | | | | | | | | | | | | | | | | | | | assignment For one-to-one nested associations, if you build the new (in-memory) child object yourself before assignment, then the NestedAttributes module will not overwrite it, e.g.: class Member < ActiveRecord::Base has_one :avatar accepts_nested_attributes_for :avatar def avatar super || build_avatar(width: 200) end end member = Member.new member.avatar_attributes = {icon: 'sad'} member.avatar.width # => 200
* Add Error#full_message test; Fix typosVipul A M2013-03-221-1/+1
| | | | | Introduce test on Error#full_message for attribute with underscores; Fix some typos
* fix typos in AR. lots of them.Vipul A M2013-03-191-1/+1
|
* Namespace HashWithIndifferentAccessAkira Matsuda2013-01-071-2/+2
|
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-54/+54
|
* Add test to avoid regression of 58e48d5292242f000dc8a87fdbb1c0ccdcf286d8Gabriel Sobrinho & Ricardo Henrique2012-11-081-0/+11
|
* Ensure nested attributes is restored in case of a test failureCarlos Antonio da Silva2012-11-031-1/+1
|
* Simplify query conditions a bit in nested attributes testCarlos Antonio da Silva2012-11-031-5/+3
| | | | Also refactor the test a bit.
* gradually moving documentation to new hash syntaxAvnerCohen2012-10-101-1/+1
|