0

我正在编写测试 (RPSEC) 和设计上传模型(其中包含描述、照片和 user_id)

我正在使用回形针 gem,除了测试之外,所有东西都很好用,因为我不知道如何指定 image_tag ..

我的 design_spec 如下

describe Design do
  let(:user) { FactoryGirl.create(:user) }

   before do
     @design = Design.new(description: "Lorem ipsum", user_id: user.id, photo: ( THIS IS WHERE I NEED HELP )
   end

   subject { @design }

   it { should respond_to(:description) }
   it { should respond_to(:user_id) }
   it { should have_attached_file(:photo) }
   it { should validate_attachment_presence(:photo) }

   it { should be_valid }

   describe "when user_id is not present" do
     before { @design.user_id = nil }

     it { should_not be_valid }
   end
 end

我需要帮助的是如何证明设计有照片附件。显然,通过描述我可以使用字符串,但图像并非如此。

在此先感谢您的帮助。

4

1 回答 1

2

您是否尝试过获取本地存储在 HDD 上的文件?

@design.photo = File.new("/path/to/my-image.png")
于 2013-08-30T16:11:56.147 回答