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

时间:2009-06-24 03:23:20

标签: ruby-on-rails cucumber nested-forms

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

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

1 个答案:

答案 0 :(得分:4)

Topic.create!(:title => title, :image_attributes => {:image => File.new(image) } ) # this works!