require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DattsRight, ".add_definition(key, value)" do before do reset_database end it "should add a definition to the existing definition" do c = Category.create c.definition = {:robot => {:object_type => "string"}} c.save c.add_definition(:name, :object_type => "string", :description => "This is great") c.save c.definition[:name].should == {:object_type => "string", :description => "This is great"} end it "should raise DattsRight::AttributeAlreadyExists if the attribute is already there" do c = Category.create c.definition = {:robot => {:object_type => "string"}} c.save lambda {c.add_definition(:robot, "whatever")}.should raise_error(DattsRight::AlreadyDefined, "robot is already defined") end it "should raise NoMethodError if it doesn't have definition => true" do lambda {Page.create.add_definition(:fake, :object_type => "string")}.should raise_error(DattsRight::NoDefinitionError) end end