Skip to content

Commit

Permalink
belongs_to causes unnecessary db hit
Browse files Browse the repository at this point in the history
  • Loading branch information
ssendev committed May 25, 2016
1 parent a701777 commit b4c49cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/serializers/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ def test_associations_custom_keys
assert expected_association_keys.include? :site
end

def test_belongs_to_doesnt_load_record
class << @post
def blog
fail 'should use blog_id'
end
end

post_serializer = Class.new(ActiveModel::Serializer) do
belongs_to :blog
end

actual = serializable(@post, adapter: :json_api, serializer: post_serializer).as_json
expected = { data: { id: 'post', type: 'posts', relationships: { blog: { data: { id: 'blog', type: 'blogs' } } } } }

assert_equal expected, actual
end

class InlineAssociationTestPostSerializer < ActiveModel::Serializer
has_many :comments
has_many :comments, key: :last_comments do
Expand Down

0 comments on commit b4c49cd

Please sign in to comment.