Skip to content
Open
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
1 change: 1 addition & 0 deletions app/controllers/administrate/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def create
def update
@resource = resource = requested_resource
if resource.update(resource_params)
yield(resource) if block_given?
redirect_to(
after_resource_updated_path(resource),
notice: translate_with_resource("update.success"),
Expand Down
27 changes: 26 additions & 1 deletion spec/controllers/admin/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def after_resource_updated_path(requested_resource)
end
end

describe "creation yeilds resource" do
describe "creation yields resource" do
controller(Admin::OrdersController) do
attr_reader :resource

Expand All @@ -73,6 +73,31 @@ def create
end
end

describe "updating yields resource" do
controller(Admin::OrdersController) do
attr_reader :resource

def update
super do |resource|
@resource = resource
end
end
end

it "yields the updated resource after creation" do
order = create(:order)
params = order.attributes.except(
"id",
"created_at",
"updated_at",
"shipped_at"
)

put :update, params: {id: order.to_param, order: params}

expect(controller.resource).to be_a(Order)
end
end
describe "authorization" do
controller(Administrate::ApplicationController) do
def resource_class
Expand Down