From ee1146671b2cba0a185fcbed9a88fc3c1682849a 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 e7e2b35..0a0d079 100644 --- a/test/scaffold_api_controller_generator_test.rb +++ b/test/scaffold_api_controller_generator_test.rb @@ -6,7 +6,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 @@ -57,7 +57,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 @@ -68,7 +68,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase if Rails::VERSION::MAJOR >= 6 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 f2a06f9..b46eb84 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 @@ -70,7 +70,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase if Rails::VERSION::MAJOR >= 6 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 @@ -88,7 +88,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 @@ -98,7 +98,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase if Rails::VERSION::MAJOR >= 6 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 743838a2d90b43edc89e56a1adde9a884a77c14a 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 9aa2531aebaa5945dbe85618aa284a984e39da52 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 | 7 +++++++ Appraisals | 4 ++++ gemfiles/rails_7_2.gemfile | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 gemfiles/rails_7_2.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8e4daa7..40d94e8 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,15 +23,22 @@ jobs: gemfile: - "rails_7_0" - "rails_7_1" + - "rails_7_2" - "rails_head" exclude: + - ruby: '3.0' + gemfile: rails_7_2 - ruby: '3.0' gemfile: rails_head include: + - ruby: '3.1' + gemfile: rails_7_2 - ruby: '3.1' gemfile: rails_head + - ruby: '3.2' + gemfile: rails_7_2 - ruby: '3.2' gemfile: rails_head - ruby: head diff --git a/Appraisals b/Appraisals index 9316733..8b92535 100644 --- a/Appraisals +++ b/Appraisals @@ -7,6 +7,10 @@ if RUBY_VERSION >= "2.7.0" gem "rails", "~> 7.1.0" end + appraise "rails-7-2" do + gem "rails", "~> 7.2.0" + end + appraise "rails-head" do gem "rails", github: "rails/rails", branch: "main" 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 9e0540bddf101890b6d3636e4f38db429622c297 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 edf849b8ba0ee74787e16852935b2cd1c96456d9 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 b12624b..04180b3 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -3,7 +3,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 386e6da..b489e74 100644 --- a/lib/jbuilder/errors.rb +++ b/lib/jbuilder/errors.rb @@ -1,4 +1,4 @@ -require 'jbuilder/jbuilder' +require 'jbuilder/version' class Jbuilder class NullError < ::NoMethodError diff --git a/lib/jbuilder/jbuilder.rb b/lib/jbuilder/jbuilder.rb index 22b0ac4..cb07cd1 100644 --- a/lib/jbuilder/jbuilder.rb +++ b/lib/jbuilder/jbuilder.rb @@ -1 +1 @@ -Jbuilder = Class.new(BasicObject) +require 'jbuilder/version' diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index 2a62782..1bad832 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,3 +1,3 @@ -class Jbuilder +class Jbuilder < BasicObject VERSION = "2.13.0" end