Sha256: 11cae0e4a4ec88cea8bd27cbe8619f16fc225573e6e2c59989bf263612ad2ab0

Contents?: true

Size: 1.05 KB

Versions: 73

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe "nested hash resources" do
  before do
    class NestedResource < ActiveTriples::Resource
      property :title, predicate: ::RDF::Vocab::DC.title
      ## Necessary to get AT to create hash URIs.
      def initialize(uri, parent)
        if uri.try(:node?)
          uri = RDF::URI("#nested_#{uri.to_s.gsub('_:', '')}")
        elsif uri.start_with?("#")
          uri = RDF::URI(uri)
        end
        super
      end

      def final_parent
        parent
      end
    end
    class ExampleOwner < ActiveFedora::Base
      property :relation, predicate: ::RDF::Vocab::DC.relation, class_name: NestedResource
      accepts_nested_attributes_for :relation
    end
  end
  after do
    Object.send(:remove_const, :NestedResource)
    Object.send(:remove_const, :ExampleOwner)
  end
  it "is able to nest resources" do
    obj = ExampleOwner.new
    obj.attributes = {
      relation_attributes: [
        {
          title: "Test"
        }
      ]
    }
    obj.save!

    expect(obj.reload.relation.first.title).to eq ["Test"]
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.2.3 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.5.6 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.2.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.2.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.2.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.0.3 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.5.5 spec/integration/nested_hash_resources_spec.rb
active-fedora-13.1.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-13.1.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-13.1.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-13.0.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.1.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.1.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.5.4 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.5.3 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.0.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.0.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.5.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-12.0.0 spec/integration/nested_hash_resources_spec.rb