Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mock finder #2721

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/models/mock_spike_finder_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class MockSpikeFinderDocument < Document
FORMAT_SPECIFIC_FIELDS = %i[
mock_spike_finder_document_facet_one
mock_spike_finder_document_facet_two
].freeze

attr_accessor(*FORMAT_SPECIFIC_FIELDS)

def initialize(params = {})
super(params, FORMAT_SPECIFIC_FIELDS)
end

def self.title
"Mock Spike Finder Document"
end

def primary_publishing_organisation
"af07d5a5-df63-4ddc-9383-6a666845ebe9"
end
end
28 changes: 28 additions & 0 deletions app/views/metadata_fields/_mock_spike_finder_documents.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= render layout: "shared/form_group", locals: { f: f, field: :mock_spike_finder_document_facet_one, label: "Facet 1" } do %>
<%= f.select :mock_spike_finder_document_facet_one,
facet_options(f, :mock_spike_finder_document_facet_one),
{},
{
class: 'select2 form-control',
multiple: true,
data:
{
placeholder: 'Select Facet One'
}
}
%>
<% end %>

<%= render layout: "shared/form_group", locals: { f: f, field: :mock_spike_finder_document_facet_two, label: "Facet 2" } do %>
<%= f.select :mock_spike_finder_document_facet_two,
facet_options(f, :mock_spike_finder_document_facet_two),
{},
{
class: 'select2 form-control',
data:
{
placeholder: 'Select Facet Two'
}
}
%>
<% end %>
46 changes: 46 additions & 0 deletions lib/documents/schemas/mock_spike_finder_documents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"pre-production": true,
"content_id": "66e7df00-5d57-43b5-8fc4-b233db73d787",
"base_path": "/mock-spike-finder",
"format_name": "Mock spike finder",
"name": "Mock spike finder",
"description": "Mock spike finder description",
"summary": "Mock spike finder summary",
"filter": {
"format": "mock_spike_finder_document"
},
"show_summaries": true,
"organisations": ["af07d5a5-df63-4ddc-9383-6a666845ebe9"],
"related": [
"af07d5a5-df63-4ddc-9383-6a666845ebe9"
],
"document_noun": "mock document",
"facets": [
{
"key": "mock_spike_finder_document_facet_one",
"name": "Mock spike finder document facet one",
"short_name": "F1",
"type": "text",
"preposition": "helps with",
"display_as_result_metadata": true,
"filterable": true,
"allowed_values": [
{"label": "Facet one value one", "value": "facet_one_value_one"},
{"label": "Facet one value two", "value": "facet_one_value_two"}
]
},
{
"key": "mock_spike_finder_document_facet_two",
"name": "Mock spike finder document facet two",
"short_name": "F2",
"type": "text",
"preposition": "helps with",
"display_as_result_metadata": true,
"filterable": true,
"allowed_values": [
{"label": "Facet two value one", "value": "facet_two_value_one"},
{"label": "Facet two value two", "value": "facet_two_value_two"}
]
}
]
}
13 changes: 13 additions & 0 deletions spec/fixtures/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@
end
end

factory :mock_spike_finder_document, parent: :document do
base_path { "/mock-spike-finder/example-document" }
document_type { "mock_spike_finder_document" }
transient do
default_metadata do
{
"mock_spike_finder_document_facet_one" => %w[facet_one_value_one],
"mock_spike_finder_document_facet_two" => "facet_two_value_one",
}
end
end
end

factory :marine_equipment_approved_recommendation, parent: :document do
base_path { "/marine-equipment-approved-recommendations/example-document" }
document_type { "marine_equipment_approved_recommendation" }
Expand Down
11 changes: 11 additions & 0 deletions spec/models/mock_spike_finder_document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "spec_helper"
require "models/valid_against_schema"

RSpec.describe MockSpikeFinderDocument do
let(:payload) { FactoryBot.create(:mock_spike_finder_document) }
include_examples "it saves payloads that are valid against the 'specialist_document' schema"

it "is not exportable" do
expect(described_class).not_to be_exportable
end
end
Loading