Sha256: f43fbae479322c0199a5676f68c5c57c3ed446253219955297b7959ae4dd1720

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "hanami"

RSpec.describe "App view / Template", :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

    module TestApp
      class View < Hanami::View
      end
    end
  end

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

  context "Ordinary app view" do
    before do
      module TestApp
        module Views
          module Article
            class Index < TestApp::View
            end
          end
        end
      end
    end

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

    it "configures the tempalte to match the class name" do
      expect(template).to eq "article/index"
    end
  end

  context "Slice view with namespace matching template inference base" do
    before do
      module TestApp
        module MyViews
          module Users
            class Show < TestApp::View
            end
          end
        end
      end
    end

    let(:app_hook) {
      proc do
        config.views.template_inference_base = "my_views"
      end
    }

    let(:view_class) { TestApp::MyViews::Users::Show }

    it "configures the tempalte to match the class name" do
      expect(template).to eq "users/show"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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