From 4a1654ed6a2393279ba6227454acbc3a80559d7d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 16 Jan 2014 20:29:18 +0200 Subject: Replace context with service in specs Signed-off-by: Dmitriy Zaporozhets --- spec/contexts/fork_context_spec.rb | 57 --------- spec/contexts/issues/bulk_update_context_spec.rb | 113 ------------------ spec/contexts/projects_create_context_spec.rb | 142 ----------------------- spec/contexts/projects_update_context_spec.rb | 111 ------------------ spec/contexts/search_context_spec.rb | 54 --------- 5 files changed, 477 deletions(-) delete mode 100644 spec/contexts/fork_context_spec.rb delete mode 100644 spec/contexts/issues/bulk_update_context_spec.rb delete mode 100644 spec/contexts/projects_create_context_spec.rb delete mode 100644 spec/contexts/projects_update_context_spec.rb delete mode 100644 spec/contexts/search_context_spec.rb (limited to 'spec/contexts') diff --git a/spec/contexts/fork_context_spec.rb b/spec/contexts/fork_context_spec.rb deleted file mode 100644 index 70f650bc83d..00000000000 --- a/spec/contexts/fork_context_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' - -describe Projects::ForkContext do - describe :fork_by_user do - before do - @from_namespace = create(:namespace) - @from_user = create(:user, namespace: @from_namespace ) - @from_project = create(:project, creator_id: @from_user.id, namespace: @from_namespace) - @to_namespace = create(:namespace) - @to_user = create(:user, namespace: @to_namespace) - end - - context 'fork project' do - - it "successfully creates project in the user namespace" do - @to_project = fork_project(@from_project, @to_user) - - @to_project.owner.should == @to_user - @to_project.namespace.should == @to_user.namespace - end - end - - context 'fork project failure' do - - it "fails due to transaction failure" do - # make the mock gitlab-shell fail - @to_project = fork_project(@from_project, @to_user, false) - - @to_project.errors.should_not be_empty - @to_project.errors[:base].should include("Fork transaction failed.") - end - - end - - context 'project already exists' do - - it "should fail due to validation, not transaction failure" do - @existing_project = create(:project, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace) - @to_project = fork_project(@from_project, @to_user) - - @existing_project.persisted?.should be_true - @to_project.errors[:base].should include("Invalid fork destination") - @to_project.errors[:base].should_not include("Fork transaction failed.") - end - - end - end - - def fork_project(from_project, user, fork_success = true) - context = Projects::ForkContext.new(from_project, user) - shell = double("gitlab_shell") - shell.stub(fork_repository: fork_success) - context.stub(gitlab_shell: shell) - context.execute - end - -end diff --git a/spec/contexts/issues/bulk_update_context_spec.rb b/spec/contexts/issues/bulk_update_context_spec.rb deleted file mode 100644 index 058e43ba090..00000000000 --- a/spec/contexts/issues/bulk_update_context_spec.rb +++ /dev/null @@ -1,113 +0,0 @@ -require 'spec_helper' - -describe Issues::BulkUpdateContext do - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - - let(:issue) { - create(:issue, project: @project) - } - - before do - @user = create :user - opts = { - name: "GitLab", - namespace: @user.namespace - } - @project = Projects::CreateContext.new(@user, opts).execute - end - - describe :close_issue do - - before do - @issues = 5.times.collect do - create(:issue, project: @project) - end - @params = { - update: { - status: 'closed', - issues_ids: @issues.map(&:id) - } - } - end - - it { - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute - result[:success].should be_true - result[:count].should == @issues.count - - @project.issues.opened.should be_empty - @project.issues.closed.should_not be_empty - } - - end - - describe :reopen_issues do - - before do - @issues = 5.times.collect do - create(:closed_issue, project: @project) - end - @params = { - update: { - status: 'reopen', - issues_ids: @issues.map(&:id) - } - } - end - - it { - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute - result[:success].should be_true - result[:count].should == @issues.count - - @project.issues.closed.should be_empty - @project.issues.opened.should_not be_empty - } - - end - - describe :update_assignee do - - before do - @new_assignee = create :user - @params = { - update: { - issues_ids: [issue.id], - assignee_id: @new_assignee.id - } - } - end - - it { - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute - result[:success].should be_true - result[:count].should == 1 - - @project.issues.first.assignee.should == @new_assignee - } - - end - - describe :update_milestone do - - before do - @milestone = create :milestone - @params = { - update: { - issues_ids: [issue.id], - milestone_id: @milestone.id - } - } - end - - it { - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute - result[:success].should be_true - result[:count].should == 1 - - @project.issues.first.milestone.should == @milestone - } - end - -end diff --git a/spec/contexts/projects_create_context_spec.rb b/spec/contexts/projects_create_context_spec.rb deleted file mode 100644 index d5b1cb83510..00000000000 --- a/spec/contexts/projects_create_context_spec.rb +++ /dev/null @@ -1,142 +0,0 @@ -require 'spec_helper' - -describe Projects::CreateContext do - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } - - describe :create_by_user do - before do - @user = create :user - @admin = create :user, admin: true - @opts = { - name: "GitLab", - namespace: @user.namespace - } - end - - context 'user namespace' do - before do - @project = create_project(@user, @opts) - end - - it { @project.should be_valid } - it { @project.owner.should == @user } - it { @project.namespace.should == @user.namespace } - end - - context 'group namespace' do - before do - @group = create :group - @group.add_owner(@user) - - @opts.merge!(namespace_id: @group.id) - @project = create_project(@user, @opts) - end - - it { @project.should be_valid } - it { @project.owner.should == @group } - it { @project.namespace.should == @group } - end - - context 'respect configured visibility 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 } - 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(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } - @project = create_project(@user, @opts) - end - - it { @project.public?.should be_true } - end - - context 'should be private when setting is private' do - before do - @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } - @project = create_project(@user, @opts) - end - - 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 - - def create_project(user, opts) - 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 deleted file mode 100644 index edcaf844e5d..00000000000 --- a/spec/contexts/projects_update_context_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -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 deleted file mode 100644 index 38a6b55383a..00000000000 --- a/spec/contexts/search_context_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe 'Search::GlobalContext' 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, 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, 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 - context 'unauthenticated' do - it 'should return public projects only' do - context = Search::GlobalContext.new(nil, search: "searchable") - results = context.execute - results[:projects].should have(1).items - results[:projects].should include(public_project) - end - end - - context 'authenticated' do - it 'should return public, internal and private projects' do - context = Search::GlobalContext.new(user, search: "searchable") - results = context.execute - results[:projects].should have(3).items - results[:projects].should include(public_project) - results[:projects].should include(found_project) - results[:projects].should include(internal_project) - end - - it 'should return only public & internal projects' do - context = Search::GlobalContext.new(internal_user, search: "searchable") - results = context.execute - results[:projects].should have(2).items - results[:projects].should include(internal_project) - results[:projects].should include(public_project) - end - - it 'namespace name should be searchable' do - context = Search::GlobalContext.new(user, search: "searchable namespace") - results = context.execute - results[:projects].should == [found_project] - end - end - end -end -- cgit v1.2.3