gitreport 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
@@ -0,0 +1,37 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::BatchSender' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#body!' do
14
+ it 'should return a Hash containing author, project and commit data separated' do
15
+ json_string = GitReport::BatchSender.body(GitReport::BatchSender.batches(:history).first)
16
+ json_string.should be_a(String)
17
+
18
+ data = JSON.parse(json_string)
19
+ data.size.should == 3
20
+ [:author, :project, :commits].each do |key|
21
+ data.keys.include?(key.to_s).should be_true
22
+ end
23
+ data["author"].should == GitReport::GitConfiguration.user_name
24
+ data["commits"].size.should == 3
25
+ data["commits"].collect{ |c| c["sha"] }.each do |sha|
26
+ GitReport.project.revlist.include?(sha).should be_true
27
+ end
28
+ data["project"].size.should == 7
29
+ data["project"]["project_name"].should == GitReport.project.name
30
+ end
31
+ end
32
+
33
+ describe '#batches' do
34
+ it 'should create batches in relation to batchsize from configuration'
35
+ end
36
+
37
+ end
@@ -0,0 +1,87 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Commit' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first, @project.identifier)
11
+ end
12
+
13
+ describe '#sha' do
14
+ it 'should return the sha of a commit' do
15
+ @commit.sha.should == @project.log.first.sha
16
+ end
17
+ end
18
+
19
+ describe '#short_sha' do
20
+ it 'should return the shortened sha' do
21
+ @commit.short_sha.should == @project.log.first.sha[0..6]
22
+ end
23
+ end
24
+
25
+ describe '#message' do
26
+ it 'should return the commits message' do
27
+ @commit.message.should == @project.log.first.message
28
+ end
29
+ end
30
+
31
+ describe '#time' do
32
+ it 'should return the commit time' do
33
+ @commit.time.should_not be_nil
34
+ @commit.time.is_a?(Time).should be_true
35
+ end
36
+ end
37
+
38
+ describe '#author' do
39
+ it 'should return the correct author' do
40
+ @commit.author.name.should == "Bugs Bunny"
41
+ @commit.author.email.should == "bugs@acme.com"
42
+ end
43
+ end
44
+
45
+ describe '#stats' do
46
+ it 'should return the commit stats'
47
+ end
48
+
49
+ describe '#project_identifier' do
50
+ it 'should equal the projects first commits sha' do
51
+ @commit.project_identifier.should == @project.revlist.last
52
+ end
53
+ end
54
+
55
+ describe '#data' do
56
+ it 'should return the data to be transferred during a single commit including project data' do
57
+ data = @commit.data
58
+ data.size.should == 13
59
+ [:project_path, :project_name, :current_branch, :remotes, :remote_urls, :remote_branches].each do |attr|
60
+ data.keys.include?(attr).should be_true
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#batch_data' do
66
+ it 'should return the data to be transferred during a batch import without project data' do
67
+ data = @commit.batch_data
68
+ data.size.should == 7
69
+ [:project_path, :current_branch, :remotes, :remote_urls, :remote_branches].each do |attr|
70
+ data.keys.include?(attr).should be_false
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#to_json' do
76
+ it 'should return the full commit data including project data as JSON' do
77
+ json_string = @commit.to_json
78
+ data = JSON.parse(json_string)
79
+
80
+ data.each_pair do |key, value|
81
+ @commit.data[key.to_sym].should == value
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+
@@ -0,0 +1,69 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Configuration' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport.project
10
+ @commit = GitReport::Commit.new(@project.log.last)
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'should set the correct project' do
15
+ config = GitReport::Configuration.new
16
+
17
+ config.instance_variable_get(:@project).should == GitReport.project
18
+ end
19
+
20
+ it 'should set the config from a project config file in case one exists' do
21
+ @repo.create_project_config_file
22
+ config = GitReport::Configuration.new
23
+
24
+ config.host.should == "some.host.anywhere"
25
+ config.port.should == 42
26
+ config.auth_token.should == "12345ab"
27
+ config.proxy_host.should == "some.proxy.host"
28
+ config.proxy_port.should == 23
29
+ end
30
+
31
+ it 'should set the config from the user file in case no project config file exists' do
32
+ @repo.create_user_config_file
33
+
34
+ class TestConfiguration < GitReport::Configuration
35
+ def user_configuration_file
36
+ File.join(@project.path, '.gitreport_user')
37
+ end
38
+ end
39
+
40
+ config = TestConfiguration.new
41
+
42
+ config.host.should == "user.host.anywhere"
43
+ config.port.should == 43
44
+ config.auth_token.should == "xyz987565"
45
+ config.proxy_host.should == "user.proxy.host"
46
+ config.proxy_port.should == 24
47
+ end
48
+
49
+ it 'should set the config to default in case no user- and no project config file exists' do
50
+
51
+ class TestConfiguration < GitReport::Configuration
52
+ def user_configuration_file
53
+ nil
54
+ end
55
+ end
56
+
57
+ config = TestConfiguration.new
58
+
59
+ config.host.should == "api.gitreport.com"
60
+ config.port.should == 80
61
+ config.auth_token.should == "is_unset_check_your_config"
62
+ config.proxy_host.should be_nil
63
+ config.proxy_port.should be_nil
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
@@ -0,0 +1,22 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::CurrentBranch' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ @project = GitReport::Project.new(@repo.path)
9
+ @commit = GitReport::Commit.new(@project.log.first)
10
+ end
11
+
12
+ describe '#name' do
13
+ it 'should return the name of the currently checked out branch' do
14
+ @project.instance_variable_get(:@branch).name.should == "master"
15
+
16
+ @project.project.branch('new_branch').checkout
17
+ @project.instance_variable_get(:@branch).name.should == "new_branch"
18
+ end
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,26 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::GitConfiguration' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#user_name' do
14
+ it 'should return the users name from gitconfig' do
15
+ GitReport::GitConfiguration.user_name.should == "Duffy Duck"
16
+ end
17
+ end
18
+
19
+ describe '#user_email' do
20
+ it 'should return the users email from gitconfig' do
21
+ GitReport::GitConfiguration.user_email.should == "duffy@acme.com"
22
+ end
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,50 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::History' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#commits' do
14
+ it 'should return the users commits if called with scope = :user' do
15
+ commits = GitReport::History.commits(:user)
16
+
17
+ commits.size.should == 2
18
+ commits.first.data[:author_name].should == "Duffy Duck"
19
+ commits.last.data[:author_name].should == "Duffy Duck"
20
+ end
21
+
22
+ it 'should return all commits if called with any scope but :user' do
23
+ commits = GitReport::History.commits(:all)
24
+
25
+ commits.size.should == 3
26
+ commits[0].data[:author_name].should == "Bugs Bunny"
27
+ commits[1].data[:author_name].should == "Duffy Duck"
28
+ commits[2].data[:author_name].should == "Duffy Duck"
29
+ end
30
+
31
+ it 'should return commits that are not part of the currently checked out branch' do
32
+ @project.project.branch('new_branch').checkout
33
+
34
+ File.open("#{@project.path}/file4", 'w+') do |file|
35
+ file.write "file content 4"
36
+ end
37
+
38
+ @project.project.add('file4')
39
+ @project.project.commit('commit with file4 on new_branch')
40
+
41
+ @project.project.branch('master').checkout
42
+
43
+ commits = GitReport::History.commits(:all)
44
+ commits.size.should == 4
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,64 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Hook' do
5
+
6
+ before :each do
7
+ GitReport::Hook.stub!(:puts)
8
+ @repo = FakeRepository.new
9
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
10
+ @project = GitReport::Project.new(@repo.path)
11
+ @commit = GitReport::Commit.new(@project.log.first)
12
+ end
13
+
14
+ describe '#set!' do
15
+ it 'should create a proper post-commit hook file if none exists' do
16
+ GitReport::Hook.set!
17
+ hook_file = "#{GitReport.project.path}/.git/hooks/post-commit"
18
+ (File.exists?(hook_file)).should be_true
19
+ content = File.open(hook_file, 'r').read
20
+
21
+ content.match(/\nbundle\sexec\sgitreport\scommit\s&\n/).should be_true
22
+ end
23
+
24
+ it 'should insert the gitreport hook into an existing post-commit hook file' do
25
+ hook_file = "#{GitReport.project.path}/.git/hooks/post-commit"
26
+
27
+ File.open(hook_file, 'w+') do |file|
28
+ file.write "# some preexisting hook file\n"
29
+ end
30
+
31
+ GitReport::Hook.set!
32
+ content = File.open(hook_file, 'r').read
33
+ content.match(/\nbundle\sexec\sgitreport\scommit\s&\n/).should be_true
34
+ end
35
+ end
36
+
37
+ describe '#remove!' do
38
+ it 'should remove the post commit hook file completely in case it was not altered by someone else' do
39
+ GitReport::Hook.set!
40
+ hook_file = "#{GitReport.project.path}/.git/hooks/post-commit"
41
+ (File.exists?(hook_file)).should be_true
42
+ GitReport::Hook.remove!
43
+
44
+ (File.exists?(hook_file)).should be_false
45
+ end
46
+
47
+ it 'should only remove out line from post-commit hook file in case the file was externally altered' do
48
+ hook_file = "#{GitReport.project.path}/.git/hooks/post-commit"
49
+
50
+ File.open(hook_file, 'w+') do |file|
51
+ file.write "# some preexisting hook file\n\n"
52
+ file.write "bundle exec gitreport commit &\n"
53
+ end
54
+
55
+ GitReport::Hook.remove!
56
+
57
+ (File.exists?(hook_file)).should be_true
58
+ content = File.open(hook_file, 'r').read
59
+ content.should match(/\ssome\spreexisting\shook\sfile\n/)
60
+ content.should_not match(/\nbundle\sexec\sgitreport\scommit\s&\n/)
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,47 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Log' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#commits!' do
14
+ it 'should return an array containing all commits of the currently checked out branch' do
15
+ commits = GitReport::Log.new(GitReport.project.instance_variable_get(:@project)).commits
16
+
17
+ commits.should be_a(Array)
18
+ commits.size.should == 3
19
+ end
20
+
21
+ it 'should return the commits ordered by commit date' do
22
+ commits = GitReport::Log.new(GitReport.project.instance_variable_get(:@project)).commits
23
+
24
+ commits.map(&:message).should == ["commit with file3 from foreigner", "commit with file2", "initial commit with file1"]
25
+ end
26
+ end
27
+
28
+ describe '#last!' do
29
+ it 'should return the last commit of the current branch' do
30
+ last = GitReport::Log.new(GitReport.project.instance_variable_get(:@project)).last
31
+
32
+ last.should be_a(Git::Object::Commit)
33
+ last.message.should == "initial commit with file1"
34
+ end
35
+ end
36
+
37
+ describe '#first!' do
38
+ it 'should return the first commit of the current branch' do
39
+ first = GitReport::Log.new(GitReport.project.instance_variable_get(:@project)).first
40
+
41
+ first.should be_a(Git::Object::Commit)
42
+ first.message.should == "commit with file3 from foreigner"
43
+ end
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,93 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Project' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#path!' do
14
+ it 'should return the projects path' do
15
+ GitReport.project.path.should == @repo.path
16
+ end
17
+ end
18
+
19
+ describe '#name' do
20
+ it 'should return the projects name' do
21
+ GitReport.project.name.should == "project"
22
+ end
23
+ end
24
+
25
+ describe '#remotes' do
26
+
27
+ it 'should return the projects remotes' do
28
+ GitReport.project.project.add_remote("remote1", "http://www.remote1.url/project.git")
29
+ GitReport.project.project.add_remote("remote2", "http://www.remote2.url/project.git")
30
+ remotes = GitReport.project.remotes
31
+
32
+ remotes.should be_a(Array)
33
+ remotes.size.should == 2
34
+ remotes.first.name.should == "remote1"
35
+ remotes.last.name.should == "remote2"
36
+ end
37
+ end
38
+
39
+ describe '#remote_branches' do
40
+
41
+ end
42
+
43
+ describe '#revlist' do
44
+ it 'should return the projects revlist' do
45
+ @project.project.branch('new_branch').checkout
46
+
47
+ File.open("#{@project.path}/file4", 'w+') do |file|
48
+ file.write "file content 4"
49
+ end
50
+
51
+ @project.project.add('file4')
52
+ @project.project.commit('commit with file4 on new_branch')
53
+
54
+ @project.project.branch('master').checkout
55
+
56
+ revlist = GitReport.project.revlist
57
+
58
+ revlist.should be_a(Array)
59
+ revlist.size.should == 4
60
+ revlist.each do |rev|
61
+ rev.length.should == 40
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#identifier' do
67
+ it 'should return the projects first commits sha' do
68
+ GitReport.project.identifier == @project.log.commits.first.sha
69
+ end
70
+ end
71
+
72
+ describe '#branchname' do
73
+ it 'should return the branch name' do
74
+ GitReport.project.branchname.should == "master"
75
+ end
76
+ end
77
+
78
+ describe '#data' do
79
+ it 'should return the projects core data as a hash' do
80
+ data = GitReport.project.data
81
+ data.should be_a(Hash)
82
+ data.size.should == 7
83
+ data[:project_path].should == GitReport.project.path
84
+ data[:project_name].should == GitReport.project.name
85
+ data[:current_branch].should == GitReport.project.branchname
86
+ data[:remotes].should == GitReport.project.remotes.map(&:name)
87
+ data[:remote_urls].should == GitReport.project.remotes.map(&:url)
88
+ data[:remote_branches].should == GitReport.project.remote_branches
89
+ end
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,75 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Sender' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#send!' do
14
+ it 'should send last and stored commits when called with :last_and_stored' do
15
+ # TODO: better stub please
16
+ class DummyStorage
17
+ def self.load
18
+ ["stored_commit"]
19
+ end
20
+
21
+ def self.save! options
22
+ true
23
+ end
24
+ end
25
+
26
+ GitReport::Supplier.stub!(:storage).and_return DummyStorage
27
+ GitReport::Sender.should_receive(:send_data!).twice.and_return(true)
28
+
29
+ GitReport::Sender.send! :last_and_stored
30
+ end
31
+
32
+ it 'should send stored commits when called with :stored' do
33
+ class DummyStorage
34
+ def self.load
35
+ ["stored_commit1", "stored_commit2", "stored_commit3"]
36
+ end
37
+
38
+ def self.save! options
39
+ true
40
+ end
41
+ end
42
+
43
+ GitReport::Supplier.stub!(:storage).and_return DummyStorage
44
+ GitReport::Sender.should_receive(:send_data!).exactly(3).times.and_return(true)
45
+
46
+ GitReport::Sender.send! :stored
47
+ end
48
+
49
+ it 'should send all commits (including foreign ones) from projects revlist when called with :history' do
50
+ @project.project.branch('new_branch').checkout
51
+
52
+ File.open("#{@project.path}/file4", 'w+') do |file|
53
+ file.write "file content 4"
54
+ end
55
+
56
+ @project.project.add('file4')
57
+ @project.project.commit('commit with file4 on new_branch')
58
+
59
+ @project.project.branch('master').checkout
60
+ GitReport::Sender.should_receive(:send_data!).exactly(4).times.and_return(true)
61
+
62
+ GitReport::Sender.send! :history
63
+ end
64
+
65
+ it 'should send a single commit to the server'
66
+ it 'should send two commits to the server if two commits are in the pipe'
67
+ it 'should store one commit in case of a connection error'
68
+ it 'should store one commit in case of a server timeout'
69
+ it 'should store one commit in case of a response other than 200'
70
+ it 'should store two commits in case of a connection error'
71
+ it 'should store two commits in case of a server timeout'
72
+ it 'should store two commits in case of a response other than 200'
73
+ end
74
+
75
+ end
@@ -0,0 +1,53 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Storage' do
5
+
6
+ before :each do
7
+ @tempfile = Tempfile.new('storage')
8
+ @tempdir = File.dirname(@tempfile.path)
9
+ @storage = GitReport::Storage.new(@tempdir, @tempfile)
10
+ class Foo
11
+ attr_accessor :foo, :bar
12
+
13
+ def initialize foo, bar
14
+ @foo = foo
15
+ @bar = bar
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#save!' do
21
+ it 'should save the given object to a file' do
22
+ f1 = Foo.new("foo1", "bar1")
23
+ f2 = Foo.new("foo2", "bar2")
24
+
25
+ @storage.save! [f1,f2]
26
+
27
+ restore = Marshal.load(Base64.decode64(File.read "#{@tempdir}/#{@tempfile}"))
28
+
29
+ restore.first.foo.should == f1.foo
30
+ restore.first.bar.should == f1.bar
31
+ restore.last.foo.should == f2.foo
32
+ restore.last.bar.should == f2.bar
33
+ end
34
+ end
35
+
36
+ describe '#load' do
37
+ it 'should load previously stored objects' do
38
+ f1 = Foo.new("foo1", "bar1")
39
+ f2 = Foo.new("foo2", "bar2")
40
+
41
+ @storage.save! [f1,f2]
42
+
43
+ restore = @storage.load
44
+
45
+ restore.first.foo.should == f1.foo
46
+ restore.first.bar.should == f1.bar
47
+ restore.last.foo.should == f2.foo
48
+ restore.last.bar.should == f2.bar
49
+ end
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,20 @@
1
+ # require 'spec_helper'
2
+ require 'gitreport'
3
+
4
+ describe 'GitReport::Supplier' do
5
+
6
+ before :each do
7
+ @repo = FakeRepository.new
8
+ GitReport.stub!(:project).and_return(GitReport::Project.new(@repo.path))
9
+ @project = GitReport::Project.new(@repo.path)
10
+ @commit = GitReport::Commit.new(@project.log.first)
11
+ end
12
+
13
+ describe '#commits!' do
14
+ it 'should return last and stored commits if called with :last_and_stored'
15
+ it 'should return stored commits if called with :stored'
16
+ it 'should return the whole history if called with history'
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'gitreport'
5
+ require 'webmock/rspec'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.color_enabled = true
13
+ # config.mock_with :rspec
14
+ end