diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0d5a6e3..50eb1dd 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -1,32 +1,72 @@ -name: Ruby Gem - -on: - push: - branches: [ "master" ] - pull_request: - types: [ opened, synchronize, reopened, edited, ready_for_review ] - +name: Test +on: [push, pull_request] jobs: - build: - name: Build - runs-on: ubuntu-latest - permissions: - contents: read + test: strategy: + fail-fast: false matrix: - ruby-version: ['2.7', '3.0', '3.1'] - + gemfile: + - Gemfile + - gemfiles/Gemfile-rails-7-0 + - gemfiles/Gemfile-rails-6-1 + - gemfiles/Gemfile-rails-6-0 + - gemfiles/Gemfile-rails-5-2 + - gemfiles/Gemfile-rails-5-1 + - gemfiles/Gemfile-rails-5-0 + ruby: + - '3.2' + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' + exclude: + - gemfile: Gemfile + ruby: '2.6' + - gemfile: Gemfile + ruby: '2.5' + - gemfile: gemfiles/Gemfile-rails-7-0 + ruby: '2.6' + - gemfile: gemfiles/Gemfile-rails-7-0 + ruby: '2.5' + - gemfile: gemfiles/Gemfile-rails-6-0 + ruby: '3.2' + - gemfile: gemfiles/Gemfile-rails-6-0 + ruby: '3.1' + - gemfile: gemfiles/Gemfile-rails-5-2 + ruby: '3.2' + - gemfile: gemfiles/Gemfile-rails-5-2 + ruby: '3.1' + - gemfile: gemfiles/Gemfile-rails-5-2 + ruby: '3.0' + - gemfile: gemfiles/Gemfile-rails-5-2 + ruby: '2.7' + - gemfile: gemfiles/Gemfile-rails-5-1 + ruby: '3.2' + - gemfile: gemfiles/Gemfile-rails-5-1 + ruby: '3.1' + - gemfile: gemfiles/Gemfile-rails-5-1 + ruby: '3.0' + - gemfile: gemfiles/Gemfile-rails-5-1 + ruby: '2.7' + - gemfile: gemfiles/Gemfile-rails-5-0 + ruby: '3.2' + - gemfile: gemfiles/Gemfile-rails-5-0 + ruby: '3.1' + - gemfile: gemfiles/Gemfile-rails-5-0 + ruby: '3.0' + - gemfile: gemfiles/Gemfile-rails-5-0 + ruby: '2.7' + runs-on: ubuntu-latest + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: ${{ matrix.gemfile }} steps: - uses: actions/checkout@v3 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - - name: Install Appraisal dependencies - run: bundle exec appraisal install - - - name: Run Appraisals - run: bundle exec appraisal rake + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs bundle install and caches installed gems automatically + - name: Install + run: gem install bundler -v 2.3.26 + - name: Run tests + run: bundle exec rake diff --git a/Appraisals b/Appraisals deleted file mode 100644 index 1d59145..0000000 --- a/Appraisals +++ /dev/null @@ -1,23 +0,0 @@ -appraise "rails-5.2" do - gem "rails", "~> 5.2.0" - gem 'test-unit', '~> 3.0' - gem 'sprockets', '~> 3.7' -end - -appraise "rails-6.0" do - gem "rails", "~> 6.0.0" - gem 'test-unit', '~> 3.0' - gem 'sprockets', '~> 4.0' -end - -appraise "rails-6.1" do - gem "rails", "~> 6.1.0" - gem 'test-unit', '~> 3.0' - gem 'sprockets', '~> 4.0' -end - -appraise "rails-7.0" do - gem "rails", "~> 7.0.0" - gem 'test-unit', '~> 3.0' - gem 'sprockets', '~> 4.0' -end diff --git a/Gemfile b/Gemfile index b46fafe..c52c172 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,8 @@ -source "http://rubygems.org" +source 'https://rubygems.org' gemspec -gem 'appraisal', "2.4.1" +gem 'pry' +gem 'rails', '~> 7.1.0' +gem 'sprockets', '~> 4.0' +gem 'test-unit', '~> 3.0' diff --git a/Rakefile b/Rakefile index 33e754c..5453082 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -require "rubygems" +require 'rubygems' require 'bundler/setup' require 'rake' @@ -15,4 +15,4 @@ Rake::TestTask.new(:test) do |t| end desc 'Default: run unit tests.' -task :default => :test +task default: :test diff --git a/carmen-rails.gemspec b/carmen-rails.gemspec index f2c0240..f3ae72d 100644 --- a/carmen-rails.gemspec +++ b/carmen-rails.gemspec @@ -1,21 +1,22 @@ -$:.push File.expand_path("../lib", __FILE__) +$:.push File.expand_path('../lib', __FILE__) -require "carmen/rails/version" +require 'carmen/rails/region_select_tag' +require 'carmen/rails/version' Gem::Specification.new do |s| - s.name = "carmen-rails" + s.name = 'carmen-rails' s.version = Carmen::Rails::VERSION - s.authors = ["Jim Benton"] - s.email = ["jim@autonomousmachine.com"] - s.homepage = "http://github.com/jim/carmen-rails" - s.summary = "Rails adapter for Carmen" - s.description = "Provides country_select and subregion_select form helpers." + s.authors = ['Jim Benton'] + s.email = ['jim@autonomousmachine.com'] + s.homepage = 'http://github.com/jim/carmen-rails' + s.summary = 'Rails adapter for Carmen' + s.description = 'Provides country_select and subregion_select form helpers.' - s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] - s.test_files = Dir["spec/**/*"] + s.files = Dir['{lib}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.md'] + s.test_files = Dir['spec/**/*'] - s.add_dependency "rails" - s.add_dependency "carmen", "~> 1.0" + s.add_dependency 'rails' + s.add_dependency 'carmen', '~> 1.0' - s.add_development_dependency "minitest" + s.add_development_dependency 'minitest' end diff --git a/gemfiles/Gemfile-rails-5-0 b/gemfiles/Gemfile-rails-5-0 new file mode 100644 index 0000000..8b5803d --- /dev/null +++ b/gemfiles/Gemfile-rails-5-0 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 5.0.0' +gem 'sprockets', '~> 3.7' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/Gemfile-rails-5-1 b/gemfiles/Gemfile-rails-5-1 new file mode 100644 index 0000000..95559f4 --- /dev/null +++ b/gemfiles/Gemfile-rails-5-1 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 5.1.0' +gem 'sprockets', '~> 3.7' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/Gemfile-rails-5-2 b/gemfiles/Gemfile-rails-5-2 new file mode 100644 index 0000000..86551a1 --- /dev/null +++ b/gemfiles/Gemfile-rails-5-2 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 5.2.0' +gem 'sprockets', '~> 3.7' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 new file mode 100644 index 0000000..a85acdc --- /dev/null +++ b/gemfiles/Gemfile-rails-6-0 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 6.0.0' +gem 'sprockets', '~> 4.0' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 new file mode 100644 index 0000000..c445d70 --- /dev/null +++ b/gemfiles/Gemfile-rails-6-1 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 6.1.0' +gem 'sprockets', '~> 4.0' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/Gemfile-rails-7-0 b/gemfiles/Gemfile-rails-7-0 new file mode 100644 index 0000000..6f230ee --- /dev/null +++ b/gemfiles/Gemfile-rails-7-0 @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec path: '..' + +gem 'rails', '~> 7.0.0' +gem 'sprockets', '~> 4.0' +gem 'test-unit', '~> 3.0' diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile deleted file mode 100644 index 7a73c8a..0000000 --- a/gemfiles/rails_5.2.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "2.2.0" -gem "rails", "~> 5.2.0" -gem "test-unit", "~> 3.0" -gem "sprockets", "~> 3.7" - -gemspec path: "../" diff --git a/gemfiles/rails_5.2.gemfile.lock b/gemfiles/rails_5.2.gemfile.lock deleted file mode 100644 index 99cb422..0000000 --- a/gemfiles/rails_5.2.gemfile.lock +++ /dev/null @@ -1,154 +0,0 @@ -PATH - remote: .. - specs: - carmen-rails (1.0.1) - carmen (~> 1.0) - rails - -GEM - remote: http://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) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - arel (9.0.0) - builder (3.2.4) - carmen (1.1.3) - activesupport (>= 3.0.0) - concurrent-ruby (1.2.2) - crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - loofah (2.20.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.8.1) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.1) - minitest (5.18.0) - net-imap (0.3.4) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.1) - timeout - net-smtp (0.3.3) - net-protocol - nio4r (2.5.9) - nokogiri (1.14.2) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - power_assert (2.0.3) - racc (1.6.2) - rack (2.2.6.4) - rack-test (2.1.0) - 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.5.0) - loofah (~> 2.19, >= 2.19.1) - 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) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test-unit (3.5.7) - power_assert - thor (1.2.1) - thread_safe (0.3.6) - timeout (0.3.2) - tzinfo (1.2.11) - thread_safe (~> 0.1) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (= 2.2.0) - carmen-rails! - minitest - rails (~> 5.2.0) - sprockets (~> 3.7) - test-unit (~> 3.0) - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile deleted file mode 100644 index 4fbbcd9..0000000 --- a/gemfiles/rails_6.0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "2.2.0" -gem "rails", "~> 6.0.0" -gem "test-unit", "~> 3.0" -gem "sprockets", "~> 4.0" - -gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile.lock b/gemfiles/rails_6.0.gemfile.lock deleted file mode 100644 index de535d0..0000000 --- a/gemfiles/rails_6.0.gemfile.lock +++ /dev/null @@ -1,160 +0,0 @@ -PATH - remote: .. - specs: - carmen-rails (1.0.1) - carmen (~> 1.0) - rails - -GEM - remote: http://rubygems.org/ - specs: - actioncable (6.0.0) - actionpack (= 6.0.0) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.0) - actionpack (= 6.0.0) - activejob (= 6.0.0) - activerecord (= 6.0.0) - activestorage (= 6.0.0) - activesupport (= 6.0.0) - mail (>= 2.7.1) - actionmailer (6.0.0) - actionpack (= 6.0.0) - actionview (= 6.0.0) - activejob (= 6.0.0) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.0.0) - actionview (= 6.0.0) - activesupport (= 6.0.0) - rack (~> 2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.0) - actionpack (= 6.0.0) - activerecord (= 6.0.0) - activestorage (= 6.0.0) - activesupport (= 6.0.0) - nokogiri (>= 1.8.5) - actionview (6.0.0) - activesupport (= 6.0.0) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.0) - activesupport (= 6.0.0) - globalid (>= 0.3.6) - activemodel (6.0.0) - activesupport (= 6.0.0) - activerecord (6.0.0) - activemodel (= 6.0.0) - activesupport (= 6.0.0) - activestorage (6.0.0) - actionpack (= 6.0.0) - activejob (= 6.0.0) - activerecord (= 6.0.0) - marcel (~> 0.3.1) - activesupport (6.0.0) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.1, >= 2.1.8) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - builder (3.2.3) - carmen (1.1.3) - activesupport (>= 3.0.0) - concurrent-ruby (1.1.5) - crass (1.0.5) - erubi (1.9.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.7.0) - concurrent-ruby (~> 1.0) - loofah (2.3.1) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.10) - nokogiri (~> 1) - rake - mini_mime (1.0.2) - mini_portile2 (2.8.1) - minitest (5.18.0) - nio4r (2.5.2) - nokogiri (1.14.2) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - power_assert (1.1.5) - racc (1.6.2) - rack (2.0.7) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.0.0) - actioncable (= 6.0.0) - actionmailbox (= 6.0.0) - actionmailer (= 6.0.0) - actionpack (= 6.0.0) - actiontext (= 6.0.0) - actionview (= 6.0.0) - activejob (= 6.0.0) - activemodel (= 6.0.0) - activerecord (= 6.0.0) - activestorage (= 6.0.0) - activesupport (= 6.0.0) - bundler (>= 1.3.0) - railties (= 6.0.0) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (6.0.0) - actionpack (= 6.0.0) - activesupport (= 6.0.0) - method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) - rake (13.0.0) - sprockets (4.0.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - test-unit (3.3.4) - power_assert - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - websocket-driver (0.7.1) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - zeitwerk (2.2.0) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (= 2.2.0) - carmen-rails! - minitest - rails (~> 6.0.0) - sprockets (~> 4.0) - test-unit (~> 3.0) - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile deleted file mode 100644 index 69d81d0..0000000 --- a/gemfiles/rails_6.1.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "2.2.0" -gem "rails", "~> 6.1.0" -gem "test-unit", "~> 3.0" -gem "sprockets", "~> 4.0" - -gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_6.1.gemfile.lock deleted file mode 100644 index 4557c73..0000000 --- a/gemfiles/rails_6.1.gemfile.lock +++ /dev/null @@ -1,173 +0,0 @@ -PATH - remote: .. - specs: - carmen-rails (1.0.1) - carmen (~> 1.0) - rails - -GEM - remote: http://rubygems.org/ - specs: - actioncable (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) - mail (>= 2.7.1) - actionmailer (6.1.7.3) - actionpack (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activesupport (= 6.1.7.3) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.7.3) - actionview (= 6.1.7.3) - activesupport (= 6.1.7.3) - 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.3) - actionpack (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) - nokogiri (>= 1.8.5) - actionview (6.1.7.3) - activesupport (= 6.1.7.3) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7.3) - activesupport (= 6.1.7.3) - globalid (>= 0.3.6) - activemodel (6.1.7.3) - activesupport (= 6.1.7.3) - activerecord (6.1.7.3) - activemodel (= 6.1.7.3) - activesupport (= 6.1.7.3) - activestorage (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activesupport (= 6.1.7.3) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.7.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - builder (3.2.4) - carmen (1.1.3) - activesupport (>= 3.0.0) - concurrent-ruby (1.2.2) - crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - loofah (2.20.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.8.1) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.1) - minitest (5.18.0) - net-imap (0.3.4) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.1) - timeout - net-smtp (0.3.3) - net-protocol - nio4r (2.5.9) - nokogiri (1.14.2) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - power_assert (2.0.3) - racc (1.6.2) - rack (2.2.6.4) - rack-test (2.1.0) - rack (>= 1.3) - rails (6.1.7.3) - actioncable (= 6.1.7.3) - actionmailbox (= 6.1.7.3) - actionmailer (= 6.1.7.3) - actionpack (= 6.1.7.3) - actiontext (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activemodel (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) - bundler (>= 1.15.0) - railties (= 6.1.7.3) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) - method_source - rake (>= 12.2) - thor (~> 1.0) - rake (13.0.6) - sprockets (4.2.0) - concurrent-ruby (~> 1.0) - rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test-unit (3.5.7) - power_assert - thor (1.2.1) - timeout (0.3.2) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - zeitwerk (2.6.7) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (= 2.2.0) - carmen-rails! - minitest - rails (~> 6.1.0) - sprockets (~> 4.0) - test-unit (~> 3.0) - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile deleted file mode 100644 index f21d8f5..0000000 --- a/gemfiles/rails_7.0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "appraisal", "2.2.0" -gem "rails", "~> 7.0.0" -gem "test-unit", "~> 3.0" -gem "sprockets", "~> 4.0" - -gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock deleted file mode 100644 index 4f95db1..0000000 --- a/gemfiles/rails_7.0.gemfile.lock +++ /dev/null @@ -1,175 +0,0 @@ -PATH - remote: .. - specs: - carmen-rails (1.0.1) - carmen (~> 1.0) - rails - -GEM - remote: http://rubygems.org/ - specs: - actioncable (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.0.4.3) - actionpack (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activesupport (= 7.0.4.3) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.4.3) - actionview (= 7.0.4.3) - activesupport (= 7.0.4.3) - rack (~> 2.0, >= 2.2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4.3) - actionpack (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) - globalid (>= 0.6.0) - nokogiri (>= 1.8.5) - actionview (7.0.4.3) - activesupport (= 7.0.4.3) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4.3) - activesupport (= 7.0.4.3) - globalid (>= 0.3.6) - activemodel (7.0.4.3) - activesupport (= 7.0.4.3) - activerecord (7.0.4.3) - activemodel (= 7.0.4.3) - activesupport (= 7.0.4.3) - activestorage (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activesupport (= 7.0.4.3) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.4.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - builder (3.2.4) - carmen (1.1.3) - activesupport (>= 3.0.0) - concurrent-ruby (1.2.2) - crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - loofah (2.20.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.8.1) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.1) - minitest (5.18.0) - net-imap (0.3.4) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.1) - timeout - net-smtp (0.3.3) - net-protocol - nio4r (2.5.9) - nokogiri (1.14.2) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - power_assert (2.0.3) - racc (1.6.2) - rack (2.2.6.4) - rack-test (2.1.0) - rack (>= 1.3) - rails (7.0.4.3) - actioncable (= 7.0.4.3) - actionmailbox (= 7.0.4.3) - actionmailer (= 7.0.4.3) - actionpack (= 7.0.4.3) - actiontext (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activemodel (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) - bundler (>= 1.15.0) - railties (= 7.0.4.3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) - method_source - rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) - sprockets (4.2.0) - concurrent-ruby (~> 1.0) - rack (>= 2.2.4, < 4) - test-unit (3.5.7) - power_assert - thor (1.2.1) - timeout (0.3.2) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - zeitwerk (2.6.7) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (= 2.2.0) - carmen-rails! - minitest - rails (~> 7.0.0) - sprockets (~> 4.0) - test-unit (~> 3.0) - -BUNDLED WITH - 2.1.4 diff --git a/lib/carmen-rails.rb b/lib/carmen-rails.rb index 5ed3398..f598ba7 100644 --- a/lib/carmen-rails.rb +++ b/lib/carmen-rails.rb @@ -1,4 +1,5 @@ require 'carmen' +require 'carmen/rails/region_select_tag' require 'carmen/rails/action_view/form_helper' require 'carmen/rails/version' diff --git a/lib/carmen/rails/action_view/form_helper.rb b/lib/carmen/rails/action_view/form_helper.rb index 3aacb72..e33e9b1 100644 --- a/lib/carmen/rails/action_view/form_helper.rb +++ b/lib/carmen/rails/action_view/form_helper.rb @@ -1,7 +1,6 @@ module ActionView module Helpers module FormOptionsHelper - # Generate select and subregion option tags for the given object and method. A # common use of this would be to allow users to select a state subregion within # a given country. @@ -22,7 +21,7 @@ module FormOptionsHelper # subregion_select(@object, :region, {priority: ['US', 'CA']}, class: 'region') # # Returns an `html_safe` string containing the HTML for a select element. - def subregion_select(object, method, parent_region_or_code, options={}, html_options={}) + def subregion_select(object, method, parent_region_or_code, options = {}, html_options = {}) parent_region = determine_parent(parent_region_or_code) tag = instance_tag(object, method, self, options) tag.to_region_select_tag(parent_region, options, html_options) @@ -77,10 +76,10 @@ def country_select(object, method, priorities_or_options = {}, options_or_html_o # region_options_for_select(@region.subregions, 'US', priority: ['US', 'CA']) # # Returns an `html_safe` string containing option tags. - def region_options_for_select(regions, selected=nil, options={}) + def region_options_for_select(regions, selected = nil, options = {}) options.stringify_keys! priority_region_codes = options['priority'] || [] - region_options = "" + region_options = '' unless priority_region_codes.empty? unless regions.respond_to?(:coded) @@ -93,7 +92,7 @@ def region_options_for_select(regions, selected=nil, options={}) end.compact unless priority_regions.empty? region_options += options_for_select(priority_regions, selected) - region_options += "" + region_options += '' # If a priority region is selected, don't select it again in the main list. # This prevents some browsers from selecting the second occurance of this region, @@ -103,7 +102,7 @@ def region_options_for_select(regions, selected=nil, options={}) end main_options = regions.map { |r| [r.name, r.code] } - main_options.sort!{|a, b| a.first.to_s <=> b.first.to_s} + main_options.sort! { |a, b| a.first.to_s <=> b.first.to_s } main_options.unshift [options['prompt'], ''] if options['prompt'] region_options += options_for_select(main_options, selected) @@ -127,7 +126,7 @@ def region_options_for_select(regions, selected=nil, options={}) # country_select_tag('country_code', {priority: ['US', 'CA']}, class: 'region') # # Returns an `html_safe` string containing the HTML for a select element. - def country_select_tag(name, value, options={}) + def country_select_tag(name, value, options = {}) subregion_select_tag(name, value, Carmen::World.instance, options) end @@ -154,22 +153,24 @@ def subregion_select_tag(name, value, parent_region_or_code, options = {}, html_ options.stringify_keys! parent_region = determine_parent(parent_region_or_code) opts = region_options_for_select(parent_region.subregions, value, options) - html_options = {"name" => name, - "id" => sanitize_to_id(name)}.update(html_options.stringify_keys) + html_options = { 'name' => name, 'id' => sanitize_to_id(name) }.update(html_options.stringify_keys) content_tag(:select, opts, html_options) end private def instance_tag(object_name, method_name, template_object, options = {}) - if Rails::VERSION::MAJOR == 3 + if ::Rails::VERSION::MAJOR == 3 InstanceTag.new(object_name, method_name, template_object, options.delete(:object)) else - ActionView::Helpers::Tags::Base.new(object_name, method_name, template_object, options || {}) + if [4, 5].include? ::Rails::VERSION::MAJOR + ActionView::Helpers::Tags::Base.new(object_name, method_name, template_object, options || {}) + else + ActionView::Helpers::Tags::Select.new(object_name, method_name, template_object, nil, options || {}, nil) + end end end - def determine_parent(parent_region_or_code) case parent_region_or_code when String @@ -184,45 +185,30 @@ def determine_parent(parent_region_or_code) end end - if Rails::VERSION::MAJOR == 3 + if ::Rails::VERSION::MAJOR == 3 class InstanceTag def to_region_select_tag(parent_region, options = {}, html_options = {}) html_options = html_options.stringify_keys add_default_name_and_id(html_options) priority_regions = options[:priority] || [] value = options[:selected] ? options[:selected] : value(object) - opts = add_options(region_options_for_select(parent_region.subregions, value, :priority => priority_regions), options, value) - content_tag("select", opts, html_options) + opts = add_options( + region_options_for_select(parent_region.subregions, value, priority: priority_regions), options, value) + content_tag('select', opts, html_options) end end end - if [4, 5, 6, 7].include? Rails::VERSION::MAJOR + if [4, 5].include? ::Rails::VERSION::MAJOR module Tags class Base - def to_region_select_tag(parent_region, options = {}, html_options = {}) - html_options = html_options.stringify_keys - add_default_name_and_id(html_options) - - if (Rails::VERSION::MAJOR == 4 && !select_not_required?(html_options)) || - ([5, 6, 7].include?(Rails::VERSION::MAJOR) && placeholder_required?(html_options)) - raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false - options[:include_blank] ||= true unless options[:prompt] - end - - value = options[:selected] ? options[:selected] : (method(:value).arity.zero? ? value() : value(object)) - priority_regions = options[:priority] || [] - opts = add_options(region_options_for_select(parent_region.subregions, value, - :priority => priority_regions), - options, value) - select = content_tag("select", opts, html_options) - if html_options["multiple"] && options.fetch(:include_hidden, true) - tag("input", :disabled => html_options["disabled"], :name => html_options["name"], - :type => "hidden", :value => "") + select - else - select - end - end + include Carmen::Rails::RegionSelectTag + end + end + else + module Tags + class Select + include Carmen::Rails::RegionSelectTag end end end @@ -251,9 +237,9 @@ def country_select(method, priorities_or_options = {}, options_or_html_options = # # See `FormOptionsHelper::subregion_select` for more information. def subregion_select(method, parent_region_or_code, options = {}, html_options = {}) - @template.subregion_select(@object_name, method, parent_region_or_code, objectify_options(options), @default_options.merge(html_options)) + @template.subregion_select(@object_name, method, parent_region_or_code, objectify_options(options), + @default_options.merge(html_options)) end end - end end diff --git a/lib/carmen/rails/region_select_tag.rb b/lib/carmen/rails/region_select_tag.rb new file mode 100644 index 0000000..9cfebcb --- /dev/null +++ b/lib/carmen/rails/region_select_tag.rb @@ -0,0 +1,29 @@ +module Carmen + module Rails + module RegionSelectTag + def to_region_select_tag(parent_region, options = {}, html_options = {}) + html_options = html_options.stringify_keys + add_default_name_and_id(html_options) + if (::Rails::VERSION::MAJOR == 4 && !select_not_required?(html_options)) || + ([5, 6, 7].include?(::Rails::VERSION::MAJOR) && placeholder_required?(html_options)) + raise ArgumentError, 'include_blank cannot be false for a required field.' if options[:include_blank] == false + + options[:include_blank] ||= true unless options[:prompt] + end + + value = options[:selected] ? options[:selected] : (method(:value).arity.zero? ? value() : value(object)) + priority_regions = options[:priority] || [] + opts = add_options(region_options_for_select(parent_region.subregions, value, + priority: priority_regions), + options, value) + select = content_tag('select', opts, html_options) + if html_options['multiple'] && options.fetch(:include_hidden, true) + tag('input', disabled: html_options['disabled'], name: html_options['name'], + type: 'hidden', value: '') + select + else + select + end + end + end + end +end diff --git a/lib/carmen/rails/version.rb b/lib/carmen/rails/version.rb index 3efeb4c..860771e 100644 --- a/lib/carmen/rails/version.rb +++ b/lib/carmen/rails/version.rb @@ -1,5 +1,5 @@ module Carmen module Rails - VERSION = "1.0.1" + VERSION = '1.0.1' end end diff --git a/test/carmen/action_view/helpers/carmen_view_helper_test.rb b/test/carmen/action_view/helpers/carmen_view_helper_test.rb index 5a5d017..755d9f9 100644 --- a/test/carmen/action_view/helpers/carmen_view_helper_test.rb +++ b/test/carmen/action_view/helpers/carmen_view_helper_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class CarmenViewHelperTest < MiniTest::Test +class CarmenViewHelperTest < Minitest::Test include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::FormTagHelper @@ -38,14 +38,14 @@ def document_root_element end def test_country_selected_value - @html = country_select(:object, :country_code, :selected => 'OC') + @html = country_select(:object, :country_code, selected: 'OC') assert_select('option[selected="selected"][value="OC"]') end def test_country_selected_object_option @object.country_code = 'OC' - override_object = OpenStruct.new(:country_code => 'ES') - @html = country_select(@object, :country_code, {:object => override_object}) + override_object = OpenStruct.new(country_code: 'ES') + @html = country_select(@object, :country_code, { object: override_object }) assert_select('option[selected="selected"][value="ES"]') end @@ -64,7 +64,7 @@ def test_basic_country_select_tag end def test_country_select_tag_with_prompt - html = country_select_tag('attribute_name', nil, :prompt => 'Please Select') + html = country_select_tag('attribute_name', nil, prompt: 'Please Select') expected = <<-HTML @@ -114,7 +115,7 @@ def test_priority_country_select_deprecated_api def test_country_select_selected_priority_region_not_selected_twice @object.country_code = 'ES' - html = country_select(@object, :country_code, :priority => ['ES']) + html = country_select(@object, :country_code, priority: ['ES']) expected = <<-HTML HTML - html = subregion_select_tag(:subregion_code, nil, oceania, :priority => ['AO']) + html = subregion_select_tag(:subregion_code, nil, oceania, priority: ['AO']) assert_equal_markup(expected, html) end @@ -228,7 +230,7 @@ def test_subregion_select_tag_with_prompt HTML - html = subregion_select_tag(:subregion_code, nil, oceania, :prompt => 'Please select') + html = subregion_select_tag(:subregion_code, nil, oceania, prompt: 'Please select') assert_equal_markup(expected, html) end @@ -261,7 +263,7 @@ def test_region_options_for_select_with_array_of_regions_and_priority HTML - html = region_options_for_select(regions, nil, :priority => ['ES']) + html = region_options_for_select(regions, nil, priority: ['ES']) assert_equal_markup(expected, html) end diff --git a/test/test_helper.rb b/test/test_helper.rb index ffdcca6..1a6835d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,7 +10,7 @@ require 'carmen-rails' require 'ostruct' -MiniTest::Spec.register_spec_type(/.*/, ActionView::TestCase) +Minitest::Spec.register_spec_type(/.*/, ActionView::TestCase) Carmen.clear_data_paths @@ -21,8 +21,8 @@ locale_path = carmen_path + '/spec_data/locale' Carmen.i18n_backend = Carmen::I18n::Simple.new(locale_path) -class MiniTest::Test - def assert_equal_markup(expected, actual, message=nil) +class Minitest::Test + def assert_equal_markup(expected, actual, message = nil) assert_equal(clean_markup(expected), clean_markup(actual), message) end