Sha256: 82e0f880b732fb8067d7dfd41ea427633c6b35ca4e5e053651347fd112465410

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

class Teaspoon::SuiteController < ActionController::Base
  def self.before(*args)
    respond_to?(:before_action) ? before_action(*args) : before_filter(*args)
  end

  before :check_env
  before :prepend_fixture_paths

  layout false

  def index
    @suites = Teaspoon::Suite.all
  end

  def show
    @suite = Teaspoon::Suite.new(params)
  end

  def hook
    hooks = Teaspoon::Suite.new(params).hooks[params[:hook].to_s]

    if hooks.present?
      hooks.each { |hook| hook.call(hook_params(params[:args])) }
      head(:ok)
    else
      render status: :not_found, json: { err: "The `#{params[:hook]}` hook is not defined in the `#{params[:suite]}` suite " }
    end
  end

  def fixtures
    render template: "/#{params[:filename]}"
  end

  private

    def check_env
      Teaspoon::Environment.check_env!
    end

    def prepend_fixture_paths
      Teaspoon.configuration.fixture_paths.each do |path|
        prepend_view_path Teaspoon.configuration.root.join(path)
      end
    end

    def hook_params(params)
      return params.permit!.to_h if params.respond_to?(:permit!)
      params
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teaspoon-1.4.0 app/controllers/teaspoon/suite_controller.rb
teaspoon-1.2.2 app/controllers/teaspoon/suite_controller.rb
teaspoon-1.2.1 app/controllers/teaspoon/suite_controller.rb
teaspoon-1.2.0 app/controllers/teaspoon/suite_controller.rb