From 55c8fa3297bf12dadb6ff4048cf557a38037d56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 8 May 2019 19:45:31 +0200 Subject: [PATCH] Fix obsolete `respond_with_bip` usage Since we removed the `best_in_place` gem, this method doesn't exist anymore. We're replacing it with what the method actually does. Note the test doesn't check the poll is correctly updated. We could add a `visit proposal_dashboard_polls_path(proposal)` before checking the "Show results" field, but then we would enter a race condition between this request and the AJAX request. A proper solution would be to provide actual feedback to the user so they know the poll has been updated, and then checking that feedback is present in the tests. --- app/controllers/dashboard/polls_controller.rb | 4 ++-- spec/features/dashboard/polls_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/dashboard/polls_controller.rb b/app/controllers/dashboard/polls_controller.rb index fc3b01108..116f1d99d 100644 --- a/app/controllers/dashboard/polls_controller.rb +++ b/app/controllers/dashboard/polls_controller.rb @@ -35,10 +35,10 @@ class Dashboard::PollsController < Dashboard::BaseController if poll.update(poll_params) format.html { redirect_to proposal_dashboard_polls_path(proposal), notice: t("flash.actions.update.poll") } - format.json { respond_with_bip(poll) } + format.json { head :no_content } else format.html { render :edit } - format.json { respond_with_bip(poll) } + format.json { render json: poll.errors.full_messages, status: :unprocessable_entity } end end end diff --git a/spec/features/dashboard/polls_spec.rb b/spec/features/dashboard/polls_spec.rb index 5ccd270b6..0164ba4e3 100644 --- a/spec/features/dashboard/polls_spec.rb +++ b/spec/features/dashboard/polls_spec.rb @@ -197,6 +197,19 @@ feature "Polls" do end end + scenario "Enable and disable results", :js do + create(:poll, related: proposal) + + visit proposal_dashboard_polls_path(proposal) + check "Show results" + + expect(find_field("Show results")).to be_checked + + uncheck "Show results" + + expect(find_field("Show results")).not_to be_checked + end + scenario "Poll card" do poll = create(:poll, :expired, related: proposal)