Skip to content
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/components/alchemy/ingredients/base_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def presence_validation?
end

def form_field_counter
element.definition.ingredients.index { |i| i.role == role }
ingredient.id
end

# Renders the translated role of ingredient.
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/alchemy/ingredient_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def presence_validation?
private

def form_field_counter
element.ingredient_definitions.index { _1.role == role }
id
end
end
end
4 changes: 2 additions & 2 deletions spec/components/alchemy/ingredients/base_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@

describe "#form_field_name" do
it "returns a name for form fields with value as default" do
expect(ingredient_editor.form_field_name).to eq("element[ingredients_attributes][1][value]")
expect(ingredient_editor.form_field_name).to eq("element[ingredients_attributes][#{ingredient.id}][value]")
end

context "with a value given" do
it "returns a name for form fields for that column" do
expect(ingredient_editor.form_field_name(:link_title)).to eq("element[ingredients_attributes][1][link_title]")
expect(ingredient_editor.form_field_name(:link_title)).to eq("element[ingredients_attributes][#{ingredient.id}][link_title]")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/decorators/alchemy/ingredient_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Alchemy::IngredientEditor, :silence_deprecations do
let(:element) { build(:alchemy_element, name: "article") }
let(:ingredient) { Alchemy::Ingredients::Text.new(role: "headline", element: element) }
let(:ingredient) { Alchemy::Ingredients::Text.new(id: 123, role: "headline", element: element) }
let(:ingredient_editor) { described_class.new(ingredient) }

describe "#ingredient" do
Expand Down Expand Up @@ -99,12 +99,12 @@

describe "#form_field_name" do
it "returns a name for form fields with value as default" do
expect(ingredient_editor.form_field_name).to eq("element[ingredients_attributes][1][value]")
expect(ingredient_editor.form_field_name).to eq("element[ingredients_attributes][123][value]")
end

context "with a value given" do
it "returns a name for form fields for that column" do
expect(ingredient_editor.form_field_name(:link_title)).to eq("element[ingredients_attributes][1][link_title]")
expect(ingredient_editor.form_field_name(:link_title)).to eq("element[ingredients_attributes][123][link_title]")
end
end
end
Expand Down
Loading