Sha256: 5ab979f29fced2a15d70be74d6a3ded6a5881af96f2bb31151370f5a5d671560

Contents?: true

Size: 1.84 KB

Versions: 20

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

module Ddr::Models::Structures
  RSpec.describe File, type: :model, structure: true do

    let(:attrs) { { id: 'abc', use: 'efg' } }
    let(:doc) { Ddr::Models::Structure.xml_template }
    let(:node) do
      node = Nokogiri::XML::Node.new('file', doc)
      node['ID'] = attrs[:id]
      node['USE'] = attrs[:use]
      doc.root.add_child(node)
      node
    end

    describe ".build" do
      it "should build the correct node" do
        expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
      end
    end

    describe ".find" do
      let(:structure) { FactoryGirl.build(:simple_structure) }
      it "finds the requested File" do
        expect(File.find(structure, 'def')).to be_a(File)
        expect(File.find(structure, 'def').id).to eq('def')
      end
    end

    describe "effective use" do
      before do
        allow(subject).to receive(:parent) { Nokogiri::XML::Node.new('fileGrp', doc) }
      end
      describe "use attribute present" do
        subject { described_class.new(node) }
        its(:effective_use) { is_expected.to eq(subject.use) }
      end
      describe "use attribute not present" do
        before do
          allow(subject).to receive(:use) { nil }
        end
        describe "parent node has effective use" do
          subject { described_class.new(node) }
          before do
            allow_any_instance_of(FileGrp).to receive(:effective_use) { 'xyz' }
          end
          its(:effective_use) { is_expected.to eq('xyz') }
        end
        describe "parent node does not have an effective use" do
          subject { described_class.new(node) }
          before do
            allow_any_instance_of(FileGrp).to receive(:effective_use) { nil }
          end
          its(:effective_use) { is_expected.to be_nil }
        end
      end
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-2.11.0 spec/models/structures/file_spec.rb
ddr-models-2.10.2 spec/models/structures/file_spec.rb
ddr-models-2.10.1 spec/models/structures/file_spec.rb
ddr-models-2.10.0 spec/models/structures/file_spec.rb
ddr-models-2.10.0.rc2 spec/models/structures/file_spec.rb
ddr-models-2.10.0.rc1 spec/models/structures/file_spec.rb
ddr-models-2.9.2 spec/models/structures/file_spec.rb
ddr-models-2.9.1 spec/models/structures/file_spec.rb
ddr-models-2.9.0 spec/models/structures/file_spec.rb
ddr-models-2.9.0.rc1 spec/models/structures/file_spec.rb
ddr-models-2.8.0 spec/models/structures/file_spec.rb
ddr-models-2.8.0.rc1 spec/models/structures/file_spec.rb
ddr-models-2.7.6 spec/models/structures/file_spec.rb
ddr-models-2.7.5 spec/models/structures/file_spec.rb
ddr-models-2.7.4 spec/models/structures/file_spec.rb
ddr-models-2.7.3 spec/models/structures/file_spec.rb
ddr-models-2.7.2 spec/models/structures/file_spec.rb
ddr-models-2.7.1 spec/models/structures/file_spec.rb
ddr-models-2.7.0 spec/models/structures/file_spec.rb
ddr-models-2.7.0.rc1 spec/models/structures/file_spec.rb