Sha256: c0fee800ad7166fe8dbd2a009082ae9d61dabaea046cfea2c7193990195f8e19

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require './spec/spec_helper'
require "./lib/mass_insert"

describe "Decimal" do

  before :each do
    @values, @options  = [{:money => 20.50}], {}
  end

  context "when exist in values hashes" do
    context "when contains an integer" do
      it "should convert integer value to decimal" do
        @values.first.merge!(:money => 10)
        User.mass_insert(@values, @options)
        User.last.money.should eq(10.0)
      end
    end

    context "when contains a string" do
      it "should convert string value to decimal" do
        @values.first.merge!(:money => "string")
        User.mass_insert(@values, @options)
        User.last.money.should eq(0.0)
      end
    end

    context "when contains a decimal" do
      it "should save the correct value" do
        User.mass_insert(@values, @options)
        User.last.money.should eq(20.50)
      end
    end

    context "when contains a boolean" do
      it "should raise an exception" do
        @values.first.merge!(:money => true)
        lambda{ User.mass_insert(@values, @options) }.should raise_exception
      end
    end
  end

  context "when not exist in values hashes" do
    it "should save the default value" do
      @values.first.delete(:money)
      User.mass_insert(@values, @options)
      User.last.money.should eq(nil)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mass_insert-0.0.3 spec/active_record_models/column_types/decimal_spec.rb
mass_insert-0.0.2 spec/active_record_models/column_types/decimal_spec.rb
mass_insert-0.0.1 spec/active_record_models/column_types/decimal_spec.rb