DEV: Apply syntax_tree formatting to spec/*

This commit is contained in:
David Taylor
2023-01-09 11:18:21 +00:00
parent 0cf6421716
commit cb932d6ee1
907 changed files with 58693 additions and 45909 deletions

View File

@ -5,15 +5,20 @@ RSpec.describe Admin::UserFieldsController do
fab!(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user) }
describe '#create' do
describe "#create" do
context "when logged in as an admin" do
before { sign_in(admin) }
it "creates a user field" do
expect {
post "/admin/customize/user_fields.json", params: {
user_field: { name: 'hello', description: 'hello desc', field_type: 'text' }
}
post "/admin/customize/user_fields.json",
params: {
user_field: {
name: "hello",
description: "hello desc",
field_type: "text",
},
}
expect(response.status).to eq(200)
}.to change(UserField, :count).by(1)
@ -21,14 +26,15 @@ RSpec.describe Admin::UserFieldsController do
it "creates a user field with options" do
expect do
post "/admin/customize/user_fields.json", params: {
user_field: {
name: 'hello',
description: 'hello desc',
field_type: 'dropdown',
options: ['a', 'b', 'c']
}
}
post "/admin/customize/user_fields.json",
params: {
user_field: {
name: "hello",
description: "hello desc",
field_type: "dropdown",
options: %w[a b c],
},
}
expect(response.status).to eq(200)
end.to change(UserField, :count).by(1)
@ -40,9 +46,14 @@ RSpec.describe Admin::UserFieldsController do
shared_examples "user field creation not allowed" do
it "prevents creation with a 404 response" do
expect do
post "/admin/customize/user_fields.json", params: {
user_field: { name: 'hello', description: 'hello desc', field_type: 'text' }
}
post "/admin/customize/user_fields.json",
params: {
user_field: {
name: "hello",
description: "hello desc",
field_type: "text",
},
}
end.not_to change { UserField.count }
expect(response.status).to eq(404)
@ -57,13 +68,13 @@ RSpec.describe Admin::UserFieldsController do
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
before { sign_in(user) }
include_examples "user field creation not allowed"
end
end
describe '#index' do
describe "#index" do
fab!(:user_field) { Fabricate(:user_field) }
context "when logged in as an admin" do
@ -73,7 +84,7 @@ RSpec.describe Admin::UserFieldsController do
get "/admin/customize/user_fields.json"
expect(response.status).to eq(200)
json = response.parsed_body
expect(json['user_fields']).to be_present
expect(json["user_fields"]).to be_present
end
end
@ -83,7 +94,7 @@ RSpec.describe Admin::UserFieldsController do
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
expect(response.parsed_body['user_fields']).to be_nil
expect(response.parsed_body["user_fields"]).to be_nil
end
end
@ -94,13 +105,13 @@ RSpec.describe Admin::UserFieldsController do
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
before { sign_in(user) }
include_examples "user fields inaccessible"
end
end
describe '#destroy' do
describe "#destroy" do
fab!(:user_field) { Fabricate(:user_field) }
context "when logged in as an admin" do
@ -116,9 +127,9 @@ RSpec.describe Admin::UserFieldsController do
shared_examples "user field deletion not allowed" do
it "prevents deletion with a 404 response" do
expect do
delete "/admin/customize/user_fields/#{user_field.id}.json"
end.not_to change { UserField.count }
expect do delete "/admin/customize/user_fields/#{user_field.id}.json" end.not_to change {
UserField.count
}
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
@ -132,69 +143,77 @@ RSpec.describe Admin::UserFieldsController do
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
before { sign_in(user) }
include_examples "user field deletion not allowed"
end
end
describe '#update' do
describe "#update" do
fab!(:user_field) { Fabricate(:user_field) }
context "when logged in as an admin" do
before { sign_in(admin) }
it "updates the user field" do
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
user_field: { name: 'fraggle', field_type: 'confirm', description: 'muppet' }
}
put "/admin/customize/user_fields/#{user_field.id}.json",
params: {
user_field: {
name: "fraggle",
field_type: "confirm",
description: "muppet",
},
}
expect(response.status).to eq(200)
user_field.reload
expect(user_field.name).to eq('fraggle')
expect(user_field.field_type).to eq('confirm')
expect(user_field.name).to eq("fraggle")
expect(user_field.field_type).to eq("confirm")
end
it "updates the user field options" do
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
user_field: {
name: 'fraggle',
field_type: 'dropdown',
description: 'muppet',
options: ['hello', 'hello', 'world']
}
}
put "/admin/customize/user_fields/#{user_field.id}.json",
params: {
user_field: {
name: "fraggle",
field_type: "dropdown",
description: "muppet",
options: %w[hello hello world],
},
}
expect(response.status).to eq(200)
user_field.reload
expect(user_field.name).to eq('fraggle')
expect(user_field.field_type).to eq('dropdown')
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
it "keeps options when updating the user field" do
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
user_field: {
name: 'fraggle',
field_type: 'dropdown',
description: 'muppet',
options: ['hello', 'hello', 'world'],
position: 1
}
}
put "/admin/customize/user_fields/#{user_field.id}.json",
params: {
user_field: {
name: "fraggle",
field_type: "dropdown",
description: "muppet",
options: %w[hello hello world],
position: 1,
},
}
expect(response.status).to eq(200)
user_field.reload
expect(user_field.user_field_options.size).to eq(2)
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
user_field: {
name: 'fraggle',
field_type: 'dropdown',
description: 'muppet',
position: 2
}
}
put "/admin/customize/user_fields/#{user_field.id}.json",
params: {
user_field: {
name: "fraggle",
field_type: "dropdown",
description: "muppet",
position: 2,
},
}
expect(response.status).to eq(200)
user_field.reload
@ -207,12 +226,17 @@ RSpec.describe Admin::UserFieldsController do
user_field_id: user_field.id,
enabled: false,
type: DirectoryColumn.types[:user_field],
position: next_position
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 }
}
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
end
@ -222,9 +246,14 @@ RSpec.describe Admin::UserFieldsController do
user_field.reload
original_name = user_field.name
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
user_field: { name: 'fraggle', field_type: 'confirm', description: 'muppet' }
}
put "/admin/customize/user_fields/#{user_field.id}.json",
params: {
user_field: {
name: "fraggle",
field_type: "confirm",
description: "muppet",
},
}
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
@ -241,7 +270,7 @@ RSpec.describe Admin::UserFieldsController do
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
before { sign_in(user) }
include_examples "user field update not allowed"
end