Search code examples
ruby-on-railsruby-on-rails-3rspec2carrierwaverspec-rails

Testing model with Carrierwave uploader


I have a pretty simple model:

class SocialGroup < ActiveRecord::Base
  validates :name, presence: true
  validates :file, presence: true

  mount_uploader :file, SocialGroupFileUploader
end

And the question is: Should I test (with rspec) the model successful save with valid file type provided (my white list of file extensions includes only csv)? Or should I test the file uploader in isolation? If answer on first question is Yes, how test shoul look like?


Solution

  • If your uploader is simple I think it's fairly safe to assume that CarrierWave's developers have done the testing there, the test suite is fairly comprehensive (but it's very much a matter of opinion, some people will and some people won't).

    I'd concentrate on making sure that the controller is tested either in rspec or the cucumber specs. There are a couple of examples of people doing this in a google search.