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

Test on Ruby 3 #612

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
with:
command: bundle exec rubocop --parallel --format github

test:
name: Ruby
needs: rubocop
Expand Down
1 change: 1 addition & 0 deletions lib/foreman_discovery.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace :test do
t.pattern = ENV['FILE'] || ENV['TEST']
else
t.pattern = "#{test_dir}/**/*_test.rb"
t.test_files = [Rails.root.join('test/unit/foreman/access_permissions_test.rb')]
end
t.verbose = true
t.warning = false
Expand Down
4 changes: 2 additions & 2 deletions lib/foreman_discovery/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Engine < ::Rails::Engine
full_name: N_("Hostname facts"),
description: N_("List of facts to use for the hostname (first wins)")

validates "discovery_hostname", presence: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It surprises me this is needed. Can't we look at the validates method to see if presence: true can be made valid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if we change its signature: https://github.com/theforeman/foreman/blob/develop/app/registries/foreman/setting_manager.rb#L58

I mean, currently validates expects 2 arguments. Due to new Ruby kwargs, they are not considered as an implicit Hash argument.

As a solution I'd suggest to finally use kwargs as Ruby wants or we could make second (validations) parameter to be optional (validations = {}).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to map to ActiveModel::Validations::ClassMethods.validates and that uses def validates(*attributes). I'm not sure that is a great API.

So I think adjusting the signature is the right thing. Just not 100% sure what it should be. Perhaps:

def validates(name, **validations)

And then special case if :proc is in validations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be, but since the old signature accepts proc as an argument (not nested under :proc key), we would still need to update places which use that. I think we would need to adjust plugins anyway if we change the signature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps def validates(name, proc = nil, **validations) would work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if #622 works.

validates "discovery_hostname", { presence: true }

setting "discovery_auto",
type: :boolean,
Expand All @@ -98,7 +98,7 @@ class Engine < ::Rails::Engine
full_name: N_("Hostname prefix"),
description: N_("The default prefix to use for the host name, must start with a letter")

validates "discovery_prefix", presence: true
validates "discovery_prefix", { presence: true }

setting "discovery_fact_column",
type: :array,
Expand Down
Loading