Sha256: db1e054d1df8f1ee1c79871c8a572d138d551417da1ad19ac2ae49bf3e4210ec

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "much-rails/mixin"

module FakeActionController
  include MuchRails::Mixin

  after_mixin_included do
    include MuchRails::Action::Controller

    attr_reader :params
    attr_reader :head_called_with, :render_called_with
  end

  mixin_class_methods do
    def before_action(method_name, **)
      before_actions << method_name
    end

    def before_actions
      @before_actions ||= []
    end
  end

  mixin_instance_methods do
    def initialize(params)
      @params = FakeParams.new(params)
      self.class.before_actions.each do |before_action|
        public_send(before_action)
      end
    end

    def head(*args)
      @head_called_with = args
      self
    end

    def render(**kargs)
      @render_called_with = kargs
    end
  end

  class FakeParams
    def initialize(params)
      @params = params
    end

    def permit!
      @permit_called = true
      self
    end

    def [](key)
      @params[key]
    end

    def to_h
      raise "params haven't been permitted" unless @permit_called

      @params
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
much-rails-0.2.8 test/support/fake_action_controller.rb
much-rails-0.2.7 test/support/fake_action_controller.rb
much-rails-0.2.6 test/support/fake_action_controller.rb
much-rails-0.2.5 test/support/fake_action_controller.rb
much-rails-0.2.4 test/support/fake_action_controller.rb
much-rails-0.2.3 test/support/fake_action_controller.rb
much-rails-0.2.2 test/support/fake_action_controller.rb
much-rails-0.2.1 test/support/fake_action_controller.rb
much-rails-0.2.0 test/support/fake_action_controller.rb
much-rails-0.1.3 test/support/fake_action_controller.rb
much-rails-0.1.2 test/support/fake_action_controller.rb
much-rails-0.1.1 test/support/fake_action_controller.rb