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

sparse fieldsets #700

Merged
merged 6 commits into from
Jan 6, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests, but need to understand how the serializer class attribute …
…_associations was getting changed.
  • Loading branch information
arenoir committed Oct 26, 2014
commit 34f08477e4cc6838668a5a87fe3f61460bac5164
18 changes: 8 additions & 10 deletions test/adapter/json_api/fieldset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ class JsonApi
class FieldsetTest < Minitest::Test
def setup
@post = Post.new(title: 'New Post', body: 'Body')
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
@second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
@post.comments = [@first_comment, @second_comment]
@first_comment.post = @post
@second_comment.post = @post
comment_1 = Comment.new(id: 1, body: 'comment one')
comment_2 = Comment.new(id: 2, body: 'comment two')
@post.comments = [comment_1, comment_2]

@serializer = PostSerializer.new(@post)
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)
end

def teardown
@serializer = nil
@adapter = nil
end

def test_fieldset_with_fields_array
Expand All @@ -44,9 +38,13 @@ def test_fieldset_with_multiple_hashes
fieldset = ActiveModel::Serializer::Fieldset.new(@serializer, {post: [:title], comment: [:body]})

assert_equal(
[{:body=>"ZOMG A COMMENT" }, {:body=>"ZOMG ANOTHER COMMENT"}],
[{:body=>"comment one" }, {:body=>"comment two"}],
@adapter.serializable_hash({fieldset: fieldset})[:linked][:comments]
)

#don't understand how this is getting set.
@serializer.class._associations[:comments][:options] = {}

end

end
Expand Down