ruby on rails - FactoryGirl with Paperclip setting the wrong image content type -


i have class seatingchart attached chart_image in factory seatingchart trying create chart_image rack::test::uploadedfile , getting error:

failures:    1) seatingchart has minimum valid factory      failure/error: expect(build :seating_chart).to be_valid        expected #<seatingchart id: nil, name: "konklab", created_at: nil, updated_at: nil, venue_id: nil, chart_image_file_name: "logoimage.jpg", chart_image_content_type: "text/plain", chart_image_file_size: 28555, chart_image_updated_at: "2015-05-13 23:29:01"> valid, got errors: chart image content type invalid, chart image invalid 

the factory seatingchart is

factorygirl.define   factory :seating_chart     name { faker::app.name }     chart_image       rack::test::uploadedfile.new rails.root.join('app',                                           'assets',                                           'images',                                           'logoimage.jpg')     end     factory :chart_with_seats       after :build |chart|         50.times           create :seat, seating_chart: chart         end       end     end   end end 

and seatingchart is

class seatingchart < activerecord::base   require 'json'   has_attached_file :chart_image   validates_attachment_content_type :chart_image, content_type: %r{ /\aimage\/.*\z/ }   validates_attachment :chart_image, presence: true   validates :name, presence: true    has_many :shows   has_many :price_sections end 

edit: new error message after specifying file type in rack::test::uploadedfile.new

failures:    1) seatingchart has minimum valid factory      failure/error: expect(build :seating_chart).to be_valid        expected #<seatingchart id: nil, name: "span", created_at: nil, updated_at: nil, venue_id: nil, chart_image_file_name: "logoimage.jpg", chart_image_content_type: "image", chart_image_file_size: 28555, chart_image_updated_at: "2015-05-13 23:44:02"> valid, got errors: chart image content type invalid, chart image invalid 

you can specify content type so:

rack::test::uploadedfile.new (rails.root.join('app',                                           'assets',                                           'images',                                           'logoimage.jpg'),                               'image/jpg' ) 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -