Sha256: 6ec9b7967f8b3962d2bb847d1122916441caee8eb35c7b5a826f9d431f15a37a

Contents?: true

Size: 1.59 KB

Versions: 26

Compression:

Stored size: 1.59 KB

Contents

module Pageflow
  # Helpers to test entry type controllers.
  #
  # @since 15.1
  module EntriesControllerTestHelper
    extend ActiveSupport::Concern

    included do
      # Entry type controllers are delegated to by
      # `Pagefow::EntriesController`. Therefore they do not have their
      # own routes. Controller specs only allow calling actions that
      # have a route. So we create a fake route to work aroung this.

      controller_name = described_class.name.sub(/Controller$/, '').underscore

      routes do
        ActionDispatch::Routing::RouteSet.new.tap do |routes|
          routes.draw do
            get '/test/entry', to: "#{controller_name}#show"
          end
        end
      end
    end

    # Invoke an action of the entries controller with the request env
    # set up just like when Pageflow delegates to the entry type's
    # frontend app.
    #
    # @param action [Symbol] Name of the action to invoke
    #
    # @param entry [Entry] Entry to render.
    #
    # @param mode [:published|:preview] Whether to render the
    #   published revision or the draft.
    def get_with_entry_env(action, entry:, mode: :published, params: {})
      revision =
        if mode == :published
          entry.published_revision
        else
          entry.draft
        end

      published_entry = PublishedEntry.new(entry, revision)
      EntriesControllerEnvHelper.add_entry_info_to_env(request.env,
                                                       entry: published_entry,
                                                       mode: mode)
      get(action, params: {**params})
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
pageflow-support-17.0.4 pageflow/entries_controller_test_helper.rb
pageflow-support-17.0.3 pageflow/entries_controller_test_helper.rb
pageflow-support-17.0.2 pageflow/entries_controller_test_helper.rb
pageflow-support-17.0.1 pageflow/entries_controller_test_helper.rb
pageflow-support-17.0.0 pageflow/entries_controller_test_helper.rb
pageflow-support-16.2.0 pageflow/entries_controller_test_helper.rb
pageflow-support-16.1.0 pageflow/entries_controller_test_helper.rb
pageflow-support-16.0.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.8.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.7.1 pageflow/entries_controller_test_helper.rb
pageflow-support-15.7.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.6.1 pageflow/entries_controller_test_helper.rb
pageflow-support-15.6.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.5.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.4.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.3.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.2.2 pageflow/entries_controller_test_helper.rb
pageflow-support-15.2.1 pageflow/entries_controller_test_helper.rb
pageflow-support-15.2.0 pageflow/entries_controller_test_helper.rb
pageflow-support-15.1.2 pageflow/entries_controller_test_helper.rb