Skip to content

Commit 79dabf3

Browse files
committed
Bugfix: properly update edited snippets, rather than duplicating them
1 parent 0ed9737 commit 79dabf3

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

app/models/ingredient.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ def ui_relevant_attributes_changed?
135135
def process_snippets
136136
return if new_snippets.blank?
137137

138-
self.snippets ||= []
139-
filtered_snippets = new_snippets.reject(&:blank?)
140-
141-
self.snippets += filtered_snippets.reject { |s| snippets.include?(s) }
138+
self.snippets = new_snippets.compact_blank
142139
end
143140

144141
def to_literal(snippet, index)

test/controllers/ingredients_controller_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def teardown
163163
patch ingredient_url(@ingredient), params: {
164164
ingredient: {
165165
template_content: @ingredient.template_content,
166-
new_snippets: [ "additional snippet" ]
166+
new_snippets: [ "existing snippet", "additional snippet" ]
167167
}
168168
}
169169

0 commit comments

Comments
 (0)