diff --git a/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb b/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb index ca1300f8..bb8b25aa 100644 --- a/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb +++ b/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb @@ -23,6 +23,14 @@ def to_markdown body.map(&:to_markdown).join("\n") end + def to_rdoc + body.map(&:to_rdoc).join("\n") + end + + def to_yard + body.map(&:to_yard).join("\n") + end + def to_default body.map(&:to_default).join("\n") end diff --git a/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb b/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb index cacb0c48..1f8a8f31 100644 --- a/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb +++ b/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb @@ -23,6 +23,14 @@ def to_markdown body.map(&:to_markdown).join("\n") end + def to_rdoc + body.map(&:to_rdoc).join("\n") + end + + def to_yard + body.map(&:to_yard).join("\n") + end + def to_default body.map(&:to_default).join("\n") end diff --git a/lib/annotate_rb/model_annotator/index_annotation/annotation.rb b/lib/annotate_rb/model_annotator/index_annotation/annotation.rb index c735782b..4cdd39c8 100644 --- a/lib/annotate_rb/model_annotator/index_annotation/annotation.rb +++ b/lib/annotate_rb/model_annotator/index_annotation/annotation.rb @@ -23,6 +23,14 @@ def to_markdown body.map(&:to_markdown).join("\n") end + def to_rdoc + body.map(&:to_rdoc).join("\n") + end + + def to_yard + body.map(&:to_yard).join("\n") + end + def to_default body.map(&:to_default).join("\n") end diff --git a/spec/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder_spec.rb b/spec/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder_spec.rb index aa36f83e..dfc413db 100644 --- a/spec/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder_spec.rb +++ b/spec/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder_spec.rb @@ -7,6 +7,8 @@ subject { described_class.new(model, options).build } let(:default_format) { subject.to_default } let(:markdown_format) { subject.to_markdown } + let(:yard_format) { subject.to_yard } + let(:rdoc_format) { subject.to_rdoc } let(:model) do instance_double( @@ -94,5 +96,41 @@ it { expect(default_format).to be_nil } end + + context "using yard format" do + let(:expected_result) do + <<~RESULT.strip + # + # Check Constraints + # + # alive (age < 150) + # missing_expression + # multiline_test (CASE WHEN (age >= 18) THEN (age <= 21) ELSE true END) + # must_be_adult (age >= 18) + RESULT + end + + it "annotates the check constraints" do + expect(yard_format).to eq(expected_result) + end + end + + context "using rdoc format" do + let(:expected_result) do + <<~RESULT.strip + # + # Check Constraints + # + # alive (age < 150) + # missing_expression + # multiline_test (CASE WHEN (age >= 18) THEN (age <= 21) ELSE true END) + # must_be_adult (age >= 18) + RESULT + end + + it "annotates the check constraints" do + expect(rdoc_format).to eq(expected_result) + end + end end end diff --git a/spec/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder_spec.rb b/spec/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder_spec.rb index f26e4902..f46db1bb 100644 --- a/spec/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder_spec.rb +++ b/spec/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder_spec.rb @@ -7,6 +7,8 @@ subject { described_class.new(model, options).build } let(:default_format) { subject.to_default } let(:markdown_format) { subject.to_markdown } + let(:yard_format) { subject.to_yard } + let(:rdoc_format) { subject.to_rdoc } let(:model) do klass = begin @@ -155,5 +157,43 @@ it { expect(markdown_format).to eq(expected_output) } end end + + describe "#to_yard" do + let(:foreign_keys) do + [mock_foreign_key("fk_rails_cf2568e89e", "foreign_thing_id", "foreign_things")] + end + + let(:expected_output) do + <<~OUTPUT.strip + # + # Foreign Keys + # + # fk_rails_cf2568e89e (foreign_thing_id => foreign_things.id) + OUTPUT + end + + it "returns annotation in yard format" do + expect(yard_format).to eq(expected_output) + end + end + + describe "#to_rdoc" do + let(:foreign_keys) do + [mock_foreign_key("fk_rails_cf2568e89e", "foreign_thing_id", "foreign_things")] + end + + let(:expected_output) do + <<~OUTPUT.strip + # + # Foreign Keys + # + # fk_rails_cf2568e89e (foreign_thing_id => foreign_things.id) + OUTPUT + end + + it "returns annotation in rdoc format" do + expect(rdoc_format).to eq(expected_output) + end + end end end diff --git a/spec/lib/annotate_rb/model_annotator/index_annotation/annotation_builder_spec.rb b/spec/lib/annotate_rb/model_annotator/index_annotation/annotation_builder_spec.rb index af814634..eb4c51e9 100644 --- a/spec/lib/annotate_rb/model_annotator/index_annotation/annotation_builder_spec.rb +++ b/spec/lib/annotate_rb/model_annotator/index_annotation/annotation_builder_spec.rb @@ -7,6 +7,8 @@ subject { described_class.new(model, options).build } let(:default_format) { subject.to_default } let(:markdown_format) { subject.to_markdown } + let(:yard_format) { subject.to_yard } + let(:rdoc_format) { subject.to_rdoc } let(:model) do klass = begin @@ -163,5 +165,43 @@ expect(default_format).to eq(expected_result) end end + + describe "#to_yard" do + let(:indexes) do + [mock_index("index_rails_02e851e3b7", columns: ["id"])] + end + + let(:expected_result) do + <<~EOS.strip + # + # Indexes + # + # index_rails_02e851e3b7 (id) + EOS + end + + it "returns annotation in yard format" do + expect(yard_format).to eq(expected_result) + end + end + + describe "#to_rdoc" do + let(:indexes) do + [mock_index("index_rails_02e851e3b7", columns: ["id"])] + end + + let(:expected_result) do + <<~EOS.strip + # + # Indexes + # + # index_rails_02e851e3b7 (id) + EOS + end + + it "returns annotation in rdoc format" do + expect(rdoc_format).to eq(expected_result) + end + end end end