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

fix: message don't appear on fail destroy on associations #2016

Merged
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
4 changes: 3 additions & 1 deletion app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,10 @@ def destroy_success_action
end

def destroy_fail_action
flash[:error] = destroy_fail_message

respond_to do |format|
format.html { redirect_back fallback_location: params[:referrer] || resources_path(resource: @resource, turbo_frame: params[:turbo_frame], view_type: params[:view_type]), error: destroy_fail_message }
format.turbo_stream { render partial: "avo/partials/flash_alerts" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that removing the redirect does not break other flows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None that I tested or that is covered by automatic tests

end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/avo/partials/_flash_alerts.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= turbo_stream.append "alerts" do %>
<%= render Avo::FlashAlertsComponent.new flashes: flash %>
<%= render Avo::FlashAlertsComponent.new flashes: flash.discard %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that the discard works well with other flows as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, it will discard the entire flash at the end of the current action

<% end %>
36 changes: 36 additions & 0 deletions spec/system/avo/has_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@
sleep 0.8
expect(page).to have_text("Record destroyed").twice
end

it "shows the notification when delete fails" do
Comment.class_eval do
def destroy
raise "Record failed to destroy"
end
end

visit url

expect {
find("[data-resource-id='#{comments.first.id}'] [data-control='destroy']").click
sleep 0.2
page.driver.browser.switch_to.alert.accept
sleep 0.2
find("[data-resource-id='#{comments.third.id}'] [data-control='destroy']").click
sleep 0.2
page.driver.browser.switch_to.alert.accept
sleep 0.2
}.to change(Comment, :count).by(0)

expect(page).to have_current_path url

expect(page).to have_text comments.third.tiny_name.to_s
expect(page).to have_text comments.first.tiny_name.to_s
expect(page).to have_text comments.second.tiny_name.to_s

sleep 0.8
expect(page).to have_text("Record failed to destroy").twice

Comment.class_eval do
def destroy
super
end
end
end
end
end

Expand Down
Loading