Skip to content

Instantly share code, notes, and snippets.

@bastianwegge
Last active June 14, 2016 17:42
Show Gist options
  • Save bastianwegge/6d2b35720e66c31e4a4e to your computer and use it in GitHub Desktop.
Save bastianwegge/6d2b35720e66c31e4a4e to your computer and use it in GitHub Desktop.
refile file upload using rspec and fixture file upload
describe "post #upload" do
it "image to object" do
container = create :container
file = fixture_file_upload(Rails.root.join('spec/fixtures/files/example.jpg'), 'image/jpeg')
container.attached_image = file
post :upload, container: container.to_param
expect(container.reload.attached_image).to be_present
end
end
@johannesboyne
Copy link

Little bit different approach:

describe "Image Uploads" do
  describe User do
    let(:user) { create :user }
    it 'should be possible to create a profile image for a user' do
      user.profile_image = File.open(File.join(Rails.root, 'db/seeds/aist.png'))
      expect(user.profile_image.id).to be_truthy
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment