Commit 4a1654ed6a2393279ba6227454acbc3a80559d7d
1 parent
1d2bdb4d
Exists in
spb-stable
and in
3 other branches
Replace context with service in specs
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
11 changed files
with
478 additions
and
478 deletions
Show diff stats
spec/contexts/fork_context_spec.rb
| ... | ... | @@ -1,57 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Projects::ForkContext do | |
| 4 | - describe :fork_by_user do | |
| 5 | - before do | |
| 6 | - @from_namespace = create(:namespace) | |
| 7 | - @from_user = create(:user, namespace: @from_namespace ) | |
| 8 | - @from_project = create(:project, creator_id: @from_user.id, namespace: @from_namespace) | |
| 9 | - @to_namespace = create(:namespace) | |
| 10 | - @to_user = create(:user, namespace: @to_namespace) | |
| 11 | - end | |
| 12 | - | |
| 13 | - context 'fork project' do | |
| 14 | - | |
| 15 | - it "successfully creates project in the user namespace" do | |
| 16 | - @to_project = fork_project(@from_project, @to_user) | |
| 17 | - | |
| 18 | - @to_project.owner.should == @to_user | |
| 19 | - @to_project.namespace.should == @to_user.namespace | |
| 20 | - end | |
| 21 | - end | |
| 22 | - | |
| 23 | - context 'fork project failure' do | |
| 24 | - | |
| 25 | - it "fails due to transaction failure" do | |
| 26 | - # make the mock gitlab-shell fail | |
| 27 | - @to_project = fork_project(@from_project, @to_user, false) | |
| 28 | - | |
| 29 | - @to_project.errors.should_not be_empty | |
| 30 | - @to_project.errors[:base].should include("Fork transaction failed.") | |
| 31 | - end | |
| 32 | - | |
| 33 | - end | |
| 34 | - | |
| 35 | - context 'project already exists' do | |
| 36 | - | |
| 37 | - it "should fail due to validation, not transaction failure" do | |
| 38 | - @existing_project = create(:project, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace) | |
| 39 | - @to_project = fork_project(@from_project, @to_user) | |
| 40 | - | |
| 41 | - @existing_project.persisted?.should be_true | |
| 42 | - @to_project.errors[:base].should include("Invalid fork destination") | |
| 43 | - @to_project.errors[:base].should_not include("Fork transaction failed.") | |
| 44 | - end | |
| 45 | - | |
| 46 | - end | |
| 47 | - end | |
| 48 | - | |
| 49 | - def fork_project(from_project, user, fork_success = true) | |
| 50 | - context = Projects::ForkContext.new(from_project, user) | |
| 51 | - shell = double("gitlab_shell") | |
| 52 | - shell.stub(fork_repository: fork_success) | |
| 53 | - context.stub(gitlab_shell: shell) | |
| 54 | - context.execute | |
| 55 | - end | |
| 56 | - | |
| 57 | -end |
spec/contexts/issues/bulk_update_context_spec.rb
| ... | ... | @@ -1,113 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Issues::BulkUpdateContext do | |
| 4 | - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | - | |
| 7 | - let(:issue) { | |
| 8 | - create(:issue, project: @project) | |
| 9 | - } | |
| 10 | - | |
| 11 | - before do | |
| 12 | - @user = create :user | |
| 13 | - opts = { | |
| 14 | - name: "GitLab", | |
| 15 | - namespace: @user.namespace | |
| 16 | - } | |
| 17 | - @project = Projects::CreateContext.new(@user, opts).execute | |
| 18 | - end | |
| 19 | - | |
| 20 | - describe :close_issue do | |
| 21 | - | |
| 22 | - before do | |
| 23 | - @issues = 5.times.collect do | |
| 24 | - create(:issue, project: @project) | |
| 25 | - end | |
| 26 | - @params = { | |
| 27 | - update: { | |
| 28 | - status: 'closed', | |
| 29 | - issues_ids: @issues.map(&:id) | |
| 30 | - } | |
| 31 | - } | |
| 32 | - end | |
| 33 | - | |
| 34 | - it { | |
| 35 | - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 36 | - result[:success].should be_true | |
| 37 | - result[:count].should == @issues.count | |
| 38 | - | |
| 39 | - @project.issues.opened.should be_empty | |
| 40 | - @project.issues.closed.should_not be_empty | |
| 41 | - } | |
| 42 | - | |
| 43 | - end | |
| 44 | - | |
| 45 | - describe :reopen_issues do | |
| 46 | - | |
| 47 | - before do | |
| 48 | - @issues = 5.times.collect do | |
| 49 | - create(:closed_issue, project: @project) | |
| 50 | - end | |
| 51 | - @params = { | |
| 52 | - update: { | |
| 53 | - status: 'reopen', | |
| 54 | - issues_ids: @issues.map(&:id) | |
| 55 | - } | |
| 56 | - } | |
| 57 | - end | |
| 58 | - | |
| 59 | - it { | |
| 60 | - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 61 | - result[:success].should be_true | |
| 62 | - result[:count].should == @issues.count | |
| 63 | - | |
| 64 | - @project.issues.closed.should be_empty | |
| 65 | - @project.issues.opened.should_not be_empty | |
| 66 | - } | |
| 67 | - | |
| 68 | - end | |
| 69 | - | |
| 70 | - describe :update_assignee do | |
| 71 | - | |
| 72 | - before do | |
| 73 | - @new_assignee = create :user | |
| 74 | - @params = { | |
| 75 | - update: { | |
| 76 | - issues_ids: [issue.id], | |
| 77 | - assignee_id: @new_assignee.id | |
| 78 | - } | |
| 79 | - } | |
| 80 | - end | |
| 81 | - | |
| 82 | - it { | |
| 83 | - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 84 | - result[:success].should be_true | |
| 85 | - result[:count].should == 1 | |
| 86 | - | |
| 87 | - @project.issues.first.assignee.should == @new_assignee | |
| 88 | - } | |
| 89 | - | |
| 90 | - end | |
| 91 | - | |
| 92 | - describe :update_milestone do | |
| 93 | - | |
| 94 | - before do | |
| 95 | - @milestone = create :milestone | |
| 96 | - @params = { | |
| 97 | - update: { | |
| 98 | - issues_ids: [issue.id], | |
| 99 | - milestone_id: @milestone.id | |
| 100 | - } | |
| 101 | - } | |
| 102 | - end | |
| 103 | - | |
| 104 | - it { | |
| 105 | - result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 106 | - result[:success].should be_true | |
| 107 | - result[:count].should == 1 | |
| 108 | - | |
| 109 | - @project.issues.first.milestone.should == @milestone | |
| 110 | - } | |
| 111 | - end | |
| 112 | - | |
| 113 | -end |
spec/contexts/projects_create_context_spec.rb
| ... | ... | @@ -1,142 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Projects::CreateContext do | |
| 4 | - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | - | |
| 7 | - describe :create_by_user do | |
| 8 | - before do | |
| 9 | - @user = create :user | |
| 10 | - @admin = create :user, admin: true | |
| 11 | - @opts = { | |
| 12 | - name: "GitLab", | |
| 13 | - namespace: @user.namespace | |
| 14 | - } | |
| 15 | - end | |
| 16 | - | |
| 17 | - context 'user namespace' do | |
| 18 | - before do | |
| 19 | - @project = create_project(@user, @opts) | |
| 20 | - end | |
| 21 | - | |
| 22 | - it { @project.should be_valid } | |
| 23 | - it { @project.owner.should == @user } | |
| 24 | - it { @project.namespace.should == @user.namespace } | |
| 25 | - end | |
| 26 | - | |
| 27 | - context 'group namespace' do | |
| 28 | - before do | |
| 29 | - @group = create :group | |
| 30 | - @group.add_owner(@user) | |
| 31 | - | |
| 32 | - @opts.merge!(namespace_id: @group.id) | |
| 33 | - @project = create_project(@user, @opts) | |
| 34 | - end | |
| 35 | - | |
| 36 | - it { @project.should be_valid } | |
| 37 | - it { @project.owner.should == @group } | |
| 38 | - it { @project.namespace.should == @group } | |
| 39 | - end | |
| 40 | - | |
| 41 | - context 'respect configured visibility setting' do | |
| 42 | - before(:each) do | |
| 43 | - @settings = double("settings") | |
| 44 | - @settings.stub(:issues) { true } | |
| 45 | - @settings.stub(:merge_requests) { true } | |
| 46 | - @settings.stub(:wiki) { true } | |
| 47 | - @settings.stub(:wall) { true } | |
| 48 | - @settings.stub(:snippets) { true } | |
| 49 | - stub_const("Settings", Class.new) | |
| 50 | - @restrictions = double("restrictions") | |
| 51 | - @restrictions.stub(:restricted_visibility_levels) { [] } | |
| 52 | - Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 53 | - Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | |
| 54 | - end | |
| 55 | - | |
| 56 | - context 'should be public when setting is public' do | |
| 57 | - before do | |
| 58 | - @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } | |
| 59 | - @project = create_project(@user, @opts) | |
| 60 | - end | |
| 61 | - | |
| 62 | - it { @project.public?.should be_true } | |
| 63 | - end | |
| 64 | - | |
| 65 | - context 'should be private when setting is private' do | |
| 66 | - before do | |
| 67 | - @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } | |
| 68 | - @project = create_project(@user, @opts) | |
| 69 | - end | |
| 70 | - | |
| 71 | - it { @project.private?.should be_true } | |
| 72 | - end | |
| 73 | - | |
| 74 | - context 'should be internal when setting is internal' do | |
| 75 | - before do | |
| 76 | - @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::INTERNAL } | |
| 77 | - @project = create_project(@user, @opts) | |
| 78 | - end | |
| 79 | - | |
| 80 | - it { @project.internal?.should be_true } | |
| 81 | - end | |
| 82 | - end | |
| 83 | - | |
| 84 | - context 'respect configured visibility restrictions setting' do | |
| 85 | - before(:each) do | |
| 86 | - @settings = double("settings") | |
| 87 | - @settings.stub(:issues) { true } | |
| 88 | - @settings.stub(:merge_requests) { true } | |
| 89 | - @settings.stub(:wiki) { true } | |
| 90 | - @settings.stub(:wall) { true } | |
| 91 | - @settings.stub(:snippets) { true } | |
| 92 | - @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } | |
| 93 | - stub_const("Settings", Class.new) | |
| 94 | - @restrictions = double("restrictions") | |
| 95 | - @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } | |
| 96 | - Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 97 | - Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | |
| 98 | - end | |
| 99 | - | |
| 100 | - context 'should be private when option is public' do | |
| 101 | - before do | |
| 102 | - @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 103 | - @project = create_project(@user, @opts) | |
| 104 | - end | |
| 105 | - | |
| 106 | - it { @project.private?.should be_true } | |
| 107 | - end | |
| 108 | - | |
| 109 | - context 'should be public when option is public for admin' do | |
| 110 | - before do | |
| 111 | - @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 112 | - @project = create_project(@admin, @opts) | |
| 113 | - end | |
| 114 | - | |
| 115 | - it { @project.public?.should be_true } | |
| 116 | - end | |
| 117 | - | |
| 118 | - context 'should be private when option is private' do | |
| 119 | - before do | |
| 120 | - @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 121 | - @project = create_project(@user, @opts) | |
| 122 | - end | |
| 123 | - | |
| 124 | - it { @project.private?.should be_true } | |
| 125 | - end | |
| 126 | - | |
| 127 | - context 'should be internal when option is internal' do | |
| 128 | - before do | |
| 129 | - @opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 130 | - @project = create_project(@user, @opts) | |
| 131 | - end | |
| 132 | - | |
| 133 | - it { @project.internal?.should be_true } | |
| 134 | - end | |
| 135 | - end | |
| 136 | - end | |
| 137 | - | |
| 138 | - def create_project(user, opts) | |
| 139 | - Projects::CreateContext.new(user, opts).execute | |
| 140 | - end | |
| 141 | -end | |
| 142 | - |
spec/contexts/projects_update_context_spec.rb
| ... | ... | @@ -1,111 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Projects::UpdateContext do | |
| 4 | - before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | - after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | - | |
| 7 | - describe :update_by_user do | |
| 8 | - before do | |
| 9 | - @user = create :user | |
| 10 | - @admin = create :user, admin: true | |
| 11 | - @project = create :project, creator_id: @user.id, namespace: @user.namespace | |
| 12 | - @opts = { project: {} } | |
| 13 | - end | |
| 14 | - | |
| 15 | - context 'should be private when updated to private' do | |
| 16 | - before do | |
| 17 | - @created_private = @project.private? | |
| 18 | - | |
| 19 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 20 | - update_project(@project, @user, @opts) | |
| 21 | - end | |
| 22 | - | |
| 23 | - it { @created_private.should be_true } | |
| 24 | - it { @project.private?.should be_true } | |
| 25 | - end | |
| 26 | - | |
| 27 | - context 'should be internal when updated to internal' do | |
| 28 | - before do | |
| 29 | - @created_private = @project.private? | |
| 30 | - | |
| 31 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 32 | - update_project(@project, @user, @opts) | |
| 33 | - end | |
| 34 | - | |
| 35 | - it { @created_private.should be_true } | |
| 36 | - it { @project.internal?.should be_true } | |
| 37 | - end | |
| 38 | - | |
| 39 | - context 'should be public when updated to public' do | |
| 40 | - before do | |
| 41 | - @created_private = @project.private? | |
| 42 | - | |
| 43 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 44 | - update_project(@project, @user, @opts) | |
| 45 | - end | |
| 46 | - | |
| 47 | - it { @created_private.should be_true } | |
| 48 | - it { @project.public?.should be_true } | |
| 49 | - end | |
| 50 | - | |
| 51 | - context 'respect configured visibility restrictions setting' do | |
| 52 | - before(:each) do | |
| 53 | - @restrictions = double("restrictions") | |
| 54 | - @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } | |
| 55 | - Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 56 | - end | |
| 57 | - | |
| 58 | - context 'should be private when updated to private' do | |
| 59 | - before do | |
| 60 | - @created_private = @project.private? | |
| 61 | - | |
| 62 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 63 | - update_project(@project, @user, @opts) | |
| 64 | - end | |
| 65 | - | |
| 66 | - it { @created_private.should be_true } | |
| 67 | - it { @project.private?.should be_true } | |
| 68 | - end | |
| 69 | - | |
| 70 | - context 'should be internal when updated to internal' do | |
| 71 | - before do | |
| 72 | - @created_private = @project.private? | |
| 73 | - | |
| 74 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 75 | - update_project(@project, @user, @opts) | |
| 76 | - end | |
| 77 | - | |
| 78 | - it { @created_private.should be_true } | |
| 79 | - it { @project.internal?.should be_true } | |
| 80 | - end | |
| 81 | - | |
| 82 | - context 'should be private when updated to public' do | |
| 83 | - before do | |
| 84 | - @created_private = @project.private? | |
| 85 | - | |
| 86 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 87 | - update_project(@project, @user, @opts) | |
| 88 | - end | |
| 89 | - | |
| 90 | - it { @created_private.should be_true } | |
| 91 | - it { @project.private?.should be_true } | |
| 92 | - end | |
| 93 | - | |
| 94 | - context 'should be public when updated to public by admin' do | |
| 95 | - before do | |
| 96 | - @created_private = @project.private? | |
| 97 | - | |
| 98 | - @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 99 | - update_project(@project, @admin, @opts) | |
| 100 | - end | |
| 101 | - | |
| 102 | - it { @created_private.should be_true } | |
| 103 | - it { @project.public?.should be_true } | |
| 104 | - end | |
| 105 | - end | |
| 106 | - end | |
| 107 | - | |
| 108 | - def update_project(project, user, opts) | |
| 109 | - Projects::UpdateContext.new(project, user, opts).execute | |
| 110 | - end | |
| 111 | -end | |
| 112 | 0 | \ No newline at end of file |
spec/contexts/search_context_spec.rb
| ... | ... | @@ -1,54 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe 'Search::GlobalContext' do | |
| 4 | - let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } | |
| 5 | - let(:user) { create(:user, namespace: found_namespace) } | |
| 6 | - let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
| 7 | - | |
| 8 | - let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') } | |
| 9 | - let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
| 10 | - | |
| 11 | - let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') } | |
| 12 | - let(:internal_user) { create(:user, namespace: internal_namespace) } | |
| 13 | - let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } | |
| 14 | - | |
| 15 | - let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') } | |
| 16 | - let(:public_user) { create(:user, namespace: public_namespace) } | |
| 17 | - let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
| 18 | - | |
| 19 | - describe '#execute' do | |
| 20 | - context 'unauthenticated' do | |
| 21 | - it 'should return public projects only' do | |
| 22 | - context = Search::GlobalContext.new(nil, search: "searchable") | |
| 23 | - results = context.execute | |
| 24 | - results[:projects].should have(1).items | |
| 25 | - results[:projects].should include(public_project) | |
| 26 | - end | |
| 27 | - end | |
| 28 | - | |
| 29 | - context 'authenticated' do | |
| 30 | - it 'should return public, internal and private projects' do | |
| 31 | - context = Search::GlobalContext.new(user, search: "searchable") | |
| 32 | - results = context.execute | |
| 33 | - results[:projects].should have(3).items | |
| 34 | - results[:projects].should include(public_project) | |
| 35 | - results[:projects].should include(found_project) | |
| 36 | - results[:projects].should include(internal_project) | |
| 37 | - end | |
| 38 | - | |
| 39 | - it 'should return only public & internal projects' do | |
| 40 | - context = Search::GlobalContext.new(internal_user, search: "searchable") | |
| 41 | - results = context.execute | |
| 42 | - results[:projects].should have(2).items | |
| 43 | - results[:projects].should include(internal_project) | |
| 44 | - results[:projects].should include(public_project) | |
| 45 | - end | |
| 46 | - | |
| 47 | - it 'namespace name should be searchable' do | |
| 48 | - context = Search::GlobalContext.new(user, search: "searchable namespace") | |
| 49 | - results = context.execute | |
| 50 | - results[:projects].should == [found_project] | |
| 51 | - end | |
| 52 | - end | |
| 53 | - end | |
| 54 | -end |
spec/models/forked_project_link_spec.rb
| ... | ... | @@ -58,7 +58,7 @@ describe :forked_from_project do |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | 60 | def fork_project(from_project, user) |
| 61 | - context = Projects::ForkContext.new(from_project, user) | |
| 61 | + context = Projects::ForkService.new(from_project, user) | |
| 62 | 62 | shell = double("gitlab_shell") |
| 63 | 63 | shell.stub(fork_repository: true) |
| 64 | 64 | context.stub(gitlab_shell: shell) | ... | ... |
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe Projects::ForkService do | |
| 4 | + describe :fork_by_user do | |
| 5 | + before do | |
| 6 | + @from_namespace = create(:namespace) | |
| 7 | + @from_user = create(:user, namespace: @from_namespace ) | |
| 8 | + @from_project = create(:project, creator_id: @from_user.id, namespace: @from_namespace) | |
| 9 | + @to_namespace = create(:namespace) | |
| 10 | + @to_user = create(:user, namespace: @to_namespace) | |
| 11 | + end | |
| 12 | + | |
| 13 | + context 'fork project' do | |
| 14 | + | |
| 15 | + it "successfully creates project in the user namespace" do | |
| 16 | + @to_project = fork_project(@from_project, @to_user) | |
| 17 | + | |
| 18 | + @to_project.owner.should == @to_user | |
| 19 | + @to_project.namespace.should == @to_user.namespace | |
| 20 | + end | |
| 21 | + end | |
| 22 | + | |
| 23 | + context 'fork project failure' do | |
| 24 | + | |
| 25 | + it "fails due to transaction failure" do | |
| 26 | + # make the mock gitlab-shell fail | |
| 27 | + @to_project = fork_project(@from_project, @to_user, false) | |
| 28 | + | |
| 29 | + @to_project.errors.should_not be_empty | |
| 30 | + @to_project.errors[:base].should include("Fork transaction failed.") | |
| 31 | + end | |
| 32 | + | |
| 33 | + end | |
| 34 | + | |
| 35 | + context 'project already exists' do | |
| 36 | + | |
| 37 | + it "should fail due to validation, not transaction failure" do | |
| 38 | + @existing_project = create(:project, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace) | |
| 39 | + @to_project = fork_project(@from_project, @to_user) | |
| 40 | + | |
| 41 | + @existing_project.persisted?.should be_true | |
| 42 | + @to_project.errors[:base].should include("Invalid fork destination") | |
| 43 | + @to_project.errors[:base].should_not include("Fork transaction failed.") | |
| 44 | + end | |
| 45 | + | |
| 46 | + end | |
| 47 | + end | |
| 48 | + | |
| 49 | + def fork_project(from_project, user, fork_success = true) | |
| 50 | + context = Projects::ForkService.new(from_project, user) | |
| 51 | + shell = double("gitlab_shell") | |
| 52 | + shell.stub(fork_repository: fork_success) | |
| 53 | + context.stub(gitlab_shell: shell) | |
| 54 | + context.execute | |
| 55 | + end | |
| 56 | + | |
| 57 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,113 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe Issues::BulkUpdateService do | |
| 4 | + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | + | |
| 7 | + let(:issue) { | |
| 8 | + create(:issue, project: @project) | |
| 9 | + } | |
| 10 | + | |
| 11 | + before do | |
| 12 | + @user = create :user | |
| 13 | + opts = { | |
| 14 | + name: "GitLab", | |
| 15 | + namespace: @user.namespace | |
| 16 | + } | |
| 17 | + @project = Projects::CreateService.new(@user, opts).execute | |
| 18 | + end | |
| 19 | + | |
| 20 | + describe :close_issue do | |
| 21 | + | |
| 22 | + before do | |
| 23 | + @issues = 5.times.collect do | |
| 24 | + create(:issue, project: @project) | |
| 25 | + end | |
| 26 | + @params = { | |
| 27 | + update: { | |
| 28 | + status: 'closed', | |
| 29 | + issues_ids: @issues.map(&:id) | |
| 30 | + } | |
| 31 | + } | |
| 32 | + end | |
| 33 | + | |
| 34 | + it { | |
| 35 | + result = Issues::BulkUpdateService.new(@project, @user, @params).execute | |
| 36 | + result[:success].should be_true | |
| 37 | + result[:count].should == @issues.count | |
| 38 | + | |
| 39 | + @project.issues.opened.should be_empty | |
| 40 | + @project.issues.closed.should_not be_empty | |
| 41 | + } | |
| 42 | + | |
| 43 | + end | |
| 44 | + | |
| 45 | + describe :reopen_issues do | |
| 46 | + | |
| 47 | + before do | |
| 48 | + @issues = 5.times.collect do | |
| 49 | + create(:closed_issue, project: @project) | |
| 50 | + end | |
| 51 | + @params = { | |
| 52 | + update: { | |
| 53 | + status: 'reopen', | |
| 54 | + issues_ids: @issues.map(&:id) | |
| 55 | + } | |
| 56 | + } | |
| 57 | + end | |
| 58 | + | |
| 59 | + it { | |
| 60 | + result = Issues::BulkUpdateService.new(@project, @user, @params).execute | |
| 61 | + result[:success].should be_true | |
| 62 | + result[:count].should == @issues.count | |
| 63 | + | |
| 64 | + @project.issues.closed.should be_empty | |
| 65 | + @project.issues.opened.should_not be_empty | |
| 66 | + } | |
| 67 | + | |
| 68 | + end | |
| 69 | + | |
| 70 | + describe :update_assignee do | |
| 71 | + | |
| 72 | + before do | |
| 73 | + @new_assignee = create :user | |
| 74 | + @params = { | |
| 75 | + update: { | |
| 76 | + issues_ids: [issue.id], | |
| 77 | + assignee_id: @new_assignee.id | |
| 78 | + } | |
| 79 | + } | |
| 80 | + end | |
| 81 | + | |
| 82 | + it { | |
| 83 | + result = Issues::BulkUpdateService.new(@project, @user, @params).execute | |
| 84 | + result[:success].should be_true | |
| 85 | + result[:count].should == 1 | |
| 86 | + | |
| 87 | + @project.issues.first.assignee.should == @new_assignee | |
| 88 | + } | |
| 89 | + | |
| 90 | + end | |
| 91 | + | |
| 92 | + describe :update_milestone do | |
| 93 | + | |
| 94 | + before do | |
| 95 | + @milestone = create :milestone | |
| 96 | + @params = { | |
| 97 | + update: { | |
| 98 | + issues_ids: [issue.id], | |
| 99 | + milestone_id: @milestone.id | |
| 100 | + } | |
| 101 | + } | |
| 102 | + end | |
| 103 | + | |
| 104 | + it { | |
| 105 | + result = Issues::BulkUpdateService.new(@project, @user, @params).execute | |
| 106 | + result[:success].should be_true | |
| 107 | + result[:count].should == 1 | |
| 108 | + | |
| 109 | + @project.issues.first.milestone.should == @milestone | |
| 110 | + } | |
| 111 | + end | |
| 112 | + | |
| 113 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,142 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe Projects::CreateService do | |
| 4 | + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | + | |
| 7 | + describe :create_by_user do | |
| 8 | + before do | |
| 9 | + @user = create :user | |
| 10 | + @admin = create :user, admin: true | |
| 11 | + @opts = { | |
| 12 | + name: "GitLab", | |
| 13 | + namespace: @user.namespace | |
| 14 | + } | |
| 15 | + end | |
| 16 | + | |
| 17 | + context 'user namespace' do | |
| 18 | + before do | |
| 19 | + @project = create_project(@user, @opts) | |
| 20 | + end | |
| 21 | + | |
| 22 | + it { @project.should be_valid } | |
| 23 | + it { @project.owner.should == @user } | |
| 24 | + it { @project.namespace.should == @user.namespace } | |
| 25 | + end | |
| 26 | + | |
| 27 | + context 'group namespace' do | |
| 28 | + before do | |
| 29 | + @group = create :group | |
| 30 | + @group.add_owner(@user) | |
| 31 | + | |
| 32 | + @opts.merge!(namespace_id: @group.id) | |
| 33 | + @project = create_project(@user, @opts) | |
| 34 | + end | |
| 35 | + | |
| 36 | + it { @project.should be_valid } | |
| 37 | + it { @project.owner.should == @group } | |
| 38 | + it { @project.namespace.should == @group } | |
| 39 | + end | |
| 40 | + | |
| 41 | + context 'respect configured visibility setting' do | |
| 42 | + before(:each) do | |
| 43 | + @settings = double("settings") | |
| 44 | + @settings.stub(:issues) { true } | |
| 45 | + @settings.stub(:merge_requests) { true } | |
| 46 | + @settings.stub(:wiki) { true } | |
| 47 | + @settings.stub(:wall) { true } | |
| 48 | + @settings.stub(:snippets) { true } | |
| 49 | + stub_const("Settings", Class.new) | |
| 50 | + @restrictions = double("restrictions") | |
| 51 | + @restrictions.stub(:restricted_visibility_levels) { [] } | |
| 52 | + Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 53 | + Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | |
| 54 | + end | |
| 55 | + | |
| 56 | + context 'should be public when setting is public' do | |
| 57 | + before do | |
| 58 | + @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } | |
| 59 | + @project = create_project(@user, @opts) | |
| 60 | + end | |
| 61 | + | |
| 62 | + it { @project.public?.should be_true } | |
| 63 | + end | |
| 64 | + | |
| 65 | + context 'should be private when setting is private' do | |
| 66 | + before do | |
| 67 | + @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } | |
| 68 | + @project = create_project(@user, @opts) | |
| 69 | + end | |
| 70 | + | |
| 71 | + it { @project.private?.should be_true } | |
| 72 | + end | |
| 73 | + | |
| 74 | + context 'should be internal when setting is internal' do | |
| 75 | + before do | |
| 76 | + @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::INTERNAL } | |
| 77 | + @project = create_project(@user, @opts) | |
| 78 | + end | |
| 79 | + | |
| 80 | + it { @project.internal?.should be_true } | |
| 81 | + end | |
| 82 | + end | |
| 83 | + | |
| 84 | + context 'respect configured visibility restrictions setting' do | |
| 85 | + before(:each) do | |
| 86 | + @settings = double("settings") | |
| 87 | + @settings.stub(:issues) { true } | |
| 88 | + @settings.stub(:merge_requests) { true } | |
| 89 | + @settings.stub(:wiki) { true } | |
| 90 | + @settings.stub(:wall) { true } | |
| 91 | + @settings.stub(:snippets) { true } | |
| 92 | + @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } | |
| 93 | + stub_const("Settings", Class.new) | |
| 94 | + @restrictions = double("restrictions") | |
| 95 | + @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } | |
| 96 | + Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 97 | + Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | |
| 98 | + end | |
| 99 | + | |
| 100 | + context 'should be private when option is public' do | |
| 101 | + before do | |
| 102 | + @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 103 | + @project = create_project(@user, @opts) | |
| 104 | + end | |
| 105 | + | |
| 106 | + it { @project.private?.should be_true } | |
| 107 | + end | |
| 108 | + | |
| 109 | + context 'should be public when option is public for admin' do | |
| 110 | + before do | |
| 111 | + @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 112 | + @project = create_project(@admin, @opts) | |
| 113 | + end | |
| 114 | + | |
| 115 | + it { @project.public?.should be_true } | |
| 116 | + end | |
| 117 | + | |
| 118 | + context 'should be private when option is private' do | |
| 119 | + before do | |
| 120 | + @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 121 | + @project = create_project(@user, @opts) | |
| 122 | + end | |
| 123 | + | |
| 124 | + it { @project.private?.should be_true } | |
| 125 | + end | |
| 126 | + | |
| 127 | + context 'should be internal when option is internal' do | |
| 128 | + before do | |
| 129 | + @opts.merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 130 | + @project = create_project(@user, @opts) | |
| 131 | + end | |
| 132 | + | |
| 133 | + it { @project.internal?.should be_true } | |
| 134 | + end | |
| 135 | + end | |
| 136 | + end | |
| 137 | + | |
| 138 | + def create_project(user, opts) | |
| 139 | + Projects::CreateService.new(user, opts).execute | |
| 140 | + end | |
| 141 | +end | |
| 142 | + | ... | ... |
| ... | ... | @@ -0,0 +1,111 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe Projects::UpdateService do | |
| 4 | + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } | |
| 5 | + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } | |
| 6 | + | |
| 7 | + describe :update_by_user do | |
| 8 | + before do | |
| 9 | + @user = create :user | |
| 10 | + @admin = create :user, admin: true | |
| 11 | + @project = create :project, creator_id: @user.id, namespace: @user.namespace | |
| 12 | + @opts = { project: {} } | |
| 13 | + end | |
| 14 | + | |
| 15 | + context 'should be private when updated to private' do | |
| 16 | + before do | |
| 17 | + @created_private = @project.private? | |
| 18 | + | |
| 19 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 20 | + update_project(@project, @user, @opts) | |
| 21 | + end | |
| 22 | + | |
| 23 | + it { @created_private.should be_true } | |
| 24 | + it { @project.private?.should be_true } | |
| 25 | + end | |
| 26 | + | |
| 27 | + context 'should be internal when updated to internal' do | |
| 28 | + before do | |
| 29 | + @created_private = @project.private? | |
| 30 | + | |
| 31 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 32 | + update_project(@project, @user, @opts) | |
| 33 | + end | |
| 34 | + | |
| 35 | + it { @created_private.should be_true } | |
| 36 | + it { @project.internal?.should be_true } | |
| 37 | + end | |
| 38 | + | |
| 39 | + context 'should be public when updated to public' do | |
| 40 | + before do | |
| 41 | + @created_private = @project.private? | |
| 42 | + | |
| 43 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 44 | + update_project(@project, @user, @opts) | |
| 45 | + end | |
| 46 | + | |
| 47 | + it { @created_private.should be_true } | |
| 48 | + it { @project.public?.should be_true } | |
| 49 | + end | |
| 50 | + | |
| 51 | + context 'respect configured visibility restrictions setting' do | |
| 52 | + before(:each) do | |
| 53 | + @restrictions = double("restrictions") | |
| 54 | + @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } | |
| 55 | + Settings.stub_chain(:gitlab).and_return(@restrictions) | |
| 56 | + end | |
| 57 | + | |
| 58 | + context 'should be private when updated to private' do | |
| 59 | + before do | |
| 60 | + @created_private = @project.private? | |
| 61 | + | |
| 62 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) | |
| 63 | + update_project(@project, @user, @opts) | |
| 64 | + end | |
| 65 | + | |
| 66 | + it { @created_private.should be_true } | |
| 67 | + it { @project.private?.should be_true } | |
| 68 | + end | |
| 69 | + | |
| 70 | + context 'should be internal when updated to internal' do | |
| 71 | + before do | |
| 72 | + @created_private = @project.private? | |
| 73 | + | |
| 74 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
| 75 | + update_project(@project, @user, @opts) | |
| 76 | + end | |
| 77 | + | |
| 78 | + it { @created_private.should be_true } | |
| 79 | + it { @project.internal?.should be_true } | |
| 80 | + end | |
| 81 | + | |
| 82 | + context 'should be private when updated to public' do | |
| 83 | + before do | |
| 84 | + @created_private = @project.private? | |
| 85 | + | |
| 86 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 87 | + update_project(@project, @user, @opts) | |
| 88 | + end | |
| 89 | + | |
| 90 | + it { @created_private.should be_true } | |
| 91 | + it { @project.private?.should be_true } | |
| 92 | + end | |
| 93 | + | |
| 94 | + context 'should be public when updated to public by admin' do | |
| 95 | + before do | |
| 96 | + @created_private = @project.private? | |
| 97 | + | |
| 98 | + @opts[:project].merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
| 99 | + update_project(@project, @admin, @opts) | |
| 100 | + end | |
| 101 | + | |
| 102 | + it { @created_private.should be_true } | |
| 103 | + it { @project.public?.should be_true } | |
| 104 | + end | |
| 105 | + end | |
| 106 | + end | |
| 107 | + | |
| 108 | + def update_project(project, user, opts) | |
| 109 | + Projects::UpdateService.new(project, user, opts).execute | |
| 110 | + end | |
| 111 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe 'Search::GlobalService' do | |
| 4 | + let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } | |
| 5 | + let(:user) { create(:user, namespace: found_namespace) } | |
| 6 | + let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
| 7 | + | |
| 8 | + let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') } | |
| 9 | + let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
| 10 | + | |
| 11 | + let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') } | |
| 12 | + let(:internal_user) { create(:user, namespace: internal_namespace) } | |
| 13 | + let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } | |
| 14 | + | |
| 15 | + let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') } | |
| 16 | + let(:public_user) { create(:user, namespace: public_namespace) } | |
| 17 | + let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
| 18 | + | |
| 19 | + describe '#execute' do | |
| 20 | + context 'unauthenticated' do | |
| 21 | + it 'should return public projects only' do | |
| 22 | + context = Search::GlobalService.new(nil, search: "searchable") | |
| 23 | + results = context.execute | |
| 24 | + results[:projects].should have(1).items | |
| 25 | + results[:projects].should include(public_project) | |
| 26 | + end | |
| 27 | + end | |
| 28 | + | |
| 29 | + context 'authenticated' do | |
| 30 | + it 'should return public, internal and private projects' do | |
| 31 | + context = Search::GlobalService.new(user, search: "searchable") | |
| 32 | + results = context.execute | |
| 33 | + results[:projects].should have(3).items | |
| 34 | + results[:projects].should include(public_project) | |
| 35 | + results[:projects].should include(found_project) | |
| 36 | + results[:projects].should include(internal_project) | |
| 37 | + end | |
| 38 | + | |
| 39 | + it 'should return only public & internal projects' do | |
| 40 | + context = Search::GlobalService.new(internal_user, search: "searchable") | |
| 41 | + results = context.execute | |
| 42 | + results[:projects].should have(2).items | |
| 43 | + results[:projects].should include(internal_project) | |
| 44 | + results[:projects].should include(public_project) | |
| 45 | + end | |
| 46 | + | |
| 47 | + it 'namespace name should be searchable' do | |
| 48 | + context = Search::GlobalService.new(user, search: "searchable namespace") | |
| 49 | + results = context.execute | |
| 50 | + results[:projects].should == [found_project] | |
| 51 | + end | |
| 52 | + end | |
| 53 | + end | |
| 54 | +end | ... | ... |