Sha256: 21e405a0a285a91c00976ae08526eed038f9b6fbb7db751ec0812bd4ecd28594

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe DattsRight, ".update_definition(key, value)" do
  before do
    reset_database
  end
  
  it "should update attr_key of a definition" do
    c = Category.create
    c.definition = {:robot => {:object_type => "string"}}
    c.update_definition(:robot, :attr_key => "bodi")
    c.definition[:robot].should be_nil
    c.definition[:bodi].should == {:object_type => "string"}
  end

  it "should be able to update the rest (all except attr_key) of the definition" do
    c = Category.create
    c.definition = {:robot => {:object_type => "string", :desc => "hi"}}
    c.update_definition(:robot, :object_type => "integer", :desc => "wyt")
    c.definition[:robot].should == {:object_type => "integer", :desc => "wyt"}
  end

  it "should raise NotDefinedError if it doesn't exist" do
    lambda {Category.create.update_definition(:robot, {})}.should raise_error(DattsRight::NotDefinedError, "robot is not defined")
  end

  it "should raise NoDefinitionError if it doesn't have definition => true" do
    lambda {Page.create.update_definition(:fake, {})}.should raise_error(DattsRight::NoDefinitionError)
  end

  it "should be able to handle if definition is nil" do
    c = Category.create
    c.definition = nil
    c.save
    lambda {c.update_definition(:real, :object_type => "string")}.should raise_error(DattsRight::NotDefinedError)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datts_right-0.0.29 spec/datts_right/update_definition_spec.rb
datts_right-0.0.28 spec/datts_right/update_definition_spec.rb