Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not validate element during toggle fold and create #2186

Merged
merged 2 commits into from
Sep 2, 2021
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
12 changes: 8 additions & 4 deletions app/controllers/alchemy/admin/elements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def create
if @paste_from_clipboard = params[:paste_from_clipboard].present?
@element = paste_element_from_clipboard
else
@element = Element.create(create_element_params)
@element = Element.new(create_element_params)
end
if @page.definition["insert_elements_at"] == "top"
@insert_at_top = true
@element.move_to_top
@element.position = 1
end
end
if @element.valid?
if @element.save
render :create
else
@element.page_version = @page_version
Expand Down Expand Up @@ -91,10 +91,14 @@ def order
end
end

# Toggle fodls the element and persists the state in the db
#
# Ingredient validations might make the element invalid.
# In this case we are just toggling a UI state and do not care about the validations.
def fold
@page = @element.page
@element.folded = [email protected]
@element.save
@element.save(validate: false)
end

private
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/alchemy/admin/elements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ module Alchemy
expect(subject).to render_template(:new)
end
end

context "with ingredient validations" do
subject do
post :create, params: { element: { page_version_id: page_version.id, name: "all_you_can_eat_ingredients" } }, xhr: true
end

it "creates element without error" do
expect(subject).to render_template(:create)
end
end
end

describe "#update" do
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/alchemy/admin/elements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
post fold_admin_element_path(id: element.id, format: :js)
expect(response.body).to include("Alchemy.Tinymce.init([#{element.ingredient_by_role(:text).id}]);")
end

context "with validations" do
let(:element) { create(:alchemy_element, :with_ingredients, name: :all_you_can_eat_ingredients) }

it "saves without running validations" do
post fold_admin_element_path(id: element.id, format: :js)
expect(element.reload).to be_folded
end
end
end
end

Expand Down