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

Remove duplicate test helper #1161

Merged
merged 1 commit into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 1 addition & 15 deletions test/action_controller/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Serialization
class ImplicitSerializerTest < ActionController::TestCase
include ActiveSupport::Testing::Stream
class ImplicitSerializationTestController < ActionController::Base
include SerializationTesting
def render_using_implicit_serializer
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
render json: @profile
Expand Down Expand Up @@ -123,21 +124,6 @@ def render_fragment_changed_object_with_relationship

render json: like
end

private

def generate_cached_serializer(obj)
ActiveModel::SerializableResource.new(obj).to_json
end

def with_adapter(adapter)
old_adapter = ActiveModel::Serializer.config.adapter
# JSON-API adapter sets root by default
ActiveModel::Serializer.config.adapter = adapter
yield
ensure
ActiveModel::Serializer.config.adapter = old_adapter
end
end

tests ImplicitSerializationTestController
Expand Down
22 changes: 19 additions & 3 deletions test/support/serialization_testing.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
class Minitest::Test
def before_setup
ActionController::Base.cache_store.clear
module SerializationTesting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

private

def generate_cached_serializer(obj)
ActiveModel::SerializableResource.new(obj).to_json
end

# Aliased as :with_configured_adapter to clarify that
# this method tests the configured adapter.
# When not testing configuration, it may be preferable
# to pass in the +adapter+ option to <tt>ActiveModel::SerializableResource</tt>.
# e.g ActiveModel::SerializableResource.new(resource, adapter: :json_api)
def with_adapter(adapter)
old_adapter = ActiveModel::Serializer.config.adapter
ActiveModel::Serializer.config.adapter = adapter
yield
ensure
ActiveModel::Serializer.config.adapter = old_adapter
end
alias_method :with_configured_adapter, :with_adapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the with_configured_adapter. Could you show me a situation where it makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the comment at the top of the method answer that question?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before SerializableResource, the only way to specify an adapter was global, as an option to render, or by building the serializer and adapter yourself.. now we don't need global quite as much

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I got it. I was reading that as "do stuff with the adapter I'm providing, that I have given a specific configuration", instead of "do stuff with this adapter by setting it as the configured adapter".

end

class Minitest::Test
def before_setup
ActionController::Base.cache_store.clear
end

include SerializationTesting
end