Skip to content

Commit

Permalink
Use ProposalSettings#deep_copy also in SettingsGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Apr 3, 2019
1 parent f3746c8 commit 37f3f2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/y2storage/proposal/settings_generator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def next_settings
#
# @param settings [ProposalSettings]
def initialize_settings(settings)
@settings = Yast.deep_copy(settings)
@settings = settings.deep_copy
end

# Sets the initial adjustments
Expand All @@ -104,7 +104,7 @@ def initial_settings
#
# @return [ProposalSettings]
def copy_settings
Yast.deep_copy(settings)
settings.deep_copy
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions test/y2storage/proposal/settings_generator/legacy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
describe Y2Storage::Proposal::SettingsGenerator::Legacy do
subject { described_class.new(settings) }

def remove_object_ids(input)
input.gsub(/:0x\w+ /, "")
end

describe "#next_settings" do
before do
stub_product_features("partitioning" => partitioning_features)
Expand All @@ -47,14 +51,17 @@
next_settings = subject.next_settings

expect(next_settings).to be_a(Y2Storage::ProposalSettings)
expect(next_settings.object_id).to_not eq(settings.object_id)
expect(next_settings.to_s).to_not eq(settings.to_s)
end

context "when called for first time" do
it "returns the same values as the initial settings" do
next_settings = subject.next_settings

expect(next_settings.to_s).to eq(settings.to_s)
settings_content = remove_object_ids(settings.to_s)
next_settings_content = remove_object_ids(next_settings.to_s)

expect(next_settings_content).to eq(settings_content)
end
end

Expand Down
11 changes: 9 additions & 2 deletions test/y2storage/proposal/settings_generator/ng_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def volume_from_settings(settings, mount_point)
settings.volumes.find { |v| v.mount_point == mount_point }
end

def remove_object_ids(input)
input.gsub(/:0x\w+ /, "")
end

describe "#next_settings" do
before do
stub_product_features("partitioning" => partitioning_features)
Expand Down Expand Up @@ -75,14 +79,17 @@ def volume_from_settings(settings, mount_point)
next_settings = subject.next_settings

expect(next_settings).to be_a(Y2Storage::ProposalSettings)
expect(next_settings.object_id).to_not eq(settings.object_id)
expect(next_settings.to_s).to_not eq(settings.to_s)
end

context "when called for first time" do
it "returns the same values as the initial settings" do
next_settings = subject.next_settings

expect(next_settings.to_s).to eq(settings.to_s)
settings_content = remove_object_ids(settings.to_s)
next_settings_content = remove_object_ids(next_settings.to_s)

expect(next_settings_content).to eq(settings_content)
end

it "creates an empty SettingsAdjustment object" do
Expand Down

0 comments on commit 37f3f2f

Please sign in to comment.