Sha256: 63e251ffe62567cbe639289f072278f8a43aed634bbf102189da6537f5df6b94

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require "hanami"

RSpec.describe "App view / Context / Routes", :app_integration do
  it "accesses app routes" do
    with_tmp_directory(Dir.mktmpdir) do
      write "config/app.rb", <<~RUBY
        require "hanami"

        module TestApp
          class App < Hanami::App
          end
        end
      RUBY

      write "config/routes.rb", <<~RUBY
        module TestApp
          class Routes < Hanami::Routes
            define do
              root to: "home.index"
            end
          end
        end
      RUBY

      write "app/action.rb", <<~RUBY
        require "hanami/action"

        module TestApp
          class Action < Hanami::Action
          end
        end
      RUBY

      write "app/actions/home/index.rb", <<~RUBY
        module TestApp
          module Actions
            module Home
              class Index < Hanami::Action
              end
            end
          end
        end
      RUBY

      write "app/views/context.rb", <<~RUBY
        require "hanami/view/context"

        module TestApp
          module Views
            class Context < Hanami::View::Context
            end
          end
        end
      RUBY

      require "hanami/prepare"

      context = TestApp::Views::Context.new
      expect(context.routes.path(:root)).to eq "/"
    end
  end

  it "can inject routes" do
    module TestApp
      class App < Hanami::App
      end
    end

    Hanami.prepare

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

    routes = double(:routes)

    context = TestApp::Views::Context.new(routes: routes)

    expect(context.routes).to be(routes)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-2.0.0.beta2 spec/new_integration/view/context/routes_spec.rb
hanami-2.0.0.beta1.1 spec/new_integration/view/context/routes_spec.rb
hanami-2.0.0.beta1 spec/new_integration/view/context/routes_spec.rb