I'm writing my User model spec with RSpec and I want to test if photo uploading works as it should - pretty straight forward.
But I haven't gotten very far. An excerpt of my model spec is like this:
it "does not allow uploading files other than images for avatar" do
user = create(:user)
user.avatar = File.new("#{Rails.root}/public/robots.txt")
end
I have created my user, trying to attach my file… but as to how to actually test the upload or just to validate if it indeed is an image or not (I suppose uploading isn't necessary per se, I just need to validate the attached file). No idea.
I have looked into Paperclip shoulda matchers, like for example
it { should validate_attachment_content_type(:icon).
allowing('image/png', 'image/gif').
rejecting('text/plain', 'text/xml') }
but to me it seems entirely pointless, as all it does is say it should validate content type. But does it? How do I know if it does? How do I attach a file and see if it does?
I have searched far and wide, with all the possible keyword combinations to find an answer to this, but with no luck so far. Am I just somehow conceptually not getting it? I'm clearly a beginner, so please don't burn me for asking what might seem dumb to you.