spec/lib/test_gitrepo.rb in treet-0.11.0 vs spec/lib/test_gitrepo.rb in treet-0.13.1
- old
+ new
@@ -1,8 +1,7 @@
# encoding: UTF-8
require "test_helper"
-require "pp"
# convert a hash to a gitrepo
# convert a plain repo to a gitrepo
# convert a gitrepo to a plain repo
# initialize a treet git from an existing gitrepo (with a treet::repo structure)
@@ -40,17 +39,22 @@
"full" => "John Bigbooté"
}
}
thash = Treet::Hash.new(data)
trepo = thash.to_repo(Dir.mktmpdir('repo', $topdir))
- Treet::Gitrepo.new(trepo.root, :author => {:name => 'Bob', :email => 'bob@example.com'})
+ r = Treet::Gitrepo.new(trepo.root, :author => {:name => 'Bob', :email => 'bob@example.com'})
+ r.patch([]) # should be no-op, trigger no commit
+ r
end
end
let(:johnb) { self.class.make_johnb }
it "should have exactly one commit" do
+ Dir.chdir(johnb.root) do
+ `git log --oneline`.lines.count.must_equal 1
+ end
johnb.head.wont_be_nil
johnb.refs.count.must_equal 1
johnb.refs.first.target.must_equal johnb.head.target
r = Rugged::Repository.new(johnb.root)
r.lookup(johnb.head.target).parents.must_be_empty
@@ -67,28 +71,59 @@
it "should have no tags" do
johnb.tags.must_be_empty
end
- it "should fail on unknown tag lookups" do
- ->{johnb.to_hash(:tag => 'nosuchtag')}.must_raise ArgumentError
- end
-
it "should have no branches" do
johnb.branches.must_be_empty
end
it "should return commit SHA for version label" do
johnb.version.must_equal johnb.head.target
end
- it "should return nil for unknown tag versions" do
- johnb.version(:tag => 'nosuchtag').must_be_nil
+ describe "an unknown tag" do
+ it "should have no commit" do
+ johnb.version(:tag => 'nosuchtag').must_be_nil
+ end
+ it "should not be present" do
+ refute johnb.tagged?('nosuchtag')
+ end
+ it "should return empty data" do
+ assert johnb.to_hash(:tag => 'nosuchtag').empty?
+ end
end
end
+ describe "a gitrepo with an array of strings" do
+ def self.make_repo
+ @repo ||= begin
+ data = {
+ "label" => "Rainbow Colors",
+ "colors" => %w{red orange yellow green blue purple}
+ }
+ thash = Treet::Hash.new(data)
+ trepo = thash.to_repo(Dir.mktmpdir('repo', $topdir))
+ Treet::Gitrepo.new(trepo.root, :author => {:name => 'Bob', :email => 'bob@example.com'})
+ end
+ end
+ let(:repo) { self.class.make_repo }
+
+ it "should fetch directly from file system" do
+ repo.to_hash.wont_be_nil
+ end
+
+ it "should fetch via git" do
+ data = repo.to_hash(:commit => repo.head.target)
+ data.wont_be_nil
+ assert data['label'] == 'Rainbow Colors'
+ assert data['colors'].to_set == %w{red orange yellow green blue purple}.to_set
+ end
+ end
+
+
describe "a patched gitrepo" do
def self.patch_johnb
@memo ||= begin
data = {
"name" => {
@@ -189,11 +224,11 @@
r = make_gitrepo('two',
:author => {:name => 'Bob', :email => 'bob@example.com'},
:xrefkey => 'app1',
:xref => 'APP1_ID'
)
- r.tag('app1')
+ r.tag('pre-edit')
r.patch([
[
"-",
"emails[]",
{ "label" => "home", "email" => "johns@lectroid.com" }
@@ -218,29 +253,36 @@
repo.entries.must_include 'name'
repo.entries.grep(/^emails/).wont_be_empty
repo.index.count.must_equal 2
end
- it "should have tag not pointing to HEAD" do
+ it "should have one tag" do
repo.tags.count.must_equal 1
- repo.tags.first.name.must_equal "refs/tags/app1"
- repo.tags.first.target.wont_equal repo.head.target
end
- it "should have the original image for the tag" do
- refute hashalike(repo.to_hash, repo.to_hash(:tag => 'app1'))
- assert hashalike(repo.to_hash(:tag => 'app1'), load_json('two'))
- end
-
it "should have no branches" do
repo.branches.must_be_empty
end
- it "should track version label by tag" do
- repo.version.must_equal repo.head.target
- repo.version(:tag => 'app1').must_equal repo.tags.first.target
+ describe "head state" do
+ it "should track version label by tag" do
+ assert repo.version == repo.head.target
+ end
end
+
+ describe "pre-patch state" do
+ it "should not be same as HEAD" do
+ assert repo.tagged?("pre-edit")
+ refute repo.current?("pre-edit")
+ assert repo.version(:tag => "pre-edit") != repo.version
+ end
+
+ it "should have the original image" do
+ refute hashalike(repo.to_hash, repo.to_hash(:tag => 'pre-edit'))
+ assert hashalike(repo.to_hash(:tag => 'pre-edit'), load_json('two'))
+ end
+ end
end
describe "a tagged repo" do
let(:repo) do
r = make_gitrepo('two', :author => {:name => 'Bob', :email => 'bob@example.com'})
@@ -249,10 +291,12 @@
end
it "should have tags" do
repo.tags.count.must_equal 1
repo.tags.first.name.must_equal "refs/tags/source1"
+ assert repo.tagged?("source1")
+ assert repo.current?("source1")
end
it "should have no branches" do
repo.branches.must_be_empty
end
@@ -328,19 +372,59 @@
it "should have different version labels for each tag" do
versions = ['app1', 'app2', 'app3', 'app4'].map {|s| repo[:repo].version(:tag => s)}
versions.uniq.count.must_equal 4
end
+
+ it "should know which tag matches the HEAD state" do
+ end
end
describe "a branched gitrepo" do
let(:repo) do
r = make_gitrepo('one', :author => {:name => 'Bob', :email => 'bob@example.com'})
r.branch('mybranch')
r
end
it "should show a branch" do
- repo.branches.must_equal ['refs/heads/mybranch']
+ repo.branches.must_equal ['mybranch']
+ end
+ end
+
+ describe "repo with non-gitified attributes" do
+ let(:repo) do
+ @data = {'foo' => 'bar', '.attr' => {'key' => 'value'}}
+ thash = Treet::Hash.new(@data)
+ trepo = thash.to_repo(Dir.mktmpdir('repo', $topdir))
+ r = Treet::Gitrepo.new(trepo.root, :author => {:name => 'Bob', :email => 'bob@example.com'})
+ r.tag('testing')
+ r.patch([["~", ".attr.key", "newvalue"]])
+ @updated = {'foo' => 'bar', '.attr' => {'key' => 'newvalue'}}
+ r
+ end
+
+ it "should retrieve all attributes" do
+ repo.to_hash.must_equal @updated
+ end
+
+ it "should not create new commits for edits to dot attributes" do
+ Dir.chdir(repo.root) do
+ `git log --oneline`.lines.count.must_equal 1
+ end
+ end
+
+ it "should retrieve non-gitified attrs even via tags and commits" do
+ repo.to_hash(:tag => 'testing').must_equal @updated
+ repo.to_hash(:commit => repo.version(:tag => 'testing')).must_equal @updated
+ repo.to_hash(:commit => repo.version).must_equal @updated
+ end
+
+ it "should not commit the dot-prefixed attributes" do
+ Dir.chdir(repo.root) do
+ gitified = `git ls-tree --name-only HEAD`
+ gitified.must_include('foo')
+ gitified.wont_include('.attr')
+ end
end
end
end