summaryrefslogtreecommitdiff
path: root/spec/lib/constraints
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-11-14 16:55:31 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-11-23 14:08:36 +0200
commit6683fdcfb0ae4ceb368b6f5f63dde0a10a4a3e1b (patch)
tree7530562c2e0702df3e74fc8ca8288e2e3f4ef0a2 /spec/lib/constraints
parentb1b5060dbad15975184ec20a1914c7c48fc804db (diff)
downloadgitlab-ce-6683fdcfb0ae4ceb368b6f5f63dde0a10a4a3e1b.tar.gz
Add nested groups support to the routingdz-allow-nested-group-routing
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec/lib/constraints')
-rw-r--r--spec/lib/constraints/constrainer_helper_spec.rb20
-rw-r--r--spec/lib/constraints/group_url_constrainer_spec.rb20
-rw-r--r--spec/lib/constraints/project_url_constrainer_spec.rb32
-rw-r--r--spec/lib/constraints/user_url_constrainer_spec.rb21
4 files changed, 58 insertions, 35 deletions
diff --git a/spec/lib/constraints/constrainer_helper_spec.rb b/spec/lib/constraints/constrainer_helper_spec.rb
deleted file mode 100644
index 27c8d72aefc..00000000000
--- a/spec/lib/constraints/constrainer_helper_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe ConstrainerHelper, lib: true do
- include ConstrainerHelper
-
- describe '#extract_resource_path' do
- it { expect(extract_resource_path('/gitlab/')).to eq('gitlab') }
- it { expect(extract_resource_path('///gitlab//')).to eq('gitlab') }
- it { expect(extract_resource_path('/gitlab.atom')).to eq('gitlab') }
-
- context 'relative url' do
- before do
- allow(Gitlab::Application.config).to receive(:relative_url_root) { '/gitlab' }
- end
-
- it { expect(extract_resource_path('/gitlab/foo')).to eq('foo') }
- it { expect(extract_resource_path('/foo/bar')).to eq('foo/bar') }
- end
- end
-end
diff --git a/spec/lib/constraints/group_url_constrainer_spec.rb b/spec/lib/constraints/group_url_constrainer_spec.rb
index 42299b17c2b..892554f2870 100644
--- a/spec/lib/constraints/group_url_constrainer_spec.rb
+++ b/spec/lib/constraints/group_url_constrainer_spec.rb
@@ -4,16 +4,20 @@ describe GroupUrlConstrainer, lib: true do
let!(:group) { create(:group, path: 'gitlab') }
describe '#matches?' do
- context 'root group' do
- it { expect(subject.matches?(request '/gitlab')).to be_truthy }
- it { expect(subject.matches?(request '/gitlab.atom')).to be_truthy }
- it { expect(subject.matches?(request '/gitlab/edit')).to be_falsey }
- it { expect(subject.matches?(request '/gitlab-ce')).to be_falsey }
- it { expect(subject.matches?(request '/.gitlab')).to be_falsey }
+ context 'valid request' do
+ let(:request) { build_request(group.path) }
+
+ it { expect(subject.matches?(request)).to be_truthy }
+ end
+
+ context 'invalid request' do
+ let(:request) { build_request('foo') }
+
+ it { expect(subject.matches?(request)).to be_falsey }
end
end
- def request(path)
- double(:request, path: path)
+ def build_request(path)
+ double(:request, params: { id: path })
end
end
diff --git a/spec/lib/constraints/project_url_constrainer_spec.rb b/spec/lib/constraints/project_url_constrainer_spec.rb
new file mode 100644
index 00000000000..94266f6653b
--- /dev/null
+++ b/spec/lib/constraints/project_url_constrainer_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe ProjectUrlConstrainer, lib: true do
+ let!(:project) { create(:project) }
+ let!(:namespace) { project.namespace }
+
+ describe '#matches?' do
+ context 'valid request' do
+ let(:request) { build_request(namespace.path, project.path) }
+
+ it { expect(subject.matches?(request)).to be_truthy }
+ end
+
+ context 'invalid request' do
+ context "non-existing project" do
+ let(:request) { build_request('foo', 'bar') }
+
+ it { expect(subject.matches?(request)).to be_falsey }
+ end
+
+ context "project id ending with .git" do
+ let(:request) { build_request(namespace.path, project.path + '.git') }
+
+ it { expect(subject.matches?(request)).to be_falsey }
+ end
+ end
+ end
+
+ def build_request(namespace, project)
+ double(:request, params: { namespace_id: namespace, id: project })
+ end
+end
diff --git a/spec/lib/constraints/user_url_constrainer_spec.rb b/spec/lib/constraints/user_url_constrainer_spec.rb
index b3f8530c609..207b6fe6c9e 100644
--- a/spec/lib/constraints/user_url_constrainer_spec.rb
+++ b/spec/lib/constraints/user_url_constrainer_spec.rb
@@ -1,16 +1,23 @@
require 'spec_helper'
describe UserUrlConstrainer, lib: true do
- let!(:username) { create(:user, username: 'dz') }
+ let!(:user) { create(:user, username: 'dz') }
describe '#matches?' do
- it { expect(subject.matches?(request '/dz')).to be_truthy }
- it { expect(subject.matches?(request '/dz.atom')).to be_truthy }
- it { expect(subject.matches?(request '/dz/projects')).to be_falsey }
- it { expect(subject.matches?(request '/gitlab')).to be_falsey }
+ context 'valid request' do
+ let(:request) { build_request(user.username) }
+
+ it { expect(subject.matches?(request)).to be_truthy }
+ end
+
+ context 'invalid request' do
+ let(:request) { build_request('foo') }
+
+ it { expect(subject.matches?(request)).to be_falsey }
+ end
end
- def request(path)
- double(:request, path: path)
+ def build_request(username)
+ double(:request, params: { username: username })
end
end