Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bulk_update_service_spec.rb « issues « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 504213e667fa04c3627ef606fad59ac7443f975b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'spec_helper'

describe Issues::BulkUpdateService do
  let(:issue) {
    create(:issue, project: @project)
  }

  before do
    @user = create :user
    opts = {
      name: "GitLab",
      namespace: @user.namespace
    }
    @project = Projects::CreateService.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::BulkUpdateService.new(@project, @user, @params).execute
      expect(result[:success]).to be_truthy
      expect(result[:count]).to eq(@issues.count)

      expect(@project.issues.opened).to be_empty
      expect(@project.issues.closed).not_to 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::BulkUpdateService.new(@project, @user, @params).execute
      expect(result[:success]).to be_truthy
      expect(result[:count]).to eq(@issues.count)

      expect(@project.issues.closed).to be_empty
      expect(@project.issues.opened).not_to 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::BulkUpdateService.new(@project, @user, @params).execute
      expect(result[:success]).to be_truthy
      expect(result[:count]).to eq(1)

      expect(@project.issues.first.assignee).to eq(@new_assignee)
    }

    it 'allows mass-unassigning' do
      @project.issues.first.update_attribute(:assignee, @new_assignee)
      expect(@project.issues.first.assignee).not_to be_nil

      @params[:update][:assignee_id] = -1

      Issues::BulkUpdateService.new(@project, @user, @params).execute
      expect(@project.issues.first.assignee).to be_nil
    end

    it 'does not unassign when assignee_id is not present' do
      @project.issues.first.update_attribute(:assignee, @new_assignee)
      expect(@project.issues.first.assignee).not_to be_nil

      @params[:update][:assignee_id] = ''

      Issues::BulkUpdateService.new(@project, @user, @params).execute
      expect(@project.issues.first.assignee).not_to be_nil
    end
  end

  describe :update_milestone do

    before do
      @milestone = create :milestone
      @params = {
        update: {
          issues_ids: [issue.id],
          milestone_id: @milestone.id
        }
      }
    end

    it {
      result = Issues::BulkUpdateService.new(@project, @user, @params).execute
      expect(result[:success]).to be_truthy
      expect(result[:count]).to eq(1)

      expect(@project.issues.first.milestone).to eq(@milestone)
    }
  end

end