|
11 | 11 | GroupForm.create!(form_id: 4, group:) |
12 | 12 | end |
13 | 13 |
|
| 14 | + describe "Constraint" do |
| 15 | + it "returns true if given the name of a defined report in slug format" do |
| 16 | + expect(described_class::Constraint.matches?(OpenStruct.new(params: { report: "forms-with-routes" }))).to be true |
| 17 | + expect(described_class::Constraint.matches?(OpenStruct.new(params: { report: "questions-with-add-another-answer" }))).to be true |
| 18 | + end |
| 19 | + |
| 20 | + it "returns false if names does not match a defined report" do |
| 21 | + expect(described_class.matches_report?(OpenStruct.new(params: { report: "report" }))).to be false |
| 22 | + expect(described_class.matches_report?(OpenStruct.new(params: { report: "inspect" }))).to be false |
| 23 | + expect(described_class.matches_report?(OpenStruct.new(params: { report: "display" }))).to be false |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe ".matches_report?" do |
| 28 | + it "returns true if given the name of a defined report" do |
| 29 | + expect(described_class.matches_report?(:forms_with_routes)).to be true |
| 30 | + expect(described_class.matches_report?(:questions_with_add_another_answer)).to be true |
| 31 | + end |
| 32 | + |
| 33 | + it "returns false if names does not match a defined report" do |
| 34 | + expect(described_class.matches_report?(:report)).to be false |
| 35 | + expect(described_class.matches_report?(:inspect)).to be false |
| 36 | + expect(described_class.matches_report?(:display)).to be false |
| 37 | + end |
| 38 | + end |
| 39 | + |
14 | 40 | describe "#report" do |
15 | 41 | it "returns the feature report" do |
16 | 42 | report = described_class.new(form_documents).report |
|
44 | 70 | }, |
45 | 71 | }) |
46 | 72 | end |
| 73 | + |
| 74 | + context "with the name of a feature report" do |
| 75 | + it "returns that report" do |
| 76 | + report = [] |
| 77 | + feature_report_service = described_class.new(form_documents) |
| 78 | + allow(feature_report_service).to receive(:forms_with_routes).and_return report |
| 79 | + |
| 80 | + expect(feature_report_service.report(:forms_with_routes)).to be report |
| 81 | + |
| 82 | + expect(feature_report_service).to have_received(:forms_with_routes) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "with the name of a method that is not a feature report" do |
| 87 | + it "raises an error" do |
| 88 | + feature_report_service = described_class.new(form_documents) |
| 89 | + allow(feature_report_service).to receive(:display) |
| 90 | + |
| 91 | + expect { feature_report_service.report(:display) }.to raise_error(/not a defined report/) |
| 92 | + |
| 93 | + expect(feature_report_service).not_to have_received(:display) |
| 94 | + end |
| 95 | + end |
47 | 96 | end |
48 | 97 |
|
49 | 98 | describe "#questions" do |
|
0 commit comments