>> 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"
当你有反斜杠时,稍微改变一下语法
assert_difference 'Reply.where("body = 'line1\r\n\r\nline2\r\n'").count' do