summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-06-11 13:29:37 +0000
committerDouwe Maan <douwe@gitlab.com>2018-06-11 13:29:37 +0000
commit1418afc2d6e7699f08a1fc5f33b78ea847ac1451 (patch)
tree7f1cd2621237c4dd234651bd16d6e304989b731d /spec/validators
parent180dc237152d60d05e4f75d8c936e81ba783b6cd (diff)
downloadgitlab-ce-1418afc2d6e7699f08a1fc5f33b78ea847ac1451.tar.gz
Avoid checking the user format in every url validation
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/url_validator_spec.rb53
1 files changed, 48 insertions, 5 deletions
diff --git a/spec/validators/url_validator_spec.rb b/spec/validators/url_validator_spec.rb
index 2d719263fc8..93fe013d11c 100644
--- a/spec/validators/url_validator_spec.rb
+++ b/spec/validators/url_validator_spec.rb
@@ -50,13 +50,56 @@ describe UrlValidator do
end
end
- context 'when ports is set' do
- let(:validator) { described_class.new(attributes: [:link_url], ports: [443]) }
+ context 'when ports is' do
+ let(:validator) { described_class.new(attributes: [:link_url], ports: ports) }
- it 'blocks urls with a different port' do
- subject
+ context 'empty' do
+ let(:ports) { [] }
- expect(badge.errors.empty?).to be false
+ it 'does not block any port' do
+ subject
+
+ expect(badge.errors.empty?).to be true
+ end
+ end
+
+ context 'set' do
+ let(:ports) { [443] }
+
+ it 'blocks urls with a different port' do
+ subject
+
+ expect(badge.errors.empty?).to be false
+ end
+ end
+ end
+
+ context 'when enforce_user is' do
+ let(:url) { 'http://$user@example.com'}
+ let(:validator) { described_class.new(attributes: [:link_url], enforce_user: enforce_user) }
+
+ context 'true' do
+ let(:enforce_user) { true }
+
+ it 'checks user format' do
+ badge.link_url = url
+
+ subject
+
+ expect(badge.errors.empty?).to be false
+ end
+ end
+
+ context 'false (default)' do
+ let(:enforce_user) { false }
+
+ it 'does not check user format' do
+ badge.link_url = url
+
+ subject
+
+ expect(badge.errors.empty?).to be true
+ end
end
end
end