Sha256: e3b3adf3e42246fec0535de252f9c664ae29be1b584f1e3aaaa302b7c35e12e6

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

RSpec.describe "assets", type: :integration do
  describe "CDN mode" do
    it "servers assets with CDN url" do
      with_project do
        generate "action web home#index --url=/"

        write "apps/web/assets/javascripts/app.css", <<~EOF
          body { color: #333 };
        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

        replace_last "apps/web/app.rb", "# scheme 'https'",           "scheme 'https'"
        replace      "apps/web/app.rb", "# host   'cdn.example.org'", "host   'cdn.example.org'"
        replace_last "apps/web/app.rb", "# port   443",               "port   443"

        #
        # Precompile
        #
        RSpec::Support::Env["HANAMI_ENV"]   = "production"
        RSpec::Support::Env["DATABASE_URL"] = "sqlite://#{Pathname.new('db').join('bookshelf.sqlite')}"
        RSpec::Support::Env["SMTP_HOST"]    = "localhost"
        RSpec::Support::Env["SMTP_PORT"]    = "25"

        hanami "assets precompile"

        server do
          visit "/"

          expect(page.body).to include(%(<link href="https://cdn.example.org/assets/app-5df86b4e9cbd733a027762b2f6bf8693.css" type="text/css" rel="stylesheet" integrity="sha256-LxaTcWkL8TAWFQWeHJ7OqoSoEXXaYapNIS+TCvGNf48=" crossorigin="anonymous">))
        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/cdn_spec.rb
hanami-2.0.0.beta1.1 spec/integration/assets/cdn_spec.rb
hanami-2.0.0.beta1 spec/integration/assets/cdn_spec.rb