Sha256: 89a693febb33f596a90b230162049f740056d2a8df487fbf35572507e9c3dc39

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require 'resources_spec_helper'

unless sk_available?
  puts "Sorry cannot connect to your SalesKing server, skipping real connections tests. Please check connection settings in spec_helper"
else

  describe Product, "in general" do

    before :all do
      #setup test product to work with
      @product = Product.new(:name=>'Eis am Stiel', :price => 1.50)
      @product.save.should be true
    end

    after :all do
      #delete test product
      @product.destroy
      lambda {
        product = Product.find(@product.id)
      }.should raise_error(ActiveResource::ResourceNotFound)
    end

    it "should create a product" do
      @product.number.should_not be_nil
      @product.price.should == 1.50
      @product.new?.should be false
    end

    it "should fail create a product without name" do
      product = Product.new(:price => 2.50)
      product.save.should == false
      product.errors.count.should == 1
      product.errors.full_messages.should ==  ["Name can't be blank"]
    end

    it "should fail create a product with empty price" do
      product = Product.new(:name => 'No brain', :price =>' ')
      product.save.should be false
      product.errors.full_messages.should ==  ["Price can't be blank", "Price is not a number"]
    end

    it "should find a product by id" do
      product = Product.find(@product.id)
      product.name.should == @product.name
    end

    it "should fail edit a product" do
      @product.name = ''
      @product.save.should == false
      @product.errors.count.should == 1
      if @product.errors.respond_to? :on # TODO kick with AR 2.3
        @product.errors.on(:name).should == "can't be blank"
      else
        @product.errors[:name].should == ["can't be blank"]
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sk_sdk-0.4.3 spec/sk_sdk/resources/product_spec.rb
sk_sdk-0.4.2 spec/sk_sdk/resources/product_spec.rb