spec/model_spec.rb in cistern-0.1.4 vs spec/model_spec.rb in cistern-0.2.0

- old
+ new

@@ -28,10 +28,14 @@ attribute :list, type: :array attribute :number, type: :integer attribute :floater, type: :float attribute :butternut, type: :integer, aliases: "squash", squash: "id" attribute :custom, parser: lambda{|v, opts| "X!#{v}"} + + def save + requires :flag + end end it "should parse string" do TypeSpec.new(name: 1).name.should == "1" end @@ -72,8 +76,18 @@ TypeSpec.new({"squash" => {"id" => "12"}}).butternut.should == 12 end it "should slice out unaccounted for attributes" do TypeSpec.new({"something" => {"id" => "12"}}).attributes.keys.should_not include("something") + end + + describe "#requires" do + it "should raise if attribute not provided" do + lambda { TypeSpec.new({"connection" => "fake", "something" => {"id" => "12"}}).save }.should raise_exception(ArgumentError) + end + + it "should raise if attribute is provided and is nil" do + lambda { TypeSpec.new({"connection" => "fake", "custom" => nil}).save }.should raise_exception(ArgumentError) + end end end end