Sha256: f4757baf1dbdd748a016bbbc02d8fe3ca7916dad3d26b03eabe8dfd9163a02b6

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

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

describe DattsRight, ".add_definitions(hash)" do
  before do
    reset_database
  end
  
  it "should add a definition to the existing definition" do
    c = Category.create
    c.should_receive(:add_definition).with(:robot, :object_type => "text")
    c.should_receive(:add_definition).with(:another, :object_type => "string")
    c.add_definitions(:robot => {:object_type => "text"}, :another => {:object_type => "string"})
  end

  it "should accept 'flat' hashes in an array (straight from a form)" do
    # [{"name"=>"A key", "description"=>"asd", "attr_key"=>"a_key"}, {"name"=>"A key", "description"=>"asd", "attr_key"=>"b_key"}]
    c = Category.create
    c.should_receive(:add_definition).with(:a_key, {"name"=>"A key"})
    c.should_receive(:add_definition).with(:b_key, {"name"=>"B key"})
    c.add_definitions({"name"=>"A key", "attr_key"=>"a_key"}, {"name"=>"B key", "attr_key"=>"b_key"})
    c = Category.create
    c.should_receive(:add_definition).with(:a_key, {"name"=>"A key"})
    c.should_receive(:add_definition).with(:b_key, {"name"=>"B key"})
    c.add_definitions([{"name"=>"A key", "attr_key"=>"a_key"}, {"name"=>"B key", "attr_key"=>"b_key"}])
  end

  # HashWithIndifferentAccess is something Rails seems to use for the params hash
  it "should work with HashWithIndifferentAccess" do
    hash = ActiveSupport::HashWithIndifferentAccess.new("name"=>"A key", "attr_key"=>"a_key")
    c = Category.create
    lambda {c.add_definitions(hash)}.should_not raise_error(NoMethodError)
  end

  it "should not explode if nil is passed" do
    lambda {Category.create.add_definitions(nil)}.should_not raise_error(NoMethodError)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datts_right-0.0.32 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.31 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.30 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.29 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.28 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.27 spec/datts_right/add_definitions_spec.rb
datts_right-0.0.26 spec/datts_right/add_definitions_spec.rb