Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from constantcontact/nested_attributes
add test and fix for nested_attributes update
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require File.expand_path('../abstract_unit', __FILE__) | ||
|
||
# Testing the find action on composite ActiveRecords with two primary keys | ||
class TestNestedAttributes < ActiveSupport::TestCase | ||
fixtures :reference_types | ||
|
||
def setup | ||
@reference_type = ReferenceType.first | ||
end | ||
|
||
def test_nested_atttribute_create | ||
code_id = 1001 | ||
@reference_type.update_attribute :reference_codes_attributes, [{ | ||
:reference_code => code_id, | ||
:code_label => 'XX', | ||
:abbreviation => 'Xx' | ||
}] | ||
assert_not_nil ReferenceCode.find_by_reference_code(code_id) | ||
end | ||
|
||
def test_nested_atttribute_update | ||
code_id = 1002 | ||
@reference_type.update_attribute :reference_codes_attributes, [{ | ||
:reference_code => code_id, | ||
:code_label => 'XX', | ||
:abbreviation => 'Xx' | ||
}] | ||
reference_code = ReferenceCode.find_by_reference_code(code_id) | ||
cpk = CompositePrimaryKeys::CompositeKeys[@reference_type.reference_type_id, code_id] | ||
@reference_type.update_attribute :reference_codes_attributes, [{ | ||
:id => cpk, | ||
:code_label => 'AAA', | ||
:abbreviation => 'Aaa' | ||
}] | ||
reference_code = ReferenceCode.find_by_reference_code(code_id) | ||
assert_kind_of(ReferenceCode, reference_code) | ||
assert_equal(reference_code.code_label, 'AAA') | ||
end | ||
end |