mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 19:11:13 +00:00
* DEV: Implement staff logs for user columns edits * deleted extra space in staff logger detail string, deleted string when no changes are made, added basic test coverage for EditDirectoryColumnsController * fixed change made to #self.staff_actions un UserHistory * implemented a method that builds the details, previous_values and new_values in a dynamic way * removed details of changes * refactored small merge
64 lines
1.6 KiB
Ruby
64 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rspec"
|
|
|
|
RSpec.describe EditDirectoryColumnsController do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
fab!(:normal_user) { Fabricate(:user) }
|
|
let!(:payload) do
|
|
{
|
|
directory_columns: {
|
|
"0": {
|
|
id: "1",
|
|
enabled: "true",
|
|
position: "2",
|
|
},
|
|
"1": {
|
|
id: "2",
|
|
enabled: "true",
|
|
position: "1",
|
|
},
|
|
},
|
|
format: "json",
|
|
}
|
|
end
|
|
|
|
describe "#update" do
|
|
describe "when user is an admin or moderator" do
|
|
before { sign_in(admin) }
|
|
describe "user saves a new configuration" do
|
|
it "logs the new information using StaffActionLogger" do
|
|
put edit_directory_columns_path(params: payload)
|
|
staff_log = UserHistory.last
|
|
|
|
expect(staff_log.custom_type).to eq("update_directory_columns")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "when user is not an admin or moderator" do
|
|
before { sign_in(normal_user) }
|
|
describe "user saves a new configuration" do
|
|
it "does not allow saving" do
|
|
put edit_directory_columns_path(params: payload)
|
|
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#index" do
|
|
describe "when user is not an admin or moderator" do
|
|
before { sign_in(normal_user) }
|
|
describe "user checks current configuration" do
|
|
it "does not allow the configuration to load" do
|
|
get edit_directory_columns_path << ".json"
|
|
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|