Skip to content

Commit

Permalink
fix: Corrected test class names and use #render_as_json in AsJson mod…
Browse files Browse the repository at this point in the history
…ules
  • Loading branch information
joelmoss committed Jun 30, 2020
1 parent 721b632 commit 9a02dca
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/shreddies/as_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def as_json(options = {})
serializer = options.delete(:serializer) || "#{model_name}Serializer"

if serializer.is_a?(String) || serializer.is_a?(Symbol)
serializer.to_s.constantize.render self, options
serializer.to_s.constantize.render_as_json self, options
else
serializer.render self, options
end
Expand All @@ -21,7 +21,7 @@ def as_json(options = {})
serializer = options.delete(:serializer) || "#{model_name}Serializer"

if serializer.is_a?(String) || serializer.is_a?(Symbol)
serializer.to_s.constantize.render self, options
serializer.to_s.constantize.render_as_json self, options
else
serializer.render self, options
end
Expand Down
1 change: 0 additions & 1 deletion lib/shreddies/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def render(subject, options = {})
end
end

# legacy support - can be removed once all serializers ise JsonSerializer
alias render_as_json render
end

Expand Down
Binary file modified test/internal/db/combustion_test.sqlite
Binary file not shown.
4 changes: 2 additions & 2 deletions test/shreddies/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup

def test_render_a_single_plain_ruby_object
expect = { 'name' => 'Joel Moss' }
assert_equal expect, MySerializer.render(first_name: 'Joel', last_name: 'Moss')
assert_equal expect, MyUserSerializer.render(first_name: 'Joel', last_name: 'Moss')
end

def test_render_a_single_active_record
Expand All @@ -35,7 +35,7 @@ def test_render_an_array_with_index_by_option
]

assert_equal({ 'Joel' => { 'name' => 'Joel Moss' }, 'Joel2' => { 'name' => 'Joel2 Moss2' } },
MySerializer.render(data, index_by: :first_name))
MyUserSerializer.render(data, index_by: :first_name))
end

def test_render_a_collection_of_records
Expand Down

0 comments on commit 9a02dca

Please sign in to comment.