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-11.0.0.rc6 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.2.1 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.0.0.rc5 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.0.0.rc4 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.2.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.0.0.rc3 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.0.0.rc2 spec/integration/nested_hash_resources_spec.rb
active-fedora-11.0.0.rc1 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.1.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.1.0.rc1 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.7.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.0.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.0.0.beta4 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.0.0.beta3 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.0.0.beta2 spec/integration/nested_hash_resources_spec.rb
active-fedora-10.0.0.beta1 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.13.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.12.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.11.0 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.10.4 spec/integration/nested_hash_resources_spec.rb