summaryrefslogtreecommitdiff
path: root/spec/gitlab_access_spec.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-02-11 23:43:57 +0100
committerDouwe Maan <douwe@gitlab.com>2015-02-11 23:43:57 +0100
commit562d7eb4ecaa9ca35f970567c0f09cdb29d26521 (patch)
tree032eb81a84675799500b5ecb54789fea90f3fcb6 /spec/gitlab_access_spec.rb
parentf92a9c5a5f3f1cfc8a827abcf67a508133f39f04 (diff)
downloadgitlab-shell-562d7eb4ecaa9ca35f970567c0f09cdb29d26521.tar.gz
Show nice error message when internal API is unreachable.
Diffstat (limited to 'spec/gitlab_access_spec.rb')
-rw-r--r--spec/gitlab_access_spec.rb49
1 files changed, 45 insertions, 4 deletions
diff --git a/spec/gitlab_access_spec.rb b/spec/gitlab_access_spec.rb
index 13db4bd..4768c71 100644
--- a/spec/gitlab_access_spec.rb
+++ b/spec/gitlab_access_spec.rb
@@ -5,15 +5,56 @@ describe GitlabAccess do
let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
- let(:gitlab_access) { GitlabAccess.new(repo_path, 'key-123', 'wow') }
+ let(:api) do
+ double(GitlabNet).tap do |api|
+ api.stub(check_access: GitAccessStatus.new(true))
+ end
+ end
+ subject do
+ GitlabAccess.new(repo_path, 'key-123', 'wow').tap do |access|
+ access.stub(exec_cmd: :exec_called)
+ access.stub(api: api)
+ end
+ end
before do
GitlabConfig.any_instance.stub(repos_path: repository_path)
end
describe :initialize do
- it { gitlab_access.repo_name.should == repo_name }
- it { gitlab_access.repo_path.should == repo_path }
- it { gitlab_access.changes.should == ['wow'] }
+ it { subject.repo_name.should == repo_name }
+ it { subject.repo_path.should == repo_path }
+ it { subject.changes.should == ['wow'] }
+ end
+
+ describe "#exec" do
+ context "access is granted" do
+
+ it "returns true" do
+ expect(subject.exec).to be_true
+ end
+ end
+
+ context "access is denied" do
+
+ before do
+ api.stub(check_access: GitAccessStatus.new(false))
+ end
+
+ it "returns false" do
+ expect(subject.exec).to be_false
+ end
+ end
+
+ context "API connection fails" do
+
+ before do
+ api.stub(:check_access).and_raise(GitlabNet::ApiUnreachableError)
+ end
+
+ it "returns false" do
+ expect(subject.exec).to be_false
+ end
+ end
end
end