diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..43be565 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_GITHUB__HTTPS: "true" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..283a2ea --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,76 @@ +on: + pull_request: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + strategy: + matrix: + ruby: + - ruby-head + - jruby-head + rails: + - 7 + - master + rails_api_only: + - 0 + - 1 + jruby_ar_jdbc_adapter_version: + - v70.0.pre + experimental: + - true + include: + - ruby: 2.7 + rails: 5 + rails_api_only: 0 + experimental: false + - ruby: 2.7 + rails: 5 + rails_api_only: 1 + experimental: false + - ruby: 2.7 + rails: 6 + rails_api_only: 0 + experimental: false + - ruby: 2.7 + rails: 6 + rails_api_only: 1 + experimental: false + - ruby: 3.1 + rails: 7 + rails_api_only: 0 + experimental: false + - ruby: 3.1 + rails: 7 + rails_api_only: 1 + experimental: false + - ruby: jruby-9.1 + rails: 5 + rails_api_only: 0 + jruby_ar_jdbc_adapter_version: v52.8 + experimental: false + - ruby: jruby-9.2 + rails: 6 + rails_api_only: 0 + jruby_ar_jdbc_adapter_version: v60.0 + experimental: false + + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + env: + RAILS_VERSION: ${{ matrix.rails }} + RAILS_API_ONLY: ${{ matrix.rails_api_only }} + JRUBY_AR_JDBC_ADAPTER_VERSION: ${{ matrix.jruby_ar_jdbc_adapter_version }} + - run: bundle exec rake + env: + RAILS_VERSION: ${{ matrix.rails }} + RAILS_API_ONLY: ${{ matrix.rails_api_only }} + JRUBY_AR_JDBC_ADAPTER_VERSION: ${{ matrix.jruby_ar_jdbc_adapter_version }} diff --git a/.gitignore b/.gitignore index b355420..58587c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.gem -.bundle Gemfile.lock + pkg/* tmp/* diff --git a/.travis.yml b/.travis.yml index a2ab44c..1088739 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,48 +1,6 @@ language: ruby cache: bundler -rvm: -- 2.5.0 -- 2.4.4 -- 2.3.5 -- jruby-9.1.13.0 -- ruby-head -- jruby-head -env: -- RAILS_VERSION=master -- RAILS_VERSION=master RAILS_API_ONLY=1 -- RAILS_VERSION=5.2 -- RAILS_VERSION=5.2 RAILS_API_ONLY=1 -- RAILS_VERSION=5.1 -- RAILS_VERSION=5.1 RAILS_API_ONLY=1 -- RAILS_VERSION=5.0 -- RAILS_VERSION=5.0 RAILS_API_ONLY=1 -matrix: - include: - - rvm: 2.2.8 - env: RAILS_VERSION=4.2 - - rvm: 2.1.10 - env: RAILS_VERSION=4.2 - - rvm: 2.0.0 - env: RAILS_VERSION=4.2 - - rvm: 2.2.8 - env: RAILS_VERSION=4.1 - - rvm: 2.1.10 - env: RAILS_VERSION=4.1 - - rvm: 2.0.0 - env: RAILS_VERSION=4.1 - exclude: - - rvm: 2.4.4 - env: RAILS_VERSION=master - - rvm: 2.4.4 - env: RAILS_VERSION=master RAILS_API_ONLY=1 - - rvm: 2.3.5 - env: RAILS_VERSION=master - - rvm: 2.3.5 - env: RAILS_VERSION=master RAILS_API_ONLY=1 - allow_failures: - - rvm: jruby-9.1.13.0 - - rvm: ruby-head - - rvm: jruby-head +ruby: 2.5.0 before_deploy: bundle exec rake assets:compile deploy: provider: rubygems diff --git a/Gemfile b/Gemfile index adef53c..fa3531a 100644 --- a/Gemfile +++ b/Gemfile @@ -23,8 +23,10 @@ group :test do gem 'sassc-rails' end - gem "activerecord-jdbcsqlite3-adapter", platform: :jruby, - github: "jruby/activerecord-jdbc-adapter" + if RUBY_PLATFORM == 'java' + gem "activerecord-jdbcsqlite3-adapter", platform: :jruby, + github: "jruby/activerecord-jdbc-adapter", tag: ENV['JRUBY_AR_JDBC_ADAPTER_VERSION'] + end gem "minitest", ">= 4.2" gem "capybara", ">= 2.6" diff --git a/README.md b/README.md index 5f0fa0b..d1b7279 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[Build Status](https://travis-ci.org/voormedia/flipflop) +![GitHub Actions](https://github.com/voormedia/flipflop/actions/workflows/test.yml/badge.svg) # Flipflop your features diff --git a/lib/flipflop/configurable.rb b/lib/flipflop/configurable.rb index 4eb3ebe..8974942 100644 --- a/lib/flipflop/configurable.rb +++ b/lib/flipflop/configurable.rb @@ -15,10 +15,10 @@ def feature(feature, **options) FeatureSet.current.add(feature) end - def strategy(strategy = nil, **options) + def strategy(strategy = nil, **options, &block) if block_given? options[:name] = strategy.to_s - options[:lambda] = Proc.new + options[:lambda] = block strategy = Strategies::LambdaStrategy end diff --git a/lib/flipflop/facade.rb b/lib/flipflop/facade.rb index 3bf1be0..ef90001 100644 --- a/lib/flipflop/facade.rb +++ b/lib/flipflop/facade.rb @@ -11,6 +11,8 @@ def feature_set end def respond_to_missing?(method, include_private = false) + return false if method == :use_relative_model_naming? + method[-1] == "?" end diff --git a/lib/flipflop/strategies/cookie_strategy.rb b/lib/flipflop/strategies/cookie_strategy.rb index 996781d..d84f906 100644 --- a/lib/flipflop/strategies/cookie_strategy.rb +++ b/lib/flipflop/strategies/cookie_strategy.rb @@ -32,7 +32,8 @@ def switch!(feature, enabled) end def clear!(feature) - request.cookie_jar.delete(cookie_key(feature), **@options) + options = @options.dup + request.cookie_jar.delete(cookie_key(feature), **options) end protected diff --git a/test/test_helper.rb b/test/test_helper.rb index f145ccb..e59f562 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,6 +5,7 @@ require "minitest/autorun" require "action_controller" +require "action_controller/test_case" require "rails/generators" # Who is setting this to true? :o @@ -14,6 +15,7 @@ def create_request env = Rack::MockRequest.env_for("/example") request = ActionDispatch::TestRequest.new(env) request.host = "example.com" + request.session = ActionController::TestSession.new class << request def cookie_jar @@ -46,7 +48,7 @@ def capture_stderr end def reload_constant(name) - ActiveSupport::Dependencies.remove_constant(name.to_s) + Object.send(:remove_const, name.to_s) path = ActiveSupport::Dependencies.search_for_file(name.to_s.underscore).sub!(/\.rb\z/, "") ActiveSupport::Dependencies.loaded.delete(path) Object.const_get(name) @@ -112,10 +114,11 @@ def create! Rails::Generators::AppGenerator.new([path], quiet: true, - api: ENV["RAILS_API_ONLY"].to_i.nonzero?, + api: rails_api_only?, skip_active_job: true, skip_active_storage: true, skip_action_cable: true, + skip_action_mailer: true, skip_bootsnap: true, skip_bundle: true, skip_puma: true, @@ -128,6 +131,13 @@ def create! skip_turbolinks: true, ).invoke_all + if rails_api_only? + project_root = Pathname.new(__dir__.to_s).parent + manifest_path = project_root.join(path).join("app/assets/config/manifest.js") + manifest_path.dirname.mkpath + manifest_path.write(project_root.join("app/assets/config/manifest.js").read) + end + # Remove bootsnap if present, this interferes with reloading apps. boot_path = File.expand_path("../../" + path + "/config/boot.rb", __FILE__) File.write(boot_path, File.read(boot_path).gsub("require 'bootsnap/setup'", "")) @@ -146,11 +156,17 @@ def load! require "rails" require "flipflop/engine" - ActiveSupport::Dependencies.autoloaded_constants.clear + ActiveSupport::Dependencies.autoload_paths = [] + ActiveSupport::Dependencies.autoload_once_paths = [] load File.expand_path("../../#{path}/config/application.rb", __FILE__) + Zeitwerk::Registry.loaders.each(&:unregister) if defined?(Zeitwerk) load File.expand_path("../../#{path}/config/environments/test.rb", __FILE__) Rails.application.config.cache_classes = false - Rails.application.config.action_view.raise_on_missing_translations = true + if Gem::Version.new(Rails.version) < Gem::Version.new('7') + Rails.application.config.action_view.raise_on_missing_translations = true + else + Rails.application.config.i18n.raise_on_missing_translations = true + end Rails.application.config.i18n.enforce_available_locales = false Rails.application.config.autoloader = :classic # Disable Zeitwerk in Rails 6+ @@ -166,7 +182,9 @@ def load! Rails.application.config.action_view.finalize_compiled_template_methods = ActionView::Railtie::NULL_OPTION end + Rails.application.config.active_support.remove_deprecated_time_with_zone_name = false Rails.application.initialize! + Zeitwerk::Registry.loaders.each(&:unregister) if defined?(Zeitwerk) I18n.locale = :en @@ -202,12 +220,16 @@ def unload! Rails.instance_variable_set(:@application, nil) I18n::Railtie.instance_variable_set(:@i18n_inited, false) - ActiveSupport::Dependencies.remove_constant(name.camelize) - ActiveSupport::Dependencies.remove_constant("Flipflop::Feature") + Object.send(:remove_const, name.camelize) + Flipflop.send(:remove_const, "Feature") end private + def rails_api_only? + ENV["RAILS_API_ONLY"].to_i.nonzero? + end + def path "tmp/" + name end diff --git a/test/unit/feature_definition_test.rb b/test/unit/feature_definition_test.rb index 97d2390..c7db05e 100644 --- a/test/unit/feature_definition_test.rb +++ b/test/unit/feature_definition_test.rb @@ -32,7 +32,8 @@ it "should have location" do # Because we have no indirection via FeatureSet, the location is minitest. - assert_equal "instance_eval", subject.location.label + expected = RUBY_PLATFORM == "java" ? "block in let" : "instance_eval" + assert_equal expected, subject.location.label end end @@ -71,7 +72,8 @@ it "should have location" do # Because we have no indirection via FeatureSet, the location is minitest. - assert_equal "instance_eval", subject.location.label + expected = RUBY_PLATFORM == "java" ? "block in let" : "instance_eval" + assert_equal expected, subject.location.label end end diff --git a/test/unit/tasks/support/methods_test.rb b/test/unit/tasks/support/methods_test.rb index 01a90ff..6631bad 100644 --- a/test/unit/tasks/support/methods_test.rb +++ b/test/unit/tasks/support/methods_test.rb @@ -51,7 +51,7 @@ def with_feature_and_strategy(strategy = 'Test') describe 'when the strategy is not switchable' do it 'raises an error' do with_feature_and_strategy 'Lambda' do |strategy, feature| - -> { subject.switch_feature!('world_domination', 'lambda', true) }.must_raise + _{ subject.switch_feature!('world_domination', 'lambda', true) }.must_raise end end end