I\'m trying to write a test for a model with a picture, using paperclip. I\'m using the test framework default, no shoulda or rspec. In this context, how should I test it? Shoul
This is in Rspec, but can be easily switched over
before do # setup
@file = File.new(File.join(RAILS_ROOT, "/spec/fixtures/paperclip", "photo.jpg"), 'rb')
@model = Model.create!(@valid_attributes.merge(:photo => @file))
end
it "should receive photo_file_name from :photo" do # def .... || should ....
@model.photo_file_name.should == "photo.jpg"
# assert_equal "photo.jpg", @model.photo_file_name
end
Since Paperclip is pretty well tested, I usually don't focus too much on the act of "uploading", unless i'm doing something out of the ordinary. But I will try to focus more on ensuring that the configurations of the attachment, in relation to the model it belongs, meet my needs.
it "should have an attachment :path of :rails_root/path/:basename.:extension" do
Model.attachment_definitions[:photo][:path].should == ":rails_root/path/:basename.:extension"
# assert_equal ":rails_root/path/:basename.:extension", Model.attachment_definitions[:photo][:path]
end
All the goodies can be found in Model.attachment_definitions
.