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 touch pages when toggling element #2377

Merged
merged 2 commits into from Sep 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/controllers/alchemy/admin/elements_controller.rb
Expand Up @@ -90,14 +90,12 @@ def order
end
end

# Toggle fodls the element and persists the state in the db
# Toggle folds 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 = !@element.folded
@element.save(validate: false)
# We do not want to trigger the touch callback or any validations
@element.update_columns(folded: !@element.folded)
end

private
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/alchemy/admin/elements_controller_spec.rb
Expand Up @@ -282,28 +282,28 @@ module Alchemy
describe "#fold" do
subject { post :fold, params: { id: element.id }, xhr: true }

let(:element) { build_stubbed(:alchemy_element) }
let(:page) { create(:alchemy_page) }

before do
expect(element).to receive(:save).and_return true
expect(Element).to receive(:find).and_return element
expect(Element).to receive(:find).and_return(element)
element.touchable_pages << page
end

context "if element is folded" do
before { expect(element).to receive(:folded).and_return true }
let(:element) { create(:alchemy_element, folded: true) }

it "sets folded to false." do
expect(element).to receive(:folded=).with(false).and_return(false)
subject
expect(page).not_to receive(:touch)
expect { subject }.to change { element.folded }.to(false)
end
end

context "if element is not folded" do
before { expect(element).to receive(:folded).and_return false }
let(:element) { create(:alchemy_element, folded: false) }

it "sets folded to true." do
expect(element).to receive(:folded=).with(true).and_return(true)
subject
expect(page).not_to receive(:touch)
expect { subject }.to change { element.folded }.to(true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/admin/pages_controller_spec.rb
Expand Up @@ -65,7 +65,7 @@
it "removes the page" do
delete :destroy, params: { id: page.id, format: :js }
expect(response).to redirect_to admin_page_path(page.id)
expect(flash[:notice]).to eq("A Page 61 deleted")
expect(flash[:notice]).to eq Alchemy.t("Page deleted", name: page.name)
end
end
end
Expand Down