summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/api_helpers.rb11
-rw-r--r--spec/support/filter_spec_helper.rb2
-rw-r--r--spec/support/gitlab_stubs/gitlab_ci.yml63
-rw-r--r--spec/support/gitlab_stubs/project_8.json45
-rw-r--r--spec/support/gitlab_stubs/project_8_hooks.json1
-rw-r--r--spec/support/gitlab_stubs/projects.json1
-rw-r--r--spec/support/gitlab_stubs/session.json20
-rw-r--r--spec/support/gitlab_stubs/user.json20
-rw-r--r--spec/support/login_helpers.rb4
-rw-r--r--spec/support/setup_builds_storage.rb17
-rw-r--r--spec/support/stub_gitlab_calls.rb77
-rw-r--r--spec/support/stub_gitlab_data.rb5
12 files changed, 265 insertions, 1 deletions
diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb
index f63322776d4..1b3cafb497c 100644
--- a/spec/support/api_helpers.rb
+++ b/spec/support/api_helpers.rb
@@ -28,6 +28,17 @@ module ApiHelpers
"&private_token=#{user.private_token}" : "")
end
+ def ci_api(path, user = nil)
+ "/ci/api/v1/#{path}" +
+
+ # Normalize query string
+ (path.index('?') ? '' : '?') +
+
+ # Append private_token if given a User object
+ (user.respond_to?(:private_token) ?
+ "&private_token=#{user.private_token}" : "")
+ end
+
def json_response
@_json_response ||= JSON.parse(response.body)
end
diff --git a/spec/support/filter_spec_helper.rb b/spec/support/filter_spec_helper.rb
index 755964e9a3d..203117aee70 100644
--- a/spec/support/filter_spec_helper.rb
+++ b/spec/support/filter_spec_helper.rb
@@ -72,6 +72,6 @@ module FilterSpecHelper
# Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module
def urls
- Rails.application.routes.url_helpers
+ Gitlab::Application.routes.url_helpers
end
end
diff --git a/spec/support/gitlab_stubs/gitlab_ci.yml b/spec/support/gitlab_stubs/gitlab_ci.yml
new file mode 100644
index 00000000000..3482145404e
--- /dev/null
+++ b/spec/support/gitlab_stubs/gitlab_ci.yml
@@ -0,0 +1,63 @@
+image: ruby:2.1
+services:
+ - postgres
+
+before_script:
+ - gem install bundler
+ - bundle install
+ - bundle exec rake db:create
+
+variables:
+ DB_NAME: postgres
+
+types:
+ - test
+ - deploy
+ - notify
+
+rspec:
+ script: "rake spec"
+ tags:
+ - ruby
+ - postgres
+ only:
+ - branches
+
+spinach:
+ script: "rake spinach"
+ allow_failure: true
+ tags:
+ - ruby
+ - mysql
+ except:
+ - tags
+
+staging:
+ script: "cap deploy stating"
+ type: deploy
+ tags:
+ - capistrano
+ - debian
+ except:
+ - stable
+
+production:
+ type: deploy
+ script:
+ - cap deploy production
+ - cap notify
+ tags:
+ - capistrano
+ - debian
+ only:
+ - master
+ - /^deploy-.*$/
+
+dockerhub:
+ type: notify
+ script: "curl http://dockerhub/URL"
+ tags:
+ - ruby
+ - postgres
+ only:
+ - branches
diff --git a/spec/support/gitlab_stubs/project_8.json b/spec/support/gitlab_stubs/project_8.json
new file mode 100644
index 00000000000..f0a9fce859c
--- /dev/null
+++ b/spec/support/gitlab_stubs/project_8.json
@@ -0,0 +1,45 @@
+{
+ "id":8,
+ "description":"ssh access and repository management app for GitLab",
+ "default_branch":"master",
+ "public":false,
+ "visibility_level":0,
+ "ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlab-shell.git",
+ "http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlab-shell.git",
+ "web_url":"http://demo.gitlab.com/gitlab/gitlab-shell",
+ "owner": {
+ "id":4,
+ "name":"GitLab",
+ "created_at":"2012-12-21T13:03:05Z"
+ },
+ "name":"gitlab-shell",
+ "name_with_namespace":"GitLab / gitlab-shell",
+ "path":"gitlab-shell",
+ "path_with_namespace":"gitlab/gitlab-shell",
+ "issues_enabled":true,
+ "merge_requests_enabled":true,
+ "wall_enabled":false,
+ "wiki_enabled":true,
+ "snippets_enabled":false,
+ "created_at":"2013-03-20T13:28:53Z",
+ "last_activity_at":"2013-11-30T00:11:17Z",
+ "namespace":{
+ "created_at":"2012-12-21T13:03:05Z",
+ "description":"Self hosted Git management software",
+ "id":4,
+ "name":"GitLab",
+ "owner_id":1,
+ "path":"gitlab",
+ "updated_at":"2013-03-20T13:29:13Z"
+ },
+ "permissions":{
+ "project_access": {
+ "access_level": 10,
+ "notification_level": 3
+ },
+ "group_access": {
+ "access_level": 50,
+ "notification_level": 3
+ }
+ }
+} \ No newline at end of file
diff --git a/spec/support/gitlab_stubs/project_8_hooks.json b/spec/support/gitlab_stubs/project_8_hooks.json
new file mode 100644
index 00000000000..93d51406d63
--- /dev/null
+++ b/spec/support/gitlab_stubs/project_8_hooks.json
@@ -0,0 +1 @@
+[{}]
diff --git a/spec/support/gitlab_stubs/projects.json b/spec/support/gitlab_stubs/projects.json
new file mode 100644
index 00000000000..ca42c14c5d8
--- /dev/null
+++ b/spec/support/gitlab_stubs/projects.json
@@ -0,0 +1 @@
+[{"id":3,"description":"GitLab is open source software to collaborate on code. Create projects and repositories, manage access and do code reviews.","default_branch":"master","public":true,"visibility_level":20,"ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlabhq.git","http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlabhq.git","web_url":"http://demo.gitlab.com/gitlab/gitlabhq","owner":{"id":4,"name":"GitLab","created_at":"2012-12-21T13:03:05Z"},"name":"gitlabhq","name_with_namespace":"GitLab / gitlabhq","path":"gitlabhq","path_with_namespace":"gitlab/gitlabhq","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":true,"wiki_enabled":true,"snippets_enabled":true,"created_at":"2012-12-21T13:06:34Z","last_activity_at":"2013-12-02T19:10:10Z","namespace":{"created_at":"2012-12-21T13:03:05Z","description":"Self hosted Git management software","id":4,"name":"GitLab","owner_id":1,"path":"gitlab","updated_at":"2013-03-20T13:29:13Z"}},{"id":4,"description":"Component of GitLab CI. Web application","default_branch":"master","public":false,"visibility_level":0,"ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlab-ci.git","http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlab-ci.git","web_url":"http://demo.gitlab.com/gitlab/gitlab-ci","owner":{"id":4,"name":"GitLab","created_at":"2012-12-21T13:03:05Z"},"name":"gitlab-ci","name_with_namespace":"GitLab / gitlab-ci","path":"gitlab-ci","path_with_namespace":"gitlab/gitlab-ci","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":true,"wiki_enabled":true,"snippets_enabled":true,"created_at":"2012-12-21T13:06:50Z","last_activity_at":"2013-11-28T19:26:54Z","namespace":{"created_at":"2012-12-21T13:03:05Z","description":"Self hosted Git management software","id":4,"name":"GitLab","owner_id":1,"path":"gitlab","updated_at":"2013-03-20T13:29:13Z"}},{"id":5,"description":"","default_branch":"master","public":true,"visibility_level":20,"ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlab-recipes.git","http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlab-recipes.git","web_url":"http://demo.gitlab.com/gitlab/gitlab-recipes","owner":{"id":4,"name":"GitLab","created_at":"2012-12-21T13:03:05Z"},"name":"gitlab-recipes","name_with_namespace":"GitLab / gitlab-recipes","path":"gitlab-recipes","path_with_namespace":"gitlab/gitlab-recipes","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":true,"wiki_enabled":true,"snippets_enabled":true,"created_at":"2012-12-21T13:07:02Z","last_activity_at":"2013-12-02T13:54:10Z","namespace":{"created_at":"2012-12-21T13:03:05Z","description":"Self hosted Git management software","id":4,"name":"GitLab","owner_id":1,"path":"gitlab","updated_at":"2013-03-20T13:29:13Z"}},{"id":8,"description":"ssh access and repository management app for GitLab","default_branch":"master","public":false,"visibility_level":0,"ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlab-shell.git","http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlab-shell.git","web_url":"http://demo.gitlab.com/gitlab/gitlab-shell","owner":{"id":4,"name":"GitLab","created_at":"2012-12-21T13:03:05Z"},"name":"gitlab-shell","name_with_namespace":"GitLab / gitlab-shell","path":"gitlab-shell","path_with_namespace":"gitlab/gitlab-shell","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":false,"wiki_enabled":true,"snippets_enabled":false,"created_at":"2013-03-20T13:28:53Z","last_activity_at":"2013-11-30T00:11:17Z","namespace":{"created_at":"2012-12-21T13:03:05Z","description":"Self hosted Git management software","id":4,"name":"GitLab","owner_id":1,"path":"gitlab","updated_at":"2013-03-20T13:29:13Z"}},{"id":9,"description":null,"default_branch":"master","public":false,"visibility_level":0,"ssh_url_to_repo":"git@demo.gitlab.com:gitlab/gitlab_git.git","http_url_to_repo":"http://demo.gitlab.com/gitlab/gitlab_git.git","web_url":"http://demo.gitlab.com/gitlab/gitlab_git","owner":{"id":4,"name":"GitLab","created_at":"2012-12-21T13:03:05Z"},"name":"gitlab_git","name_with_namespace":"GitLab / gitlab_git","path":"gitlab_git","path_with_namespace":"gitlab/gitlab_git","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":false,"wiki_enabled":true,"snippets_enabled":false,"created_at":"2013-04-28T19:15:08Z","last_activity_at":"2013-12-02T13:07:13Z","namespace":{"created_at":"2012-12-21T13:03:05Z","description":"Self hosted Git management software","id":4,"name":"GitLab","owner_id":1,"path":"gitlab","updated_at":"2013-03-20T13:29:13Z"}},{"id":10,"description":"ultra lite authorization library http://randx.github.com/six/\\r\\n ","default_branch":"master","public":true,"visibility_level":20,"ssh_url_to_repo":"git@demo.gitlab.com:sandbox/six.git","http_url_to_repo":"http://demo.gitlab.com/sandbox/six.git","web_url":"http://demo.gitlab.com/sandbox/six","owner":{"id":8,"name":"Sandbox","created_at":"2013-08-01T16:44:17Z"},"name":"Six","name_with_namespace":"Sandbox / Six","path":"six","path_with_namespace":"sandbox/six","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":false,"wiki_enabled":true,"snippets_enabled":false,"created_at":"2013-08-01T16:45:02Z","last_activity_at":"2013-11-29T11:30:56Z","namespace":{"created_at":"2013-08-01T16:44:17Z","description":"","id":8,"name":"Sandbox","owner_id":1,"path":"sandbox","updated_at":"2013-08-01T16:44:17Z"}},{"id":11,"description":"Simple HTML5 Charts using the <canvas> tag ","default_branch":"master","public":false,"visibility_level":0,"ssh_url_to_repo":"git@demo.gitlab.com:sandbox/charts-js.git","http_url_to_repo":"http://demo.gitlab.com/sandbox/charts-js.git","web_url":"http://demo.gitlab.com/sandbox/charts-js","owner":{"id":8,"name":"Sandbox","created_at":"2013-08-01T16:44:17Z"},"name":"Charts.js","name_with_namespace":"Sandbox / Charts.js","path":"charts-js","path_with_namespace":"sandbox/charts-js","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":false,"wiki_enabled":true,"snippets_enabled":false,"created_at":"2013-08-01T16:47:29Z","last_activity_at":"2013-12-02T15:18:11Z","namespace":{"created_at":"2013-08-01T16:44:17Z","description":"","id":8,"name":"Sandbox","owner_id":1,"path":"sandbox","updated_at":"2013-08-01T16:44:17Z"}},{"id":13,"description":"","default_branch":"master","public":false,"visibility_level":0,"ssh_url_to_repo":"git@demo.gitlab.com:sandbox/afro.git","http_url_to_repo":"http://demo.gitlab.com/sandbox/afro.git","web_url":"http://demo.gitlab.com/sandbox/afro","owner":{"id":8,"name":"Sandbox","created_at":"2013-08-01T16:44:17Z"},"name":"Afro","name_with_namespace":"Sandbox / Afro","path":"afro","path_with_namespace":"sandbox/afro","issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":false,"wiki_enabled":true,"snippets_enabled":false,"created_at":"2013-11-14T17:45:19Z","last_activity_at":"2013-12-02T17:41:45Z","namespace":{"created_at":"2013-08-01T16:44:17Z","description":"","id":8,"name":"Sandbox","owner_id":1,"path":"sandbox","updated_at":"2013-08-01T16:44:17Z"}}] \ No newline at end of file
diff --git a/spec/support/gitlab_stubs/session.json b/spec/support/gitlab_stubs/session.json
new file mode 100644
index 00000000000..ce8dfe5ae75
--- /dev/null
+++ b/spec/support/gitlab_stubs/session.json
@@ -0,0 +1,20 @@
+{
+ "id":2,
+ "username":"jsmith",
+ "email":"test@test.com",
+ "name":"John Smith",
+ "bio":"",
+ "skype":"aertert",
+ "linkedin":"",
+ "twitter":"",
+ "theme_id":2,"color_scheme_id":2,
+ "state":"active",
+ "created_at":"2012-12-21T13:02:20Z",
+ "extern_uid":null,
+ "provider":null,
+ "is_admin":false,
+ "can_create_group":false,
+ "can_create_project":false,
+ "private_token":"Wvjy2Krpb7y8xi93owUz",
+ "access_token":"Wvjy2Krpb7y8xi93owUz"
+} \ No newline at end of file
diff --git a/spec/support/gitlab_stubs/user.json b/spec/support/gitlab_stubs/user.json
new file mode 100644
index 00000000000..ce8dfe5ae75
--- /dev/null
+++ b/spec/support/gitlab_stubs/user.json
@@ -0,0 +1,20 @@
+{
+ "id":2,
+ "username":"jsmith",
+ "email":"test@test.com",
+ "name":"John Smith",
+ "bio":"",
+ "skype":"aertert",
+ "linkedin":"",
+ "twitter":"",
+ "theme_id":2,"color_scheme_id":2,
+ "state":"active",
+ "created_at":"2012-12-21T13:02:20Z",
+ "extern_uid":null,
+ "provider":null,
+ "is_admin":false,
+ "can_create_group":false,
+ "can_create_project":false,
+ "private_token":"Wvjy2Krpb7y8xi93owUz",
+ "access_token":"Wvjy2Krpb7y8xi93owUz"
+} \ No newline at end of file
diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb
index ffe30a4246c..cd9fdc6f18e 100644
--- a/spec/support/login_helpers.rb
+++ b/spec/support/login_helpers.rb
@@ -44,4 +44,8 @@ module LoginHelpers
def logout_direct
page.driver.submit :delete, '/users/sign_out', {}
end
+
+ def skip_ci_admin_auth
+ allow_any_instance_of(Ci::Admin::ApplicationController).to receive_messages(authenticate_admin!: true)
+ end
end
diff --git a/spec/support/setup_builds_storage.rb b/spec/support/setup_builds_storage.rb
new file mode 100644
index 00000000000..a3e59646187
--- /dev/null
+++ b/spec/support/setup_builds_storage.rb
@@ -0,0 +1,17 @@
+RSpec.configure do |config|
+ def builds_path
+ Rails.root.join('tmp/builds')
+ end
+
+ config.before(:each) do
+ FileUtils.mkdir_p(builds_path)
+ FileUtils.touch(File.join(builds_path, ".gitkeep"))
+ Settings.gitlab_ci['builds_path'] = builds_path
+ end
+
+ config.after(:suite) do
+ Dir.chdir(builds_path) do
+ `ls | grep -v .gitkeep | xargs rm -r`
+ end
+ end
+end
diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb
new file mode 100644
index 00000000000..5e6744afda1
--- /dev/null
+++ b/spec/support/stub_gitlab_calls.rb
@@ -0,0 +1,77 @@
+module StubGitlabCalls
+ def stub_gitlab_calls
+ stub_session
+ stub_user
+ stub_project_8
+ stub_project_8_hooks
+ stub_projects
+ stub_projects_owned
+ stub_ci_enable
+ end
+
+ def stub_js_gitlab_calls
+ allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
+ end
+
+ private
+
+ def gitlab_url
+ Gitlab.config.gitlab.url
+ end
+
+ def stub_session
+ f = File.read(Rails.root.join('spec/support/gitlab_stubs/session.json'))
+
+ stub_request(:post, "#{gitlab_url}api/v3/session.json").
+ with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}",
+ headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 201, body: f, headers: { 'Content-Type'=>'application/json' })
+ end
+
+ def stub_user
+ f = File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
+
+ stub_request(:get, "#{gitlab_url}api/v3/user?private_token=Wvjy2Krpb7y8xi93owUz").
+ with(headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
+
+ stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token").
+ with(headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
+ end
+
+ def stub_project_8
+ data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json'))
+ allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data))
+ end
+
+ def stub_project_8_hooks
+ data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json'))
+ allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data))
+ end
+
+ def stub_projects
+ f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
+
+ stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
+ with(headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
+ end
+
+ def stub_projects_owned
+ stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
+ with(headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 200, body: "", headers: {})
+ end
+
+ def stub_ci_enable
+ stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz").
+ with(headers: { 'Content-Type'=>'application/json' }).
+ to_return(status: 200, body: "", headers: {})
+ end
+
+ def project_hash_array
+ f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
+ JSON.parse f
+ end
+end
diff --git a/spec/support/stub_gitlab_data.rb b/spec/support/stub_gitlab_data.rb
new file mode 100644
index 00000000000..fa402f35b95
--- /dev/null
+++ b/spec/support/stub_gitlab_data.rb
@@ -0,0 +1,5 @@
+module StubGitlabData
+ def gitlab_ci_yaml
+ File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
+ end
+end