2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe Admin::EmbeddingController do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:admin)
|
|
|
|
fab!(:moderator)
|
|
|
|
fab!(:user)
|
2022-11-02 22:42:44 -05:00
|
|
|
|
|
|
|
describe "#show" do
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when logged in as an admin" do
|
2022-11-02 22:42:44 -05:00
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
it "returns embedding" do
|
|
|
|
get "/admin/customize/embedding.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["embedding"]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "embedding accessible" do
|
|
|
|
it "returns embedding" do
|
|
|
|
get "/admin/customize/embedding.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(moderator) }
|
|
|
|
|
|
|
|
include_examples "embedding accessible"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a non-staff user" do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
include_examples "embedding accessible"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
2023-01-09 05:18:21 -06:00
|
|
|
context "when logged in as an admin" do
|
2022-11-02 22:42:44 -05:00
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
it "updates embedding" do
|
2023-01-09 05:18:21 -06:00
|
|
|
put "/admin/customize/embedding.json",
|
|
|
|
params: {
|
|
|
|
embedding: {
|
|
|
|
embed_by_username: "system",
|
|
|
|
embed_post_limit: 200,
|
|
|
|
},
|
|
|
|
}
|
2022-11-02 22:42:44 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["embedding"]["embed_by_username"]).to eq("system")
|
|
|
|
expect(response.parsed_body["embedding"]["embed_post_limit"]).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "embedding updates not allowed" do
|
|
|
|
it "prevents updates with a 404 response" do
|
2023-01-09 05:18:21 -06:00
|
|
|
put "/admin/customize/embedding.json",
|
|
|
|
params: {
|
|
|
|
embedding: {
|
|
|
|
embed_by_username: "system",
|
|
|
|
embed_post_limit: 200,
|
|
|
|
},
|
|
|
|
}
|
2022-11-02 22:42:44 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
|
|
|
expect(response.parsed_body["embedding"]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(moderator) }
|
|
|
|
|
|
|
|
include_examples "embedding updates not allowed"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
include_examples "embedding updates not allowed"
|
|
|
|
end
|
2015-08-18 16:15:46 -05:00
|
|
|
end
|
|
|
|
end
|