Sha256: 7c679f0650ec44a7a7a382444d0134f600e91e31b8703abdf35340db0c0af90d

Contents?: true

Size: 916 Bytes

Versions: 6

Compression:

Stored size: 916 Bytes

Contents

require File.dirname(__FILE__) + '/spec_helper'

class Test
  include CouchPotato::Persistence

  property :test, :default => 'Test value'
  property :complex, :default => [1, 2, 3]
end

describe 'default properties' do
  before(:all) do
    recreate_db
  end

  it "should use the default value if nothing is supplied" do
    t = Test.new

    t.test.should == 'Test value'
  end

  it "should persist the default value if nothing is supplied" do
    t = Test.new
    CouchPotato.database.save_document! t

    t = CouchPotato.database.load_document t.id
    t.test.should == 'Test value'
  end

  it "should not have the same default for two instances of the object" do
    t = Test.new
    t2 = Test.new
    t.complex.object_id.should_not == t2.complex.object_id
  end
  
  it "should not return the default value when the actual value is empty" do
    t = Test.new(:complex => []).complex.should == []
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
couch_potato-0.2.27 spec/default_property_spec.rb
couch_potato-0.2.26 spec/default_property_spec.rb
couch_potato-0.2.25 spec/default_property_spec.rb
couch_potato-0.2.24 spec/default_property_spec.rb
couch_potato-0.2.23 spec/default_property_spec.rb
couch_potato-0.2.22 spec/default_property_spec.rb