Sha256: b742a11fd384c5be0a21fc5ac51528422cedc4e5802fdaa49270ae1ba185aa82

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

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

class Watch
  include CouchPotato::Persistence
  
  property :time, :type => Time
end


describe 'properties' do
  before(:all) do
    recreate_db
  end
  
  it "should return the property names" do
    Comment.property_names.should == [:created_at, :updated_at, :title, :commenter]
  end
  
  it "should persist a string" do
    c = Comment.new :title => 'my title'
    CouchPotato.database.save_document! c
    c = CouchPotato.database.load_document c.id
    c.title.should == 'my title'
  end
  
  it "should persist a number" do
    c = Comment.new :title => 3
    CouchPotato.database.save_document! c
    c = CouchPotato.database.load_document c.id
    c.title.should == 3
  end
  
  it "should persist a hash" do
    c = Comment.new :title => {'key' => 'value'}
    CouchPotato.database.save_document! c
    c = CouchPotato.database.load_document c.id
    c.title.should == {'key' => 'value'}
  end
  
  it "should persist a Time object" do
    w = Watch.new :time => Time.now
    CouchPotato.database.save_document! w
    w = CouchPotato.database.load_document w.id
    w.time.year.should == Time.now.year
  end
  
  describe "predicate" do
    it "should return true if property set" do
      Comment.new(:title => 'title').title?.should be_true
    end
    
    it "should return false if property nil" do
      Comment.new.title?.should be_false
    end
    
    it "should return false if property false" do
      Comment.new(:title => false).title?.should be_false
    end
    
    it "should return false if property blank" do
      Comment.new(:title => '').title?.should be_false
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
langalex-couch_potato-0.2.0 spec/property_spec.rb
langalex-couch_potato-0.2.1 spec/property_spec.rb
langalex-couch_potato-0.2.2 spec/property_spec.rb
langalex-couch_potato-0.2.3 spec/property_spec.rb
langalex-couch_potato-0.2.4 spec/property_spec.rb
langalex-couch_potato-0.2.5 spec/property_spec.rb
langalex-couch_potato-0.2.6 spec/property_spec.rb
langalex-couch_potato-0.2.7 spec/property_spec.rb
speedmax-couch_potato-0.2.0 spec/property_spec.rb
speedmax-couch_potato-0.2.2 spec/property_spec.rb
thefool808-couch_potato-0.2.7 spec/property_spec.rb