Sha256: f02fe7eb0b52b9c8a9485c7cf3af8dbc22186105de4c8b6f0960e446ec07ccdb

Contents?: true

Size: 1.94 KB

Versions: 19

Compression:

Stored size: 1.94 KB

Contents

require "spec_helper"
require "rack/test/uploaded_file"
require "time"

describe ActiveMetadata do

  context "class methods" do

    it "should exist a method acts_as_metadata in the model" do
      Document.respond_to?(:acts_as_metadata).should be_true
    end

    it "should find the ancestors if no ancestors params has been provided" do
      @document = Document.create! { |d| d.name = "John" }
      @document.metadata_id.should eq @document.id
      @document.metadata_class.should eq @document.class.to_s
    end

    it "should find the metadata_root.id if an ancestors params has been specified and persists_ancestor is true" do
      @document = Document.create! { |d| d.name = "John" }
      @section = @document.create_section :title => "new section"
      @section.metadata_id.should eq @document.id
      @section.metadata_class.should eq @document.class.to_s
    end

  end

  context "saving a child object before active_metadata_ancestors" do

    it "should raise an exception cause ancestor id is not defined" do
      lambda{Section.create! :title => 'section title'}.should raise_error(RuntimeError,"[active_metdata] - Ancestor model is not yet persisted")
    end

  end

  context "ancestors" do

    it "should return the base instance class following the ancestor chain" do
      @document = Document.create! { |d| d.name = "John" }
      @chapter = Chapter.create(title: "title")
      @section = @document.create_section
      @section.metadata_id(true).should eq @document.id
      @section.metadata_class(true).should eq "Document"
    end

    it "should return the base instance class following the ancestor chain passing has_many associations" do
      @document = Document.create! { |d| d.name = "John" }
      @chapter = Chapter.create(title: "title")
      @section = @document.create_section chapter_id: @chapter.id

      @chapter.metadata_id(true).should eq @document.id
      @chapter.metadata_class(true).should eq "Document"
    end

  end


end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
active_metadata-0.8.9 spec/lib/active_metadata_spec.rb
active_metadata-0.8.8 spec/lib/active_metadata_spec.rb
active_metadata-0.8.7.1 spec/lib/active_metadata_spec.rb
active_metadata-0.8.7 spec/lib/active_metadata_spec.rb
active_metadata-0.8.6 spec/lib/active_metadata_spec.rb
active_metadata-0.8.5.2 spec/lib/active_metadata_spec.rb
active_metadata-0.8.5.1 spec/lib/active_metadata_spec.rb
active_metadata-0.8.5 spec/lib/active_metadata_spec.rb
active_metadata-0.8.4 spec/lib/active_metadata_spec.rb
active_metadata-0.8.3.1 spec/lib/active_metadata_spec.rb
active_metadata-0.8.3 spec/lib/active_metadata_spec.rb
active_metadata-0.8.2 spec/lib/active_metadata_spec.rb
active_metadata-0.8.1 spec/lib/active_metadata_spec.rb
active_metadata-0.8.0 spec/lib/active_metadata_spec.rb
active_metadata-0.7.9 spec/lib/active_metadata_spec.rb
active_metadata-0.7.8 spec/lib/active_metadata_spec.rb
active_metadata-0.7.7 spec/lib/active_metadata_spec.rb
active_metadata-0.7.6 spec/lib/active_metadata_spec.rb
active_metadata-0.7.5 spec/lib/active_metadata_spec.rb