>> Reply.first
=> #< Reply id: 1, body: "line1\r\n\r\nline2\r\n" >
しかし、私がするとき
>> Reply.first.body
=> "line1"
彼らが探している私のテストのいくつかを破っています:
assert_difference 'Reply.where(:body => "line1\r\n\r\nline2").count' do
テストに改行があることを確認するにはどうすればよいですか?
>> Reply.first
=> #< Reply id: 1, body: "line1\r\n\r\nline2\r\n" >
しかし、私がするとき
>> Reply.first.body
=> "line1"
彼らが探している私のテストのいくつかを破っています:
assert_difference 'Reply.where(:body => "line1\r\n\r\nline2").count' do
テストに改行があることを確認するにはどうすればよいですか?
次のようなカスタムゲッターがあるようです:
class Reply < ActiveRecord::Base
def body
"foo"
end
end
reply = Reply.new(body: "bar")
#=> #<Reply id:nil, body: "bar" created_at: nil, updated_at: nil>
reply.body
#=> "foo"
その場合、次を使用して生の属性を取得できますModel[:attribute_name]。
reply[:body]
#=> "bar"
バックスラッシュがある場合は、snytax を少し変更します。
assert_difference 'Reply.where("body = 'line1\r\n\r\nline2\r\n'").count' do