[英]RSPEC and PAPERCLIP gem for Ruby on Rails
I'm writing tests (RPSEC) and in a model for design uploads (which contain description, photo, and user_id) 我正在编写测试(RPSEC)和设计上传模型(包含description,photo和user_id)
Im using paperclip gem and all works great except for the tests because I dont know how to specify an image_tag.. 我使用paperclip gem,除了测试之外,所有工作都很棒,因为我不知道如何指定image_tag。
My design_spec is as follows 我的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
what i need help on is how to show that the design has a photo attachment. 我需要帮助的是如何表明该设计有照片附件。 Obviously with description I canjust use a string, but thats not the case with an image. 显然,通过描述我可以使用一个字符串,但这不是图像的情况。
thanks in advance for the help. 先谢谢您的帮助。
您是否尝试过在HDD上本地存储文件?
@design.photo = File.new("/path/to/my-image.png")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.