summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2019-01-28 16:19:10 +0530
committerrpereira2 <rpereira@gitlab.com>2019-02-07 10:37:06 +0530
commit03aa8731d984b63a0c8e15699dba22b1175fd705 (patch)
tree733126e6138b888eab147619ac63c67a91f99de3
parent85bfa37f5ac90218220e7429eb8e6beb4f5cc2d8 (diff)
downloadgitlab-ce-03aa8731d984b63a0c8e15699dba22b1175fd705.tar.gz
Add specs for org and project name methods
-rw-r--r--spec/models/error_tracking/project_error_tracking_setting_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/models/error_tracking/project_error_tracking_setting_spec.rb b/spec/models/error_tracking/project_error_tracking_setting_spec.rb
index d30228b863c..85d0e30d748 100644
--- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb
+++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb
@@ -227,6 +227,47 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
it_behaves_like 'name from api_url', :project_name, 'Project Slug'
end
+ context 'names from api_url' do
+ shared_examples_for 'name from api_url' do |name, titleized_slug|
+ let(:name_with_equals) { :"#{name}=" }
+
+ context 'name is present in DB' do
+ it 'returns name from DB' do
+ subject.public_send(name_with_equals, 'Sentry name')
+ subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
+
+ expect(subject.public_send(name)).to eq('Sentry name')
+ end
+ end
+
+ context 'name is null in DB' do
+ it 'titleizes and returns slug from api_url' do
+ subject.public_send(name_with_equals, nil)
+ subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
+
+ expect(subject.public_send(name)).to eq(titleized_slug)
+ end
+
+ it 'returns nil when api_url is incorrect' do
+ subject.public_send(name_with_equals, nil)
+ subject.api_url = 'http://gitlab.com/api/0/projects/'
+
+ expect(subject.public_send(name)).to be_nil
+ end
+
+ it 'returns nil when api_url is blank' do
+ subject.public_send(name_with_equals, nil)
+ subject.api_url = nil
+
+ expect(subject.public_send(name)).to be_nil
+ end
+ end
+ end
+
+ it_behaves_like 'name from api_url', :organization_name, 'Org Slug'
+ it_behaves_like 'name from api_url', :project_name, 'Project Slug'
+ end
+
describe '.build_api_url_from' do
it 'correctly builds api_url with slugs' do
api_url = described_class.build_api_url_from(