Sha256: b3b8f274024d57ee368e86dc510597628ef85beee010e7b43b8b73f8340fdc41

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

describe "nested hash resources" do
  before do
    class NestedResource < ActiveTriples::Resource
      property :title, predicate: ::RDF::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::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

2 entries across 2 versions & 1 rubygems

Version Path
active-fedora-9.6.2 spec/integration/nested_hash_resources_spec.rb
active-fedora-9.6.1 spec/integration/nested_hash_resources_spec.rb