mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
It is a common pattern to use JSON Schema to validate a API response[1], [2] and [3]. This patch creates the `assert_response_schema` test helper that helps people do this kind of validation easily on the controller tests. [1]: https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher [2]: https://github.com/sharethrough/json-schema-rspec [3]: https://github.com/rails-api/active_model_serializers/issues/1011#issuecomment-127608121
29 lines
930 B
Ruby
29 lines
930 B
Ruby
require 'rails/railtie'
|
|
|
|
module ActiveModel
|
|
class Railtie < Rails::Railtie
|
|
initializer 'active_model_serializers.logger' do
|
|
ActiveSupport.on_load(:active_model_serializers) do
|
|
self.logger = ActionController::Base.logger
|
|
end
|
|
end
|
|
|
|
initializer 'active_model_serializers.caching' do
|
|
ActiveSupport.on_load(:action_controller) do
|
|
ActiveModelSerializers.config.cache_store = ActionController::Base.cache_store
|
|
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
|
|
end
|
|
end
|
|
|
|
initializer 'generators' do |app|
|
|
app.load_generators
|
|
require 'generators/serializer/resource_override'
|
|
end
|
|
|
|
if Rails.env.test?
|
|
ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Schema)
|
|
ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Serializer)
|
|
end
|
|
end
|
|
end
|