active_model_serializers/test/test_helper.rb
Joao Moura 8a432ad2b3 Adding cache support to version 0.10.0
It's a new implementation of cache based on ActiveSupport::Cache.
The implementation abstracts the cache in Adapter class on a
private method called cached_object, this method is intended
to be used on Adapters inside serializable_hash method in order
to cache each instance of the object that will be returned by
the serializer.

Some of its features are:
- A different syntax. (no longer need the cache_key method).
- An options argument that have the same arguments of ActiveSupport::Cache::Store, plus a key option that will be the prefix of the object cache on a pattern "#{key}-#{object.id}".
- It cache the objects individually and not the whole Serializer return, re-using it in different requests (as a show and a index method for example.)
2015-02-02 14:53:34 -02:00

42 lines
971 B
Ruby

require 'bundler/setup'
require 'rails'
require 'action_controller'
require 'action_controller/test_case'
require 'action_controller/railtie'
require 'active_support/json'
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class Foo < Rails::Application
if Rails.version.to_s.start_with? '4'
config.action_controller.perform_caching = true
ActionController::Base.cache_store = :memory_store
end
end
require "active_model_serializers"
require 'fixtures/poro'
module TestHelper
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
get ':controller(/:action(/:id))'
get ':controller(/:action)'
end
ActionController::Base.send :include, Routes.url_helpers
end
ActionController::TestCase.class_eval do
def setup
@routes = TestHelper::Routes
end
end
def def_serializer(&block)
Class.new(ActiveModel::Serializer, &block)
end