Project

General

Profile

« Previous | Next » 

Revision eaa6aec0

Added by Joseph Magen almost 11 years ago

  • ID eaa6aec0023de21f0565b33e98f4c68990c0c2e2

fixes #2489 - fixes BMC password caused by rails bug accepts_nested_attributes_for and serialized child field

View differences:

app/models/nic/bmc.rb
class BMC < Managed
ATTRIBUTES = [:username, :password, :provider]
attr_accessible *ATTRIBUTES
attr_accessible :updated_at, *ATTRIBUTES
PROVIDERS = %w(IPMI)
validates_inclusion_of :provider, :in => PROVIDERS
app/views/hosts/_interfaces.html.erb
<%= password_f f, :password, ifs_bmc_opts(f.object) %>
<%# TODO: current rails version does not allow to pass a selected value where there is no method (e.g. providers below) rescue here is a hack %>
<%= selectable_f f, :provider, Nic::BMC::PROVIDERS, {:selected => nil}, ifs_bmc_opts(f.object) rescue f.hidden_field :provider, :value => 'IPMI' %>
<%# Hack for Rails bug in 3.2.13 - serialized field attrs does not update through accepts_nested_attributes_for if it's
the only field that is dirty. If updated_at is explicited updated, then attrs will also be updated correctly %>
<%= f.hidden_field :updated_at, :value => Time.now %>
<% end %>
<% end %>
test/functional/hosts_controller_test.rb
assert_equal old_password, @host.interfaces.bmc.first.password
end
# To test that work-around works for Rails bug with accepts_nested_attributes_for and serialized child field
# Note that both :mac annd :updated_at are dirty in :interfaces_attributes
# For unknown reason, the test didn't pass if only :updated_at was dirty, but it works in the UI to only pass :updated_at
test "BMC password updates successful in attrs serialized field if updated_at is passed explictedly" do
bmc1 = @host.interfaces.build(:name => "bmc1", :mac => '52:54:00:b0:0c:fc', :type => 'Nic::BMC',
:ip => '10.0.1.101', :username => 'user1111', :password => 'abc123456', :provider => 'IPMI')
assert bmc1.save
new_password = "topsecret"
put :update, { :commit => "Update", :id => @host.name, :host => {:interfaces_attributes => {"0" => {:id => bmc1.id, :password => new_password, :mac => "32:54:00:b0:0c:fd", :updated_at => Time.now, :id => bmc1.id} } } }, set_session_user
@host = Host.find(@host.id)
assert_equal new_password, @host.interfaces.bmc.first.password
end
# To test Rails bug still exists with accepts_nested_attributes_for and serialized child field
test "BMC password does not update due to Rails bug" do
bmc1 = @host.interfaces.build(:name => "bmc1", :mac => '52:54:00:b0:0c:fc', :type => 'Nic::BMC',
:ip => '10.0.1.101', :username => 'user1111', :password => 'abc123456', :provider => 'IPMI')
assert bmc1.save
new_password = "topsecret"
put :update, { :commit => "Update", :id => @host.name, :host => {:interfaces_attributes => {"0" => {:id => bmc1.id, :password => new_password} } } }, set_session_user
@host = Host.find(@host.id)
# assert bug that password was NOT updated to "topsecret" because :password (in serialized attrs field) was the only parameter that changed
refute_equal 'topsecret', @host.interfaces.bmc.first.password
assert_equal 'abc123456', @host.interfaces.bmc.first.password
end
private
def initialize_host

Also available in: Unified diff