Skip to content

How to properly test an Uploader? #604

Answered by janko
danielnc asked this question in Q&A
Discussion options

You must be logged in to vote

It might be easiest to test through a specific model, especially if there is model-specific code in the uploader.

photo = Photo.new
photo.image = StringIO.new("too small")
refute photo.valid?
assert_equal ["..."], photo.errors[:image]

But if the uploader doesn't reference the model, it should also be possible to test the attacher individually:

attacher = ImageUploader::Attacher.new
attacher.assign StringIO.new("too small")
assert_equal ["..."], attacher.errors

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@danielnc
Comment options

Answer selected by danielnc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants