mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 19:29:51 +00:00
DEV: Refactored and moved Edit Directory Column tests out of directory_columns_controller_spec (#22022)
This commit is contained in:
parent
17e81018a2
commit
e08f713668
@ -16,70 +16,4 @@ RSpec.describe DirectoryColumnsController do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#edit-index" do
|
|
||||||
fab!(:public_user_field) { Fabricate(:user_field, show_on_profile: true) }
|
|
||||||
fab!(:private_user_field) do
|
|
||||||
Fabricate(:user_field, show_on_profile: false, show_on_user_card: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates directory column records for public user fields" do
|
|
||||||
sign_in(admin)
|
|
||||||
|
|
||||||
expect { get "/edit-directory-columns.json" }.to change { DirectoryColumn.count }.by(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns a 403 when not logged in as staff member" do
|
|
||||||
sign_in(user)
|
|
||||||
get "/edit-directory-columns.json"
|
|
||||||
|
|
||||||
expect(response.status).to eq(404)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#update" do
|
|
||||||
let(:first_directory_column_id) { DirectoryColumn.first.id }
|
|
||||||
let(:second_directory_column_id) { DirectoryColumn.second.id }
|
|
||||||
let(:params) do
|
|
||||||
{
|
|
||||||
directory_columns: {
|
|
||||||
"0": {
|
|
||||||
id: first_directory_column_id,
|
|
||||||
enabled: false,
|
|
||||||
position: 1,
|
|
||||||
},
|
|
||||||
"1": {
|
|
||||||
id: second_directory_column_id,
|
|
||||||
enabled: true,
|
|
||||||
position: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "updates exising directory columns" do
|
|
||||||
sign_in(admin)
|
|
||||||
|
|
||||||
expect { put "/edit-directory-columns.json", params: params }.to change {
|
|
||||||
DirectoryColumn.find(first_directory_column_id).enabled
|
|
||||||
}.from(true).to(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not let all columns be disabled" do
|
|
||||||
sign_in(admin)
|
|
||||||
bad_params = params
|
|
||||||
bad_params[:directory_columns][:"1"][:enabled] = false
|
|
||||||
|
|
||||||
put "/edit-directory-columns.json", params: bad_params
|
|
||||||
|
|
||||||
expect(response.status).to eq(400)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns a 404 when not logged in as a staff member" do
|
|
||||||
sign_in(user)
|
|
||||||
put "/edit-directory-columns.json", params: params
|
|
||||||
|
|
||||||
expect(response.status).to eq(404)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -4,40 +4,58 @@ require "rspec"
|
|||||||
|
|
||||||
RSpec.describe EditDirectoryColumnsController do
|
RSpec.describe EditDirectoryColumnsController do
|
||||||
fab!(:admin) { Fabricate(:admin) }
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
fab!(:normal_user) { Fabricate(:user) }
|
fab!(: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 "#update" do
|
||||||
describe "when user is an admin or moderator" do
|
let(:first_directory_column_id) { DirectoryColumn.first.id }
|
||||||
before { sign_in(admin) }
|
let(:second_directory_column_id) { DirectoryColumn.second.id }
|
||||||
describe "user saves a new configuration" do
|
let!(:payload) do
|
||||||
it "logs the new information using StaffActionLogger" do
|
{
|
||||||
put edit_directory_columns_path(params: payload)
|
directory_columns: {
|
||||||
staff_log = UserHistory.last
|
"0": {
|
||||||
|
id: first_directory_column_id,
|
||||||
|
enabled: "false",
|
||||||
|
position: "2",
|
||||||
|
},
|
||||||
|
"1": {
|
||||||
|
id: second_directory_column_id,
|
||||||
|
enabled: "true",
|
||||||
|
position: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
format: "json",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
expect(staff_log.custom_type).to eq("update_directory_columns")
|
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
|
||||||
|
expect { put edit_directory_columns_path(params: payload) }.to change {
|
||||||
|
DirectoryColumn.find(first_directory_column_id).enabled
|
||||||
|
}.from(true).to(false)
|
||||||
|
|
||||||
|
staff_log = UserHistory.last
|
||||||
|
|
||||||
|
expect(staff_log.custom_type).to eq("update_directory_columns")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not let all columns be disabled" do
|
||||||
|
sign_in(admin)
|
||||||
|
bad_params = payload
|
||||||
|
bad_params[:directory_columns][:"1"][:enabled] = "false"
|
||||||
|
|
||||||
|
put edit_directory_columns_path(params: bad_params)
|
||||||
|
|
||||||
|
expect(response.status).to eq(400)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when user is not an admin or moderator" do
|
describe "when user is not an admin or moderator" do
|
||||||
before { sign_in(normal_user) }
|
before { sign_in(user) }
|
||||||
describe "user saves a new configuration" do
|
describe "user saves a new configuration" do
|
||||||
it "does not allow saving" do
|
it "does not allow saving" do
|
||||||
put edit_directory_columns_path(params: payload)
|
put edit_directory_columns_path(params: payload)
|
||||||
@ -49,15 +67,22 @@ RSpec.describe EditDirectoryColumnsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#index" do
|
describe "#index" do
|
||||||
describe "when user is not an admin or moderator" do
|
fab!(:public_user_field) { Fabricate(:user_field, show_on_profile: true) }
|
||||||
before { sign_in(normal_user) }
|
fab!(:private_user_field) do
|
||||||
describe "user checks current configuration" do
|
Fabricate(:user_field, show_on_profile: false, show_on_user_card: false)
|
||||||
it "does not allow the configuration to load" do
|
end
|
||||||
get edit_directory_columns_path << ".json"
|
|
||||||
|
|
||||||
expect(response.status).to eq(403)
|
it "creates directory column records for public user fields" do
|
||||||
end
|
sign_in(admin)
|
||||||
end
|
|
||||||
|
expect { get "/edit-directory-columns.json" }.to change { DirectoryColumn.count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a 403 when not logged in as staff member" do
|
||||||
|
sign_in(user)
|
||||||
|
get "/edit-directory-columns.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(403)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user