Skip to content

Commit

Permalink
Merge pull request #170 from OneBusAway/feat-delete-question
Browse files Browse the repository at this point in the history
Add Delete Functionality for Questions in Admin Panel
  • Loading branch information
aaronbrethorst authored Oct 2, 2024
2 parents 3453afa + 6ddf3e1 commit 3b5aa81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admins/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update
def destroy
@question = @survey.questions.find(params[:id])
@question.destroy
redirect_to admin_study_survey_path(@study, @survey), notice: 'Question was deleted.'
redirect_to admin_study_survey_path(@survey.study, @survey), notice: 'Question was deleted.'
end

private
Expand Down
11 changes: 10 additions & 1 deletion app/views/admins/questions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
<%= render Forms::CheckboxComponent.new(form: f, method: :required, help_text: "Mark this if this question requires a response.") %>

<%= render Forms::ButtonBarComponent.new(f) %>
<div class="flex justify-between items-center">
<% if @question.persisted? %>
<%= link_to "Delete Question", admin_study_survey_question_path(@survey.study, @survey, @question), class: "oba-btn--danger",
data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
<% end %>

<div class="flex-grow"></div>

<%= render Forms::ButtonBarComponent.new(f) %>
</div>
</div>
<% end %>
12 changes: 12 additions & 0 deletions spec/requests/admins/questions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@
end
end
end

context "DELETE /admin/studies/:study_id/surveys/:survey_id/questions/:id" do
let!(:question) { create(:question, survey:) }
it "deletes the question" do
sign_in admin
expect do
delete admin_study_survey_question_path(study, survey, question)
end.to change(Question, :count).by(-1)
expect(response).to redirect_to(admin_study_survey_path(study, survey))
expect(flash[:notice]).to eq("Question was deleted.")
end
end
end

0 comments on commit 3b5aa81

Please sign in to comment.