gitlab-org--gitlab-foss/spec/support/stub_gitlab_calls.rb

90 lines
3 KiB
Ruby
Raw Normal View History

2015-08-25 21:42:46 -04:00
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
2015-09-10 10:55:09 -04:00
allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
2015-08-25 21:42:46 -04:00
end
2015-10-05 07:12:00 -04:00
def stub_ci_commit_to_return_yaml_file
stub_ci_commit_yaml_file(gitlab_ci_yaml)
end
def stub_ci_commit_yaml_file(ci_yaml)
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { ci_yaml }
end
def stub_ci_builds_disabled
allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false)
end
2015-08-25 21:42:46 -04:00
private
def gitlab_url
2015-09-10 10:04:06 -04:00
Gitlab.config.gitlab.url
2015-08-25 21:42:46 -04:00
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").
2015-09-14 07:37:18 -04:00
with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}",
2015-09-15 08:51:03 -04:00
headers: { 'Content-Type'=>'application/json' }).
to_return(status: 201, body: f, headers: { 'Content-Type'=>'application/json' })
2015-08-25 21:42:46 -04:00
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").
2015-09-15 08:51:03 -04:00
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
2015-08-25 21:42:46 -04:00
stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token").
2015-09-15 08:51:03 -04:00
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
2015-08-25 21:42:46 -04:00
end
def stub_project_8
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json'))
2015-09-10 10:55:09 -04:00
allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data))
2015-08-25 21:42:46 -04:00
end
def stub_project_8_hooks
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json'))
2015-09-10 10:55:09 -04:00
allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data))
2015-08-25 21:42:46 -04:00
end
def stub_projects
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
2015-09-10 10:04:06 -04:00
2015-08-25 21:42:46 -04:00
stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
2015-09-15 08:51:03 -04:00
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
2015-08-25 21:42:46 -04:00
end
def stub_projects_owned
stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
2015-09-15 08:51:03 -04:00
with(headers: { 'Content-Type'=>'application/json' }).
2015-09-14 07:37:18 -04:00
to_return(status: 200, body: "", headers: {})
2015-08-25 21:42:46 -04:00
end
def stub_ci_enable
stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz").
2015-09-15 08:51:03 -04:00
with(headers: { 'Content-Type'=>'application/json' }).
2015-09-14 07:37:18 -04:00
to_return(status: 200, body: "", headers: {})
2015-08-25 21:42:46 -04:00
end
def project_hash_array
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
2015-09-14 07:37:18 -04:00
JSON.parse f
2015-08-25 21:42:46 -04:00
end
end