2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Admin::UserFieldsController do
|
2014-09-25 11:32:08 -04:00
|
|
|
it "is a subclass of AdminController" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Admin::UserFieldsController < Admin::AdminController).to eq(true)
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2018-06-11 00:50:21 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
|
2018-06-11 00:50:21 -04:00
|
|
|
describe '#create' do
|
2014-09-25 11:32:08 -04:00
|
|
|
it "creates a user field" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect {
|
2018-06-11 00:50:21 -04:00
|
|
|
post "/admin/customize/user_fields.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: { name: 'hello', description: 'hello desc', field_type: 'text' }
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2015-01-09 12:04:02 -05:00
|
|
|
}.to change(UserField, :count).by(1)
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
2015-07-28 12:29:40 -04:00
|
|
|
|
|
|
|
it "creates a user field with options" do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
2018-06-11 00:50:21 -04:00
|
|
|
post "/admin/customize/user_fields.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: {
|
|
|
|
name: 'hello',
|
|
|
|
description: 'hello desc',
|
|
|
|
field_type: 'dropdown',
|
|
|
|
options: ['a', 'b', 'c']
|
|
|
|
}
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-31 00:06:56 -04:00
|
|
|
end.to change(UserField, :count).by(1)
|
2015-07-28 12:29:40 -04:00
|
|
|
|
|
|
|
expect(UserFieldOption.count).to eq(3)
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
|
2018-06-11 00:50:21 -04:00
|
|
|
describe '#index' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user_field) { Fabricate(:user_field) }
|
2014-09-25 11:32:08 -04:00
|
|
|
|
|
|
|
it "returns a list of user fields" do
|
2018-06-11 00:50:21 -04:00
|
|
|
get "/admin/customize/user_fields.json"
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 11:04:12 -04:00
|
|
|
json = response.parsed_body
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(json['user_fields']).to be_present
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-11 00:50:21 -04:00
|
|
|
describe '#destroy' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user_field) { Fabricate(:user_field) }
|
2014-09-25 11:32:08 -04:00
|
|
|
|
2014-10-08 14:38:18 -04:00
|
|
|
it "deletes the user field" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect {
|
2018-06-11 00:50:21 -04:00
|
|
|
delete "/admin/customize/user_fields/#{user_field.id}.json"
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2015-01-09 12:04:02 -05:00
|
|
|
}.to change(UserField, :count).by(-1)
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-11 00:50:21 -04:00
|
|
|
describe '#update' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user_field) { Fabricate(:user_field) }
|
2014-09-25 11:32:08 -04:00
|
|
|
|
2014-10-08 14:38:18 -04:00
|
|
|
it "updates the user field" do
|
2018-06-11 00:50:21 -04:00
|
|
|
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: { name: 'fraggle', field_type: 'confirm', description: 'muppet' }
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2014-09-25 11:32:08 -04:00
|
|
|
user_field.reload
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(user_field.name).to eq('fraggle')
|
|
|
|
expect(user_field.field_type).to eq('confirm')
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
2015-07-28 12:29:40 -04:00
|
|
|
|
|
|
|
it "updates the user field options" do
|
2018-06-11 00:50:21 -04:00
|
|
|
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: {
|
|
|
|
name: 'fraggle',
|
|
|
|
field_type: 'dropdown',
|
|
|
|
description: 'muppet',
|
|
|
|
options: ['hello', 'hello', 'world']
|
|
|
|
}
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2015-07-28 12:29:40 -04:00
|
|
|
user_field.reload
|
|
|
|
expect(user_field.name).to eq('fraggle')
|
|
|
|
expect(user_field.field_type).to eq('dropdown')
|
|
|
|
expect(user_field.user_field_options.size).to eq(2)
|
|
|
|
end
|
2015-08-17 13:01:15 -04:00
|
|
|
|
|
|
|
it "keeps options when updating the user field" do
|
2018-06-11 00:50:21 -04:00
|
|
|
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: {
|
|
|
|
name: 'fraggle',
|
|
|
|
field_type: 'dropdown',
|
|
|
|
description: 'muppet',
|
|
|
|
options: ['hello', 'hello', 'world'],
|
|
|
|
position: 1
|
|
|
|
}
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2015-08-17 13:01:15 -04:00
|
|
|
user_field.reload
|
|
|
|
expect(user_field.user_field_options.size).to eq(2)
|
|
|
|
|
2018-06-11 00:50:21 -04:00
|
|
|
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
user_field: {
|
|
|
|
name: 'fraggle',
|
|
|
|
field_type: 'dropdown',
|
|
|
|
description: 'muppet',
|
|
|
|
position: 2
|
|
|
|
}
|
2018-06-11 00:50:21 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2015-08-17 13:01:15 -04:00
|
|
|
user_field.reload
|
|
|
|
expect(user_field.user_field_options.size).to eq(2)
|
|
|
|
end
|
2021-06-07 13:34:01 -04:00
|
|
|
|
|
|
|
it "removes directory column record if not public" do
|
|
|
|
next_position = DirectoryColumn.maximum("position") + 1
|
|
|
|
DirectoryColumn.create(
|
|
|
|
user_field_id: user_field.id,
|
|
|
|
enabled: false,
|
2021-06-22 14:00:04 -04:00
|
|
|
type: DirectoryColumn.types[:user_field],
|
2021-06-07 13:34:01 -04:00
|
|
|
position: next_position
|
|
|
|
)
|
|
|
|
expect {
|
|
|
|
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
|
|
|
user_field: { show_on_profile: false, show_on_user_card: false, searchable: true }
|
|
|
|
}
|
|
|
|
}.to change { DirectoryColumn.count }.by(-1)
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|