Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.0] Allow Rails 7.1 #2603

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
rails:
- "6.1"
- "7.0"
- "7.1"
ruby:
- "3.0"
- "3.1"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions alchemy_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/alchemy/admin/ingredients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion app/models/alchemy/picture/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions spec/controllers/alchemy/admin/ingredients_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 9 additions & 9 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions spec/models/alchemy/picture/url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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