Sha256: e941ede006fc9ff97320dbd3268b7f237ee6cb092ac0c197802c86871f5ec9dc

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Archangel
  module TestingSupport
    ##
    # View Controller testing support
    #
    module ViewControllerContext
      extend ActiveSupport::Concern

      def setup_view_and_controller
        @view                 = ActionView::Base.new
        @controller           = ActionController::Base.new
        @request              = ActionDispatch::TestRequest.new(
          "PATH_INFO" => "/"
        )
        @response             = ActionDispatch::TestResponse.new

        @response.request     = @request
        @controller.request   = @request
        @controller.response  = @response
        @controller.params    = {}

        @view.assign_controller(@controller)
        @view.class.send(:include, @controller._helpers)
        @view.class.send(:include, ::Rails.application.routes.url_helpers)
      end

      def view
        @view
      end

      def controller
        @controller
      end

      def context(assigns = {})
        options = {
          helper: @view,
          view: @view,
          controller: @controller
        }

        @context ||= ::Liquid::Context.new(assigns, {}, options)
      end

      def expect_template_result(template, expected, assigns = {})
        assigns.each { |key, value| context[key] = value }

        actual = ::Liquid::Template.parse(template).render!(context)
        expect(actual.to_s.strip).to eq(expected.to_s.strip)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
archangel-0.3.0 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.8 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.7 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.6 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.5 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.4 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.3 lib/archangel/testing_support/context/view_controller_context.rb
archangel-0.0.2 lib/archangel/testing_support/context/view_controller_context.rb