spec/models/spotlight/resources/upload_spec.rb in blacklight-spotlight-0.2.0 vs spec/models/spotlight/resources/upload_spec.rb in blacklight-spotlight-0.3.0

- old
+ new

@@ -8,44 +8,76 @@ end describe '#to_solr' do before do subject.id = "1" subject.data = { - title: "Title Data", - description: "Description Data", - attribution: "Attribution Data", - date: "Date Data", + configured_title_field: "Title Data", + spotlight_upload_description_tesim: "Description Data", + spotlight_upload_attribution_tesim: "Attribution Data", + spotlight_upload_date_tesim: "Date Data", custom_field.field => "Custom Field Data" } allow(subject).to receive(:url).and_return(stub_model(Spotlight::ItemUploader)) allow(subject.url.file).to receive(:file).and_return(File.expand_path(File.join('..', 'fixtures', '800x600.png'), Rails.root)) allow(subject.exhibit).to receive(:blacklight_config).and_return( Blacklight::Configuration.new do |config| config.index.title_field = :configured_title_field - config.index.full_image_field = :configured_full_image_field - config.index.thumbnail_field = :configured_thumbnail_field - config.index.square_image_field = :configured_square_field end ) end + it 'should have the exhibit id and the upload id as the solr id' do expect(subject.to_solr[:id]).to eq "#{subject.exhibit.id}-#{subject.id}" end it 'should have a title field using the exhibit specific blacklight_config' do expect(subject.to_solr[:configured_title_field]).to eq 'Title Data' end + + context "with a custom upload title field" do + let(:custom_title_field) { OpenStruct.new(field_name: :configured_title_field, solr_field: :some_other_field) } + + before do + allow(Spotlight::Engine.config).to receive(:upload_title_field).and_return(custom_title_field) + end + + it "should store the title field in the provided solr field" do + expect(subject.to_solr[:some_other_field]).to eq "Title Data" + end + end + it 'should have the other additional configured fields' do expect(subject.to_solr[Spotlight::Engine.config.uploaded_description_field]).to eq "Description Data" expect(subject.to_solr[Spotlight::Engine.config.uploaded_attribution_field]).to eq "Attribution Data" expect(subject.to_solr[Spotlight::Engine.config.uploaded_date_field]).to eq "Date Data" end + + context "multiple solr field mappings" do + + let :configured_fields do + [ + OpenStruct.new(field_name: 'some_field', solr_field: ['a', 'b']) + ] + end + + before do + allow(subject).to receive(:configured_fields).and_return configured_fields + + subject.data = { 'some_field' => 'value'} + end + + it "should map a single uploaded field to multiple solr fields" do + expect(subject.to_solr['a']).to eq 'value' + expect(subject.to_solr['b']).to eq 'value' + end + end + it 'should have a spotlight_resource_type field' do - expect(subject.to_solr[:spotlight_resource_type_ssm]).to eq 'spotlight/resources/uploads' + expect(subject.to_solr[:spotlight_resource_type_ssim]).to eq 'spotlight/resources/uploads' end it 'should have the various image fields' do - expect(subject.to_solr).to have_key :configured_full_image_field - expect(subject.to_solr).to have_key :configured_thumbnail_field - expect(subject.to_solr).to have_key :configured_square_field + expect(subject.to_solr).to have_key Spotlight::Engine.config.full_image_field + expect(subject.to_solr).to have_key Spotlight::Engine.config.thumbnail_field + expect(subject.to_solr).to have_key Spotlight::Engine.config.square_image_field end it 'should have the full image dimensions fields' do expect(subject.to_solr[:spotlight_full_image_height_ssm]).to eq 600 expect(subject.to_solr[:spotlight_full_image_width_ssm]).to eq 800 end