docbrown/spec/requests/admin/profile_fields_spec.rb
Daniel Uber afa214ac52
Require profile fields to belong to a group (#16390)
* Require profile fields to belong to a group

Remove the empty group dropdown from the group select tag

Remove the optional: true from the belongs_to validation (raise a
validation error on save if the group is not provided)

Update test to remove belongs_to's optional setting

* Update ProfileFields::Add spec to include profile field group

* update factory to ensure a non-empty profile field group

* Add required profile field group to seeded profile fields

Since profile field is required, create was failing (silently).

Add required field so these are available in e2e tests.

* Use factory `association` to create a profile field group

https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#explicit-definition

* provide required profile field group when posting data

* Fix one spec, drop another

Both of these scripts will be removed in the other branch (changing
the attribute name) - dropping the test here seems lower trouble than
modifying an out of data data update script to pass.

* skip test slated for removal

Similar to the last commit - this test exercises a script about to be
archived in the other branch.
2022-02-15 09:27:18 -06:00

94 lines
3.1 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/customization/profile_fields", type: :request do
let(:admin) { create(:user, :super_admin) }
before do
sign_in admin
allow(FeatureFlag).to receive(:enabled?).and_call_original
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
describe "GET /admin/customization/profile_fields" do
it "renders successfully" do
get admin_profile_fields_path
expect(response).to be_successful
end
it "lists the profile fields" do
profile_field = create(:profile_field)
get admin_profile_fields_path
expect(response.body).to include(
profile_field.label,
profile_field.input_type,
profile_field.description,
profile_field.placeholder_text,
)
end
end
describe "POST /admin/customization/profile_fields" do
let(:profile_field_group) { create(:profile_field_group) }
let(:new_profile_field) do
{
label: "Test Location",
input_type: "text_field",
description: "users' location",
placeholder_text: "new york",
profile_field_group_id: profile_field_group.id
}
end
it "redirects successfully" do
post admin_profile_fields_path, params: { profile_field: new_profile_field }
expect(response).to redirect_to admin_profile_fields_path
end
it "creates a profile_field" do
expect do
post admin_profile_fields_path, params: { profile_field: new_profile_field }
end.to change { ProfileField.all.count }.by(1)
last_profile_field_record = ProfileField.last
expect(last_profile_field_record.label).to eq(new_profile_field[:label])
expect(last_profile_field_record.input_type).to eq(new_profile_field[:input_type])
expect(last_profile_field_record.description).to eq(new_profile_field[:description])
expect(last_profile_field_record.placeholder_text).to eq(new_profile_field[:placeholder_text])
end
end
describe "PUT /admin/profile_fields/:id" do
let(:profile_field) { create(:profile_field) }
it "redirects successfully" do
put "#{admin_profile_fields_path}/#{profile_field.id}",
params: { profile_field: { show_in_onboarding: false } }
expect(response).to redirect_to admin_profile_fields_path
end
it "updates the profile field values" do
put "#{admin_profile_fields_path}/#{profile_field.id}",
params: { profile_field: { show_in_onboarding: false } }
changed_profile_record = ProfileField.find(profile_field.id)
expect(changed_profile_record.show_in_onboarding).to be(false)
end
end
describe "DELETE /admin/profile_fields/:id" do
let!(:profile_field) do
create(:profile_field)
end
it "redirects successfully" do
delete "#{admin_profile_fields_path}/#{profile_field.id}"
expect(response).to redirect_to admin_profile_fields_path
end
it "removes a profile field" do
expect do
delete "#{admin_profile_fields_path}/#{profile_field.id}"
end.to change(ProfileField, :count).by(-1)
end
end
end