spec/candy_spec.rb in candy-0.0.2 vs spec/candy_spec.rb in candy-0.1.0

- old
+ new

@@ -42,10 +42,33 @@ @this.licks = 7 @this.center = 0.5 @this.licks.should == 7 end + it "can set properties explicity" do + @this.set(:licks, 17) + @this.licks.should == 17 + end + + it "can set properties from a hash" do + @this.set(:licks => 19, :center => -2.5) + @this.licks.should == 19 + @this.center.should == -2.5 + end + + it "wraps objects" do + o = Object.new + @this.object = o + @verifier.find_one["object"]["__object_"]["class"].should == "Object" + end + + it "unwraps objects" do + @verifier.update({:_id => @this.id}, {:center => {"__object_" => {:class => "Object", :ivars => {"@foo" => "bar"}}}}) + @this.center.should be_an(Object) + @this.center.instance_variable_get(:@foo).should == "bar" + end + describe "retrieval" do it "can find a record by its ID" do @this.licks = 10 that = Zagnut.find(@this.id) that.licks.should == 10 @@ -108,9 +131,72 @@ those.collect{|z| z.weight}.should == [-5, 11.8] end end + describe "arrays" do + it "can push items" do + @this.push(:colors, 'red') + @this.colors.should == ['red'] + end + + it "can push an array of items" do + @this.push(:potpourri, 'red', 75, nil) + @this.potpourri.should == ['red', 75, nil] + end + end + + describe "numbers" do + it "can be incremented by 1 when not set" do + @this.inc(:bites) + @this.bites.should == 1 + end + + it "can be incremented by 1 when set" do + @this.bites = 11 + @this.inc(:bites) + @this.bites.should == 12 + end + + it "can be incremented by any number" do + @this.bites = -6 + @this.inc(:bites, 15) + @this.bites.should == 9 + end + end + + describe "timestamp" do + it "can be set on creation" do + Zagnut.class_eval("timestamp :create") + z = Zagnut.new + z.created_at.should be_a(Time) + z.updated_at.should be_nil + end + + it "can be set on modification" do + Zagnut.class_eval("timestamp :update") + z = Zagnut.new + z.created_at.should be_nil + z.updated_at.should be_nil + z.bites = 11 + z.created_at.should be_nil + z.updated_at.should be_a(Time) + end + + it "sets both by default" do + Zagnut.class_eval("timestamp") + z = Zagnut.new + z.bites = 11 + z.created_at.should be_a(Time) + z.updated_at.should be_a(Time) + end + + + after(:each) do + Zagnut.class_eval("timestamp nil") + end + + end after(:each) do Zagnut.collection.remove end