Sha256: a48aef86858be4c0ee2ff5fa0233e21b47287d7a127e7d333642489c8f441db5

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

$routes = ActionDispatch::Routing::RouteSet.new
$routes.draw do
  get '/index' => 'test#index'
end

class ActiveSupport::TestCase
  setup do
    @routes = $routes
  end
end

class ArModel < ActiveRecord::Base
  has_many :ar_assoc_models
  def as_json(opts = {})
    id
  end
end

class ArAssocModel < ActiveRecord::Base
  def as_json(opts = {})
    id
  end
end

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:'
)
ActiveRecord::Base.connection.execute <<SQL
  CREATE TABLE ar_models (id INTEGER PRIMARY KEY AUTOINCREMENT);
SQL
ActiveRecord::Base.connection.execute <<SQL
  CREATE TABLE ar_assoc_models (
    id INTEGER PRIMARY KEY AUTOINCREMENT, ar_model_id INTEGER
  );
SQL

676.times do
  ArModel.create!.tap do |ar_model|
    5.times do
      ar_model.ar_assoc_models.create!
    end
  end
end

class TestResponder < ActionController::Responder
  include Responders::PaginateResponder
end

class TestController < ActionController::Base
  include $routes.url_helpers

  attr_accessor :resource

  self.responder = TestResponder

  respond_to :json

  def index
    respond_with resource
  end
end

module TestSpecConfiguration
  extend ActiveSupport::Concern

  included do
    before do
      @routes = $routes
      @controller = TestController.new
    end

    def resource=(resource)
      @controller.resource = resource
    end
  end
end

RSpec.configure do |config|
  config.include TestSpecConfiguration
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
paginate-responder-2.1.0 spec/support/10-application.rb
paginate-responder-2.0.0 spec/support/10-application.rb
paginate-responder-1.8.0 spec/support/10-application.rb
paginate-responder-1.7.0 spec/support/10-application.rb
paginate-responder-1.6.0 spec/support/10-application.rb
paginate-responder-1.6.0.b0 spec/support/10-application.rb