Sha256: 818adb19d29a816b4aaad5e9e78e3d81911b09fddf4224671a406eb545fe4beb

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

RSpec.describe "assets", type: :integration do
  describe "serve" do
    it "compiles and serves assets in development mode" do
      project = "bookshelf_serve_assets"

      with_project(project, gems: ['sassc']) do
        generate "action web home#index --url=/"

        write "apps/web/assets/javascripts/app.css.sass", <<~EOF
          $font-family: Helvetica, sans-serif

          body
            font: 100% $font-family
        EOF
        rewrite "apps/web/templates/app.html.erb", <<~EOF
          <!DOCTYPE html>
          <html>
            <head>
              <title>Web</title>
              <%= favicon %>
              <%= stylesheet 'app' %>
            </head>
            <body>
              <%= yield %>
            </body>
          </html>
        EOF

        server do
          visit "/"
          expect(page.body).to include(%(<link href="/assets/app.css" type="text/css" rel="stylesheet">))

          visit "/assets/app.css"
          expect(page.body).to include(%(body {\n  font: 100% Helvetica, sans-serif; }\n))
        end
      end
    end

    it "serve assets with prefixes" do
      with_project do
        generate "action web home#index --url=/"

        replace(
          "apps/web/app.rb",
          "# Specify sources for assets",
          "prefix '/library/assets'\n# Specify sources for assets"
        )

        replace(
          "apps/web/config/routes.rb",
          "/",
          "namespace :library { get '/', to: 'home#index' }"
        )

        write "apps/web/assets/javascripts/app.js", <<~EOF
          console.log('test');
        EOF

        hanami "assets precompile"

        server do
          visit "/library/assets/app.js"
          expect(page).to have_content("console.log('test');")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-2.0.0.beta2 spec/integration/assets/serve_spec.rb
hanami-2.0.0.beta1.1 spec/integration/assets/serve_spec.rb
hanami-2.0.0.beta1 spec/integration/assets/serve_spec.rb