未验证 提交 ea70d204 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #31926 from composerinteralia/am-attributes

Add ActiveModel::Attributes#attributes
......@@ -66,6 +66,10 @@ def initialize(*)
super
end
def attributes
@attributes.to_hash
end
private
def write_attribute(attr_name, value)
......
......@@ -47,6 +47,26 @@ class GrandchildModelForAttributesTest < ChildModelForAttributesTest
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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册