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::Orders::CustomFieldOrder#custom_field
Ivan Kuchin244a69cd2fbc
diff --git a/spec/models/queries/projects/orders/custom_field_order_spec.rb b/spec/models/queries/projects/orders/custom_field_order_spec.rbindex 47816576cd2..4e87d93e5fa 100644--- a/spec/models/queries/projects/orders/custom_field_order_spec.rb+++ b/spec/models/queries/projects/orders/custom_field_order_spec.rb@@ -85,4 +85,49 @@ RSpec.describe Queries::Projects::Orders::CustomFieldOrder doendendend++ describe "#custom_field" do+ let(:instance) { described_class.new(name) }+ let(:name) { "cf_42" }+ let(:id) { 42 }++ before do+ where = double+ where_not = double+ visible = double++ allow(ProjectCustomField).to receive(:where).and_return(where)+ allow(where).to receive(:not).with(field_format: %w[text]).and_return(where_not)+ allow(where_not).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(:where).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(:where).once+ end+ end+ endend