require 'spec_helper' describe CurationConcerns::Renderers::AttributeRenderer do let(:field) { :name } let(:renderer) { described_class.new(field, ['Bob', 'Jessica']) } let(:yml_path) { File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'locales', '*.{rb,yml}') } before do I18n.load_path += Dir[File.join(yml_path)] I18n.reload! end after do I18n.load_path -= Dir[File.join(yml_path)] I18n.reload! end describe "#attribute_to_html" do subject { Nokogiri::HTML(renderer.render) } let(:expected) { Nokogiri::HTML(tr_content) } context 'without microdata enabled' do before do allow(CurationConcerns.config).to receive(:display_microdata).and_return(false) end let(:tr_content) { "Name\n" \ "" } it { expect(renderer).not_to be_microdata(field) } it { expect(subject).to be_equivalent_to(expected) } end context 'with an integer attribute' do let(:field) { :height } let(:renderer) { described_class.new(field, [567]) } let(:tr_content) do "Height\n" \ "" end it { expect(subject).to be_equivalent_to(expected) } end context 'with microdata enabled' do let(:tr_content) { "Name\n" \ "" } it { expect(renderer).to be_microdata(field) } it { expect(subject).to be_equivalent_to(expected) } end context 'with links and < characters' do let(:field) { :description } let(:renderer) { described_class.new(field, ['Foo < Bar http://www.example.com. & More Text']) } let(:tr_content) do "Description\n" \ "" end it { expect(subject).to be_equivalent_to(expected) } end end end