From 76c6aeb9bc9855e9a65bb08db862e92ac923255e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Sep 2015 13:37:50 +0200 Subject: Merge CI factories and CI spec/support with GitLab --- spec/support/stub_gitlab_calls.rb | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 spec/support/stub_gitlab_calls.rb (limited to 'spec/support/stub_gitlab_calls.rb') diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb new file mode 100644 index 00000000000..931ef963c0f --- /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 + Network.any_instance.stub(:projects) { project_hash_array } + end + + private + + def gitlab_url + GitlabCi.config.gitlab_server.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')) + Network.any_instance.stub(: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')) + Network.any_instance.stub(: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')) + return JSON.parse f + end +end -- cgit v1.2.1