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

0.9.3 boolean attrs returns method missing #845

Closed
colinreidbrown opened this issue Mar 16, 2015 · 5 comments
Closed

0.9.3 boolean attrs returns method missing #845

colinreidbrown opened this issue Mar 16, 2015 · 5 comments

Comments

@colinreidbrown
Copy link

in 0.9.3 the following returns method missing where previous versions did not:

class ThingSerializer < ActiveModel::Serializer
attributes :uses_thing?

def uses_thing?
  true
end
end
def uses_thing
  true 
end  

would also return the declared attr before but 0.9.3 returns the method name instead of the declared attr name fyi

@colinreidbrown
Copy link
Author

as a clarification it is not specifically boolean but attr / methods with a trailing "?" in the name

@kurko
Copy link
Member

kurko commented Apr 9, 2015

Could you check the 0.9-stable branch, whether this was fixed or not already? We're about to release 0.9.4 via #871 and I'd love to know if that was fixed.

If not, do you think you can venture a PR with a fix?

@prasadsurase
Copy link

Checked with and without method name using '?'. This is broken on '0-9-stable' too.
// method using '?'
0-9-stable, 0.9.3, 0.9.1 => error: undefined method
0.9.2, 0.9.0 => returns attribute as expected(with '?').

// method without using '?'
0-9-stable, 0.9.2, 0.9.0 => error: undefined method
0.9.3, 0.9.1 => returns method name as attribute

@prasadsurase
Copy link

Further digging revealed that the functionality to autostrip question mark was introduced in #662 which was in response to #605 issue.

I think that we shouldn't autostrip any characters from the attributes specified in the serializer since user can always add own logic to get custom attributes.

@ace-subido
Copy link

Just posting here since it has a label "Needs bug verification". I might have the same case, I also ran into something like this when we allowed active_model_serializer, "~> 0.9" on our Gemfile instead of nailing it at 0.9.0.

# Serializer
class SomethingSerializer < ActiveModel::Serializer
  attributes :some_bool_attribute?
end

# Class
class Something
    # has an attribute called `some_bool_attribute`
end

Tests that expected the serializer hash to contain the some_bool_attribute? key are currently failing.

@remear remear closed this as completed Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants