Merge branch 'master' into develop

This commit is contained in:
Luca Guidi 2021-01-16 09:39:12 +01:00
commit 7bae3d8a53
No known key found for this signature in database
GPG Key ID: CD1966BB1CEAC68F
46 changed files with 322 additions and 449 deletions

View File

@ -1,349 +0,0 @@
kind: pipeline
name: ruby-2-6
group: build
steps:
- name: install
image: hanami/ruby-2.6-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- ruby -v
- gem install bundler
- bundle install --jobs=3 --retry=3
- name: unit
image: hanami/ruby-2.6-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- COVERAGE=true bundle exec rake spec:unit
- name: isolation
image: hanami/ruby-2.6-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test isolation
- name: integration
image: hanami/ruby-2.6-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test integration
- name: quality
image: hanami/ruby-2.6-full
docker:
stdin_open: true
tty: true
environment:
CI: true
CODECOV_TOKEN:
from_secret: codecov
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- CI=true bundle exec rake codecov:upload
volumes:
- name: bundle
temp: {}
---
kind: pipeline
name: ruby-2-5
group: build
steps:
- name: install
image: hanami/ruby-2.5-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- ruby -v
- gem install bundler
- bundle install --jobs=3 --retry=3
- name: unit
image: hanami/ruby-2.5-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- COVERAGE=true bundle exec rake spec:unit
- name: isolation
image: hanami/ruby-2.5-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test isolation
- name: integration
image: hanami/ruby-2.5-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test integration
- name: quality
image: hanami/ruby-2.5-full
docker:
stdin_open: true
tty: true
environment:
CI: true
CODECOV_TOKEN:
from_secret: codecov
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- CI=true bundle exec rake codecov:upload
volumes:
- name: bundle
temp: {}
---
kind: pipeline
name: ruby-2-4
group: build
steps:
- name: install
image: hanami/ruby-2.4-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- ruby -v
- gem install bundler
- bundle install --jobs=3 --retry=3
- name: unit
image: hanami/ruby-2.4-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- COVERAGE=true bundle exec rake spec:unit
- name: isolation
image: hanami/ruby-2.4-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test isolation
- name: integration
image: hanami/ruby-2.4-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test integration
- name: quality
image: hanami/ruby-2.4-full
docker:
stdin_open: true
tty: true
environment:
CI: true
CODECOV_TOKEN:
from_secret: codecov
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- CI=true bundle exec rake codecov:upload
volumes:
- name: bundle
temp: {}
---
kind: pipeline
name: ruby-2-3
group: build
steps:
- name: install
image: hanami/ruby-2.3-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- ruby -v
- gem install bundler
- bundle install --jobs=3 --retry=3
- name: unit
image: hanami/ruby-2.3-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
path: /usr/local/bundle
commands:
- COVERAGE=true bundle exec rake spec:unit
- name: isolation
image: hanami/ruby-2.3-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test isolation
- name: integration
image: hanami/ruby-2.3-full
docker:
stdin_open: true
tty: true
environment:
CI: true
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- ./script/test integration
- name: quality
image: hanami/ruby-2.3-full
docker:
stdin_open: true
tty: true
environment:
CI: true
CODECOV_TOKEN:
from_secret: codecov
volumes:
- name: bundle
# path: /drone/src/vendor/cache
path: /usr/local/bundle
commands:
- CI=true bundle exec rake codecov:upload
volumes:
- name: bundle
temp: {}
---
kind: pipeline
name: slack
group: build
clone:
disable: true
depends_on:
- ruby-2-3
steps:
- name: slack
image: plugins/slack
settings:
link_names: true
webhook:
from_secret: slack
channel: dev
when:
event:
- push

43
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: ci
"on":
push:
paths:
- ".github/workflows/ci.yml"
- "lib/**"
- "*.gemspec"
- "spec/**"
- "Rakefile"
- "Gemfile"
- ".rubocop.yml"
pull_request:
branches:
- master
create:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- "2.7"
- "2.6"
- "2.5"
- "2.4"
steps:
- uses: actions/checkout@v1
- name: Install package dependencies
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
- name: Install latest bundler
run: |
gem install bundler --no-document
- name: Bundle install
run: bundle install --jobs 4 --retry 3
- name: Run all tests
run: script/ci

View File

@ -1,24 +0,0 @@
language: ruby
sudo: false
cache: bundler
install: true
before_install:
- mkdir $PWD/vendor/phantomjs && tar -xjf $PWD/vendor/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/vendor/phantomjs --strip-components=1
- export PATH=$PWD/vendor/phantomjs/bin:$PATH
- phantomjs --version
- gem update --system # Required to install rainbow 2.2.1 https://github.com/sickill/rainbow/issues/44#issuecomment-274412027
script:
- './script/ci'
rvm:
- 2.3.8
- 2.4.5
- 2.5.3
- 2.6.0
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/fde2367248d53de4fe70
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always

View File

@ -1,6 +1,21 @@
# Hanami
The web, with simplicity.
## v1.3.3 - 2019-09-20
### Added
- [Gray Manley] Standardize file loading for `.env` files (see: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
### Fixed
- [Alfonso Uceda & Luca Guidi] Ensure to use `:host` option when mounting an application in main router (e.g. `mount Beta::Application.new, at: "/", host: "beta.hanami.test"`)
## v1.3.2 - 2019-07-26
### Added
- [Luca Guidi] Support both `hanami-validations` 1 and 2
### Fixed
- [Wisnu Adi Nurcahyo] Ensure `hanami generate` syntax for Welcome page is compatible with ZSH
- [Luca Guidi] Don't let `hanami` to crash when called without `bundle exec`
## v1.3.1 - 2019-01-18
### Added
- [Luca Guidi] Official support for Ruby: MRI 2.6
@ -9,7 +24,7 @@ The web, with simplicity.
### Fixed
- [Aidan Coyle] Remove from app generator support for deprecated `force_ssl` setting
- [Alessandro Caporrini] Remove from app generator support for deprecated `body_parsers` setting
- [Daphne Rouw & Sean Collins] Make app generator to work when code in `config/enviroment.rb` uses double quotes
- [Daphne Rouw & Sean Collins] Make app generator to work when code in `config/environment.rb` uses double quotes
## v1.3.0 - 2018-10-24
### Added
@ -26,7 +41,7 @@ The web, with simplicity.
### Fixed
- [Anton Davydov] Make possible to pass extra settings for custom logger instances (eg. `logger SemanticLogger.new, :foo, :bar`)
- [graywolf] Ensure `hanami generate app` to work without `require_relative` entries in `config/enviroment.rb`
- [graywolf] Ensure `hanami generate app` to work without `require_relative` entries in `config/environment.rb`
- [Makoto Tajitsu & Luca Guidi] Fixed regression for `hanami new .` that used to generate a broken project
### Fixed
@ -143,7 +158,7 @@ The web, with simplicity.
- [Luca Guidi] Make compatible with Rack 2.0 only
- [Luca Guidi] Removed `logger` settings from Hanami applications
- [Luca Guidi] Removed logger for Hanami applications (eg `Web.logger`)
- [Luca Guidi] Changed mailer syntax in `config/enviroment.rb`
- [Luca Guidi] Changed mailer syntax in `config/environment.rb`
## v0.9.2 - 2016-12-19
## Added
@ -232,11 +247,11 @@ The web, with simplicity.
## v0.7.2 - 2016-02-09
### Fixed
- [Alfonso Uceda Pompa] Fixed routing issue when static assets server tried to hijiack paths that are matching directories in public directory
- [Alfonso Uceda Pompa] Fixed routing issue when static assets server tried to hijack paths that are matching directories in public directory
## v0.7.1 - 2016-02-05
### Fixed
- [Anton Davydov] Fixed routing issue when static assets server tried to hijiack requests belonging to dynamic endpoints
- [Anton Davydov] Fixed routing issue when static assets server tried to hijack requests belonging to dynamic endpoints
- [Anatolii Didukh] Ensure to fallback to default engine for `hanami console`
## v0.7.0 - 2016-01-22
@ -371,7 +386,7 @@ The web, with simplicity.
## v0.3.0 - 2015-03-23
### Added
- [Luca Guidi] Introduced action generator. Eg. `bundle exec lotus generate action web dashboard#index`
- [Alfonso Uceda Pompa] Allow to specify default coookies options in application configuration. Eg. `cookies true, { domain: 'lotusrb.org' }`
- [Alfonso Uceda Pompa] Allow to specify default cookies options in application configuration. Eg. `cookies true, { domain: 'lotusrb.org' }`
- [Tom Kadwill] Include `Lotus::Helpers` in views.
- [Linus Pettersson] Allow to specify `--database` CLI option when generate a new project. Eg. `lotus new bookshelf --database=postgresql`
- [Linus Pettersson] Initialize a Git repository when generating a new project

View File

@ -3,6 +3,12 @@
## Features
## v1.3.3 - 2019-09-20
- Standardize file loading for `.env` files (see: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
## v1.3.2 - 2019-07-26
## v1.3.1 - 2019-01-18
## v1.3.0 - 2018-10-24
@ -20,7 +26,7 @@
- Unobtrusive JavaScript (UJS) (via `hanami-ujs` gem)
- Interactive console for development error page (via `hanami-webconsole` gem)
- CLI: register callbacks for `hanami` commands (`Hanami::CLI.after("db migrate", MyCallback.new)` or `Hanami::CLI.after("db migrate") { ... }`)
- Project level Rack middleware stack (`Hanami.configure { middleware.use MyRackMiddlewre }`)
- Project level Rack middleware stack (`Hanami.configure { middleware.use MyRackMiddleware }`)
- Plugins can hook into project configuration (`Hanami.plugin { middleware.use AnotherRackMiddleware }`)
- Custom repository commands
- Coloured logging

View File

@ -12,7 +12,7 @@ gem 'hanami-utils', '~> 1.3', require: false, git: 'https://github.com/han
gem 'hanami-validations', '~> 1.3', require: false, git: 'https://github.com/hanami/validations.git', branch: 'develop'
gem 'hanami-router', '~> 1.3', require: false, git: 'https://github.com/hanami/router.git', branch: 'develop'
gem 'hanami-controller', '~> 1.3', require: false, git: 'https://github.com/hanami/controller.git', branch: 'develop'
gem 'hanami-view', '~> 1.3', require: false, git: 'https://github.com/hanami/view.git', branch: 'develop'
gem 'hanami-view', '~> 1.3', require: false, git: 'https://github.com/hanami/view.git', branch: '1.x-master'
gem 'hanami-model', '~> 1.3', require: false, git: 'https://github.com/hanami/model.git', branch: 'develop'
gem 'hanami-helpers', '~> 1.3', require: false, git: 'https://github.com/hanami/helpers.git', branch: 'develop'
gem 'hanami-mailer', '~> 1.3', require: false, git: 'https://github.com/hanami/mailer.git', branch: 'develop'
@ -41,7 +41,7 @@ if RUBY_DESCRIPTION =~ /linux/
end
# `hanami assets` integration tests
gem 'sass', require: false
gem 'sassc', require: false
gem 'coffee-script', require: false
gem 'dotenv', '~> 2.4', require: false

View File

@ -1,4 +1,4 @@
Copyright © 2014-2019 Luca Guidi
Copyright © 2014-2021 Luca Guidi
MIT License

View File

@ -18,7 +18,6 @@ which provides the glue that ties all the parts together:
* [**Hanami::Helpers**](https://github.com/hanami/helpers) - View helpers for Ruby applications
* [**Hanami::Mailer**](https://github.com/hanami/mailer) - Mail for Ruby applications
* [**Hanami::Assets**](https://github.com/hanami/assets) - Assets management for Ruby
* [**Hanami::CLI**](https://github.com/hanami/cli) - Ruby command line interface
* [**Hanami::Utils**](https://github.com/hanami/utils) - Ruby core extensions and class utilities
These components are designed to be used independently or together in a Hanami application.
@ -26,7 +25,7 @@ These components are designed to be used independently or together in a Hanami a
## Status
[![Gem Version](https://badge.fury.io/rb/hanami.svg)](https://badge.fury.io/rb/hanami)
[![TravisCI](https://travis-ci.org/hanami/hanami.svg?branch=master)](https://travis-ci.org/hanami/hanami)
[![CI](https://github.com/hanami/hanami/workflows/ci/badge.svg?branch=master)](https://github.com/hanami/hanami/actions?query=workflow%3Aci+branch%3Amaster)
[![Test Coverage](https://codecov.io/gh/hanami/hanami/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/hanami)
[![Depfu](https://badges.depfu.com/badges/ba000e0f69e6ef1c44cd3038caaa1841/overview.svg)](https://depfu.com/github/hanami/hanami?project=Bundler)
[![Inline Docs](http://inch-ci.org/github/hanami/hanami.svg)](http://inch-ci.org/github/hanami/hanami)
@ -137,4 +136,4 @@ Released under MIT License.
This project was formerly known as Lotus (`lotusrb`).
Copyright © 2014-2019 Luca Guidi.
Copyright © 2014-2021 Luca Guidi.

View File

@ -3,4 +3,4 @@ require 'bundler'
require 'hanami/cli/commands'
::Bundler.require(:plugins) if File.exist?(ENV["BUNDLE_GEMFILE"] || "Gemfile")
Hanami::CLI.new(Hanami::CLI::Commands).call
Dry::CLI.new(Hanami::CLI::Commands).call

View File

@ -22,19 +22,19 @@ Gem::Specification.new do |spec|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
spec.add_dependency 'hanami-utils', '~> 1.3'
spec.add_dependency 'hanami-validations', '~> 1.3', '< 3'
spec.add_dependency 'hanami-validations', '>= 1.3', '< 3'
spec.add_dependency 'hanami-router', '~> 1.3'
spec.add_dependency 'hanami-controller', '~> 1.3'
spec.add_dependency 'hanami-view', '~> 1.3'
spec.add_dependency 'hanami-helpers', '~> 1.3'
spec.add_dependency 'hanami-mailer', '~> 1.3'
spec.add_dependency 'hanami-assets', '~> 1.3'
spec.add_dependency 'hanami-cli', '~> 0.3'
spec.add_dependency 'dry-cli', '~> 0.5'
spec.add_dependency 'concurrent-ruby', '~> 1.0'
spec.add_dependency 'bundler', '>= 1.6', '< 3'
spec.add_development_dependency 'rspec', '~> 3.7'
spec.add_development_dependency 'rack-test', '~> 1.1'
spec.add_development_dependency 'aruba', '~> 0.14'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rake', '~> 13.0'
end

View File

@ -62,7 +62,7 @@ module Hanami
# @api private
def mount(configuration)
configuration.mounted.each do |klass, app|
routes.mount(klass, at: app.path_prefix)
routes.mount(klass, at: app.path_prefix, host: app.host)
end
end

View File

@ -1,4 +1,4 @@
require 'hanami/cli'
require 'dry/cli'
require 'ostruct'
module Hanami
@ -54,7 +54,7 @@ module Hanami
# @since 1.1.0
# @api private
module Commands
extend Hanami::CLI::Registry
extend Dry::CLI::Registry
# CLI command context
#

View File

@ -1,7 +1,7 @@
require 'hanami'
require 'hanami/environment'
require 'hanami/components'
require 'hanami/cli/command'
require 'dry/cli/command'
require 'hanami/cli/commands/project'
require 'hanami/cli/commands/templates'
require 'concurrent'
@ -17,7 +17,7 @@ module Hanami
# Abstract command
#
# @since 1.1.0
class Command < Hanami::CLI::Command
class Command < Dry::CLI::Command
# @since 1.1.0
# @api private
def self.inherited(component)
@ -82,7 +82,7 @@ module Hanami
options = environment.to_options.merge(options)
end
super(options)
super(**options)
rescue StandardError => e
warn e.message
warn e.backtrace.join("\n\t")
@ -92,9 +92,7 @@ module Hanami
# @since 1.1.0
# @api private
def initialize(command_name:, out: $stdout, files: Utils::Files)
super(command_name: command_name)
def initialize(out: $stdout, files: Utils::Files)
@out = out
@files = files
@templates = Templates.new(self.class)

View File

@ -502,7 +502,7 @@ module Hanami
# @since 1.1.0
# @api private
def generate_app(context)
Hanami::CLI::Commands::New::App.new(command_name: "generate app", out: @out, files: @files).call(app: context.application_name, application_base_url: context.application_base_url, **context.options)
Hanami::CLI::Commands::New::App.new(out: @out, files: @files).call(app: context.application_name, application_base_url: context.application_base_url, **context.options)
end
# @since 1.1.0
@ -565,8 +565,8 @@ module Hanami
# @since 1.1.0
# @api private
def initialize(*)
super
def initialize(*args, **kwargs)
super(*args, **kwargs)
@templates = Templates.new(self.class.superclass)
end
end

View File

@ -10,7 +10,6 @@ gem 'hanami-controller', require: false, git: 'https://github.com/hanami/contro
gem 'hanami-view', require: false, git: 'https://github.com/hanami/view.git', branch: 'develop'
gem 'hanami-helpers', require: false, git: 'https://github.com/hanami/helpers.git', branch: 'develop'
gem 'hanami-mailer', require: false, git: 'https://github.com/hanami/mailer.git', branch: 'develop'
gem 'hanami-cli', require: false, git: 'https://github.com/hanami/cli.git', branch: 'develop'
gem 'hanami-assets', require: false, git: 'https://github.com/hanami/assets.git', branch: 'develop'
gem 'hanami-model', require: false, git: 'https://github.com/hanami/model.git', branch: 'develop'
gem 'hanami', git: 'https://github.com/hanami/hanami.git', branch: 'develop'

View File

@ -1,2 +1,4 @@
/public/assets*
/tmp
.env.local
.env.*.local

View File

@ -1,3 +1,5 @@
/db/*.sqlite
/public/assets*
/tmp
.env.local
.env.*.local

View File

@ -5,7 +5,7 @@ module Hanami
# @since 0.9.0
# @api private
module App
# hanami-assets configuration for a sigle Hanami application in the project.
# hanami-assets configuration for a single Hanami application in the project.
#
# @since 0.9.0
# @api private

View File

@ -8,7 +8,7 @@ module Hanami
# @since 0.9.0
# @api private
module App
# hanami-controller configuration for a sigle Hanami application in the project.
# hanami-controller configuration for a single Hanami application in the project.
#
# @since 0.9.0
# @api private

View File

@ -8,7 +8,7 @@ module Hanami
# @since 0.9.0
# @api private
module App
# hanami-router configuration for a sigle Hanami application in the project.
# hanami-router configuration for a single Hanami application in the project.
#
# @since 0.9.0
# @api private

View File

@ -5,7 +5,7 @@ module Hanami
# @since 0.9.0
# @api private
module App
# hanami-view configuration for a sigle Hanami application in the project.
# hanami-view configuration for a single Hanami application in the project.
#
# @since 0.9.0
# @api private

View File

@ -20,6 +20,7 @@ module Hanami
# @param app [#call] an application compatible with Rack SPEC
# @param options [Hash] a set of options
# @option :at [String] options the mount point
# @option :host [String] options the mount point
#
# @since 0.9.0
#
@ -27,12 +28,14 @@ module Hanami
# # config/environment.rb
# # ...
# Hanami.configure do
# mount Beta::Application, at: '/', host: 'beta.bookshelf.com'
# mount Admin::Application, at: '/api'
# mount Web::Application, at: '/'
#
# # ...
# end
def mount(app, options)
mounted[app] = App.new(app, options.fetch(:at))
mounted[app] = App.new(app, options)
end
# Configure database

View File

@ -7,11 +7,14 @@ module Hanami
class App < SimpleDelegator
# @api private
attr_reader :path_prefix
# @api private
attr_reader :host
# @api private
def initialize(app, path_prefix)
def initialize(app, options = {})
super(app)
@path_prefix = path_prefix
@path_prefix = options[:at]
@host = options[:host]
end
end
end

View File

@ -3,7 +3,7 @@
module Hanami
# HTTP/2 Early Hints Rack middleware
#
# It sends extra responses **before** the main reponse is sent.
# It sends extra responses **before** the main response is sent.
# These extra responses are HTTP/2 Early Hints (103).
# They specify the web assets (javascripts, stylesheets, etc..) to be "pushed",
# so modern browsers pre-fetch them in parallel with the main HTTP response.

View File

@ -36,6 +36,12 @@ module Hanami
# @api private
DEFAULT_ENV = 'development'.freeze
# Test environment
#
# @since 1.3.3
# @api private
TEST_ENV = 'test'.freeze
# Production environment
#
# @since 0.6.0
@ -48,11 +54,21 @@ module Hanami
# @api private
RACK_ENV_DEPLOYMENT = 'deployment'.freeze
# Default `.env` per environment file name
#
# @since 0.2.0
# @since 1.3.3
# @api private
DEFAULT_DOTENV_ENV = '.env.%s'.freeze
DOTENV_LOCAL_FILE = '.env.local'.freeze
# Default `.env` files that are loaded. The entries are ordered from highest
# to lowest priority.
#
# @since 1.3.3
# @api private
DOTENV_FILES = [
'.env.%{environment}.local'.freeze,
DOTENV_LOCAL_FILE,
'.env.%{environment}'.freeze,
'.env'.freeze
].freeze
# Default configuration directory under application root
#
@ -132,9 +148,8 @@ module Hanami
# located under the config directory. All the settings in those files will
# be exported as `ENV` variables.
#
# Master .env file is ignored to suggest clear separation of environment
# configurations and discourage putting sensitive information into source
# control.
# This table: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
# has more info on the priority of the .env files.
#
# The format of those `.env.<environment>` files follows UNIX and UNIX-like
# operating system environment variable declaration format and compatible
@ -487,10 +502,13 @@ module Hanami
# @since 0.2.0
# @api private
def set_application_env_vars!
dotenv = root.join(DEFAULT_DOTENV_ENV % environment)
return unless dotenv.exist?
DOTENV_FILES.each do |filename_format|
file = filename_format % { environment: environment }
next unless dotenv_applicable?(file)
env.load!(dotenv)
path = root.join(file)
env.load!(path) if path.exist?
end
end
# @since 0.1.0
@ -509,5 +527,15 @@ module Hanami
env[RACK_ENV]
end
end
# @api private
# @since 1.3.3
#
# @see https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
def dotenv_applicable?(file)
return false if file == DOTENV_LOCAL_FILE && environment == TEST_ENV
true
end
end
end

View File

@ -71,7 +71,7 @@ module Hanami
# @api private
def run_hanami_command(command)
require "hanami/cli/commands"
Hanami::CLI.new(Hanami::CLI::Commands).call(arguments: command.split(/[[:space:]]/))
Dry::CLI.new(Hanami::CLI::Commands).call(arguments: command.split(/[[:space:]]/))
end
# rubocop:enable Metrics/MethodLength
end

View File

@ -6,7 +6,7 @@ module Hanami
module Version
# @since 0.9.0
# @api private
VERSION = '1.3.1'.freeze
VERSION = '1.3.3'.freeze
# @since 0.9.0
# @api private

View File

@ -14,6 +14,7 @@ module Hanami
# @api private
def call(env)
@request_path = env['REQUEST_PATH'] || ''
@request_host = env['HTTP_HOST'] || ''
@body = [ERB.new(@root.join('welcome.html.erb').read).result(binding)]
[200, {}, @body]
@ -29,7 +30,11 @@ module Hanami
# @api private
def application_class
Hanami.configuration.apps do |app|
return app if @request_path.include?(app.path_prefix)
if app.host.nil?
return app if @request_path.include?(app.path_prefix)
else
return app if @request_host == app.host
end
end
end
end

View File

@ -63,11 +63,11 @@ upload_code_coverage() {
}
main() {
setup &&
run_unit_tests &&
run_isolation_tests &&
run_integration_tests &&
upload_code_coverage
setup
run_unit_tests
run_isolation_tests
run_integration_tests
upload_code_coverage
}
trap teardown EXIT

View File

@ -20,7 +20,7 @@ bundle_package() {
}
install_hanami_frameworks() {
declare -a frameworks=(utils validations router helpers model view controller mailer assets cli webconsole)
declare -a frameworks=(utils validations router helpers model view controller mailer assets webconsole)
for framework in "${frameworks[@]}"
do

View File

@ -3,7 +3,7 @@ set -euo pipefail
IFS=$'\n\t'
uninstall_hanami_gems() {
declare -a frameworks=(hanami hanami-assets hanami-mailer hanami-controller hanami-view hanami-model hanami-helpers hanami-router hanami-validations hanami-cli hanami-webconsole hanami-utils)
declare -a frameworks=(hanami hanami-assets hanami-mailer hanami-controller hanami-view hanami-model hanami-helpers hanami-router hanami-validations hanami-webconsole hanami-utils)
for framework in "${frameworks[@]}"
do

View File

@ -3,7 +3,7 @@ RSpec.describe "assets", type: :integration do
it "compiles and serves assets in development mode" do
project = "bookshelf_serve_assets"
with_project(project, gems: ['sass']) do
with_project(project, gems: ['sassc']) do
generate "action web home#index --url=/"
write "apps/web/assets/javascripts/application.css.sass", <<-EOF

View File

@ -3,7 +3,7 @@ require 'json'
RSpec.describe 'hanami assets', type: :integration do
describe 'precompile' do
it "precompiles assets" do
gems = ['sass', 'coffee-script']
gems = ['sassc', 'coffee-script']
Platform.match do
os(:linux).engine(:ruby) { gems.push('therubyracer') }

View File

@ -1,6 +1,6 @@
RSpec.describe "hanami db", type: :integration do
describe "apply" do
it "migrates, dumps structure, deletes migrations" do
it "migrates, dumps structure, deletes migrations", if: RUBY_VERSION < '2.4' do
with_project do
versions = generate_migrations
@ -24,6 +24,31 @@ SQL
end
end
it "migrates, dumps structure, deletes migrations", if: RUBY_VERSION >= '2.4' do
with_project do
versions = generate_migrations
hanami "db apply"
hanami "db version"
expect(out).to include(versions.last.to_s)
db = Pathname.new('db')
schema = db.join('schema.sql').to_s
migrations = db.join('migrations')
expect(schema).to have_file_content <<-SQL
CREATE TABLE `schema_migrations` (`filename` varchar(255) NOT NULL PRIMARY KEY);
CREATE TABLE `users` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` varchar(255), `age` integer);
CREATE TABLE sqlite_sequence(name,seq);
INSERT INTO schema_migrations VALUES('#{versions.first}_create_users.rb');
INSERT INTO schema_migrations VALUES('#{versions.last}_add_age_to_users.rb');
SQL
expect(migrations.children).to be_empty
end
end
it "prints help message" do
with_project do
output = <<-OUT

View File

@ -262,7 +262,7 @@ RSpec.describe "hanami generate", type: :integration do
end
it "fails with unknown argument" do
with_project('bookshelf_generate_action_uknown_method') do
with_project('bookshelf_generate_action_unknown_method') do
output = "`FOO' is not a valid HTTP method. Please use one of: `GET' `POST' `PUT' `DELETE' `HEAD' `OPTIONS' `TRACE' `PATCH' `OPTIONS' `LINK' `UNLINK'"
run_cmd "hanami generate action web books#create --method=FOO", output, exit_status: 1
end

View File

@ -64,6 +64,8 @@ RSpec.describe "hanami new", type: :integration do
expect(".gitignore").to have_file_content <<-END
/public/assets*
/tmp
.env.local
.env.*.local
END
end
end
@ -134,6 +136,8 @@ RSpec.describe "hanami new", type: :integration do
/db/*.sqlite
/public/assets*
/tmp
.env.local
.env.*.local
END
end
end
@ -203,6 +207,8 @@ RSpec.describe "hanami new", type: :integration do
expect(".gitignore").to have_file_content <<-END
/public/assets*
/tmp
.env.local
.env.*.local
END
end
end

View File

@ -16,7 +16,6 @@ RSpec.describe "hanami new", type: :integration do
expect('Gemfile').to have_file_content(%r{gem 'hanami-view', require: false, git: 'https://github.com/hanami/view.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami-helpers', require: false, git: 'https://github.com/hanami/helpers.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami-mailer', require: false, git: 'https://github.com/hanami/mailer.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami-cli', require: false, git: 'https://github.com/hanami/cli.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami-assets', require: false, git: 'https://github.com/hanami/assets.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami-model', require: false, git: 'https://github.com/hanami/model.git', branch: 'develop'})
expect('Gemfile').to have_file_content(%r{gem 'hanami', git: 'https://github.com/hanami/hanami.git', branch: 'develop'})

View File

@ -453,6 +453,8 @@ END
/db/*.sqlite
/public/assets*
/tmp
.env.local
.env.*.local
END
#

View File

@ -0,0 +1,88 @@
require "resolv-replace"
require "net/http"
require "uri"
RSpec.describe "mount applications", type: :integration do
before do
stub_dns_hosts("127.0.0.1 #{host} www.#{host} #{subdomain} localhost")
end
let(:host) { "bookshelf.test" }
let(:subdomain) { "beta.#{host}" }
context "with apps mounted with path" do
it "shows welcome page" do
with_project do
generate_host_middleware
generate "app admin"
generate "app beta"
replace "config/environment.rb", "Beta::Application", %( mount Beta::Application, at: "/", host: "#{subdomain}")
server do
# Web
visit "/"
expect(page).to have_content("bundle exec hanami generate action web 'home#index' --url=/")
# Admin
visit "/admin"
expect(page).to have_content("bundle exec hanami generate action admin 'home#index' --url=/")
end
end
end
end
context "when apps mounted with host: option" do
it "shows welcome page" do
with_project do
generate_host_middleware
generate "app admin"
generate "app beta"
replace "config/environment.rb", "Beta::Application", %( mount Beta::Application, at: "/", host: "#{subdomain}")
port = RSpec::Support::RandomPort.call
server(port: port) do
# Beta
response = raw_http_request("http://#{subdomain}:#{port}")
expect(response.body).to include("bundle exec hanami generate action beta 'home#index' --url=/")
end
end
end
end
private
def generate_host_middleware
unshift "config/environment.rb", 'require_relative "./middleware/host"'
inject_line_after "config/environment.rb", "Hanami.configure", <<-EOL
middleware.use Middleware::Host
EOL
write "config/middleware/host.rb", <<-EOF
require "uri"
module Middleware
class Host
def initialize(app)
@app = app
end
def call(env)
host = URI.parse(env["REQUEST_URI"]).host
env["SERVER_NAME"] = host
env["HTTP_HOST"] = host
env["HTTP_X_FORWARDED_HOST"] = host
@app.call(env)
end
end
end
EOF
end
def raw_http_request(uri)
Net::HTTP.get_response(URI.parse(uri))
end
end

View File

@ -1,10 +1,12 @@
RSpec.describe "Hanami.configure" do
before do
application = app
model_config = model_configuration
application = app
beta_application = beta_app
model_config = model_configuration
mailer_config = mailer_configuration
Hanami.configure do
mount beta_application, at: '/', host: 'beta.hanamirb.test'
mount application, at: '/'
model(&model_config)
mailer(&mailer_config)
@ -12,6 +14,7 @@ RSpec.describe "Hanami.configure" do
end
let(:app) { double('app') }
let(:beta_app) { double('beta_app') }
let(:model_configuration) do
lambda do
@ -30,7 +33,8 @@ RSpec.describe "Hanami.configure" do
it "setups apps" do
mounted = Hanami.configuration.mounted
expect(mounted[app]).to eq(Hanami::Configuration::App.new(app, '/'))
expect(mounted[app]).to eq(Hanami::Configuration::App.new(app, at: '/'))
expect(mounted[beta_app]).to eq(Hanami::Configuration::App.new(beta_app, at: '/', host: 'beta.hanamirb.test'))
end
it "holds model configuration" do

View File

@ -1,3 +1,4 @@
HANAMI_PORT=42
BAZ="yes"
WAT="true"
LOADED_ENV_FILE='.env.development'

View File

@ -0,0 +1 @@
LOADED_ENV_FILE='.env.development.local'

View File

@ -0,0 +1 @@
GLOBAL_ENV_LOCAL='true'

View File

@ -87,6 +87,8 @@ END
/db/*.sqlite
/public/assets*
/tmp
.env.local
.env.*.local
END
end
end

View File

@ -20,21 +20,27 @@ RSpec.describe Hanami::Environment do
end
describe "#initialize" do
context "global .env" do
it "doesn't set env vars from .env" do
with_directory('spec/support/fixtures') do
context 'when environment is test' do
let(:env) { Hash['HANAMI_ENV' => 'test'] }
it 'does not set env variables from .env.local' do
with_directory('spec/support/fixtures/dotenv') do
described_class.new(env: env)
expect(env['FOO']).to be_nil # see spec/support/fixtures/.env
expect(env['GLOBAL_ENV_LOCAL']).to eq(nil)
end
end
end
it "doesn't sets port" do
with_directory('spec/support/fixtures') do
subject = described_class.new(env: env)
context 'when environment is not test' do
let(:env) { Hash['HANAMI_ENV' => 'development'] }
# returns default instead the value from spec/support/fixtures/.env
expect(subject.port).to eq(2300)
it 'loads environment variables from .env.local' do
with_directory('spec/support/fixtures/dotenv') do
described_class.new(env: env)
expect(env['GLOBAL_ENV_LOCAL']).to eq('true')
end
end
end
@ -51,6 +57,14 @@ RSpec.describe Hanami::Environment do
end
end
it 'sets env variables from env specific .local files with highest priority' do
with_directory('spec/support/fixtures/dotenv') do
env = Hash['HANAMI_ENV' => 'development']
described_class.new(env: env)
expect(env['LOADED_ENV_FILE']).to eq('.env.development.local')
end
end
it "sets port from .env.development" do
with_directory('spec/support/fixtures/dotenv') do
subject = described_class.new(env: env)

View File

@ -1,5 +1,5 @@
RSpec.describe "Hanami::VERSION" do
it "returns current version" do
expect(Hanami::VERSION).to eq("1.3.1")
expect(Hanami::VERSION).to eq("1.3.3")
end
end