-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor page redirect target path
this will make us easier to override redirect path fix syntax fix hound restore unchanged lines fix hound review Update application_controller.rb fix hound review Add specs and doc for override redirect feature Update docs/customizing_controller_actions.md Co-authored-by: Pablo Brasero <36066+pablobm@users.noreply.github.com> use anonimous controller for custom redirect
- Loading branch information
1 parent
d82bf26
commit c3c0568
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Admin::OrdersController, type: :controller do | ||
controller(Admin::OrdersController) do | ||
def after_resource_destroyed_path(_requested_resource) | ||
{ action: :index, controller: :customers } | ||
end | ||
|
||
def after_resource_created_path(requested_resource) | ||
[namespace, requested_resource.customer] | ||
end | ||
|
||
def after_resource_updated_path(requested_resource) | ||
[namespace, requested_resource.customer] | ||
end | ||
end | ||
|
||
it "redirect to custom route after destroy" do | ||
order = create(:order) | ||
|
||
delete :destroy, id: order.to_param | ||
expect(response).to redirect_to(admin_customers_path) | ||
end | ||
|
||
it "redirect to custom route after create" do | ||
customer = create(:customer) | ||
order_attributes = build(:order, customer: customer).attributes | ||
params = order_attributes.except("id", "created_at", "updated_at", "shipped_at") | ||
|
||
post :create, order: params | ||
expect(response).to redirect_to(admin_customer_path(customer)) | ||
end | ||
|
||
it "redirect to custom route after update" do | ||
order = create(:order) | ||
order_params = { address_line_one: order.address_line_one } | ||
|
||
put :update, id: order.to_param, order: order_params | ||
expect(response).to redirect_to(admin_customer_path(order.customer)) | ||
end | ||
end |