测试 [已解决] factory girl 构造数据格式问题

tsinghan · April 27, 2013 · Last by zhangyuan replied at April 27, 2013 · 2135 hits

model 中有一个属性 content 的类型为 text,从数据库读出来的格式是一个 hash, 现在我想用 factory girl 来构造测试数据

factory :hot_type do
           id       4
          city_id 1
          content {  url: 'xxx', title 'xxx', count 11 } 
end

但是报 content 的 语法错误,这种应该如何构造?

factory :hot_type do
           id       4
          city_id 1
          content {{ url: 'xxx', title 'xxx', count 11 }}
end

#1 楼 @zhangyuan It's very nice of you. 👙

ruby 会将 空格 + {} 解释为一个代码块。所以报语法错误。使用括号就能解决

content({ url: 'xxx', title 'xxx', count 11 }})
You need to Sign in before reply, if you don't have an account, please Sign up first.