Sha256: 12aa10bf3de75dc184a94b91b70907d0c19e996491038c7c018932e5f12e7d09

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe "delegating properties" do
  describe "that have a reader and writer" do
    before :all do
      class TitledObject < ActiveFedora::Base
        has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
          m.field "title", :string
        end
        delegate :title, to: 'foo', multiple: false
      end
    end
    after :all do
      Object.send(:remove_const, :TitledObject)
    end

    describe "save" do
      subject do
        obj = TitledObject.create 
        obj.title = "Hydra for Dummies"
        obj.save
        obj
      end
      it "should keep a list of changes after a successful save" do
        subject.previous_changes.should_not be_empty
        subject.previous_changes.keys.should include("title")
      end
      it "should clean out changes" do
        subject.title_changed?.should be_false
        subject.changes.should be_empty
      end
    end
  end

  describe "that only have a writer" do
    before :all do
      class TestDatastream < ActiveFedora::NtriplesRDFDatastream
        # accepts_nested_attributes_for :title, would generate a method like this:
        def title_attributes=(attributes)
        end
      end
      class TitledObject < ActiveFedora::Base
        has_metadata 'foo', type: TestDatastream
        delegate :title_attributes, to: 'foo', multiple: false
      end
    end
    after :all do
      Object.send(:remove_const, :TitledObject)
      Object.send(:remove_const, :TestDatastream)
    end

    subject { TitledObject.new }

    it "Should delegate the method" do
      subject.title_attributes = {'0' => {'title' => 'Hello'}}
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-6.7.8 spec/integration/delegating_spec.rb
active-fedora-6.7.7 spec/integration/delegating_spec.rb
active-fedora-6.7.6 spec/integration/delegating_spec.rb
active-fedora-6.7.5 spec/integration/delegating_spec.rb
active-fedora-6.7.4 spec/integration/delegating_spec.rb
active-fedora-6.7.3 spec/integration/delegating_spec.rb
active-fedora-6.7.2 spec/integration/delegating_spec.rb
active-fedora-6.7.1 spec/integration/delegating_spec.rb
active-fedora-6.7.0 spec/integration/delegating_spec.rb
active-fedora-6.7.0.rc1 spec/integration/delegating_spec.rb
active-fedora-6.6.1 spec/integration/delegating_spec.rb