OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
test Queries::Projects::Selects::CustomField#custom_field
Ivan Kuchin3e3248591a85
diff --git a/spec/models/queries/projects/selects/custom_field_spec.rb b/spec/models/queries/projects/selects/custom_field_spec.rbindex a3f39925aa2..9acd2933341 100644--- a/spec/models/queries/projects/selects/custom_field_spec.rb+++ b/spec/models/queries/projects/selects/custom_field_spec.rb@@ -46,4 +46,45 @@ RSpec.describe Queries::Projects::Selects::CustomField doexpect(described_class.key).not_to match("cf_42x")endend++ describe "#custom_field" do+ let(:instance) { described_class.new(name) }+ let(:name) { "cf_42" }+ let(:id) { 42 }++ before do+ visible = double++ allow(ProjectCustomField).to receive(:visible).and_return(visible)+ allow(visible).to receive(:find_by).with(id: id.to_s).and_return(custom_field)+ end++ context "when custom field exists" do+ let(:custom_field) { instance_double(ProjectCustomField) }++ it "returns the custom field" do+ expect(instance.custom_field).to eq(custom_field)+ end++ it "memoizes the custom field" do+ 2.times { instance.custom_field }++ expect(ProjectCustomField).to have_received(:visible).once+ end+ end++ context "when custom field doesn't exist" do+ let(:custom_field) { nil }++ it "returns the custom field" do+ expect(instance.custom_field).to be_nil+ end++ it "memoizes the custom field" do+ 2.times { instance.custom_field }++ expect(ProjectCustomField).to have_received(:visible).once+ end+ end+ endend