Commit e91ff84df72a76b91bb8c24a6e677cdca98120de

Authored by Dmitriy Zaporozhets
1 parent 3011ac41

keep same dir structure for specs as in lib/

spec/lib/git/commit_spec.rb
@@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
1 -require "spec_helper"  
2 -  
3 -describe Gitlab::Git::Commit do  
4 - let(:commit) { create(:project_with_code).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 - authored_date: Date.yesterday,  
24 - parents: [],  
25 - message: 'Refactoring specs'  
26 - )  
27 -  
28 - @commit = Gitlab::Git::Commit.new(@raw_commit)  
29 - end  
30 -  
31 - it { @commit.short_id.should == "bcf03b5de6a" }  
32 - it { @commit.safe_message.should == @raw_commit.message }  
33 - it { @commit.created_at.should == @raw_commit.committed_date }  
34 - it { @commit.author_email.should == @author.email }  
35 - it { @commit.author_name.should == @author.name }  
36 - it { @commit.committer_name.should == @committer.name }  
37 - it { @commit.committer_email.should == @committer.email }  
38 - it { @commit.different_committer?.should be_true }  
39 - end  
40 -  
41 - describe "Class methods" do  
42 - subject { Gitlab::Git::Commit }  
43 -  
44 - it { should respond_to(:find_or_first) }  
45 - it { should respond_to(:fresh_commits) }  
46 - it { should respond_to(:commits_with_refs) }  
47 - it { should respond_to(:commits_since) }  
48 - it { should respond_to(:commits_between) }  
49 - it { should respond_to(:commits) }  
50 - end  
51 -end  
spec/lib/git/repository_spec.rb
@@ -1,104 +0,0 @@ @@ -1,104 +0,0 @@
1 -require "spec_helper"  
2 -  
3 -describe Gitlab::Git::Repository do  
4 - let(:repository) { Gitlab::Git::Repository.new('gitlabhq', 'master') }  
5 -  
6 - describe "Respond to" do  
7 - subject { repository }  
8 -  
9 - it { should respond_to(:repo) }  
10 - it { should respond_to(:tree) }  
11 - it { should respond_to(:root_ref) }  
12 - it { should respond_to(:tags) }  
13 - it { should respond_to(:commit) }  
14 - it { should respond_to(:commits) }  
15 - it { should respond_to(:commits_between) }  
16 - it { should respond_to(:commits_with_refs) }  
17 - it { should respond_to(:commits_since) }  
18 - it { should respond_to(:commits_between) }  
19 - end  
20 -  
21 -  
22 - describe "#discover_default_branch" do  
23 - let(:master) { 'master' }  
24 - let(:stable) { 'stable' }  
25 -  
26 - it "returns 'master' when master exists" do  
27 - repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])  
28 - repository.discover_default_branch.should == 'master'  
29 - end  
30 -  
31 - it "returns non-master when master exists but default branch is set to something else" do  
32 - repository.root_ref = 'stable'  
33 - repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])  
34 - repository.discover_default_branch.should == 'stable'  
35 - end  
36 -  
37 - it "returns a non-master branch when only one exists" do  
38 - repository.should_receive(:branch_names).at_least(:once).and_return([stable])  
39 - repository.discover_default_branch.should == 'stable'  
40 - end  
41 -  
42 - it "returns nil when no branch exists" do  
43 - repository.should_receive(:branch_names).at_least(:once).and_return([])  
44 - repository.discover_default_branch.should be_nil  
45 - end  
46 - end  
47 -  
48 - describe :commit do  
49 - it "should return first head commit if without params" do  
50 - repository.commit.id.should == repository.repo.commits.first.id  
51 - end  
52 -  
53 - it "should return valid commit" do  
54 - repository.commit(ValidCommit::ID).should be_valid_commit  
55 - end  
56 -  
57 - it "should return nil" do  
58 - repository.commit("+123_4532530XYZ").should be_nil  
59 - end  
60 - end  
61 -  
62 - describe :tree do  
63 - before do  
64 - @commit = repository.commit(ValidCommit::ID)  
65 - end  
66 -  
67 - it "should raise error w/o arguments" do  
68 - lambda { repository.tree }.should raise_error  
69 - end  
70 -  
71 - it "should return root tree for commit" do  
72 - tree = repository.tree(@commit)  
73 - tree.contents.size.should == ValidCommit::FILES_COUNT  
74 - tree.contents.map(&:name).should == ValidCommit::FILES  
75 - end  
76 -  
77 - it "should return root tree for commit with correct path" do  
78 - tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)  
79 - tree.contents.map(&:name).should == ValidCommit::C_FILES  
80 - end  
81 -  
82 - it "should return root tree for commit with incorrect path" do  
83 - repository.tree(@commit, "invalid_path").should be_nil  
84 - end  
85 - end  
86 -  
87 - describe "fresh commits" do  
88 - it { repository.fresh_commits(3).count.should == 3 }  
89 - it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }  
90 - it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }  
91 - end  
92 -  
93 - describe "commits_between" do  
94 - subject do  
95 - commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",  
96 - "8470d70da67355c9c009e4401746b1d5410af2e3")  
97 - commits.map { |c| c.id }  
98 - end  
99 -  
100 - it { should have(3).elements }  
101 - it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }  
102 - it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }  
103 - end  
104 -end  
spec/lib/gitlab/backend/shell_spec.rb 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::Shell do
  4 + let(:project) { double('Project', id: 7, path: 'diaspora') }
  5 + let(:gitlab_shell) { Gitlab::Shell.new }
  6 +
  7 + before do
  8 + Project.stub(find: project)
  9 + end
  10 +
  11 + it { should respond_to :add_key }
  12 + it { should respond_to :remove_key }
  13 + it { should respond_to :add_repository }
  14 + it { should respond_to :remove_repository }
  15 +
  16 + it { gitlab_shell.url_to_repo('diaspora').should == Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git" }
  17 +end
spec/lib/gitlab/git/commit_spec.rb 0 → 100644
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +require "spec_helper"
  2 +
  3 +describe Gitlab::Git::Commit do
  4 + let(:commit) { create(:project_with_code).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 + authored_date: Date.yesterday,
  24 + parents: [],
  25 + message: 'Refactoring specs'
  26 + )
  27 +
  28 + @commit = Gitlab::Git::Commit.new(@raw_commit)
  29 + end
  30 +
  31 + it { @commit.short_id.should == "bcf03b5de6a" }
  32 + it { @commit.safe_message.should == @raw_commit.message }
  33 + it { @commit.created_at.should == @raw_commit.committed_date }
  34 + it { @commit.author_email.should == @author.email }
  35 + it { @commit.author_name.should == @author.name }
  36 + it { @commit.committer_name.should == @committer.name }
  37 + it { @commit.committer_email.should == @committer.email }
  38 + it { @commit.different_committer?.should be_true }
  39 + end
  40 +end
spec/lib/gitlab/git/repository_spec.rb 0 → 100644
@@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
  1 +require "spec_helper"
  2 +
  3 +describe Gitlab::Git::Repository do
  4 + let(:repository) { Gitlab::Git::Repository.new('gitlabhq', 'master') }
  5 +
  6 + describe "Respond to" do
  7 + subject { repository }
  8 +
  9 + it { should respond_to(:repo) }
  10 + it { should respond_to(:tree) }
  11 + it { should respond_to(:root_ref) }
  12 + it { should respond_to(:tags) }
  13 + it { should respond_to(:commit) }
  14 + it { should respond_to(:commits) }
  15 + it { should respond_to(:commits_between) }
  16 + it { should respond_to(:commits_with_refs) }
  17 + end
  18 +
  19 +
  20 + describe "#discover_default_branch" do
  21 + let(:master) { 'master' }
  22 + let(:stable) { 'stable' }
  23 +
  24 + it "returns 'master' when master exists" do
  25 + repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
  26 + repository.discover_default_branch.should == 'master'
  27 + end
  28 +
  29 + it "returns non-master when master exists but default branch is set to something else" do
  30 + repository.root_ref = 'stable'
  31 + repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
  32 + repository.discover_default_branch.should == 'stable'
  33 + end
  34 +
  35 + it "returns a non-master branch when only one exists" do
  36 + repository.should_receive(:branch_names).at_least(:once).and_return([stable])
  37 + repository.discover_default_branch.should == 'stable'
  38 + end
  39 +
  40 + it "returns nil when no branch exists" do
  41 + repository.should_receive(:branch_names).at_least(:once).and_return([])
  42 + repository.discover_default_branch.should be_nil
  43 + end
  44 + end
  45 +
  46 + describe :commit do
  47 + it "should return first head commit if without params" do
  48 + repository.commit.id.should == repository.repo.commits.first.id
  49 + end
  50 +
  51 + it "should return valid commit" do
  52 + repository.commit(ValidCommit::ID).should be_valid_commit
  53 + end
  54 +
  55 + it "should return nil" do
  56 + repository.commit("+123_4532530XYZ").should be_nil
  57 + end
  58 + end
  59 +
  60 + describe :tree do
  61 + before do
  62 + @commit = repository.commit(ValidCommit::ID)
  63 + end
  64 +
  65 + it "should raise error w/o arguments" do
  66 + lambda { repository.tree }.should raise_error
  67 + end
  68 +
  69 + it "should return root tree for commit" do
  70 + tree = repository.tree(@commit)
  71 + tree.contents.size.should == ValidCommit::FILES_COUNT
  72 + tree.contents.map(&:name).should == ValidCommit::FILES
  73 + end
  74 +
  75 + it "should return root tree for commit with correct path" do
  76 + tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)
  77 + tree.contents.map(&:name).should == ValidCommit::C_FILES
  78 + end
  79 +
  80 + it "should return root tree for commit with incorrect path" do
  81 + repository.tree(@commit, "invalid_path").should be_nil
  82 + end
  83 + end
  84 +
  85 + describe "commits_between" do
  86 + subject do
  87 + commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
  88 + "8470d70da67355c9c009e4401746b1d5410af2e3")
  89 + commits.map { |c| c.id }
  90 + end
  91 +
  92 + it { should have(3).elements }
  93 + it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
  94 + it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
  95 + end
  96 +end
spec/lib/gitlab/popen_spec.rb 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'Gitlab::Popen', no_db: true do
  4 + let (:path) { Rails.root.join('tmp').to_s }
  5 +
  6 + before do
  7 + @klass = Class.new(Object)
  8 + @klass.send(:include, Gitlab::Popen)
  9 + end
  10 +
  11 + context 'zero status' do
  12 + before do
  13 + @output, @status = @klass.new.popen('ls', path)
  14 + end
  15 +
  16 + it { @status.should be_zero }
  17 + it { @output.should include('cache') }
  18 + end
  19 +
  20 + context 'non-zero status' do
  21 + before do
  22 + @output, @status = @klass.new.popen('cat NOTHING', path)
  23 + end
  24 +
  25 + it { @status.should == 1 }
  26 + it { @output.should include('No such file or directory') }
  27 + end
  28 +end
  29 +
spec/lib/popen_spec.rb
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -require 'spec_helper'  
2 -  
3 -describe 'Gitlab::Popen', no_db: true do  
4 - let (:path) { Rails.root.join('tmp').to_s }  
5 -  
6 - before do  
7 - @klass = Class.new(Object)  
8 - @klass.send(:include, Gitlab::Popen)  
9 - end  
10 -  
11 - context 'zero status' do  
12 - before do  
13 - @output, @status = @klass.new.popen('ls', path)  
14 - end  
15 -  
16 - it { @status.should be_zero }  
17 - it { @output.should include('cache') }  
18 - end  
19 -  
20 - context 'non-zero status' do  
21 - before do  
22 - @output, @status = @klass.new.popen('cat NOTHING', path)  
23 - end  
24 -  
25 - it { @status.should == 1 }  
26 - it { @output.should include('No such file or directory') }  
27 - end  
28 -end  
29 -  
spec/lib/shell_spec.rb
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
1 -require 'spec_helper'  
2 -  
3 -describe Gitlab::Shell do  
4 - let(:project) { double('Project', id: 7, path: 'diaspora') }  
5 - let(:gitlab_shell) { Gitlab::Shell.new }  
6 -  
7 - before do  
8 - Project.stub(find: project)  
9 - end  
10 -  
11 - it { should respond_to :add_key }  
12 - it { should respond_to :remove_key }  
13 - it { should respond_to :add_repository }  
14 - it { should respond_to :remove_repository }  
15 -  
16 - it { gitlab_shell.url_to_repo('diaspora').should == Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git" }  
17 -end