Sha256: 5a35693b7a7b077c06d9ec2aa81be2ffad5da09af69155b9ec68e8f581bc060e

Contents?: true

Size: 1.29 KB

Versions: 50

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"

describe Mongoid::Field do

  describe "#default" do

    before do
      @field = Mongoid::Field.new(:score, :default => 0)
    end

    it "returns the default option" do
      @field.default.should == 0
    end

  end

  describe "#name" do

    before do
      @field = Mongoid::Field.new(:score, :default => 0)
    end

    it "returns the name" do
      @field.name.should == :score
    end

  end

  describe "#type" do

    before do
      @field = Mongoid::Field.new(:name)
    end

    it "defaults to String" do
      @field.type.should == String
    end

  end

  describe "#set" do

    before do
      @type = mock
      @field = Mongoid::Field.new(:score, :default => 10, :type => @type)
    end

    context "nil is provided" do

      it "returns the default value" do
        @field.set(nil).should == 10
      end

    end

    context "value is provided" do

      it "sets the value" do
        @type.expects(:set).with("30").returns(30)
        @field.set("30").should == 30
      end

    end

  end

  describe "#get" do

    before do
      @type = mock
      @field = Mongoid::Field.new(:score, :default => 10, :type => @type)
    end

    it "returns the value" do
      @type.expects(:get).with(30).returns(30)
      @field.get(30).should == 30
    end

  end

end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
mongoid-1.2.8 spec/unit/mongoid/field_spec.rb
mongoid-1.2.7 spec/unit/mongoid/field_spec.rb
mongoid-pre-2.0.0.pre spec/unit/mongoid/field_spec.rb
mongoid-1.2.6 spec/unit/mongoid/field_spec.rb
mongoid-1.2.5 spec/unit/mongoid/field_spec.rb
mongoid-1.2.4 spec/unit/mongoid/field_spec.rb
mongoid-1.2.3 spec/unit/mongoid/field_spec.rb
mongoid-1.2.2 spec/unit/mongoid/field_spec.rb
mongoid-1.2.1 spec/unit/mongoid/field_spec.rb
mongoid-1.2.0 spec/unit/mongoid/field_spec.rb
mongoid-1.1.4 spec/unit/mongoid/field_spec.rb
mongoid-1.1.3 spec/unit/mongoid/field_spec.rb
mongoid-1.1.2 spec/unit/mongoid/field_spec.rb
mongoid-1.1.1 spec/unit/mongoid/field_spec.rb
mongoid-1.1.0 spec/unit/mongoid/field_spec.rb
mongoid-1.0.6 spec/unit/mongoid/field_spec.rb
mongoid-1.0.5 spec/unit/mongoid/field_spec.rb
mongoid-1.0.4 spec/unit/mongoid/field_spec.rb
mongoid-1.0.3 spec/unit/mongoid/field_spec.rb
mongoid-1.0.2 spec/unit/mongoid/field_spec.rb