1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activemodel/test/cases/nested_error_test.rb
yuuji.yaginuma ac1ba44f8d Fix test case name to fit file name
This fixes the following warnings.

```
/rails/activemodel/test/cases/nested_error_test.rb:9: warning: method redefined; discarding old test_initialize
/rails/activemodel/test/cases/error_test.rb:29: warning: previous definition of test_initialize was here
```
2019-05-04 17:49:25 +09:00

54 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require "cases/helper"
require "active_model/nested_error"
require "models/topic"
require "models/reply"
class NestedErrorTest < ActiveModel::TestCase
def test_initialize
topic = Topic.new
inner_error = ActiveModel::Error.new(topic, :title, :not_enough, count: 2)
reply = Reply.new
error = ActiveModel::NestedError.new(reply, inner_error)
assert_equal reply, error.base
assert_equal inner_error.attribute, error.attribute
assert_equal inner_error.type, error.type
assert_equal(inner_error.options, error.options)
end
test "initialize with overriding attribute and type" do
topic = Topic.new
inner_error = ActiveModel::Error.new(topic, :title, :not_enough, count: 2)
reply = Reply.new
error = ActiveModel::NestedError.new(reply, inner_error, attribute: :parent, type: :foo)
assert_equal reply, error.base
assert_equal :parent, error.attribute
assert_equal :foo, error.type
assert_equal(inner_error.options, error.options)
end
def test_message
topic = Topic.new(author_name: "Bruce")
inner_error = ActiveModel::Error.new(topic, :title, :not_enough, message: Proc.new { |model, options|
"not good enough for #{model.author_name}"
})
reply = Reply.new(author_name: "Mark")
error = ActiveModel::NestedError.new(reply, inner_error)
assert_equal "not good enough for Bruce", error.message
end
def test_full_message
topic = Topic.new(author_name: "Bruce")
inner_error = ActiveModel::Error.new(topic, :title, :not_enough, message: Proc.new { |model, options|
"not good enough for #{model.author_name}"
})
reply = Reply.new(author_name: "Mark")
error = ActiveModel::NestedError.new(reply, inner_error)
assert_equal "Title not good enough for Bruce", error.full_message
end
end