Paperclip testing with rspec

After spending the better part of a day getting this figured out - here's how to test for attachment uploads using Rspec and paperclip

In the model spec

@attr = { :name => "Example Name", 
              :description => "Example Description",
              :image => Rack::Test::UploadedFile.new('spec/fixtures/images/test.jpg', 'image/jpeg')
            }

In the controller spec

Rails commands I use but can never remember the command or syntax

rake db:migrate

rake db:test:prepare

rails generate migration AddColumnToTable col_name:type

Image Uploads for a Rails app

https://github.com/thoughtbot/paperclip#readme

Requires ImageMagick

sudo apt-get install imagemagick libmagickcore-dev

add

gem "paperclip", "~> 2.4"

to your Gemfile then

bundle install

Done

 

 

Test Driven Development - What to test for

What should I test for when I'm doing test driven development?

Data (Model) Tests

  • Validations
  • Methods

Function (controllers)  Tests

  • Request Success (e.g. 200 or 300 received)
  • Got the correct page
  • Authenticated correctly
  • Proper objects as expected
  • Proper message displayed

Integration Tests

  • Test the interactions between functions/controllers

Test Routes

  • For RoR check that the urls go to the correct place

Test Mailers

Syndicate content