2016-08-26 01:14:56 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe StepsController do
|
|
|
|
|
2016-09-15 04:36:08 +08:00
|
|
|
before do
|
|
|
|
SiteSetting.wizard_enabled = true
|
|
|
|
end
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
it 'needs you to be logged in' do
|
2017-08-31 12:06:56 +08:00
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
id: 'made-up-id', fields: { forum_title: "updated title" }
|
|
|
|
}, format: :json
|
|
|
|
end.to raise_error(Discourse::NotLoggedIn)
|
2016-08-26 01:14:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error if you aren't an admin" do
|
2016-09-22 23:12:34 +08:00
|
|
|
log_in(:moderator)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
|
|
|
put :update, params: {
|
|
|
|
id: 'made-up-id', fields: { forum_title: "updated title" }
|
|
|
|
}, format: :json
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as an admin" do
|
|
|
|
before do
|
|
|
|
log_in(:admin)
|
|
|
|
end
|
|
|
|
|
2016-09-15 04:36:08 +08:00
|
|
|
it "raises an error if the wizard is disabled" do
|
|
|
|
SiteSetting.wizard_enabled = false
|
2017-08-31 12:06:56 +08:00
|
|
|
put :update, params: {
|
|
|
|
id: 'contact', fields: { contact_email: "eviltrout@example.com" }
|
|
|
|
}, format: :json
|
2016-09-15 04:36:08 +08:00
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
it "updates properly if you are staff" do
|
2017-08-31 12:06:56 +08:00
|
|
|
put :update, params: {
|
|
|
|
id: 'contact', fields: { contact_email: "eviltrout@example.com" }
|
|
|
|
}, format: :json
|
|
|
|
|
2016-08-26 01:14:56 +08:00
|
|
|
expect(response).to be_success
|
2016-09-01 01:35:49 +08:00
|
|
|
expect(SiteSetting.contact_email).to eq("eviltrout@example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns errors if the field has them" do
|
2017-08-31 12:06:56 +08:00
|
|
|
put :update, params: {
|
|
|
|
id: 'contact', fields: { contact_email: "not-an-email" }
|
|
|
|
}, format: :json
|
|
|
|
|
2016-09-01 01:35:49 +08:00
|
|
|
expect(response).to_not be_success
|
2016-08-26 01:14:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|