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 6d8da68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ def set_nested_facet_attributes(attrs)
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 6d8da68

Please sign in to comment.