aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Merge pull request #5248 from ↵Jon Leighton2012-09-211-0/+16
|\ | | | | | | | | jcoleman/should-unset-association-when-an-existing-record-is-destroyed Unset association when existing record is destroyed.
| * Unset association when existing record is destroyed.James Coleman2012-03-021-0/+16
| | | | | | | | To avoid foreign key errors (and invalid data) in the database, when a belongs_to association is destroyed, it should also be nil'd out on the parent object.
* | ensures that the test repairs the validation setupFrancesco Rodriguez2012-08-271-7/+9
| |
* | allow to pass Symbol or Proc into :limit option of ↵Mikhail Dieterle2012-08-261-7/+31
| | | | | | | | #accepts_nested_attributes_for
* | Made ArgumentError messages consistent.Philip Arndt2012-07-061-1/+1
| |
* | Validates_numericality_of is skipped when changing 0 to to non-empty stringAngelo capilleri2012-06-191-0/+10
| | | | | | | | | | | | | | | | | | | | This happens when A has_many many B and A accepts_nested_attributes B that has a numeric colum with initial 0 value. So a.update_attributes({:b_attributes => { :id => b.id, :numeric => 'foo' }}) passes the validation test but, the value of :numeric doesn't change. his commit forces that the update fails with the above conditions. Fixes #6393 Fixes #2331
* | Nested attribute setters can be overridden.Jonathan Mukai & Peter Jaros2012-03-281-0/+13
| | | | | | | | Overriding implementation can call super.
* | remove usages of AS::OrderedHashVishnu Atrai2012-03-031-1/+1
| |
* | Refactored codeRaghunadh2012-02-101-1/+1
|/
* added failing tests for has_many, has_one and belongs_to associations with ↵Jakub Kuźma2011-12-211-5/+0
| | | | strict mass assignment sanitizer, fixed build_record to not merge creation_attributes, removed failing nested attributes tests (that feature was broken anyway) #4051
* Allow nested attributes in associations to update values in it's owner ↵Andrew Kaspick2011-12-141-0/+5
| | | | object. Fixes a regression from 3.0.x
* Exclude _destroy parameter in :all_blank check (issue #2937)Aaron Christy2011-10-171-0/+8
|
* assign_nested_attributes_for_collection_association should work with Ruby ↵Franck Verrot2011-07-201-0/+5
| | | | | | 1.9 [Closes #2106] Children attributes can be either String's or Symbol's, so let's check if the object responds to to_i.
* 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.
* Destroying records via nested attributes works independent of reject_if:Durran Jordan2011-04-051-0/+8
| | | | | | | | | | - When a :_destroy truthiness is provided in the attributes hash, the record should get destroyed regardless of the result of the proc or method supplied to :reject_if. (If :allow_destroy is true) [#6006 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Split AssociationProxy into an Association class (and subclasses) which ↵Jon Leighton2011-02-181-5/+5
| | | | manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more.
* Fixing incorrectly writtent testcaseAlexey Nayden2011-01-281-2/+2
|
* test_first_and_array_index_zero_methods_return_the_same_value_when_nested_at ↵Alexey Nayden2011-01-281-0/+9
| | | | tributes_are_set_to_update_existing_record added
* In a number of places in the tests, we only need to turn off transactional ↵Jon Leighton2011-01-111-2/+2
| | | | fixtures when the DB does not support savepoints. This speeds the test run up by about 8-9% on my computer, when running rake test_sqlite3_mem :)
* Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-1/+0
| | | | | | | | | | state:resolved] This required changing the code to keep the association proxy for a belongs_to around, despite its target being nil. Which in turn required various changes to the way that stale target checking is handled, in order to support various edge cases (loaded target is nil then foreign key added, foreign key is changed and then changed back, etc). A side effect is that the code is nicer and more succinct. Note that I am removing test_no_unexpected_aliasing since that is basically checking that the proxy for a belongs_to *does* change, which is the exact opposite of the intention of this commit. Also adding various tests for various edge cases and related things. Phew, long commit message!
* Improved strategy for updating a belongs_to association when the foreign key ↵Jon Leighton2010-12-231-2/+3
| | | | changes. Rather than resetting each affected association when the foreign key changes, we should lazily check for 'staleness' (where fk does not match target id) when the association is accessed.
* fix warnings, stop using global variablesAaron Patterson2010-11-301-2/+1
|
* If a nested_attribute is being marked for destruction and at the same time ↵Neeraj Singh2010-11-241-1/+14
| | | | | | | | an attr_accessor value is being assigned then the value being assigned is being ignored. This patch is a fix for that issue. [#5939 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Fixed bug in active_record/nested_attributes where an empty string id caused ↵Santiago Pastorino2010-11-111-0/+8
| | | | | | | | an ActiveRecord::RecordNotFound error. Found by [Ben Tillman] [#5638 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-8/+8
| | | | | | | | | | | - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Revert 0c0b0aa0f223523331afdc157fb3992a121bf497 which introduced a security ↵Michael Koziarski2010-10-151-14/+12
| | | | | | | | | | vulnerability. This addresses CVE-2010-3933 Conflicts: activerecord/lib/active_record/nested_attributes.rb