Skip to content

Commit

Permalink
Adjustments: Wire _and_sync methods up to controller
Browse files Browse the repository at this point in the history
This changes the `AdjustmentsController` to now call the new `_and_sync`
methods provided by the `DiscoveryEngineSyncable` concern on
`Adjustment`.
  • Loading branch information
csutter committed Jan 27, 2025
1 parent ce82914 commit c2d05bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/controllers/adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def new
def create
@adjustment = Adjustment.new(adjustment_params)

if @adjustment.save
if @adjustment.save_and_sync
redirect_to @adjustment, notice: t(".success")
else
render :new, status: :unprocessable_entity
Expand All @@ -26,15 +26,17 @@ def show; end
def edit; end

def update
if @adjustment.update(adjustment_params)
@adjustment.assign_attributes(adjustment_params)

if @adjustment.save_and_sync
redirect_to @adjustment, notice: t(".success")
else
render :edit, status: :unprocessable_entity
end
end

def destroy
if @adjustment.destroy
if @adjustment.destroy_and_sync
redirect_to adjustments_path, notice: t(".success")
else
redirect_to @adjustment, alert: t(".failure")
Expand Down
13 changes: 13 additions & 0 deletions spec/system/adjustments_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
RSpec.describe "Adjustments", type: :system do
let(:control) do
instance_double(DiscoveryEngine::Control, create!: true, update!: true, delete!: true)
end

before do
allow(DiscoveryEngine::Control).to receive(:new).and_return(control)
end

scenario "Viewing adjustments" do
given_several_adjustments_exist
when_i_visit_the_adjustments_page
Expand Down Expand Up @@ -127,11 +135,13 @@ def and_i_can_click_through_to_see_more_details
def then_the_boost_adjustment_should_be_created
expect(page).to have_content("The adjustment was successfully created.")
expect(Adjustment.first).to be_boost_kind
expect(control).to have_received(:create!)
end

def then_the_filter_adjustment_should_be_created
expect(page).to have_content("The adjustment was successfully created.")
expect(Adjustment.first).to be_filter_kind
expect(control).to have_received(:create!)
end

def and_i_can_see_the_boost_adjustment_details
Expand All @@ -148,11 +158,13 @@ def and_i_can_see_the_filter_adjustment_details
def then_the_boost_adjustment_should_be_updated
expect(page).to have_content("The adjustment was successfully updated.")
expect(@boost_adjustment.reload.name).to eq("Updated adjustment")
expect(control).to have_received(:update!)
end

def then_the_filter_adjustment_should_be_updated
expect(page).to have_content("The adjustment was successfully updated.")
expect(@filter_adjustment.reload.name).to eq("Updated adjustment")
expect(control).to have_received(:update!)
end

def and_i_can_see_the_updated_details
Expand All @@ -162,5 +174,6 @@ def and_i_can_see_the_updated_details
def then_the_boost_adjustment_should_be_deleted
expect(page).to have_content("The adjustment was successfully deleted.")
expect(Adjustment.count).to be_zero
expect(control).to have_received(:delete!)
end
end

0 comments on commit c2d05bb

Please sign in to comment.