Sha256: b8ac0075034c30903414f5d76565257459e4a50eea5a700dfba6abe48bc61ceb

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe GitModel::Transaction do

  describe '#execute' do
    it "yields to a given block" do
      m = mock("mock")
      m.should_receive(:a_method)
      GitModel::Transaction.new.execute do
        m.a_method
      end
    end

    describe "when called the first time" do
      it "creates a new Git index" do
        index = mock("index")
        index.stub!(:read_tree)
        index.stub!(:commit)
        Grit::Index.should_receive(:new).and_return(index)
        GitModel::Transaction.new.execute {}
      end

      it "commits after yielding" do
        index = mock("index")
        index.stub!(:read_tree)
        index.should_receive(:commit)
        Grit::Index.should_receive(:new).and_return(index)
        GitModel::Transaction.new.execute {}
      end

      it "can create the first commit in the repo" do
        GitModel::Transaction.new.execute do |t|
          t.index.add "foo", "foo"
        end
      end

      # TODO it "locks the branch while committing"

      # TODO it "merges commits from concurrent transactions"

    end

    describe "when called recursively" do

      it "re-uses the existing git index and doesn't commit" do
        index = mock("index")
        index.stub!(:read_tree)
        index.should_receive(:commit).once
        Grit::Index.should_receive(:new).and_return(index)
        GitModel::Transaction.new.execute do |t|
          t.execute {}
        end
      end

    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gitmodel-0.0.8 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.7 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.6 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.5 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.4 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.3 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.2 spec/gitmodel/transaction_spec.rb
gitmodel-0.0.1 spec/gitmodel/transaction_spec.rb