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

Fixes #22104 - adapt to Rails 5.1 change tracking #5133

Merged
merged 1 commit into from
Feb 19, 2018
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
2 changes: 1 addition & 1 deletion app/models/concerns/authorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def check_permissions_after_save
return true if Thread.current[:ignore_permission_check]

authorizer = Authorizer.new(User.current)
creation = self.id_changed?
creation = self.saved_change_to_id?
name = permission_name(creation ? :create : :edit)

Foreman::Logging.logger('permissions').debug { "verifying the transaction by permission #{name} for class #{self.class}" }
Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/nested_ancestry_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module NestedAncestryCommon

before_validation :set_title
after_save :set_other_titles, :on => [:update, :destroy]
after_save :update_matchers, :on => :update, :if => Proc.new { |obj| obj.title_changed? }
after_save :update_matchers, :on => :update, :if => Proc.new { |obj| obj.saved_change_to_title? }

validate :title_and_lookup_key_length

Expand Down Expand Up @@ -84,7 +84,7 @@ def set_title
end

def set_other_titles
if name_changed? || ancestry_changed?
if saved_change_to_name? || saved_change_to_ancestry?
self.class.where('ancestry IS NOT NULL').find_each do |obj|
if obj.path_ids.include?(self.id)
obj.update_attributes(:title => obj.get_title)
Expand All @@ -98,7 +98,7 @@ def obj_type
end

def update_matchers
lookup_values = LookupValue.where(:match => "#{obj_type}=#{title_was}")
lookup_values = LookupValue.where(:match => "#{obj_type}=#{title_before_last_save}")
lookup_values.update_all(:match => "#{obj_type}=#{title}")
end

Expand Down
3 changes: 1 addition & 2 deletions app/models/host/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def dup
:subnet, :subnet_id, :subnet_name,
:subnet6, :subnet6_id, :subnet6_name,
:domain, :domain_id, :domain_name,
:hostname, :fqdn, :fqdn_changed?,
:fqdn_was, :shortname,
:hostname, :fqdn, :shortname,
:to => :primary_interface, :allow_nil => true
delegate :name=, :ip=, :ip6=, :mac=,
:subnet=, :subnet_id=, :subnet_name=,
Expand Down
12 changes: 6 additions & 6 deletions app/models/nic/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def alias?
self.virtual? && self.identifier.present? && self.identifier.include?(':')
end

def fqdn_changed?
name_changed? || domain_id_changed?
def saved_change_to_fqdn?
saved_change_to_name? || saved_change_to_domain_id?
end

def fqdn_was
domain_was = Domain.find(domain_id_was) unless domain_id_was.blank?
return name_was if name_was.blank? || domain_was.blank?
name_was.include?('.') ? name_was : "#{name_was}.#{domain_was}"
def fqdn_before_last_save
domain_before_last_save = Domain.find(domain_id_before_last_save) unless domain_id_before_last_save.blank?
return name_before_last_save if name_before_last_save.blank? || domain_before_last_save.blank?
name_before_last_save.include?('.') ? name_before_last_save : "#{name_before_last_save}.#{domain_before_last_save}"
end

protected
Expand Down
4 changes: 2 additions & 2 deletions app/models/nic/managed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def set_provisioning_flag

def update_lookup_value_fqdn_matchers
return unless primary?
return unless fqdn_changed?
return unless saved_change_to_fqdn?
return unless host.present?
LookupValue.where(:match => "fqdn=#{fqdn_was}").
LookupValue.where(:match => "fqdn=#{fqdn_before_last_save}").
update_all(:match => host.lookup_value_match)
end

Expand Down
81 changes: 6 additions & 75 deletions config/as_deprecation_whitelist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# http://projects.theforeman.org/issues/7570
- message: You didn't set `secret_key_base`. Read the upgrade documentation to learn
more about this new config option.
callstack:
- message: You didn't set `secret_key_base`. Read the upgrade documentation to learn
more about this new config option.
callstack: test/test_helper.rb:36:in `before_setup'

- message: Using a dynamic :controller segment in a route is deprecated and will be
removed in Rails 5.2.
callstack: config/routes.rb:19:in `block in <top (required)>'
callstack: config/routes.rb:17:in `block in <top (required)>'

# Not a "true" deprecation, no action required, it's being used correctly.
- message: "#table_exists? currently checks both tables and views. This behavior is
Expand All @@ -26,86 +31,22 @@
calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute` instead.
callstack: app/models/concerns/strip_whitespace.rb:9:in `strip_spaces'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/authorizable.rb:8:in `check_permissions_after_save'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/encryptable.rb:41:in `block in encrypt_setters'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/nested_ancestry_common.rb:101:in `update_matchers'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/nested_ancestry_common.rb:11:in `block (2 levels)
in <module:NestedAncestryCommon>'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/nested_ancestry_common.rb:87:in `set_other_titles'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/concerns/strip_whitespace.rb:9:in `strip_spaces'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/nic/interface.rb:60:in `fqdn_changed?'
- message: The behavior of `attribute_changed?` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_change_to_attribute?` instead.
callstack: app/models/nic/interface.rb:64:in `fqdn_was'
- message: The behavior of `attribute_was` inside of after callbacks will be changing
in the next version of Rails. The new return value will reflect the behavior of
calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `attribute_before_last_save` instead.
callstack: app/models/concerns/nested_ancestry_common.rb:101:in `update_matchers'
- message: The behavior of `attribute_was` inside of after callbacks will be changing
in the next version of Rails. The new return value will reflect the behavior of
calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `attribute_before_last_save` instead.
callstack: app/models/nic/interface.rb:64:in `fqdn_was'
- message: The behavior of `changed_attributes` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_changes.transform_values(&:first)`
instead.
callstack: app/models/concerns/nested_ancestry_common.rb:101:in `update_matchers'
- message: The behavior of `changed_attributes` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_changes.transform_values(&:first)`
instead.
callstack: app/models/concerns/nested_ancestry_common.rb:87:in `set_other_titles'
- message: The behavior of `changed_attributes` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_changes.transform_values(&:first)`
instead.
callstack: app/models/concerns/strip_whitespace.rb:9:in `strip_spaces'
- message: The behavior of `changed_attributes` inside of after callbacks will be
changing in the next version of Rails. The new return value will reflect the behavior
of calling the method after `save` returned (e.g. the opposite of what it returns
now). To maintain the current behavior, use `saved_changes.transform_values(&:first)`
instead.
callstack: app/models/nic/interface.rb:65:in `fqdn_was'
- message: The behavior of `changed` inside of after callbacks will be changing in
the next version of Rails. The new return value will reflect the behavior of calling
the method after `save` returned (e.g. the opposite of what it returns now). To
maintain the current behavior, use `saved_changes.keys` instead.
callstack: app/models/concerns/nested_ancestry_common.rb:87:in `set_other_titles'
- message: The behavior of `changed` inside of after callbacks will be changing in
the next version of Rails. The new return value will reflect the behavior of calling
the method after `save` returned (e.g. the opposite of what it returns now). To
Expand All @@ -116,13 +57,3 @@
the method after `save` returned (e.g. the opposite of what it returns now). To
maintain the current behavior, use `saved_changes` instead.
callstack: app/models/concerns/strip_whitespace.rb:9:in `strip_spaces'
- message: password_changed is not an attribute known to Active Record. This behavior
is deprecated and will be removed in the next version of Rails. If you'd like
password_changed to be managed by Active Record, add `attribute :password_changed
to your class.
callstack: app/models/image.rb:31:in `set_password_changed'
- message: password_changed is not an attribute known to Active Record. This behavior
is deprecated and will be removed in the next version of Rails. If you'd like
password_changed to be managed by Active Record, add `attribute :password_changed
to your class.
callstack: app/models/user.rb:527:in `set_password_changed'
24 changes: 12 additions & 12 deletions test/models/nic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,22 @@ class DisallowedTestNic < Nic::Base
assert_nil Nic::Base.type_by_name("DisallowedTestNic")
end

test 'fqdn_changed? should be true if name changes' do
@nic.stubs(:name_changed?).returns(true)
@nic.stubs(:domain_id_changed?).returns(false)
assert @nic.fqdn_changed?
test 'saved_change_to_fqdn? should be true if name changes' do
@nic.stubs(:saved_change_to_name?).returns(true)
@nic.stubs(:saved_change_to_domain_id?).returns(false)
assert @nic.saved_change_to_fqdn?
end

test 'fqdn_changed? should be true if domain changes' do
@nic.stubs(:name_changed?).returns(false)
@nic.stubs(:domain_id_changed?).returns(true)
assert @nic.fqdn_changed?
test 'saved_change_to_fqdn? should be true if domain changes' do
@nic.stubs(:saved_change_to_name?).returns(false)
@nic.stubs(:saved_change_to_domain_id?).returns(true)
assert @nic.saved_change_to_fqdn?
end

test 'fqdn_changed? should be true if name and domain change' do
@nic.stubs(:name_changed?).returns(true)
@nic.stubs(:domain_id_changed?).returns(true)
assert @nic.fqdn_changed?
test 'saved_change_to_fqdn? should be true if name and domain change' do
@nic.stubs(:saved_change_to_name?).returns(true)
@nic.stubs(:saved_change_to_domain_id?).returns(true)
assert @nic.saved_change_to_fqdn?
end
end

Expand Down