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
[wip] use built in default values via rails attribute #20596
[wip] use built in default values via rails attribute #20596
Conversation
@d-m-u if this gets approved, let's create an epic to replace |
…ality miq_policy defaults are well tested already so this is the first of many if it gets approval Keenan caught it a couple days ago
11a630b
to
f64226b
Compare
Checked commit d-m-u@f64226b with ruby 2.6.3, rubocop 0.69.0, haml-lint 0.28.0, and yamllint |
cc @jrafanie, keep me honest/complete here... So, the use cases for default_value_for are (see also their README): class MyModel < ActiveRecord::Base
default_value_for :foo, "bar"
end
If all of the above still hold, then I'm 100% on board with dropping default_value_for |
Here are the first three cases: 2.5.5 :001 > MiqPolicy.new.mode
=> "control"
2.5.5 :002 > MiqPolicy.new(:mode => 'something_else').mode
=> "something_else"
2.5.5 :003 > MiqPolicy.create!(:mode => 'compliance', :description => 'foo')
=> #<MiqPolicy id: 11, name: "a1eafa54-9501-4d1c-8120-5f4befb42e7a", description: "foo", created_on: "2020-09-24 16:29:36", updated_on: "2020-09-24 16:29:36", expression: nil, towhat: "Vm", guid: "a1eafa54-9501-4d1c-8120-5f4befb42e7a", created_by: nil, updated_by: nil, notes: nil, active: true, mode: "compliance", read_only: nil>
2.5.5 :004 > MiqPolicy.last.mode
=> "compliance" with #default_value_for(:settings) { Hash.new }
attribute :settings, :text, :default => proc { Hash.new } 2.5.5 :001 > User.new.settings
=> {} |
I agree. If the cases @Fryguy mentioned pass and the tests pass, including cross-repo, I'd be good with dropping default_value_for in favor of using attribute default. |
Closing: the attribute type is required, and we're going to run into issues with anything like the |
miq policy defaults are well tested already so this is the first of many if it gets approval
Keenan caught it a couple days ago on September 22, 2020 11:50 AM
@kbrock @Fryguy could I get opinions, please?
@miq-bot add_label refactoring
it's work in progress until i'm sure that our use cases can sufficiently be satisfied