Commit d444a23ad6d9c2455a0159435d0c63342aca5edb
1 parent
676bce2a
Exists in
master
and in
4 other branches
specs for Gitlab::Git::Repository and Gitlab::Git::Commit
Showing
2 changed files
with
155 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +require "spec_helper" | ||
2 | + | ||
3 | +describe Gitlab::Git::Commit do | ||
4 | + let(:commit) { create(:project).repository.commit } | ||
5 | + | ||
6 | + describe "Commit info" do | ||
7 | + before do | ||
8 | + @committer = double( | ||
9 | + email: 'mike@smith.com', | ||
10 | + name: 'Mike Smith' | ||
11 | + ) | ||
12 | + | ||
13 | + @author = double( | ||
14 | + email: 'john@smith.com', | ||
15 | + name: 'John Smith' | ||
16 | + ) | ||
17 | + | ||
18 | + @raw_commit = double( | ||
19 | + id: "bcf03b5de6abcf03b5de6c", | ||
20 | + author: @author, | ||
21 | + committer: @committer, | ||
22 | + committed_date: Date.yesterday, | ||
23 | + message: 'Refactoring specs' | ||
24 | + ) | ||
25 | + | ||
26 | + @commit = Gitlab::Git::Commit.new(@raw_commit) | ||
27 | + end | ||
28 | + | ||
29 | + it { @commit.short_id.should == "bcf03b5de6a" } | ||
30 | + it { @commit.safe_message.should == @raw_commit.message } | ||
31 | + it { @commit.created_at.should == @raw_commit.committed_date } | ||
32 | + it { @commit.author_email.should == @author.email } | ||
33 | + it { @commit.author_name.should == @author.name } | ||
34 | + it { @commit.committer_name.should == @committer.name } | ||
35 | + it { @commit.committer_email.should == @committer.email } | ||
36 | + it { @commit.different_committer?.should be_true } | ||
37 | + end | ||
38 | + | ||
39 | + describe "Class methods" do | ||
40 | + subject { Gitlab::Git::Commit } | ||
41 | + | ||
42 | + it { should respond_to(:find_or_first) } | ||
43 | + it { should respond_to(:fresh_commits) } | ||
44 | + it { should respond_to(:commits_with_refs) } | ||
45 | + it { should respond_to(:commits_since) } | ||
46 | + it { should respond_to(:commits_between) } | ||
47 | + it { should respond_to(:commits) } | ||
48 | + it { should respond_to(:compare) } | ||
49 | + end | ||
50 | +end |
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +require "spec_helper" | ||
2 | + | ||
3 | +describe Gitlab::Git::Repository do | ||
4 | + let(:project) { create(:project) } | ||
5 | + let(:repository) { project.repository } | ||
6 | + | ||
7 | + describe "Respond to" do | ||
8 | + subject { repository } | ||
9 | + | ||
10 | + it { should respond_to(:repo) } | ||
11 | + it { should respond_to(:tree) } | ||
12 | + it { should respond_to(:root_ref) } | ||
13 | + it { should respond_to(:tags) } | ||
14 | + it { should respond_to(:commit) } | ||
15 | + it { should respond_to(:commits) } | ||
16 | + it { should respond_to(:commits_between) } | ||
17 | + it { should respond_to(:commits_with_refs) } | ||
18 | + it { should respond_to(:commits_since) } | ||
19 | + it { should respond_to(:commits_between) } | ||
20 | + end | ||
21 | + | ||
22 | + | ||
23 | + describe "#discover_default_branch" do | ||
24 | + let(:master) { 'master' } | ||
25 | + let(:stable) { 'stable' } | ||
26 | + | ||
27 | + it "returns 'master' when master exists" do | ||
28 | + repository.should_receive(:branch_names).at_least(:once).and_return([stable, master]) | ||
29 | + repository.discover_default_branch.should == 'master' | ||
30 | + end | ||
31 | + | ||
32 | + it "returns non-master when master exists but default branch is set to something else" do | ||
33 | + repository.root_ref = 'stable' | ||
34 | + repository.should_receive(:branch_names).at_least(:once).and_return([stable, master]) | ||
35 | + repository.discover_default_branch.should == 'stable' | ||
36 | + end | ||
37 | + | ||
38 | + it "returns a non-master branch when only one exists" do | ||
39 | + repository.should_receive(:branch_names).at_least(:once).and_return([stable]) | ||
40 | + repository.discover_default_branch.should == 'stable' | ||
41 | + end | ||
42 | + | ||
43 | + it "returns nil when no branch exists" do | ||
44 | + repository.should_receive(:branch_names).at_least(:once).and_return([]) | ||
45 | + repository.discover_default_branch.should be_nil | ||
46 | + end | ||
47 | + end | ||
48 | + | ||
49 | + describe :commit do | ||
50 | + it "should return first head commit if without params" do | ||
51 | + repository.commit.id.should == repository.repo.commits.first.id | ||
52 | + end | ||
53 | + | ||
54 | + it "should return valid commit" do | ||
55 | + repository.commit(ValidCommit::ID).should be_valid_commit | ||
56 | + end | ||
57 | + | ||
58 | + it "should return nil" do | ||
59 | + repository.commit("+123_4532530XYZ").should be_nil | ||
60 | + end | ||
61 | + end | ||
62 | + | ||
63 | + describe :tree do | ||
64 | + before do | ||
65 | + @commit = repository.commit(ValidCommit::ID) | ||
66 | + end | ||
67 | + | ||
68 | + it "should raise error w/o arguments" do | ||
69 | + lambda { repository.tree }.should raise_error | ||
70 | + end | ||
71 | + | ||
72 | + it "should return root tree for commit" do | ||
73 | + tree = repository.tree(@commit) | ||
74 | + tree.contents.size.should == ValidCommit::FILES_COUNT | ||
75 | + tree.contents.map(&:name).should == ValidCommit::FILES | ||
76 | + end | ||
77 | + | ||
78 | + it "should return root tree for commit with correct path" do | ||
79 | + tree = repository.tree(@commit, ValidCommit::C_FILE_PATH) | ||
80 | + tree.contents.map(&:name).should == ValidCommit::C_FILES | ||
81 | + end | ||
82 | + | ||
83 | + it "should return root tree for commit with incorrect path" do | ||
84 | + repository.tree(@commit, "invalid_path").should be_nil | ||
85 | + end | ||
86 | + end | ||
87 | + | ||
88 | + describe "fresh commits" do | ||
89 | + it { repository.fresh_commits(3).count.should == 3 } | ||
90 | + it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" } | ||
91 | + it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" } | ||
92 | + end | ||
93 | + | ||
94 | + describe "commits_between" do | ||
95 | + subject do | ||
96 | + commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff", | ||
97 | + "8470d70da67355c9c009e4401746b1d5410af2e3") | ||
98 | + commits.map { |c| c.id } | ||
99 | + end | ||
100 | + | ||
101 | + it { should have(3).elements } | ||
102 | + it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") } | ||
103 | + it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") } | ||
104 | + end | ||
105 | +end |