Sha256: 4bf6a3d94f9ef09df3ce53188c17c5f242a9ec6ce195361997514f6d31d3c5d6

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require 'helper'

module Oprah
  class ControllerHelpersTest < Minitest::Test
    class Controller
      @@helper_methods = []

      class << self
        def helper_methods
          @@helper_methods
        end

        def helper_method(method)
          @@helper_methods << method
        end
      end

      def view_context
        :ok
      end

      include Oprah::ControllerHelpers
    end

    include Fixtures

    def setup
      super
      @controller = Controller.new
    end

    def test_present
      presenter = @controller.present(User.new)

      assert_kind_of UserPresenter, presenter
      assert_kind_of EntityPresenter, presenter

      assert_equal "ok", presenter.view_context.to_s
    end

    def test_present_custom_view_context
      presenter = @controller.present(User.new, view_context: :foobar)
      assert_equal :foobar, presenter.view_context
    end

    def test_present_many
      presenters = @controller.present_many([User.new, User.new])

      assert_equal 2, presenters.length

      presenters.each do |presenter|
        assert_equal "Foo Bar", presenter.name
        assert_equal "ok", presenter.view_context.to_s
      end
    end

    def test_helper_method
      assert_equal [:present, :present_many], Controller.helper_methods
    end

    def test_oprah_view_context
      assert_equal @controller.oprah_view_context, @controller.view_context
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
detaso-oprah-0.3.1 test/oprah/controller_helpers_test.rb
detaso-oprah-0.3.0 test/oprah/controller_helpers_test.rb
oprah-0.3.0 test/oprah/controller_helpers_test.rb
oprah-0.2.1 test/oprah/controller_helpers_test.rb
oprah-0.2.0 test/oprah/controller_helpers_test.rb
oprah-0.1.3 test/oprah/controller_helpers_test.rb