Skip to content

Commit

Permalink
Remove duplicate test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Sep 16, 2015
1 parent 610775a commit 26277ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
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
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
end

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

include SerializationTesting
end

0 comments on commit 26277ea

Please sign in to comment.