summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorReuben Pereira <rpereira@gitlab.com>2019-04-26 17:23:26 +0000
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2019-04-26 17:23:26 +0000
commit4376167a04aaeed084ad93aab2e65550109235c6 (patch)
tree99fa950932bf6ea5c0d453c9d4494a0adb0c16f3 /spec/models
parentbb6908cd5bcb14d70dfadbc2a16d7310bfa65445 (diff)
downloadgitlab-ce-4376167a04aaeed084ad93aab2e65550109235c6.tar.gz
Add ProjectMetricsDashboardSetting model and table
This new table will be used to store the external_dashboard_url which allows users to add a link to their external dashboards (ex Grafana) to the Metrics dashboard.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/project_metrics_setting_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/project_metrics_setting_spec.rb b/spec/models/project_metrics_setting_spec.rb
new file mode 100644
index 00000000000..7df01625ba1
--- /dev/null
+++ b/spec/models/project_metrics_setting_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ProjectMetricsSetting do
+ describe 'Associations' do
+ it { is_expected.to belong_to(:project) }
+ end
+
+ describe 'Validations' do
+ context 'when external_dashboard_url is over 255 chars' do
+ before do
+ subject.external_dashboard_url = 'https://' + 'a' * 250
+ end
+
+ it 'fails validation' do
+ expect(subject).not_to be_valid
+ expect(subject.errors.messages[:external_dashboard_url])
+ .to include('is too long (maximum is 255 characters)')
+ end
+ end
+
+ context 'with unsafe url' do
+ before do
+ subject.external_dashboard_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}
+ end
+
+ it { is_expected.to be_invalid }
+ end
+
+ context 'non ascii chars in external_dashboard_url' do
+ before do
+ subject.external_dashboard_url = 'http://gitlab.com/api/0/projects/project1/something€'
+ end
+
+ it { is_expected.to be_invalid }
+ end
+
+ context 'internal url in external_dashboard_url' do
+ before do
+ subject.external_dashboard_url = 'http://192.168.1.1'
+ end
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'external_dashboard_url is blank' do
+ before do
+ subject.external_dashboard_url = ''
+ end
+
+ it { is_expected.to be_invalid }
+ end
+ end
+end