Skip to content

Commit

Permalink
Merge pull request #13578 from opf/refactor/simplify-custom-field-fac…
Browse files Browse the repository at this point in the history
…tory

Refactor CustomField factories using traits
  • Loading branch information
aaron-contreras committed Aug 29, 2023
2 parents 102b777 + df827db commit a09a1ae
Show file tree
Hide file tree
Showing 67 changed files with 212 additions and 446 deletions.
2 changes: 1 addition & 1 deletion modules/bim/spec/features/bcf/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
create(:type, custom_fields: [integer_cf])
end
let(:integer_cf) do
create(:int_wp_custom_field)
create(:integer_wp_custom_field)
end

shared_examples 'bcf details creation' do |with_viewpoints|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
end

context 'for a custom value' do
let(:custom_field) { build_stubbed(:text_time_entry_custom_field) }
let(:custom_field) { build_stubbed(:time_entry_custom_field) }
let(:path) { "customField#{custom_field.id}" }
let(:writable_attributes) { [custom_field.attribute_name] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
described_class.create(time_entry, current_user: user, embed_links: true)
end
let(:user_custom_field) do
build_stubbed(:time_entry_custom_field, field_format: 'user')
build_stubbed(:time_entry_custom_field, :user)
end
let(:test_custom_field) do
build_stubbed(:time_entry_custom_field, field_format: 'text')
let(:text_custom_field) do
build_stubbed(:time_entry_custom_field)
end

let(:hash) do
Expand All @@ -81,7 +81,7 @@
"raw" => "some comment"
},
"spentOn" => "2017-07-28",
test_custom_field.attribute_name(:camel_case) => {
text_custom_field.attribute_name(:camel_case) => {
"raw" => "some text"
}
}
Expand All @@ -90,7 +90,7 @@
before do
allow(time_entry)
.to receive(:available_custom_fields)
.and_return([test_custom_field, user_custom_field])
.and_return([text_custom_field, user_custom_field])
end

describe '_links' do
Expand Down Expand Up @@ -171,7 +171,7 @@
it 'updates the custom value' do
time_entry = representer.from_hash(hash)

expect(time_entry.custom_field_values.detect { |cv| cv.custom_field_id == test_custom_field.id }.value)
expect(time_entry.custom_field_values.detect { |cv| cv.custom_field_id == text_custom_field.id }.value)
.to eql("some text")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

context 'custom value' do
let(:custom_field) do
build_stubbed(:time_entry_custom_field, field_format: 'user')
build_stubbed(:time_entry_custom_field, :user)
end
let(:custom_value) do
double('CustomValue',
Expand Down Expand Up @@ -255,7 +255,7 @@
end

context 'custom value' do
let(:custom_field) { build_stubbed(:text_time_entry_custom_field) }
let(:custom_field) { build_stubbed(:time_entry_custom_field) }
let(:custom_value) do
CustomValue.new(custom_field:,
value: '1234',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
TimeEntryActivitiesProject.insert(project_id: project.id, activity_id: tea.id, active: false)
end
end
let(:custom_field) { create(:text_time_entry_custom_field) }
let(:custom_field) { create(:time_entry_custom_field) }
let(:user) do
create(:user,
member_in_project: project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TimeEntryActivitiesProject.insert(project_id: project.id, activity_id: tea.id, active: false)
end
end
let(:custom_field) { create(:text_time_entry_custom_field) }
let(:custom_field) { create(:time_entry_custom_field) }
let(:user) do
create(:user,
member_in_project: project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
let(:other_project) { other_work_package.project }
let(:role) { create(:role, permissions:) }
let(:permissions) { %i(view_time_entries view_work_packages) }
let(:custom_field) { create(:text_time_entry_custom_field) }
let(:custom_field) { create(:time_entry_custom_field) }
let(:custom_value) do
CustomValue.create(custom_field:,
value: '1234',
Expand Down
4 changes: 2 additions & 2 deletions modules/dashboards/spec/features/project_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

RSpec.describe 'Project details widget on dashboard', js: true do
let!(:version_cf) { create(:version_project_custom_field) }
let!(:bool_cf) { create(:bool_project_custom_field) }
let!(:bool_cf) { create(:boolean_project_custom_field) }
let!(:user_cf) { create(:user_project_custom_field) }
let!(:int_cf) { create(:int_project_custom_field) }
let!(:int_cf) { create(:integer_project_custom_field) }
let!(:float_cf) { create(:float_project_custom_field) }
let!(:text_cf) { create(:text_project_custom_field) }
let!(:string_cf) { create(:string_project_custom_field) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
hours: 4)
end
let!(:custom_field) do
create(:time_entry_custom_field, field_format: 'text')
create(:time_entry_custom_field)
end
let(:other_user) do
create(:user)
Expand Down
8 changes: 4 additions & 4 deletions spec/contracts/projects/shared_contract_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def expect_valid(valid, symbols = {})
end

describe 'available_custom_fields' do
let(:visible_custom_field) { build_stubbed(:int_project_custom_field, visible: true) }
let(:invisible_custom_field) { build_stubbed(:int_project_custom_field, visible: false) }
let(:visible_custom_field) { build_stubbed(:integer_project_custom_field, visible: true) }
let(:invisible_custom_field) { build_stubbed(:integer_project_custom_field, visible: false) }

before do
allow(project)
Expand All @@ -280,14 +280,14 @@ def expect_valid(valid, symbols = {})

it 'returns all available_custom_fields of the project' do
expect(subject.available_custom_fields)
.to match_array([visible_custom_field, invisible_custom_field])
.to contain_exactly(visible_custom_field, invisible_custom_field)
end
end

context 'if the user is no admin' do
it 'returns all visible and available_custom_fields of the project' do
expect(subject.available_custom_fields)
.to match_array([visible_custom_field])
.to contain_exactly(visible_custom_field)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/my_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
end

describe 'account' do
let(:custom_field) { create(:text_user_custom_field) }
let(:custom_field) { create(:user_custom_field, :text) }

before do
custom_field
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/work_packages/bulk_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
is_for_all: true)
end
let(:custom_field2) { create(:work_package_custom_field) }
let(:custom_field_user) { create(:user_issue_custom_field) }
let(:custom_field_user) { create(:issue_custom_field, :user) }
let(:status) { create(:status) }
let(:type) do
create(:type_standard,
Expand Down

0 comments on commit a09a1ae

Please sign in to comment.