Sha256: 4f4bc44f1374edae635cfbc79c99ae15fa9dea3126266edcf23a8cc07ba714dc

Contents?: true

Size: 1.94 KB

Versions: 10

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require "hanami"

RSpec.describe "App view / Part namespace", :app_integration do
  before do
    module TestApp
      class App < Hanami::App
        config.root = "/test_app"
      end
    end

    Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
    Hanami.app.register_slice :main
    Hanami.app.prepare

    # The parts module (or any related setup) must exist _before_ we subclass
    # Hanami::View, because the parts_namespace is configured at the time of
    # subclassing (which happens right below)
    parts_module! if respond_to?(:parts_module!)

    module TestApp
      class View < Hanami::View
      end
    end

    module TestApp
      module Views
        module Article
          class Index < TestApp::View
          end
        end
      end
    end
  end

  subject(:part_namespace) { view_class.config.part_namespace }

  let(:view_class) { TestApp::Views::Article::Index }

  context "default parts_path" do
    let(:parts_module!) do
      module TestApp
        module Views
          module Parts
          end
        end
      end
    end

    it "is View::Parts" do
      is_expected.to eq TestApp::Views::Parts
    end
  end

  context "custom parts_path configured" do
    let(:app_hook) {
      proc do
        config.views.parts_path = "views/custom_parts"
      end
    }

    context "parts module exists" do
      let(:parts_module!) do
        module TestApp
          module Views
            module CustomParts
            end
          end
        end
      end

      it "is the matching module within the slice" do
        is_expected.to eq TestApp::Views::CustomParts
      end
    end

    context "namespace does not exist" do
      it "is nil" do
        is_expected.to be_nil
      end
    end
  end

  context "nil parts_path configured" do
    let(:app_hook) {
      proc do
        config.views.parts_path = nil
      end
    }

    it "is nil" do
      is_expected.to be_nil
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hanami-2.0.3 spec/integration/view/part_namespace_spec.rb
hanami-2.0.2 spec/integration/view/part_namespace_spec.rb
hanami-2.0.1 spec/integration/view/part_namespace_spec.rb
hanami-2.0.0 spec/integration/view/part_namespace_spec.rb
hanami-2.0.0.rc1 spec/integration/view/part_namespace_spec.rb
hanami-2.0.0.beta4 spec/integration/view/part_namespace_spec.rb
hanami-2.0.0.beta3 spec/integration/view/part_namespace_spec.rb
hanami-2.0.0.beta2 spec/new_integration/view/part_namespace_spec.rb
hanami-2.0.0.beta1.1 spec/new_integration/view/part_namespace_spec.rb
hanami-2.0.0.beta1 spec/new_integration/view/part_namespace_spec.rb