require 'spec_helper' def mods_display_access_condition(mods_record) ModsDisplay::AccessCondition.new( mods_record, ModsDisplay::Configuration::AccessCondition.new, double('controller') ) end def mods_display_non_ignore_access_condition(mods_record) ModsDisplay::AccessCondition.new( mods_record, ModsDisplay::Configuration::AccessCondition.new { display! }, double('controller') ) end describe ModsDisplay::AccessCondition do include AccessConditionFixtures before :all do @access_condition = Stanford::Mods::Record.new.from_str(simple_access_condition_fixture, false).accessCondition @restrict_condition = Stanford::Mods::Record.new.from_str(restricted_access_fixture, false).accessCondition @copyright_note = Stanford::Mods::Record.new.from_str(copyright_access_fixture, false).accessCondition @cc_license_note = Stanford::Mods::Record.new.from_str(cc_license_fixture, false).accessCondition @odc_license_note = Stanford::Mods::Record.new.from_str(odc_license_fixture, false).accessCondition @no_link_license_note = Stanford::Mods::Record.new.from_str(no_license_fixture, false).accessCondition end describe 'labels' do it 'should normalize types and assign proper labels' do fields = mods_display_access_condition(@restrict_condition).fields expect(fields.length).to eq(1) expect(fields.first.label).to eq('Restriction on access:') fields.first.values.each_with_index do |value, index| expect(value).to match(/^Restrict Access Note#{index + 1}/) end end end describe 'fields' do describe 'copyright' do it "should replace instances of '(c) copyright' with the HTML copyright entity" do fields = mods_display_access_condition(@copyright_note).fields expect(fields.length).to eq(1) expect(fields.first.values.length).to eq(1) expect(fields.first.values.first).to eq( 'This is a © Note. Single instances of © should also be replaced in these notes.' ) end end describe 'licenses' do it 'should add the appropriate classes to the html around the license' do fields = mods_display_access_condition(@no_link_license_note).fields expect(fields.length).to eq(1) expect(fields.first.values.length).to eq(1) expect(fields.first.values.first).to match(%r{^