diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e716fefab..22c5dc7df2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,7 @@ jobs: rails: - "6.1" - "7.0" + - "7.1" ruby: - "3.0" - "3.1" diff --git a/Gemfile b/Gemfile index 4fef90d27a..e4eedafb0a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gemspec -rails_version = ENV.fetch("RAILS_VERSION", 7.0).to_f +rails_version = ENV.fetch("RAILS_VERSION", "7.1") gem "rails", "~> #{rails_version}.0" if ENV["DB"].nil? || ENV["DB"] == "sqlite" diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index d476c318d3..53cdb2f458 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -29,10 +29,10 @@ Gem::Specification.new do |gem| activesupport railties ].each do |rails_gem| - gem.add_runtime_dependency rails_gem, [">= 6.1", "< 7.1"] + gem.add_runtime_dependency rails_gem, [">= 6.1", "< 7.2"] end - gem.add_runtime_dependency "active_model_serializers", ["~> 0.10.0"] + gem.add_runtime_dependency "active_model_serializers", ["~> 0.10.14"] gem.add_runtime_dependency "acts_as_list", [">= 0.3", "< 2"] gem.add_runtime_dependency "awesome_nested_set", ["~> 3.1"] gem.add_runtime_dependency "cancancan", [">= 2.1", "< 4.0"] diff --git a/app/controllers/alchemy/admin/ingredients_controller.rb b/app/controllers/alchemy/admin/ingredients_controller.rb index ec55f1dae3..936e9ec7ae 100644 --- a/app/controllers/alchemy/admin/ingredients_controller.rb +++ b/app/controllers/alchemy/admin/ingredients_controller.rb @@ -19,7 +19,8 @@ def update private def ingredient_params - params[:ingredient]&.permit(@ingredient.class.stored_attributes[:data]) || {} + params[:ingredient]&.permit(@ingredient.class.stored_attributes[:data]) || + ActionController::Parameters.new end def load_croppable_resource diff --git a/app/models/alchemy/picture/url.rb b/app/models/alchemy/picture/url.rb index 4915a90927..3b0c031881 100644 --- a/app/models/alchemy/picture/url.rb +++ b/app/models/alchemy/picture/url.rb @@ -35,7 +35,7 @@ def uid thumb.uid else uid = PictureThumb::Uid.call(signature, variant) - ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role) do + ActiveRecord::Base.connected_to(role: db_writing_role) do PictureThumb::Create.call(variant, signature, uid) end uid @@ -49,6 +49,14 @@ def find_thumb_by(signature) variant.picture.thumbs.find_by(signature: signature) end end + + def db_writing_role + if ActiveRecord::Base.respond_to?(:writing_role) + ActiveRecord::Base.writing_role + else + ActiveRecord.writing_role + end + end end end end diff --git a/spec/controllers/alchemy/admin/ingredients_controller_spec.rb b/spec/controllers/alchemy/admin/ingredients_controller_spec.rb index 6b57dec210..e8b2c2395a 100644 --- a/spec/controllers/alchemy/admin/ingredients_controller_spec.rb +++ b/spec/controllers/alchemy/admin/ingredients_controller_spec.rb @@ -97,7 +97,7 @@ end it "does not update the attributes of ingredient" do - expect(ingredient).to receive(:update).with({}) + expect(ingredient).to receive(:update).with(ActionController::Parameters.new.permit) patch :update, params: params, xhr: true end end @@ -110,7 +110,7 @@ end it "does not update the attributes of ingredient" do - expect(ingredient).to receive(:update).with({}) + expect(ingredient).to receive(:update).with(ActionController::Parameters.new) patch :update, params: params, xhr: true end end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index e2d4aebe81..0c591f5a06 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_05_05_132743) do +ActiveRecord::Schema[7.1].define(version: 2023_05_05_132743) do create_table "alchemy_attachments", force: :cascade do |t| t.string "name" t.string "file_name" diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 25c6f04954..7d10605f9c 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -1594,36 +1594,36 @@ def copy_children_to(new_parent) end describe "#set_language" do - let(:default_language) { mock_model("Language", code: "es") } - let(:page) { Page.new } - - before { allow(page).to receive(:parent).and_return(parent) } + let(:default_language) { build(:alchemy_language, code: "es") } + let(:page) { build(:alchemy_page, parent: parent) } subject { page } context "parent has a language" do - let(:parent) { mock_model("Page", language: default_language, language_id: default_language.id, language_code: default_language.code) } + let(:parent) { create(:alchemy_page, language: default_language, language_id: default_language.id, language_code: default_language.code) } before do page.send(:set_language) end describe "#language_id" do - subject { super().language_id } + subject { page.language_id } + it { is_expected.to eq(parent.language_id) } end end context "parent has no language" do - let(:parent) { mock_model("Page", language: nil, language_id: nil, language_code: nil) } + let(:parent) { build(:alchemy_page, language: nil, language_id: nil, language_code: nil) } before do - allow(Language).to receive(:default).and_return(default_language) + expect(Language).to receive(:current).twice { default_language } page.send(:set_language) end describe "#language_id" do - subject { super().language_id } + subject { page.language_id } + it { is_expected.to eq(default_language.id) } end end diff --git a/spec/models/alchemy/picture/url_spec.rb b/spec/models/alchemy/picture/url_spec.rb index c78853a5bf..38e6fb951a 100644 --- a/spec/models/alchemy/picture/url_spec.rb +++ b/spec/models/alchemy/picture/url_spec.rb @@ -35,10 +35,22 @@ is_expected.to match(/\/pictures\/\d+\/.+\/image\.png/) end - it "connects to writing database" do - writing_role = ActiveRecord::Base.writing_role - expect(ActiveRecord::Base).to receive(:connected_to).with(role: writing_role) - subject + if Rails.version.to_f >= 7.1 + context "in Rails >= 7.1" do + it "connects to writing database" do + writing_role = ActiveRecord.writing_role + expect(ActiveRecord::Base).to receive(:connected_to).with(role: writing_role) + subject + end + end + else + context "in Rails < 7.1" do + it "connects to writing database" do + writing_role = ActiveRecord::Base.writing_role + expect(ActiveRecord::Base).to receive(:connected_to).with(role: writing_role) + subject + end + end end end end