diff --git a/.github/workflows/master_and_pr.yml b/.github/workflows/master_and_pr.yml new file mode 100644 index 0000000..d3e4b92 --- /dev/null +++ b/.github/workflows/master_and_pr.yml @@ -0,0 +1,64 @@ +name: master & PR +on: + pull_request: + push: + branches: + - master +jobs: + spec: + runs-on: ubuntu-latest + strategy: + matrix: + rails_version: + - "5.0" + - "5.1" + - "5.2" + - "6.0" + - "6.1" + ruby_version: + - "2.7" + - "3.1" + autoloader: + - "zeitwerk" + - "classic" + eager_load: + - "true" + - "false" + exclude: + - rails_version: "5.0" + ruby_version: "3.1" + - rails_version: "5.1" + ruby_version: "3.1" + - rails_version: "5.2" + ruby_version: "3.1" + - rails_version: "5.0" + autoloader: "zeitwerk" + - rails_version: "5.1" + autoloader: "zeitwerk" + - rails_version: "5.2" + autoloader: "zeitwerk" + - rails_version: "5.0" + autoloader: "classic" + - rails_version: "5.1" + autoloader: "classic" + - rails_version: "5.2" + autoloader: "classic" + name: Test on Rails ${{ matrix.rails_version }} & Ruby ${{ matrix.ruby_version }} & Autoloader ${{ matrix.autoloader }} & EagerLoad ${{ matrix.eager_load }} + env: + BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb + CI: true + EAGER_LOAD: ${{ matrix.eager_load }} + AUTOLOADER : ${{ matrix.autoloader }} + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: rspec + run: bundle exec rspec + - name: Coveralls + if: matrix.rails_version == '6.1' && matrix.ruby_version == '3.1' + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c3612b6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -rvm: - - 2.6 - - 2.7 - - 3.0 -branches: - only: - - master -sudo: false diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 5d92aa5..0000000 --- a/Gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source "https://rubygems.org" - -gemspec - -group :development, :test do - gem "pry-rails" -end diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..c2ab260 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +for path in gemfiles/Gemfile_*.rb; do + BUNDLE_GEMFILE="${path}" bundle install +done diff --git a/bin/test b/bin/test new file mode 100755 index 0000000..e7e606f --- /dev/null +++ b/bin/test @@ -0,0 +1,7 @@ +set -euo pipefail +IFS=$'\n\t' +set -vx + +for path in gemfiles/Gemfile_*.rb; do + BUNDLE_GEMFILE="${path}" bundle exec rspec +done diff --git a/chanko.gemspec b/chanko.gemspec index 9ef77e2..edfeb38 100644 --- a/chanko.gemspec +++ b/chanko.gemspec @@ -18,13 +18,15 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 2.6.0' gem.add_dependency "rails", ">= 4.0.0" + gem.add_development_dependency "byebug" gem.add_development_dependency "coffee-rails", ">= 3.0.10" - gem.add_development_dependency "coveralls" gem.add_development_dependency "jquery-rails" gem.add_development_dependency "pry" + gem.add_development_dependency "pry-rails" gem.add_development_dependency "rspec-rails", ">= 3.0.0" gem.add_development_dependency "sass-rails", ">= 3.0.10" gem.add_development_dependency "simplecov" + gem.add_development_dependency 'simplecov-lcov' gem.add_development_dependency "slim" gem.add_development_dependency "sqlite3" gem.add_development_dependency "thin" diff --git a/gemfiles/Gemfile_rails_5.0.rb b/gemfiles/Gemfile_rails_5.0.rb new file mode 100644 index 0000000..4c8bb7e --- /dev/null +++ b/gemfiles/Gemfile_rails_5.0.rb @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gemspec path: '..' + +gem 'rails', '~> 5.0.0' +gem 'sqlite3', '~> 1.3.6' diff --git a/gemfiles/Gemfile_rails_5.0.rb.lock b/gemfiles/Gemfile_rails_5.0.rb.lock new file mode 100644 index 0000000..a65e5ce --- /dev/null +++ b/gemfiles/Gemfile_rails_5.0.rb.lock @@ -0,0 +1,203 @@ +PATH + remote: .. + specs: + chanko (2.2.1) + rails (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (7.1.4) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + daemons (1.4.1) + diff-lcs (1.5.0) + docile (1.4.0) + erubis (2.7.0) + eventmachine (1.2.7) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + loofah (2.19.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + racc (1.6.0) + rack (2.2.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (13.0.6) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (4.1.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + temple (0.8.2) + thin (1.8.1) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.2.1) + thread_safe (0.3.6) + tilt (2.0.11) + tzinfo (1.2.10) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + chanko! + coffee-rails (>= 3.0.10) + jquery-rails + pry + pry-rails + rails (~> 5.0.0) + rspec-rails (>= 3.0.0) + sass-rails (>= 3.0.10) + simplecov + simplecov-lcov + slim + sqlite3 (~> 1.3.6) + thin + uglifier + +BUNDLED WITH + 2.3.26 diff --git a/gemfiles/Gemfile_rails_5.1.rb b/gemfiles/Gemfile_rails_5.1.rb new file mode 100644 index 0000000..333f2eb --- /dev/null +++ b/gemfiles/Gemfile_rails_5.1.rb @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gemspec path: '..' + +gem 'rails', '~> 5.1.0' +gem 'sqlite3', '~> 1.3.6' diff --git a/gemfiles/Gemfile_rails_5.1.rb.lock b/gemfiles/Gemfile_rails_5.1.rb.lock new file mode 100644 index 0000000..99e6ef4 --- /dev/null +++ b/gemfiles/Gemfile_rails_5.1.rb.lock @@ -0,0 +1,203 @@ +PATH + remote: .. + specs: + chanko (2.2.1) + rails (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.7) + actionpack (= 5.1.7) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.7) + actionview (= 5.1.7) + activesupport (= 5.1.7) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.7) + activesupport (= 5.1.7) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.7) + activesupport (= 5.1.7) + globalid (>= 0.3.6) + activemodel (5.1.7) + activesupport (= 5.1.7) + activerecord (5.1.7) + activemodel (= 5.1.7) + activesupport (= 5.1.7) + arel (~> 8.0) + activesupport (5.1.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (8.0.0) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + daemons (1.4.1) + diff-lcs (1.5.0) + docile (1.4.0) + erubi (1.11.0) + eventmachine (1.2.7) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + loofah (2.19.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + racc (1.6.0) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (5.1.7) + actioncable (= 5.1.7) + actionmailer (= 5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) + activemodel (= 5.1.7) + activerecord (= 5.1.7) + activesupport (= 5.1.7) + bundler (>= 1.3.0) + railties (= 5.1.7) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (5.1.7) + actionpack (= 5.1.7) + activesupport (= 5.1.7) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (13.0.6) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (4.1.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + temple (0.8.2) + thin (1.8.1) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.2.1) + thread_safe (0.3.6) + tilt (2.0.11) + tzinfo (1.2.10) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + chanko! + coffee-rails (>= 3.0.10) + jquery-rails + pry + pry-rails + rails (~> 5.1.0) + rspec-rails (>= 3.0.0) + sass-rails (>= 3.0.10) + simplecov + simplecov-lcov + slim + sqlite3 (~> 1.3.6) + thin + uglifier + +BUNDLED WITH + 2.3.26 diff --git a/gemfiles/Gemfile_rails_5.2.rb b/gemfiles/Gemfile_rails_5.2.rb new file mode 100644 index 0000000..a1fe02e --- /dev/null +++ b/gemfiles/Gemfile_rails_5.2.rb @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gemspec path: '..' + +gem 'rails', '~> 5.2.0' +gem 'sqlite3', '~> 1.3.6' diff --git a/gemfiles/Gemfile_rails_5.2.rb.lock b/gemfiles/Gemfile_rails_5.2.rb.lock new file mode 100644 index 0000000..c0934bc --- /dev/null +++ b/gemfiles/Gemfile_rails_5.2.rb.lock @@ -0,0 +1,209 @@ +PATH + remote: .. + specs: + chanko (2.2.1) + rails (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) + globalid (>= 0.3.6) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) + activesupport (5.2.8.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (9.0.0) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + daemons (1.4.1) + diff-lcs (1.5.0) + docile (1.4.0) + erubi (1.11.0) + eventmachine (1.2.7) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + loofah (2.19.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + racc (1.6.0) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) + bundler (>= 1.3.0) + railties (= 5.2.8.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (13.0.6) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (5.1.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + temple (0.8.2) + thin (1.8.1) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.2.1) + thread_safe (0.3.6) + tilt (2.0.11) + tzinfo (1.2.10) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + chanko! + coffee-rails (>= 3.0.10) + jquery-rails + pry + pry-rails + rails (~> 5.2.0) + rspec-rails (>= 3.0.0) + sass-rails (>= 3.0.10) + simplecov + simplecov-lcov + slim + sqlite3 (~> 1.3.6) + thin + uglifier + +BUNDLED WITH + 2.3.26 diff --git a/gemfiles/Gemfile_rails_6.0.rb b/gemfiles/Gemfile_rails_6.0.rb new file mode 100644 index 0000000..8da51e2 --- /dev/null +++ b/gemfiles/Gemfile_rails_6.0.rb @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gemspec path: '..' + +gem 'rails', '~> 6.0.0' +gem 'net-smtp' +gem 'net-pop' +gem 'net-imap' diff --git a/gemfiles/Gemfile_rails_6.0.rb.lock b/gemfiles/Gemfile_rails_6.0.rb.lock new file mode 100644 index 0000000..90cd7b1 --- /dev/null +++ b/gemfiles/Gemfile_rails_6.0.rb.lock @@ -0,0 +1,238 @@ +PATH + remote: .. + specs: + chanko (2.2.1) + rails (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.0.6) + actionpack (= 6.0.6) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.0.6) + actionpack (= 6.0.6) + activejob (= 6.0.6) + activerecord (= 6.0.6) + activestorage (= 6.0.6) + activesupport (= 6.0.6) + mail (>= 2.7.1) + actionmailer (6.0.6) + actionpack (= 6.0.6) + actionview (= 6.0.6) + activejob (= 6.0.6) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.0.6) + actionview (= 6.0.6) + activesupport (= 6.0.6) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.6) + actionpack (= 6.0.6) + activerecord (= 6.0.6) + activestorage (= 6.0.6) + activesupport (= 6.0.6) + nokogiri (>= 1.8.5) + actionview (6.0.6) + activesupport (= 6.0.6) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.6) + activesupport (= 6.0.6) + globalid (>= 0.3.6) + activemodel (6.0.6) + activesupport (= 6.0.6) + activerecord (6.0.6) + activemodel (= 6.0.6) + activesupport (= 6.0.6) + activestorage (6.0.6) + actionpack (= 6.0.6) + activejob (= 6.0.6) + activerecord (= 6.0.6) + marcel (~> 1.0) + activesupport (6.0.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + daemons (1.4.1) + diff-lcs (1.5.0) + docile (1.4.0) + erubi (1.11.0) + eventmachine (1.2.7) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + loofah (2.19.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.1.3) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + racc (1.6.0) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (6.0.6) + actioncable (= 6.0.6) + actionmailbox (= 6.0.6) + actionmailer (= 6.0.6) + actionpack (= 6.0.6) + actiontext (= 6.0.6) + actionview (= 6.0.6) + activejob (= 6.0.6) + activemodel (= 6.0.6) + activerecord (= 6.0.6) + activestorage (= 6.0.6) + activesupport (= 6.0.6) + bundler (>= 1.3.0) + railties (= 6.0.6) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (6.0.6) + actionpack (= 6.0.6) + activesupport (= 6.0.6) + method_source + rake (>= 0.8.7) + thor (>= 0.20.3, < 2.0) + rake (13.0.6) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (5.1.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) + temple (0.8.2) + thin (1.8.1) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.2.1) + thread_safe (0.3.6) + tilt (2.0.11) + timeout (0.3.0) + tzinfo (1.2.10) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.6) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + chanko! + coffee-rails (>= 3.0.10) + jquery-rails + net-imap + net-pop + net-smtp + pry + pry-rails + rails (~> 6.0.0) + rspec-rails (>= 3.0.0) + sass-rails (>= 3.0.10) + simplecov + simplecov-lcov + slim + sqlite3 + thin + uglifier + +BUNDLED WITH + 2.3.26 diff --git a/gemfiles/Gemfile_rails_6.1.rb b/gemfiles/Gemfile_rails_6.1.rb new file mode 100644 index 0000000..ae45666 --- /dev/null +++ b/gemfiles/Gemfile_rails_6.1.rb @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gemspec path: '..' + +gem 'rails', '~> 6.1.0' +gem 'net-smtp' +gem 'net-pop' +gem 'net-imap' diff --git a/gemfiles/Gemfile_rails_6.1.rb.lock b/gemfiles/Gemfile_rails_6.1.rb.lock new file mode 100644 index 0000000..6955803 --- /dev/null +++ b/gemfiles/Gemfile_rails_6.1.rb.lock @@ -0,0 +1,241 @@ +PATH + remote: .. + specs: + chanko (2.2.1) + rails (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.1.7) + actionpack (= 6.1.7) + activesupport (= 6.1.7) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.7) + actionpack (= 6.1.7) + activejob (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + mail (>= 2.7.1) + actionmailer (6.1.7) + actionpack (= 6.1.7) + actionview (= 6.1.7) + activejob (= 6.1.7) + activesupport (= 6.1.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.1.7) + actionview (= 6.1.7) + activesupport (= 6.1.7) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7) + actionpack (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + nokogiri (>= 1.8.5) + actionview (6.1.7) + activesupport (= 6.1.7) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7) + activesupport (= 6.1.7) + globalid (>= 0.3.6) + activemodel (6.1.7) + activesupport (= 6.1.7) + activerecord (6.1.7) + activemodel (= 6.1.7) + activesupport (= 6.1.7) + activestorage (6.1.7) + actionpack (= 6.1.7) + activejob (= 6.1.7) + activerecord (= 6.1.7) + activesupport (= 6.1.7) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + daemons (1.4.1) + diff-lcs (1.5.0) + docile (1.4.0) + erubi (1.11.0) + eventmachine (1.2.7) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + loofah (2.19.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.1.3) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + racc (1.6.0) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (6.1.7) + actioncable (= 6.1.7) + actionmailbox (= 6.1.7) + actionmailer (= 6.1.7) + actionpack (= 6.1.7) + actiontext (= 6.1.7) + actionview (= 6.1.7) + activejob (= 6.1.7) + activemodel (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + bundler (>= 1.15.0) + railties (= 6.1.7) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (6.1.7) + actionpack (= 6.1.7) + activesupport (= 6.1.7) + method_source + rake (>= 12.2) + thor (~> 1.0) + rake (13.0.6) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (6.0.1) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.11) + rspec-expectations (~> 3.11) + rspec-mocks (~> 3.11) + rspec-support (~> 3.11) + rspec-support (3.12.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) + temple (0.8.2) + thin (1.8.1) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.2.1) + tilt (2.0.11) + timeout (0.3.0) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.6) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + chanko! + coffee-rails (>= 3.0.10) + jquery-rails + net-imap + net-pop + net-smtp + pry + pry-rails + rails (~> 6.1.0) + rspec-rails (>= 3.0.0) + sass-rails (>= 3.0.10) + simplecov + simplecov-lcov + slim + sqlite3 + thin + uglifier + +BUNDLED WITH + 2.3.26 diff --git a/lib/chanko/config.rb b/lib/chanko/config.rb index 503ada9..556df4e 100644 --- a/lib/chanko/config.rb +++ b/lib/chanko/config.rb @@ -6,13 +6,11 @@ class << self :backtrace_limit, :cache_units, :compatible_css_class, - :eager_load, :enable_logger, :propagated_errors, :proxy_method_name, :raise_error, :resolver, - :units_directory_path ) def reset @@ -20,13 +18,20 @@ def reset self.backtrace_limit = 10 self.compatible_css_class = false self.enable_logger = true - self.eager_load = Rails.env.production? self.propagated_errors = [] self.proxy_method_name = :unit self.raise_error = Rails.env.development? self.resolver = Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('7') ? ActionView::FileSystemResolver : ActionView::OptimizedFileSystemResolver self.units_directory_path = "app/units" end + + def units_directory_path=(path) + @units_directory_path = path + end + + def units_directory_path + @resolved_units_directory_path ||= Rails.root.join(@units_directory_path).to_s + end end reset diff --git a/lib/chanko/loader.rb b/lib/chanko/loader.rb index fe77a4a..3edc550 100644 --- a/lib/chanko/loader.rb +++ b/lib/chanko/loader.rb @@ -1,73 +1,148 @@ require "pathname" - module Chanko - class Loader + module Loader + class MissingEagarLoadEsettingError < StandardError; end + class << self - def load(unit_name) - new(unit_name).load + delegate :load, :cache, :eager_load_units!, to: "loader" + end + + def self.loader + zeitwerk? ? ZeitwerkLoader : ClassicLoader + end + + def self.zeitwerk? + Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled? + end + + def self.classic? + !zeitwerk? + end + + def self.prepare_eager_load(mode: ) + if mode == :zeitwerk && zeitwerk? + self.loader.prepare_eager_load + elsif mode == :classic && classic? + self.loader.prepare_eager_load end + end - def cache - @cache ||= {} + class ZeitwerkLoader + def self.load(name) + self.new(name).load + end + + def self.cache + # backward compatibility + { } end - def eager_load_units! - Pathname.glob("#{Rails.root}/#{Config.units_directory_path}/*").select(&:directory?).each do |path| - load(path.to_s.split("/").last.to_sym) rescue nil + def self.eager_load_units! + # Zeitwerk load chanko units as default + end + + def self.prepare_eager_load + add_unit_directory_to_eager_load_paths + Rails.autoloaders.main.collapse(Chanko::Config.units_directory_path + '/*') + Rails.autoloaders.main.ignore(Chanko::Config.units_directory_path + '/*/spec*') + end + + def self.add_unit_directory_to_eager_load_paths + path = Chanko::Config.units_directory_path + + unless Rails.configuration.eager_load_paths.include?(path) + Rails.configuration.eager_load_paths << path end end - end - def initialize(name) - @name = name - end + def initialize(name) + @name = name + end - def load - if loaded? - load_from_cache - else - load_from_file + def load + constantize + rescue NameError + # Chanko never raise error even if the constant fails to reference + nil end - end - def loaded? - cache[@name] != nil + def constantize + @name.to_s.camelize.constantize + end end - def load_from_cache - cache[@name] - end + class ClassicLoader + def self.cache + @cache ||= {} + end - def load_from_file - add_autoload_path - cache[@name] = constantize - rescue Exception => exception - ExceptionHandler.handle(exception) - cache[@name] = false - nil - end + def self.eager_load_units! + Pathname.glob("#{Chanko::Config.units_directory_path}/*").select(&:directory?).each do |path| + Chanko::Loader::ClassicLoader.load(path.basename.to_s.to_sym) + end + end + + def self.prepare_eager_load + raise MissingEagarLoadEsettingError if Rails.configuration.eager_load.nil? + + if Rails.configuration.eager_load + ruleout_unit_files_from_rails_eager_loading + end + end + + def self.ruleout_unit_files_from_rails_eager_loading + Rails.configuration.eager_load_paths.delete(Chanko::Config.units_directory_path) + end - def add_autoload_path - unless Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled? + def self.load(name) + self.new(name).load + end + + def initialize(name) + @name = name + end + + def load + if loaded? + load_from_cache + else + load_from_file + end + end + + def loaded? + cache[@name] != nil + end + + def load_from_cache + cache[@name] + end + + def load_from_file + add_autoload_path + cache[@name] = constantize + rescue Exception => exception + ExceptionHandler.handle(exception) + cache[@name] = false + nil + end + + def add_autoload_path ActiveSupport::Dependencies.autoload_paths << autoload_path ActiveSupport::Dependencies.autoload_paths.uniq! end - end - - def autoload_path - Rails.root.join("#{directory_path}/#@name").to_s - end - def directory_path - Config.units_directory_path - end + def autoload_path + "#{Config.units_directory_path }/#{@name}" + end - def constantize - @name.to_s.camelize.constantize - end + def constantize + @name.to_s.camelize.constantize + end - def cache - self.class.cache + def cache + self.class.cache + end end end end diff --git a/lib/chanko/railtie.rb b/lib/chanko/railtie.rb index 5f21439..2ce3965 100644 --- a/lib/chanko/railtie.rb +++ b/lib/chanko/railtie.rb @@ -1,6 +1,6 @@ module Chanko class Railtie < Rails::Railtie - initializer "chanko" do |app| + initializer "chanko.include", before: :eager_load! do |app| ActiveSupport.on_load :action_view do ::ActionView::Base.send(:include, Helper, Invoker, UnitProxyProvider) end @@ -14,22 +14,25 @@ class Railtie < Rails::Railtie end end - initializer("chanko.support_zeitwerk") do |app| - if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled? - Rails.autoloaders.main.collapse(Rails.root.join(Chanko::Config.units_directory_path, '*')) - end + + initializer("chanko.zeitwerk.prepare_eager_load", before: :set_autoload_paths) do |app| + # zeitwerk freezes autoload_paths after :set_autoload_paths. + # So we need to prepare before set_autoload_paths + Chanko::Loader.prepare_eager_load(mode: :zeitwerk) end - initializer("chanko.prevent_units_directory_from_eager_loading", before: :set_autoload_paths) do |app| - if Chanko::Config.eager_load - Rails.configuration.eager_load_paths.delete(Rails.root.join(Chanko::Config.units_directory_path).to_s) - end + initializer("chanko.classic.prepare_eager_load", after: :load_environment_config) do |app| + # Rails5 doens't load environments/*.rb files before :set_autoload_paths. + # In other words, at this stage, config.eager_load cannot be determined to be true or false. + # But classic loader does not freeze paths on :set_autoload_paths. + # After all, It's ok if it is executed after :set_autoload_paths on Rails5 and Rails6(classic). + Chanko::Loader.prepare_eager_load(mode: :classic) end - initializer("chanko.eager_load_units") do |app| - if Chanko::Config.eager_load - Chanko::Loader.eager_load_units! - end + initializer("chanko.eager_load_units", before: :eager_load!) do |app| + # This is why we need handmade eager-loading + # https://github.com/cookpad/chanko/pull/38 + Chanko::Loader.eager_load_units! end end end diff --git a/lib/chanko/test.rb b/lib/chanko/test.rb index ef93194..bfbea17 100644 --- a/lib/chanko/test.rb +++ b/lib/chanko/test.rb @@ -8,6 +8,10 @@ def activations def included(base) base.send :include, UnitProxyProvider end + + def logger + @logger = ::Logger.new(STDOUT) + end end def enable_unit(unit_name) diff --git a/spec/chanko/function_spec.rb b/spec/chanko/function_spec.rb index 57e1420..1fec5ae 100644 --- a/spec/chanko/function_spec.rb +++ b/spec/chanko/function_spec.rb @@ -6,10 +6,25 @@ module Chanko Loader.load(:example_unit) end - let(:context) do - Class.new(ActionView::Base) do - include Chanko::Invoker + def rails5_action_view_instance + klass = Class.new(ActionView::Base) do + def current_unit + units.last + end + + def units + @units ||= [] + end + + def path + view_paths.first.to_s + end + end + klass.new + end + def rails6_action_view_instance + klass = Class.new(ActionView::Base.with_empty_template_cache) do def current_unit units.last end @@ -21,7 +36,18 @@ def units def path view_paths.first.to_s end - end.new + end + + klass.with_view_paths([], {}, nil) + end + + let(:context) do + case Rails::VERSION::MAJOR + when 5 + rails5_action_view_instance + when 6 + rails6_action_view_instance + end end let(:context_without_view_paths) do diff --git a/spec/chanko/invoker_spec.rb b/spec/chanko/invoker_spec.rb index 2d73344..f60dfb5 100644 --- a/spec/chanko/invoker_spec.rb +++ b/spec/chanko/invoker_spec.rb @@ -3,19 +3,11 @@ module Chanko describe Invoker do let(:view) do - Class.new(ActionView::Base) do - include Chanko::Invoker - include Chanko::Helper - include Chanko::UnitProxyProvider - end.new + controller.helpers end let(:controller) do - Class.new(ActionController::Base) do - include Chanko::Invoker - include Chanko::Helper - include Chanko::UnitProxyProvider - end.new + Class.new(ActionController::Base).new end describe "#invoke" do diff --git a/spec/chanko/loader_spec.rb b/spec/chanko/loader_spec.rb index 39798ac..95123a5 100644 --- a/spec/chanko/loader_spec.rb +++ b/spec/chanko/loader_spec.rb @@ -4,38 +4,38 @@ module Chanko describe Loader do describe ".load" do after do - described_class.cache.clear + Chanko::Loader.cache.clear end context "when existent unit name is passed" do it "loads unit in units directory and returns the Module" do - expect(described_class.load(:example_unit)).to eq(ExampleUnit) + expect(Chanko::Loader.load(:example_unit)).to eq(ExampleUnit) end end context "when non-existent unit name is passed" do it "returns nil" do - expect(described_class.load(:non_existent_unit)).to eq(nil) + expect(Chanko::Loader.load(:non_existent_unit)).to eq(nil) end end context "when loader has ever loaded specified unit" do - it "load unit from cache" do - expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original - described_class.load(:example_unit) - described_class.load(:example_unit) + it "load unit from cache", classic: true do + expect_any_instance_of(Chanko::Loader::ClassicLoader).to receive(:load_from_file).and_call_original + Chanko::Loader.load(:example_unit) + Chanko::Loader.load(:example_unit) end end context "when loader has ever loaded specified wrong unit" do before do - described_class.cache.clear + Chanko::Loader.cache.clear end - it "load unit from cache" do - expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original - described_class.load(:non_existent_unit) - described_class.load(:non_existent_unit) + it "load unit from cache", classic: true do + expect_any_instance_of(Chanko::Loader::ClassicLoader).to receive(:load_from_file).and_call_original + Chanko::Loader.load(:non_existent_unit) + Chanko::Loader.load(:non_existent_unit) end end end diff --git a/spec/chanko/test_spec.rb b/spec/chanko/test_spec.rb index 7705349..5f63c95 100644 --- a/spec/chanko/test_spec.rb +++ b/spec/chanko/test_spec.rb @@ -3,12 +3,22 @@ module Chanko describe Test do + def rails5_action_view_instance + Class.new(ActionView::Base).new + end + + def rails6_action_view_instance + klass = Class.new(ActionView::Base.with_empty_template_cache) + klass.with_view_paths(nil, {}, nil) + end + let(:view) do - Class.new(ActionView::Base) do - include Chanko::Invoker - include Chanko::Helper - include Chanko::UnitProxyProvider - end.new + case Rails::VERSION::MAJOR + when 5 + rails5_action_view_instance + when 6 + rails6_action_view_instance + end end describe "#enable_unit" do diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 6010f38..13cbaab 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -7,7 +7,7 @@ def index end end - it "clears cache before each request" do + it "clears cache before each request", classic: true do expect(Chanko::Loader.cache).to receive(:clear).exactly(2) get :index get :index diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 0000000..b16e53d --- /dev/null +++ b/spec/dummy/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index b0fe20d..91f1425 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -49,6 +49,18 @@ class Application < Rails::Application # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' config.assets.quiet = true if ::Rails::VERSION::MAJOR >= 5 + if Rails::VERSION::MAJOR >= 6 + if ENV['AUTOLOADER'] == 'zeitwerk' + Chanko::Test.logger.info("Autoloader: zeitwerk") + config.autoloader = :zeitwerk + else + Chanko::Test.logger.info("Autoloader: classic") + config.autoloader = :classic + end + end end end +if Rails::VERSION::MAJOR >= 6 && Rails.autoloaders.zeitwerk_enabled? + Rails.autoloaders.main.collapse(Rails.root.join('app', 'units', '*')) +end diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 5be62d5..95d6d3c 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,10 +1,9 @@ require 'rubygems' -gemfile = File.expand_path('../../../../Gemfile', __FILE__) -if File.exist?(gemfile) - ENV['BUNDLE_GEMFILE'] = gemfile - require 'bundler' - Bundler.setup +unless ENV['BUNDLE_GEMFILE'] + raise "Select Gemfile_x.rb from gemfiles dir then set BUNDLE_GEMFILE" end +require 'bundler/setup' + $:.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 3da5eb9..df3006d 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -2,4 +2,4 @@ require File.expand_path('../application', __FILE__) # Initialize the rails application -Dummy::Application.initialize! +Rails.application.initialize! diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 0d38ba0..bf79768 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -29,5 +29,12 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr - config.eager_load = false + if ENV['EAGER_LOAD'] == 'true' + Chanko::Test.logger.info("EagerLoad: on") + config.eager_load = true + else + Chanko::Test.logger.info("EagerLoad: off") + config.eager_load = false + end + end diff --git a/spec/dummy/config/initializers/chanko_initializer.rb b/spec/dummy/config/initializers/chanko_initializer.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/config/storage.yml b/spec/dummy/config/storage.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spec/dummy/config/storage.yml @@ -0,0 +1 @@ + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 32c20a0..28f2c1d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,23 @@ -require "coveralls" -Coveralls.wear! +require 'simplecov' + +SimpleCov.start 'rails' do + if ENV['CI'] + require 'simplecov-lcov' + SimpleCov::Formatter::LcovFormatter.config do |c| + c.report_with_single_file = true + c.single_report_path = 'coverage/lcov.info' + end + formatter SimpleCov::Formatter::LcovFormatter + end -require "simplecov" -SimpleCov.start do add_filter "/spec\/fixtures/" add_filter "/spec\/dummy/" end ENV["RAILS_ENV"] ||= "test" require "chanko" +require "chanko/test" +Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__) require File.expand_path("../dummy/config/environment", __FILE__) require "rspec/rails" @@ -38,6 +47,11 @@ # # Equivalent to being in spec/controllers # end config.infer_spec_type_from_file_location! + + if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled? + config.filter_run_excluding classic: true + else + config.filter_run_excluding zeitwerk: true + end end -Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)