From 7ea07fd12c324e41fec19709514e8b3112191506 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:10:39 +0100 Subject: [PATCH 1/5] Fix warning about routes.rb not existing The controller scaffold generator tries to insert routes but there isn't a routes file the tmp folder so it prints a warning instead. Prevent the warning from being printed by using the option to skip routes. --- test/scaffold_api_controller_generator_test.rb | 6 +++--- test/scaffold_controller_generator_test.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/scaffold_api_controller_generator_test.rb b/test/scaffold_api_controller_generator_test.rb index 8ab4708..546749b 100644 --- a/test/scaffold_api_controller_generator_test.rb +++ b/test/scaffold_api_controller_generator_test.rb @@ -4,7 +4,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text images:attachments --api) + arguments %w(Post title body:text images:attachments --api --skip-routes) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -53,7 +53,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase end test "don't use require and permit if there are no attributes" do - run_generator %w(Post --api) + run_generator %w(Post --api --skip-routes) assert_file 'app/controllers/posts_controller.rb' do |content| assert_match %r{def post_params}, content @@ -62,7 +62,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase end test 'handles virtual attributes' do - run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"] + run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes) assert_file 'app/controllers/messages_controller.rb' do |content| if Rails::VERSION::MAJOR >= 8 diff --git a/test/scaffold_controller_generator_test.rb b/test/scaffold_controller_generator_test.rb index 795dec8..048df2a 100644 --- a/test/scaffold_controller_generator_test.rb +++ b/test/scaffold_controller_generator_test.rb @@ -4,7 +4,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text images:attachments) + arguments %w(Post title body:text images:attachments --skip-routes) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -67,7 +67,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test 'controller with namespace' do - run_generator %w(Admin::Post --model-name=Post) + run_generator %w(Admin::Post --model-name=Post --skip-routes) assert_file 'app/controllers/admin/posts_controller.rb' do |content| assert_instance_method :create, content do |m| assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m @@ -84,7 +84,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test "don't use require and permit if there are no attributes" do - run_generator %w(Post) + run_generator %w(Post --skip-routes) assert_file 'app/controllers/posts_controller.rb' do |content| assert_match %r{def post_params}, content @@ -93,7 +93,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test 'handles virtual attributes' do - run_generator %w(Message content:rich_text video:attachment photos:attachments) + run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes) assert_file 'app/controllers/messages_controller.rb' do |content| if Rails::VERSION::MAJOR >= 8 From b58d524c59cb6d9aa81efb11d8e4c2c41ba40f9e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:13:43 +0100 Subject: [PATCH 2/5] Use the correct path for the env command --- bin/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test b/bin/test index 45d4fe9..1bc5120 100755 --- a/bin/test +++ b/bin/test @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash set -e bundle install From 1a86eb8d94967fcc04cf90282f7e071b87028ef2 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:28:07 +0100 Subject: [PATCH 3/5] Add Rails 7.2 to the Appraisals file --- .github/workflows/ruby.yml | 5 +++++ Appraisals | 4 ++++ gemfiles/rails_7_2.gemfile | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 gemfiles/rails_7_2.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0d5374d..3bc499a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -24,14 +24,19 @@ jobs: gemfile: - "rails_7_0" - "rails_7_1" + - "rails_7_2" - "rails_8_0" - "rails_head" exclude: + - ruby: '3.0' + gemfile: rails_7_2 - ruby: '3.0' gemfile: rails_8_0 - ruby: '3.0' gemfile: rails_head + - ruby: '3.1' + gemfile: rails_7_2 - ruby: '3.1' gemfile: rails_8_0 - ruby: '3.1' diff --git a/Appraisals b/Appraisals index 3d1832d..3caeb7e 100644 --- a/Appraisals +++ b/Appraisals @@ -9,6 +9,10 @@ appraise "rails-7-1" do gem "rails", "~> 7.1.0" end +appraise "rails-7-2" do + gem "rails", "~> 7.2.0" +end + appraise "rails-8-0" do gem "rails", "~> 8.0.0" end diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile new file mode 100644 index 0000000..8f5a412 --- /dev/null +++ b/gemfiles/rails_7_2.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 7.2.0" + +gemspec path: "../" From 13e033b7de6cfaeb643995436c9dc39ea63b715a Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:32:36 +0100 Subject: [PATCH 4/5] Fix method redefinition warning --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index d985da9..0b4dfa6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,7 +19,7 @@ ENV["RAILS_ENV"] ||= "test" class << Rails - def cache + redefine_method :cache do @cache ||= ActiveSupport::Cache::MemoryStore.new end end From f447b6035abf83decc3afd98ae123b704af6951e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:33:38 +0100 Subject: [PATCH 5/5] Fix constant redefinition warning In e18fe2a the Jbuilder::VERSION constant was introduced but in 9aa3dd9 it was used in the gemspec which changed the loading order so that the version constant was loaded first. This defined Jbuilder as an Object subclass rather than the intended BasicObject and when jbuilder/jbuilder was required it redefined the Jbuilder constant and obliterates the VERSION constant. This commit ensures that the version constant exists and the Jbuilder parent class is BasicObject. --- lib/jbuilder.rb | 1 - lib/jbuilder/errors.rb | 2 +- lib/jbuilder/jbuilder.rb | 2 +- lib/jbuilder/version.rb | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 024e418..edf048c 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -5,7 +5,6 @@ require 'jbuilder/blank' require 'jbuilder/key_formatter' require 'jbuilder/errors' -require 'jbuilder/version' require 'json' require 'active_support/core_ext/hash/deep_merge' diff --git a/lib/jbuilder/errors.rb b/lib/jbuilder/errors.rb index e2de671..aba1f89 100644 --- a/lib/jbuilder/errors.rb +++ b/lib/jbuilder/errors.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'jbuilder/jbuilder' +require 'jbuilder/version' class Jbuilder class NullError < ::NoMethodError diff --git a/lib/jbuilder/jbuilder.rb b/lib/jbuilder/jbuilder.rb index 1fc3025..ddb5273 100644 --- a/lib/jbuilder/jbuilder.rb +++ b/lib/jbuilder/jbuilder.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -Jbuilder = Class.new(BasicObject) +require 'jbuilder/version' diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index 3fe2e27..8d4d5e2 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class Jbuilder +class Jbuilder < BasicObject VERSION = "2.13.0" end