From d2880246cdad46ba97629db7582992ac9d798559 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Wed, 6 Jun 2018 12:49:43 +0300 Subject: [PATCH] REFACTOR: steps controller specs to requests --- .../steps_controller_spec.rb | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) rename spec/{controllers => requests}/steps_controller_spec.rb (51%) diff --git a/spec/controllers/steps_controller_spec.rb b/spec/requests/steps_controller_spec.rb similarity index 51% rename from spec/controllers/steps_controller_spec.rb rename to spec/requests/steps_controller_spec.rb index 2c0603ca4cd..44a6c9bdff0 100644 --- a/spec/controllers/steps_controller_spec.rb +++ b/spec/requests/steps_controller_spec.rb @@ -1,57 +1,55 @@ require 'rails_helper' describe StepsController do - before do SiteSetting.wizard_enabled = true end it 'needs you to be logged in' do - put :update, params: { - id: 'made-up-id', fields: { forum_title: "updated title" } - }, format: :json + put "/wizard/steps/made-up-id.json", params: { + fields: { forum_title: "updated title" } + } expect(response.status).to eq(403) end it "raises an error if you aren't an admin" do - log_in(:moderator) + sign_in(Fabricate(:moderator)) - put :update, params: { - id: 'made-up-id', fields: { forum_title: "updated title" } - }, format: :json + put "/wizard/steps/made-up-id.json", params: { + fields: { forum_title: "updated title" } + } expect(response).to be_forbidden end context "as an admin" do before do - log_in(:admin) + sign_in(Fabricate(:admin)) end it "raises an error if the wizard is disabled" do SiteSetting.wizard_enabled = false - put :update, params: { - id: 'contact', fields: { contact_email: "eviltrout@example.com" } - }, format: :json + put "/wizard/steps/contact.json", params: { + fields: { contact_email: "eviltrout@example.com" } + } expect(response).to be_forbidden end it "updates properly if you are staff" do - put :update, params: { - id: 'contact', fields: { contact_email: "eviltrout@example.com" } - }, format: :json + put "/wizard/steps/contact.json", params: { + fields: { contact_email: "eviltrout@example.com" } + } expect(response).to be_successful expect(SiteSetting.contact_email).to eq("eviltrout@example.com") end it "returns errors if the field has them" do - put :update, params: { - id: 'contact', fields: { contact_email: "not-an-email" } - }, format: :json + put "/wizard/steps/contact.json", params: { + fields: { contact_email: "not-an-email" } + } - expect(response).to_not be_successful + expect(response.status).to eq(422) end end - end