Skip to content

Commit

Permalink
accept only formatted attributes' names for fields (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Azdaroth authored and fotinakis committed Oct 18, 2016
1 parent 656bc61 commit 0465994
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/jsonapi-serializers/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ def should_include_attr?(attribute_name, attr_data)
# Allow "if: :show_title?" and "unless: :hide_title?" attribute options.
if_method_name = attr_data[:options][:if]
unless_method_name = attr_data[:options][:unless]
formatted_attribute_name = format_name(attribute_name).to_sym
show_attr = true
show_attr &&= send(if_method_name) if if_method_name
show_attr &&= !send(unless_method_name) if unless_method_name
show_attr &&= @_fields[type.to_s].include?(attribute_name) if @_fields[type.to_s]
show_attr &&= @_fields[type.to_s].include?(formatted_attribute_name) if @_fields[type.to_s]
show_attr
end
protected :should_include_attr?
Expand Down
2 changes: 1 addition & 1 deletion spec/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def read_attribute_for_validation(attr)
long_comments = [first_comment, second_comment]
post = create(:post, :with_author, long_comments: long_comments)

fields = {posts: 'title,author,long_comments'}
fields = {posts: 'title,author,long-comments'}
serialized_data = JSONAPI::Serializer.serialize(post, fields: fields)
expect(serialized_data['data']['relationships']).to eq ({
'author' => {
Expand Down

0 comments on commit 0465994

Please sign in to comment.