summaryrefslogtreecommitdiff
path: root/spec/contexts
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-27 11:51:46 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-27 11:51:46 +0200
commitfa7d62494a24584c0d27d52344aae8e382304936 (patch)
treecaa8f0f35123e31c4c9e172f99b7f723f355cd6d /spec/contexts
parent9aaf478f10993ac134bf86546c95dbb4284f9f5f (diff)
parentd9bb4230cc3aa161876df821c34d8e9c53d2e7a6 (diff)
downloadgitlab-ce-fa7d62494a24584c0d27d52344aae8e382304936.tar.gz
Merge branch 'authenticated_public_mode' of https://github.com/jhollingsworth/gitlabhq into feature/internal_projects
Conflicts: app/models/project.rb Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec/contexts')
-rw-r--r--spec/contexts/projects_create_context_spec.rb79
-rw-r--r--spec/contexts/projects_update_context_spec.rb111
-rw-r--r--spec/contexts/search_context_spec.rb30
3 files changed, 207 insertions, 13 deletions
diff --git a/spec/contexts/projects_create_context_spec.rb b/spec/contexts/projects_create_context_spec.rb
index 8b2a49dbee5..d5b1cb83510 100644
--- a/spec/contexts/projects_create_context_spec.rb
+++ b/spec/contexts/projects_create_context_spec.rb
@@ -7,6 +7,7 @@ describe Projects::CreateContext do
describe :create_by_user do
before do
@user = create :user
+ @admin = create :user, admin: true
@opts = {
name: "GitLab",
namespace: @user.namespace
@@ -37,7 +38,7 @@ describe Projects::CreateContext do
it { @project.namespace.should == @group }
end
- context 'respect configured public setting' do
+ context 'respect configured visibility setting' do
before(:each) do
@settings = double("settings")
@settings.stub(:issues) { true }
@@ -46,25 +47,90 @@ describe Projects::CreateContext do
@settings.stub(:wall) { true }
@settings.stub(:snippets) { true }
stub_const("Settings", Class.new)
+ @restrictions = double("restrictions")
+ @restrictions.stub(:restricted_visibility_levels) { [] }
+ Settings.stub_chain(:gitlab).and_return(@restrictions)
Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings)
end
context 'should be public when setting is public' do
before do
- @settings.stub(:public) { true }
+ @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC }
@project = create_project(@user, @opts)
end
- it { @project.public.should be_true }
+ it { @project.public?.should be_true }
end
- context 'should be private when setting is not public' do
+ context 'should be private when setting is private' do
before do
- @settings.stub(:public) { false }
+ @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE }
@project = create_project(@user, @opts)
end
- it { @project.public.should be_false }
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be internal when setting is internal' do
+ before do
+ @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::INTERNAL }
+ @project = create_project(@user, @opts)
+ end
+
+ it { @project.internal?.should be_true }
+ end
+ end
+
+ context 'respect configured visibility restrictions setting' do
+ before(:each) do
+ @settings = double("settings")
+ @settings.stub(:issues) { true }
+ @settings.stub(:merge_requests) { true }
+ @settings.stub(:wiki) { true }
+ @settings.stub(:wall) { true }
+ @settings.stub(:snippets) { true }
+ @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE }
+ stub_const("Settings", Class.new)
+ @restrictions = double("restrictions")
+ @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] }
+ Settings.stub_chain(:gitlab).and_return(@restrictions)
+ Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings)
+ end
+
+ context 'should be private when option is public' do
+ before do
+ @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ @project = create_project(@user, @opts)
+ end
+
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be public when option is public for admin' do
+ before do
+ @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ @project = create_project(@admin, @opts)
+ end
+
+ it { @project.public?.should be_true }
+ end
+
+ context 'should be private when option is private' do
+ before do
+ @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
+ @project = create_project(@user, @opts)
+ end
+
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be internal when option is internal' do
+ before do
+ @opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
+ @project = create_project(@user, @opts)
+ end
+
+ it { @project.internal?.should be_true }
end
end
end
@@ -73,3 +139,4 @@ describe Projects::CreateContext do
Projects::CreateContext.new(user, opts).execute
end
end
+
diff --git a/spec/contexts/projects_update_context_spec.rb b/spec/contexts/projects_update_context_spec.rb
new file mode 100644
index 00000000000..edcaf844e5d
--- /dev/null
+++ b/spec/contexts/projects_update_context_spec.rb
@@ -0,0 +1,111 @@
+require 'spec_helper'
+
+describe Projects::UpdateContext do
+ before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
+ after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
+
+ describe :update_by_user do
+ before do
+ @user = create :user
+ @admin = create :user, admin: true
+ @project = create :project, creator_id: @user.id, namespace: @user.namespace
+ @opts = { project: {} }
+ end
+
+ context 'should be private when updated to private' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be internal when updated to internal' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.internal?.should be_true }
+ end
+
+ context 'should be public when updated to public' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.public?.should be_true }
+ end
+
+ context 'respect configured visibility restrictions setting' do
+ before(:each) do
+ @restrictions = double("restrictions")
+ @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] }
+ Settings.stub_chain(:gitlab).and_return(@restrictions)
+ end
+
+ context 'should be private when updated to private' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be internal when updated to internal' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.internal?.should be_true }
+ end
+
+ context 'should be private when updated to public' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ update_project(@project, @user, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.private?.should be_true }
+ end
+
+ context 'should be public when updated to public by admin' do
+ before do
+ @created_private = @project.private?
+
+ @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ update_project(@project, @admin, @opts)
+ end
+
+ it { @created_private.should be_true }
+ it { @project.public?.should be_true }
+ end
+ end
+ end
+
+ def update_project(project, user, opts)
+ Projects::UpdateContext.new(project, user, opts).execute
+ end
+end \ No newline at end of file
diff --git a/spec/contexts/search_context_spec.rb b/spec/contexts/search_context_spec.rb
index 58f747e8725..c25743e0032 100644
--- a/spec/contexts/search_context_spec.rb
+++ b/spec/contexts/search_context_spec.rb
@@ -3,23 +3,39 @@ require 'spec_helper'
describe SearchContext do
let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') }
let(:user) { create(:user, namespace: found_namespace) }
- let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, public: false) }
+ let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') }
- let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, public: false) }
- let(:public_namespace) { create(:namespace, path: 'something_else',name: 'searchable public namespace') }
- let(:other_user) { create(:user, namespace: public_namespace) }
- let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: other_user.id, namespace: public_namespace, public: true) }
+ let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
+
+ let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') }
+ let(:internal_user) { create(:user, namespace: internal_namespace) }
+ let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) }
+
+ let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') }
+ let(:public_user) { create(:user, namespace: public_namespace) }
+ let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
describe '#execute' do
it 'public projects should be searchable' do
- context = SearchContext.new([found_project.id], {search_code: false, search: "searchable"})
+ context = SearchContext.new([found_project.id], nil, {search_code: false, search: "searchable"})
results = context.execute
results[:projects].should == [found_project, public_project]
end
+ it 'internal projects should be searchable' do
+ context = SearchContext.new([found_project.id], user, {search_code: false, search: "searchable"})
+ results = context.execute
+ # can't seem to rely on the return order, so check this way
+ #subject { results[:projects] }
+ results[:projects].should have(3).items
+ results[:projects].should include(found_project)
+ results[:projects].should include(internal_project)
+ results[:projects].should include(public_project)
+ end
+
it 'namespace name should be searchable' do
- context = SearchContext.new([found_project.id], {search_code: false, search: "searchable namespace"})
+ context = SearchContext.new([found_project.id], user, {search_code: false, search: "searchable namespace"})
results = context.execute
results[:projects].should == [found_project]
end