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

assigns converts nil to empty string #33

Closed
jstoebel opened this Issue Apr 19, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@jstoebel
Copy link

jstoebel commented Apr 19, 2017

I just made the switch to Rails 5.0. I often test state of my controllers by comparing to an expected hash like so:

expected_attrs = {"id"=>38,
  "name" => "some name"
  "comments"=>nil}

actual_attrs = assigns(:post).attributes
assert_equal expected_attrs, actual_attrs

This worked find in Rails 4.2. But after the switch the two hashes are not equal. Specifically, actual_attrs["comments"] is now "" not nil.

Is this an issue in this gem or a change in Rails 5? Or is there something else I'm misunderstanding? I'm happy to work on this issue if its fixable.

@rafaelfranca

This comment has been minimized.

Copy link
Member

rafaelfranca commented Apr 19, 2017

It is a change in 5.0. Now controller tests are parsing the attributes in the same way a browser does. There is no way a parameter get in the controller with nil if your request is using the HTML format, so now Rails is behaving in the same way of a browser.

@jstoebel

This comment has been minimized.

Copy link

jstoebel commented Apr 19, 2017

gotcha, thanks so much!

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