Skip to content

Commit

Permalink
Add nil/blank checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraghiorghisor-tw committed Feb 12, 2025
1 parent 634a687 commit e54bcc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,19 @@ def self.apply_validations
private

def set_nested_facet_attributes(attrs)
byebug

Check failure on line 399 in app/models/document.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Lint/Debugger: Remove debugger entry point `byebug`.
nested_facets = finder_schema.facets.select { |f| f.dig("specialist_publisher_properties", "nested_facet") == true }
nested_facets.each do |nested_facet|
nested_facet_values = param_value(attrs, nested_facet["key"])
main_facet_value = []
sub_facet_value = []
nested_facet_values.each do |main_and_sub_tuple|
nested_facet_values&.each do |main_and_sub_tuple|
parsed_tuple = JSON.parse(main_and_sub_tuple)
main_facet_value << parsed_tuple["main_facet_value"]
sub_facet_value << parsed_tuple["sub_facet_value"]
end
public_send(:"#{clean_key(nested_facet['key'].to_s)}=", main_facet_value.uniq)
public_send(:"#{clean_key(nested_facet['sub_facet_key']&.to_s)}=", sub_facet_value.uniq)
public_send(:"#{clean_key(nested_facet['key'].to_s)}=", main_facet_value.uniq) if main_facet_value.any?
public_send(:"#{clean_key(nested_facet['sub_facet_key']&.to_s)}=", sub_facet_value.uniq) if sub_facet_value.any?
end
end

Expand Down
15 changes: 14 additions & 1 deletion spec/models/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ def initialize(params = {})
describe "validations" do
subject { Document.from_publishing_api(payload) }

before do
allow(FinderSchema).to receive(:load_from_schema)
end

context "when the document is a draft" do
let(:payload) { FactoryBot.create(:document) }

Expand Down Expand Up @@ -626,6 +630,8 @@ def initialize(params = {})

describe "when called on a class that mismatches the document_type" do
it "raises a helpful error" do
allow(FinderSchema).to receive(:load_from_schema).and_return(finder_schema)

expect {
CmaCase.find(document.content_id, document.locale)
}.to raise_error(/wrong type/)
Expand All @@ -636,6 +642,10 @@ def initialize(params = {})
describe "attachment methods" do
let(:attachment) { Attachment.new }

before do
allow(FinderSchema).to receive(:load_from_schema)
end

describe "#attachments=" do
it "creates an AttachmentCollection with the given attachments" do
subject.attachments = [attachment]
Expand Down Expand Up @@ -691,7 +701,10 @@ def initialize(params = {})
end

describe "#set_temporary_update_type!" do
before { subject.publication_state = "published" }
before do
allow(FinderSchema).to receive(:load_from_schema)
subject.publication_state = "published"
end

context "when the document has an update_type" do
before do
Expand Down

0 comments on commit e54bcc5

Please sign in to comment.