如何使用 Cucumber 测试接受嵌套属性的 Rails 模型

发布于 2024-07-25 12:09:49 字数 335 浏览 7 评论 0原文

如何测试接受图像嵌套属性的模型主题?

Given /^I have topics titled (.+)$/ do |titles|
    path ="#{RAILS_ROOT}/features/upload-files/" 
    image = File.new(path + "image.jpg")
    titles.split(', ').each do |title|
        Topic.create!(:title => title, :image => File.new(image) ) # this doesn't work!
    end
end

How do you test a model Topic that accepts nested attributes for an Image?

Given /^I have topics titled (.+)$/ do |titles|
    path ="#{RAILS_ROOT}/features/upload-files/" 
    image = File.new(path + "image.jpg")
    titles.split(', ').each do |title|
        Topic.create!(:title => title, :image => File.new(image) ) # this doesn't work!
    end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰葑 2024-08-01 12:09:49
Topic.create!(:title => title, :image_attributes => {:image => File.new(image) } ) # this works!
Topic.create!(:title => title, :image_attributes => {:image => File.new(image) } ) # this works!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文