2019-05-12 22:16:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe AdPlugin::HouseAdSettingsController do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>")
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update" do
|
|
|
|
let(:valid_params) { { value: 'Banner' } }
|
|
|
|
|
|
|
|
it "error if not logged in" do
|
2019-10-08 17:41:13 -04:00
|
|
|
put '/admin/plugins/pluginad/house_settings/topic_list_top.json', params: valid_params
|
2019-04-18 17:52:59 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "error if not staff" do
|
|
|
|
sign_in(Fabricate(:user))
|
2019-10-08 17:41:13 -04:00
|
|
|
put '/admin/plugins/pluginad/house_settings/topic_list_top.json', params: valid_params
|
2019-04-18 17:52:59 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
2022-10-03 15:36:57 -04:00
|
|
|
context "when logged in as admin" do
|
2019-04-18 17:52:59 -04:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "changes the setting" do
|
2019-10-08 17:41:13 -04:00
|
|
|
put '/admin/plugins/pluginad/house_settings/topic_list_top.json', params: valid_params
|
2019-04-18 17:52:59 -04:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(AdPlugin::HouseAdSetting.all[:topic_list_top]).to eq(valid_params[:value])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "errors on invalid setting name" do
|
2019-10-08 17:41:13 -04:00
|
|
|
put '/admin/plugins/pluginad/house_settings/nope-nope.json', params: valid_params
|
2019-04-18 17:52:59 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "errors on invalid setting value" do
|
2019-10-08 17:41:13 -04:00
|
|
|
put '/admin/plugins/pluginad/house_settings/topic_list_top.json', params: valid_params.merge(value: "Banner|<script>")
|
2019-04-18 17:52:59 -04:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|