Sha256: 7ce28ee29b5f7bfed5cc41133ccc7114026bf989b5e8d17882b59d739cfcc512

Contents?: true

Size: 1.78 KB

Versions: 12

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe "create" do
  
  describe "succeeds" do
    before(:each) do
      Time.zone = nil
    end
    
    def create_comment
      comment = Comment.new :title => 'my_title'
      CouchPotato::Database.new(double('database', :save_doc => {'rev' => '123', 'id' => '456'}, :info => nil)).save_document!(comment)
      comment
    end

    it "should assign the id" do
      expect(create_comment._id).to eq('456')
    end

    it "should assign the revision" do
      expect(create_comment._rev).to eq('123')
    end

    it "should set created at in the current time zone" do
      Time.zone = 'Europe/Berlin'
      Timecop.travel Time.zone.parse('2010-01-01 12:00 +0100') do
        expect(create_comment.created_at.to_s).to eq('2010-01-01 12:00:00 +0100')
      end
    end

    it "should set updated at in the current time zone" do
      Time.zone = 'Europe/Berlin'
      Timecop.travel Time.zone.parse('2010-01-01 12:00 +0100') do
        expect(create_comment.updated_at.to_s).to eq('2010-01-01 12:00:00 +0100')
      end
    end
  end
  
  describe "fails" do
    before(:each) do
      @comment = Comment.new
      @db = CouchPotato::Database.new(double('database', :info => nil))
      @db.save_document(@comment)
    end

    it "should not assign an id" do
      expect(@comment._id).to be_nil
    end

    it "should not assign a revision" do
      expect(@comment._rev).to be_nil
    end

    it "should not set created at" do
      expect(@comment.created_at).to be_nil
    end

    it "should set updated at" do
      expect(@comment.updated_at).to be_nil
    end
    
    describe "with !" do
      it "should raise an exception" do
        expect {
          @db.save! @comment
        }.to raise_error(CouchPotato::Database::ValidationsFailedError)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
couch_potato-1.18.0 spec/unit/create_spec.rb
couch_potato-1.17.0 spec/unit/create_spec.rb
couch_potato-1.16.0 spec/unit/create_spec.rb
couch_potato-1.15.0 spec/unit/create_spec.rb
couch_potato-1.14.0 spec/unit/create_spec.rb
couch_potato-1.13.0 spec/unit/create_spec.rb
couch_potato-1.12.1 spec/unit/create_spec.rb
couch_potato-1.12.0 spec/unit/create_spec.rb
couch_potato-1.11.0 spec/unit/create_spec.rb
couch_potato-1.10.1 spec/unit/create_spec.rb
couch_potato-1.10.0 spec/unit/create_spec.rb
couch_potato-1.9.0 spec/unit/create_spec.rb