Skip to content

Commit

Permalink
Only load test helpers in the test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
maurogeorge committed Dec 21, 2015
1 parent 1329cc8 commit a7360f4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/active_model/serializer/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Railtie < Rails::Railtie
require 'generators/serializer/resource_override'
end

ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Serializer)
if Rails.env.test?
ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Serializer)
end
end
end
2 changes: 1 addition & 1 deletion lib/active_model_serializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.config
autoload :Model
autoload :Callbacks
autoload :Logging
autoload :Test

module_function

Expand Down Expand Up @@ -51,7 +52,6 @@ def silence_warnings
require 'active_model/serializer'
require 'active_model/serializable_resource'
require 'active_model/serializer/version'
require 'active_model_serializers/test/serializer'

require 'action_controller/serialization'
ActiveSupport.on_load(:action_controller) do
Expand Down
5 changes: 5 additions & 0 deletions lib/active_model_serializers/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ActiveModelSerializers
module Test
autoload :Serializer, 'active_model_serializers/test/serializer'
end
end
2 changes: 2 additions & 0 deletions test/active_model_serializers/test/serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module ActiveModelSerializers
module Test
class SerializerTest < ActionController::TestCase
include ActiveModelSerializers::Test::Serializer

class MyController < ActionController::Base
def render_using_serializer
render json: Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
Expand Down

0 comments on commit a7360f4

Please sign in to comment.