Skip to content

Instantly share code, notes, and snippets.

@mmb
Created July 31, 2014 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmb/3cee36e6fd16bf33df0b to your computer and use it in GitHub Desktop.
Save mmb/3cee36e6fd16bf33df0b to your computer and use it in GitHub Desktop.
Rack::Test::UploadedFile doesn't respond to encoding
def create
@src_image = SrcImage.new(src_image_params)
@src_image.user = current_user
read_image_data @src_image
respond_to do |format|
if @src_image.save
create_success(format)
else
create_fail(format)
end
end
end
---
let(:image) { fixture_file_upload('/files/ti_duck.jpg', 'image/jpeg') }
it 'saves the new source image to the database' do
expect do
post :create, src_image: { image: image }
end.to change { SrcImage.count }.by(1)
end
---
1) SrcImagesController POST 'create' with valid attributes saves the new source image to the database
Failure/Error: post :create, src_image: { image: image }
NoMethodError:
undefined method `encoding' for #<Tempfile:0x007fc2b5b97e48>
# ./app/controllers/src_images_controller.rb:18:in `create'
# ./spec/controllers/src_images_controller_spec.rb:135:in `block (5 levels) in <top (required)>'
# ./spec/controllers/src_images_controller_spec.rb:134:in `block (4 levels) in <top (required)>'
# -e:1:in `load'
# -e:1:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment