diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-02-28 00:17:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-28 00:17:43 -0500 |
commit | ea70d20441a745ba3ace2e82071ccb1ef56daf2e (patch) | |
tree | 9cad5cc0772bd4092716e8e814b609e245d45baa /activemodel/test/cases | |
parent | a14a6b8834fc35136aa0e52bb27fd73f75f83c0b (diff) | |
parent | 043ce35b18662e46cb5b0d9cf203f4da4eefc421 (diff) | |
download | rails-ea70d20441a745ba3ace2e82071ccb1ef56daf2e.tar.gz rails-ea70d20441a745ba3ace2e82071ccb1ef56daf2e.tar.bz2 rails-ea70d20441a745ba3ace2e82071ccb1ef56daf2e.zip |
Merge pull request #31926 from composerinteralia/am-attributes
Add ActiveModel::Attributes#attributes
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/attributes_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activemodel/test/cases/attributes_test.rb b/activemodel/test/cases/attributes_test.rb index 7c1d813ce0..5483fb101d 100644 --- a/activemodel/test/cases/attributes_test.rb +++ b/activemodel/test/cases/attributes_test.rb @@ -47,6 +47,26 @@ module ActiveModel assert_equal true, data.boolean_field end + test "reading attributes" do + data = ModelForAttributesTest.new( + integer_field: 1.1, + string_field: 1.1, + decimal_field: 1.1, + boolean_field: 1.1 + ) + + expected_attributes = { + integer_field: 1, + string_field: "1.1", + decimal_field: BigDecimal("1.1"), + string_with_default: "default string", + date_field: Date.new(2016, 1, 1), + boolean_field: true + }.stringify_keys + + assert_equal expected_attributes, data.attributes + end + test "nonexistent attribute" do assert_raise ActiveModel::UnknownAttributeError do ModelForAttributesTest.new(nonexistent: "nonexistent") |