Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/services/custom_fields/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def instance(params)
def after_perform(call)
cf = call.result

if cf.is_a?(ProjectCustomField)
add_cf_to_visible_columns(cf)
end

if cf.field_format_calculated_value? && cf.is_required?
enqueue_recalculate_values(cf)
end
Expand All @@ -73,10 +69,6 @@ def after_perform(call)

private

def add_cf_to_visible_columns(custom_field)
Setting.enabled_projects_columns |= [custom_field.column_name]
end

def enqueue_recalculate_values(custom_field)
CustomFields::RecalculateValuesJob.perform_later(
user: User.current,
Expand Down
30 changes: 16 additions & 14 deletions spec/services/custom_fields/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,31 @@
context "when creating a project cf" do
let(:model_instance) { build_stubbed(:project_custom_field) }

it "modifies the settings on successful call" do
subject
expect(Setting.enabled_projects_columns).to include(model_instance.column_name)
it "no longer changes the enabled_projects_columns setting" do
expect { subject }
.not_to change(Setting, :enabled_projects_columns)
expect(subject).to be_success
end
end
end

describe "#call" do
shared_let(:user) { create(:admin) }
let(:contract_class) { CustomFields::CreateContract }
let(:contract_instance) { instance_double(contract_class, validate: true) }

let(:instance) do
described_class.new(user:)
let!(:contract_instance) do
instance_double(contract_class, validate: true).tap do |contract|
allow(contract_class)
.to receive(:new).with(instance_of(custom_field_class), user, options: {}).and_return(contract)
end
end

subject(:instance_call) { instance.call(attributes) }
let(:contract_class) { CustomFields::CreateContract }
let(:custom_field_class) { ProjectCustomField }
let(:instance) { described_class.new(user:) }

before do
User.current = user
allow(contract_class)
.to receive(:new).with(instance_of(ProjectCustomField), user, options: {}).and_return(contract_instance)
end
current_user { user }

subject(:instance_call) { instance.call(attributes) }

describe "calculated value custom field",
with_ee: %i[calculated_values],
Expand All @@ -75,7 +77,7 @@

let(:common_attributes) do
{
type: "ProjectCustomField",
type: custom_field_class.to_s,
field_format: "calculated_value",
name: "foo",
custom_field_section_id: project_custom_field_section.id
Expand Down
Loading