Sha256: d08d8316356eaf738f8b88f26e531200fc30d858d3768426b6dc8871a1a5b3ee

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe "Nesting attribute behavior of RDF resources" do
  before do
    class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
      property :Topic
    end

    class ComplexResource < ActiveFedora::Base
      property :topic, predicate: DummyMADS.Topic, class_name: "ComplexResource::Topic"

      class Topic < ActiveTriples::Resource
        property :subject, predicate: ::RDF::DC.subject
      end
    end
  end

  after do
    Object.send(:remove_const, :ComplexResource)
    Object.send(:remove_const, :DummyMADS)
  end

  subject { ComplexResource.new }

  let(:params) { [{ subject: 'Foo' }, { subject: 'Bar' }] }

  before do
    ComplexResource.accepts_nested_attributes_for *args
    subject.topic_attributes = params
  end

  context "when no options are set" do
    let(:args) { [:topic] }

    it "should set the attributes" do
      expect(subject.topic.size).to eq 2
      expect(subject.topic.map(&:subject)).to eq [['Foo'], ['Bar']]
    end

    it "should mark the attributes as changed" do
      expect(subject.changed_attributes).to eq('topic' => [])
    end
  end

  context "when reject_if is set" do
    let(:args) { [:topic, reject_if: reject_proc] }
    let(:reject_proc) { lambda { |attributes| attributes[:subject] == 'Bar' } }
    let(:params) { [{ subject: 'Foo' }, { subject: 'Bar' }] }

    it "should not add terms for which the proc is true" do
      expect(subject.topic.map(&:subject)).to eq [['Foo']]
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active-fedora-9.5.0 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.4.3 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.4.2 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.4.1 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.4.0 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.3.0 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.2.1 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.2.0 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.2.0.rc2 spec/integration/rdf_nested_attributes_spec.rb
active-fedora-9.2.0.rc1 spec/integration/rdf_nested_attributes_spec.rb