Sha256: 6dcdf058b0c5d5fa205aaa8b0f8572cf964085b538c8d65925f3cef7c75b334a

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

# https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/testing/integration.rb
# rubocop:disable Style/ClassAndModuleChildren:
class ActionController::Serialization::HttpCacheTest < ActionController::TestCase
  # class ActionController::Serialization::HttpCacheTest < ActionDispatch::IntegrationTest
  class HttpCacheTestController < ActionController::Base
    class Model < ActiveModelSerializers::Model
      attr_accessor :name, :description, :comments
    end
    class ModelSerializer < ActiveModel::Serializer
      attributes :name, :description, :comments
    end

    def render_as_serializable_object
      render serialization_options.merge!(json: model)
    end

    def render_as_json_string
      json = ActiveModelSerializers::SerializableResource.new(model, serialization_options).to_json
      render json: json
    end

    private

    def model
      Model.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
    end

    def serialization_options
      { serializer: ModelSerializer, adapter: :json }
    end
  end

  tests HttpCacheTestController

  DATE          = 'Date'.freeze
  LAST_MODIFIED = 'Last-Modified'.freeze
  ETAG          = 'ETag'.freeze
  CACHE_CONTROL = 'Cache-Control'.freeze
  SPECIAL_KEYS  = Set.new(%w(extras no-cache max-age public must-revalidate))
  def test_render_as_serializable_object
    10.times do
      get :render_as_serializable_object
    end
    p [@response.etag?, @response.last_modified, @response.date, @response.headers[CACHE_CONTROL], @response.headers[ETAG], @response.headers[LAST_MODIFIED], @response.headers[DATE]]
  end

  def test_render_as_json_string
    10.times do
      get :render_as_json_string
    end
    p [@response.etag?, @response.last_modified, @response.date, @response.headers[CACHE_CONTROL], @response.headers[ETAG], @response.headers[LAST_MODIFIED], @response.headers[DATE]]
  end
end
# rubocop:enable Style/ClassAndModuleChildren:

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers-0.9.6 test/action_controller/http_cache_test.rb