Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple mounts: ApplicationRecord instance "to_json" result is weird. #2106

Closed
ejvalmores opened this issue Jan 27, 2017 · 2 comments
Closed

Comments

@ejvalmores
Copy link

I am trying to make an API only Rails app (Rails 5.0.1). In my Service model I have something like:

class Service < ApplicationRecord
   mount_uploaders :photos, ServicePhotoUploader
end

I noticed this issue while I was making the test script for my ServicesController. However, I managed to replicate it in the test environment console.

> service = Service.new()
> service.photos = [ Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec', 'fixtures', 'images', 'altia.jpg')) ]
> service.save!
> service.to_json
=> "{\"id\":3053,\"photos\":[{\"url\":\"/uploads/service/photos/3053/altia.jpg\"}]}"

The result looks ok. But when I do service.reload the result looks weird.

> service.reload
> service.to_json
=> "{\"id\":3053, \"photos\":[{\"url\":\"/uploads/service/photos/3053/%5B%22altia.jpg%22%5D\"}]}"

Decoded, the 'url' value loooks like:

> URI.decode "/uploads/service/photos/3053/%5B%22altia.jpg%22%5D"
=> "/uploads/service/photos/3053/[\"altia.jpg\"]"

This is causing an issue when I to JSON.parse( respond.body ) in my test script.

Is this the expected result? or am I doing something wrong?

Thanks!

@mshibuya
Copy link
Member

Not reproducible here, how does your uploader and test code look like?

@ejvalmores
Copy link
Author

Hi,

I can't replicate this in the latest version anymore.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants