Skip to content

Commit

Permalink
move object factory specs to all be in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Nov 9, 2023
1 parent 2e2fbfe commit 6cc6abc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
35 changes: 2 additions & 33 deletions spec/factories/bulkrax/object_factory_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Bulkrax::ObjectFactory do
# Why aren't there more tests? In part because so much of the ObjectFactory require that we boot
# up Fedora and SOLR; something that remains non-desirous due to speed.
describe "#transform_attributes" do
context 'default behavior' do
it "does not empty arrays that only have empty values" do
attributes = { empty_array: ["", ""], empty_string: "", filled_array: ["A", "B"], filled_string: "A" }
factory = described_class.new(attributes: attributes,
source_identifier_value: 123,
work_identifier: "filled_string",
work_identifier_search_field: 'filled_string_sim')
factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string]
expect(factory.send(:transform_attributes)).to eq(attributes.stringify_keys)
end
end

context 'when :transformation_removes_blank_hash_values = true' do
it "empties arrays that only have empty values" do
attributes = { empty_array: ["", ""], empty_string: "", filled_array: ["A", "B"], filled_string: "A" }
factory = described_class.new(attributes: attributes,
source_identifier_value: 123,
work_identifier: "filled_string",
work_identifier_search_field: 'filled_string_sim')
factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string]
factory.transformation_removes_blank_hash_values = true
expect(factory.send(:transform_attributes))
.to eq({ empty_array: [], empty_string: nil, filled_array: ["A", "B"], filled_string: "A" }.stringify_keys)
end
end
end
end
# NOTE: do not put any specs here. FactoryBot autoloads every ruby file in spec/factories so even through it better
# mirrors the app/ path, we put the ObjectFactory specs in spec/models/bulkrax/object_factory_spec.rb
31 changes: 31 additions & 0 deletions spec/models/bulkrax/object_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,42 @@
module Bulkrax
# NOTE: Unable to put this file in spec/factories/bulkrax (where it would mirror the path in app/) because
# (presumably) FactoryBot autoloads all files in spec/factories, which would always run this spec.
# Why aren't there more tests? In part because so much of the ObjectFactory require that we boot
# up Fedora and SOLR; something that remains non-desirous due to speed.

RSpec.describe ObjectFactory do
subject(:object_factory) { build(:object_factory) }

describe 'is capable of looking up records dynamically' do
include_examples 'dynamic record lookup'
end

describe "#transform_attributes" do
context 'default behavior' do
it "does not empty arrays that only have empty values" do
attributes = { empty_array: ["", ""], empty_string: "", filled_array: ["A", "B"], filled_string: "A" }
factory = described_class.new(attributes: attributes,
source_identifier_value: 123,
work_identifier: "filled_string",
work_identifier_search_field: 'filled_string_sim')
factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string]
expect(factory.send(:transform_attributes)).to eq(attributes.stringify_keys)
end
end

context 'when :transformation_removes_blank_hash_values = true' do
it "empties arrays that only have empty values" do
attributes = { empty_array: ["", ""], empty_string: "", filled_array: ["A", "B"], filled_string: "A" }
factory = described_class.new(attributes: attributes,
source_identifier_value: 123,
work_identifier: "filled_string",
work_identifier_search_field: 'filled_string_sim')
factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string]
factory.transformation_removes_blank_hash_values = true
expect(factory.send(:transform_attributes))
.to eq({ empty_array: [], empty_string: nil, filled_array: ["A", "B"], filled_string: "A" }.stringify_keys)
end
end
end
end
end

0 comments on commit 6cc6abc

Please sign in to comment.