Skip to content

Commit

Permalink
Merge pull request #67 from byohay/feature/fix-adding-simple-attribut…
Browse files Browse the repository at this point in the history
…e-with-default-value
  • Loading branch information
byohay committed Jun 6, 2022
2 parents f210942 + 75a5efd commit f00b748
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/kintsugi/apply_change_to_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])

attribute_name = attribute_name_from_change_name(change_name)
if simple_attribute?(component, attribute_name)
apply_change_to_simple_attribute(component, attribute_name, {added: change_value})
simple_attribute_change = {
added: change_value,
removed: simple_attribute_default_value(component, attribute_name)
}
apply_change_to_simple_attribute(component, attribute_name, simple_attribute_change)
next
end

Expand All @@ -694,6 +698,12 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])
end
end

def simple_attribute_default_value(component, attribute_name)
component.simple_attributes.find do |attribute|
attribute.name == attribute_name
end.default_value
end

def find_file(project, file_reference_change, file_filter: ->(_) { true })
file_references = project.files.select do |file_reference|
file_reference.path == file_reference_change["path"] && file_filter.call(file_reference)
Expand Down
14 changes: 14 additions & 0 deletions spec/kintsugi_apply_change_to_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,20 @@
expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "adds build phase with a simple attribute value that has non nil default" do
theirs_project = create_copy_of_project(base_project.path, "theirs")

theirs_project.targets[0].new_shell_script_build_phase("bar")
theirs_project.targets[0].build_phases.last.shell_script = "Other value"

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(base_project, changes_to_apply)
base_project.save

expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "removes build phase" do
base_project.targets[0].new_shell_script_build_phase("bar")

Expand Down

0 comments on commit f00b748

Please sign in to comment.