issues_spec.rb 23.6 KB
Newer Older
N
Nihad Abbasov 已提交
1 2
require 'spec_helper'

J
Jeroen van Baarsen 已提交
3
describe API::API, api: true  do
4
  include ApiHelpers
5
  let(:user)        { create(:user) }
6
  let(:user2)       { create(:user) }
7 8 9 10
  let(:non_member)  { create(:user) }
  let(:author)      { create(:author) }
  let(:assignee)    { create(:assignee) }
  let(:admin)       { create(:user, :admin) }
R
Robert Schilling 已提交
11
  let!(:project)    { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
J
jubianchi 已提交
12 13 14 15 16 17 18 19
  let!(:closed_issue) do
    create :closed_issue,
           author: user,
           assignee: user,
           project: project,
           state: :closed,
           milestone: milestone
  end
20 21 22 23 24 25 26
  let!(:confidential_issue) do
    create :issue,
           :confidential,
           project: project,
           author: author,
           assignee: assignee
  end
J
jubianchi 已提交
27 28 29 30 31 32 33
  let!(:issue) do
    create :issue,
           author: user,
           assignee: user,
           project: project,
           milestone: milestone
  end
34 35 36
  let!(:label) do
    create(:label, title: 'label', color: '#FFAABB', project: project)
  end
J
jubianchi 已提交
37
  let!(:label_link) { create(:label_link, label: label, target: issue) }
J
jubianchi 已提交
38 39 40 41
  let!(:milestone) { create(:milestone, title: '1.0.0', project: project) }
  let!(:empty_milestone) do
    create(:milestone, title: '2.0.0', project: project)
  end
C
cnam-dep 已提交
42
  let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
43

D
Dmitriy Zaporozhets 已提交
44
  before { project.team << [user, :reporter] }
N
Nihad Abbasov 已提交
45 46

  describe "GET /issues" do
47 48 49
    context "when unauthenticated" do
      it "should return authentication error" do
        get api("/issues")
50
        expect(response.status).to eq(401)
51
      end
N
Nihad Abbasov 已提交
52 53
    end

54
    context "when authenticated" do
N
Nihad Abbasov 已提交
55
      it "should return an array of issues" do
R
Robert Speicher 已提交
56
        get api("/issues", user)
57 58 59
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.first['title']).to eq(issue.title)
N
Nihad Abbasov 已提交
60
      end
N
Nihad Abbasov 已提交
61

62 63
      it "should add pagination headers and keep query params" do
        get api("/issues?state=closed&per_page=3", user)
64
        expect(response.headers['Link']).to eq(
65
          '<http://www.example.com/api/v3/issues?page=1&per_page=3&private_token=%s&state=closed>; rel="first", <http://www.example.com/api/v3/issues?page=1&per_page=3&private_token=%s&state=closed>; rel="last"' % [user.private_token, user.private_token]
66
        )
N
Nihad Abbasov 已提交
67
      end
J
jubianchi 已提交
68 69 70

      it 'should return an array of closed issues' do
        get api('/issues?state=closed', user)
71 72 73 74
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['id']).to eq(closed_issue.id)
J
jubianchi 已提交
75 76 77 78
      end

      it 'should return an array of opened issues' do
        get api('/issues?state=opened', user)
79 80 81 82
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['id']).to eq(issue.id)
J
jubianchi 已提交
83 84 85 86
      end

      it 'should return an array of all issues' do
        get api('/issues?state=all', user)
87 88 89 90 91
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(2)
        expect(json_response.first['id']).to eq(issue.id)
        expect(json_response.second['id']).to eq(closed_issue.id)
J
jubianchi 已提交
92
      end
J
jubianchi 已提交
93 94 95

      it 'should return an array of labeled issues' do
        get api("/issues?labels=#{label.title}", user)
96 97 98 99
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['labels']).to eq([label.title])
J
jubianchi 已提交
100 101 102 103
      end

      it 'should return an array of labeled issues when at least one label matches' do
        get api("/issues?labels=#{label.title},foo,bar", user)
104 105 106 107
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['labels']).to eq([label.title])
J
jubianchi 已提交
108 109 110 111
      end

      it 'should return an empty array if no issue matches labels' do
        get api('/issues?labels=foo,bar', user)
112 113 114
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(0)
J
jubianchi 已提交
115 116 117 118
      end

      it 'should return an array of labeled issues matching given state' do
        get api("/issues?labels=#{label.title}&state=opened", user)
119 120 121 122 123
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['labels']).to eq([label.title])
        expect(json_response.first['state']).to eq('opened')
J
jubianchi 已提交
124 125 126 127
      end

      it 'should return an empty array if no issue matches labels and state filters' do
        get api("/issues?labels=#{label.title}&state=closed", user)
128 129 130
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(0)
J
jubianchi 已提交
131
      end
C
cnam-dep 已提交
132 133 134 135 136 137 138

      it 'should return an count notes in issue' do
        get api("/issues", user)
        expect(response.status).to eq(200)
        expect(json_response).to be_an Array
        expect(json_response.first['user_notes_count']).to eq(1)
      end
N
Nihad Abbasov 已提交
139 140 141 142
    end
  end

  describe "GET /projects/:id/issues" do
J
jubianchi 已提交
143 144 145
    let(:base_url) { "/projects/#{project.id}" }
    let(:title) { milestone.title }

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    it 'should return project issues without confidential issues for non project members' do
      get api("#{base_url}/issues", non_member)
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(2)
      expect(json_response.first['title']).to eq(issue.title)
    end

    it 'should return project confidential issues for author' do
      get api("#{base_url}/issues", author)
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(3)
      expect(json_response.first['title']).to eq(issue.title)
    end

    it 'should return project confidential issues for assignee' do
      get api("#{base_url}/issues", assignee)
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(3)
      expect(json_response.first['title']).to eq(issue.title)
    end

    it 'should return project issues with confidential issues for project members' do
J
jubianchi 已提交
171
      get api("#{base_url}/issues", user)
172 173
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
174 175 176 177 178 179 180 181 182
      expect(json_response.length).to eq(3)
      expect(json_response.first['title']).to eq(issue.title)
    end

    it 'should return project confidential issues for admin' do
      get api("#{base_url}/issues", admin)
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(3)
183
      expect(json_response.first['title']).to eq(issue.title)
N
Nihad Abbasov 已提交
184
    end
J
jubianchi 已提交
185 186

    it 'should return an array of labeled project issues' do
J
jubianchi 已提交
187
      get api("#{base_url}/issues?labels=#{label.title}", user)
188 189 190 191
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(1)
      expect(json_response.first['labels']).to eq([label.title])
J
jubianchi 已提交
192 193 194
    end

    it 'should return an array of labeled project issues when at least one label matches' do
J
jubianchi 已提交
195
      get api("#{base_url}/issues?labels=#{label.title},foo,bar", user)
196 197 198 199
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(1)
      expect(json_response.first['labels']).to eq([label.title])
J
jubianchi 已提交
200 201 202
    end

    it 'should return an empty array if no project issue matches labels' do
J
jubianchi 已提交
203
      get api("#{base_url}/issues?labels=foo,bar", user)
204 205 206
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(0)
J
jubianchi 已提交
207 208 209 210
    end

    it 'should return an empty array if no issue matches milestone' do
      get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user)
211 212 213
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(0)
J
jubianchi 已提交
214
    end
J
jubianchi 已提交
215 216 217

    it 'should return an empty array if milestone does not exist' do
      get api("#{base_url}/issues?milestone=foo", user)
218 219 220
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(0)
J
jubianchi 已提交
221 222 223 224
    end

    it 'should return an array of issues in given milestone' do
      get api("#{base_url}/issues?milestone=#{title}", user)
225 226 227 228 229
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(2)
      expect(json_response.first['id']).to eq(issue.id)
      expect(json_response.second['id']).to eq(closed_issue.id)
J
jubianchi 已提交
230 231 232 233 234
    end

    it 'should return an array of issues matching state in milestone' do
      get api("#{base_url}/issues?milestone=#{milestone.title}"\
              '&state=closed', user)
235 236 237 238
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(1)
      expect(json_response.first['id']).to eq(closed_issue.id)
J
jubianchi 已提交
239
    end
C
cnam-dep 已提交
240 241 242 243 244 245 246

    it 'should return an count notes in issue' do
      get api("#{base_url}/issues", user)
      expect(response.status).to eq(200)
      expect(json_response).to be_an Array
      expect(json_response.first['user_notes_count']).to eq(1)
    end
N
Nihad Abbasov 已提交
247 248 249 250
  end

  describe "GET /projects/:id/issues/:issue_id" do
    it "should return a project issue by id" do
251
      get api("/projects/#{project.id}/issues/#{issue.id}", user)
252 253 254
      expect(response.status).to eq(200)
      expect(json_response['title']).to eq(issue.title)
      expect(json_response['iid']).to eq(issue.iid)
N
Nihad Abbasov 已提交
255
    end
256

257 258
    it 'should return a project issue by iid' do
      get api("/projects/#{project.id}/issues?iid=#{issue.iid}", user)
259 260 261 262
      expect(response.status).to eq 200
      expect(json_response.first['title']).to eq issue.title
      expect(json_response.first['id']).to eq issue.id
      expect(json_response.first['iid']).to eq issue.iid
263 264
    end

265 266
    it "should return 404 if issue id not found" do
      get api("/projects/#{project.id}/issues/54321", user)
267
      expect(response.status).to eq(404)
268
    end
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

    context 'confidential issues' do
      it "should return 404 for non project members" do
        get api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member)
        expect(response.status).to eq(404)
      end

      it "should return confidential issue for project members" do
        get api("/projects/#{project.id}/issues/#{confidential_issue.id}", user)
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq(confidential_issue.title)
        expect(json_response['iid']).to eq(confidential_issue.iid)
      end

      it "should return confidential issue for author" do
        get api("/projects/#{project.id}/issues/#{confidential_issue.id}", author)
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq(confidential_issue.title)
        expect(json_response['iid']).to eq(confidential_issue.iid)
      end

      it "should return confidential issue for assignee" do
        get api("/projects/#{project.id}/issues/#{confidential_issue.id}", assignee)
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq(confidential_issue.title)
        expect(json_response['iid']).to eq(confidential_issue.iid)
      end

      it "should return confidential issue for admin" do
        get api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin)
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq(confidential_issue.title)
        expect(json_response['iid']).to eq(confidential_issue.iid)
      end
    end
N
Nihad Abbasov 已提交
304 305 306 307
  end

  describe "POST /projects/:id/issues" do
    it "should create a new project issue" do
308
      post api("/projects/#{project.id}/issues", user),
309
        title: 'new issue', labels: 'label, label2'
310 311 312 313
      expect(response.status).to eq(201)
      expect(json_response['title']).to eq('new issue')
      expect(json_response['description']).to be_nil
      expect(json_response['labels']).to eq(['label', 'label2'])
N
Nihad Abbasov 已提交
314
    end
315 316 317

    it "should return a 400 bad request if title not given" do
      post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
318
      expect(response.status).to eq(400)
319
    end
320

321
    it 'should return 400 on invalid label names' do
322 323 324
      post api("/projects/#{project.id}/issues", user),
           title: 'new issue',
           labels: 'label, ?'
325 326
      expect(response.status).to eq(400)
      expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
327
    end
J
jubianchi 已提交
328 329 330 331

    it 'should return 400 if title is too long' do
      post api("/projects/#{project.id}/issues", user),
           title: 'g' * 256
332 333
      expect(response.status).to eq(400)
      expect(json_response['message']['title']).to eq([
J
jubianchi 已提交
334
        'is too long (maximum is 255 characters)'
335
      ])
J
jubianchi 已提交
336
    end
337 338

    context 'when an admin or owner makes the request' do
339 340
      it 'accepts the creation date to be set' do
        creation_time = 2.weeks.ago
341
        post api("/projects/#{project.id}/issues", user),
342
          title: 'new issue', labels: 'label, label2', created_at: creation_time
343 344

        expect(response.status).to eq(201)
345
        expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
346 347
      end
    end
N
Nihad Abbasov 已提交
348 349
  end

350 351 352 353 354 355 356 357
  describe 'POST /projects/:id/issues with spam filtering' do
    before do
      Grape::Endpoint.before_each do |endpoint|
        allow(endpoint).to receive(:check_for_spam?).and_return(true)
        allow(endpoint).to receive(:is_spam?).and_return(true)
      end
    end

D
Douglas Barbosa Alexandre 已提交
358 359 360 361 362 363 364
    let(:params) do
      {
        title: 'new issue',
        description: 'content here',
        labels: 'label, label2'
      }
    end
365

D
Douglas Barbosa Alexandre 已提交
366 367
    it "should not create a new project issue" do
      expect { post api("/projects/#{project.id}/issues", user), params }.not_to change(Issue, :count)
368 369
      expect(response.status).to eq(400)
      expect(json_response['message']).to eq({ "error" => "Spam detected" })
370

371 372 373
      spam_logs = SpamLog.all
      expect(spam_logs.count).to eq(1)
      expect(spam_logs[0].title).to eq('new issue')
374
      expect(spam_logs[0].description).to eq('content here')
375 376 377 378 379 380
      expect(spam_logs[0].user).to eq(user)
      expect(spam_logs[0].noteable_type).to eq('Issue')
      expect(spam_logs[0].project_id).to eq(project.id)
    end
  end

A
Andrew8xx8 已提交
381
  describe "PUT /projects/:id/issues/:issue_id to update only title" do
N
Nihad Abbasov 已提交
382
    it "should update a project issue" do
383
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
A
Andrew8xx8 已提交
384
        title: 'updated title'
385
      expect(response.status).to eq(200)
A
Andrew8xx8 已提交
386

387
      expect(json_response['title']).to eq('updated title')
A
Andrew8xx8 已提交
388
    end
389 390 391 392

    it "should return 404 error if issue id not found" do
      put api("/projects/#{project.id}/issues/44444", user),
        title: 'updated title'
393
      expect(response.status).to eq(404)
394
    end
395

396
    it 'should return 400 on invalid label names' do
397 398 399
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          title: 'updated title',
          labels: 'label, ?'
400 401
      expect(response.status).to eq(400)
      expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
402
    end
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431

    context 'confidential issues' do
      it "should return 403 for non project members" do
        put api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member),
          title: 'updated title'
        expect(response.status).to eq(403)
      end

      it "should update a confidential issue for project members" do
        put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user),
          title: 'updated title'
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq('updated title')
      end

      it "should update a confidential issue for author" do
        put api("/projects/#{project.id}/issues/#{confidential_issue.id}", author),
          title: 'updated title'
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq('updated title')
      end

      it "should update a confidential issue for admin" do
        put api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin),
          title: 'updated title'
        expect(response.status).to eq(200)
        expect(json_response['title']).to eq('updated title')
      end
    end
432 433 434 435 436 437 438 439 440
  end

  describe 'PUT /projects/:id/issues/:issue_id to update labels' do
    let!(:label) { create(:label, title: 'dummy', project: project) }
    let!(:label_link) { create(:label_link, label: label, target: issue) }

    it 'should not update labels if not present' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          title: 'updated title'
441 442
      expect(response.status).to eq(200)
      expect(json_response['labels']).to eq([label.title])
443 444 445 446 447
    end

    it 'should remove all labels' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          labels: ''
448 449
      expect(response.status).to eq(200)
      expect(json_response['labels']).to eq([])
450 451 452 453 454
    end

    it 'should update labels' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          labels: 'foo,bar'
455 456 457
      expect(response.status).to eq(200)
      expect(json_response['labels']).to include 'foo'
      expect(json_response['labels']).to include 'bar'
458 459 460 461 462
    end

    it 'should return 400 on invalid label names' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          labels: 'label, ?'
463 464
      expect(response.status).to eq(400)
      expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
465 466 467 468 469
    end

    it 'should allow special label names' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          labels: 'label:foo, label-bar,label_bar,label/bar'
470 471 472 473 474
      expect(response.status).to eq(200)
      expect(json_response['labels']).to include 'label:foo'
      expect(json_response['labels']).to include 'label-bar'
      expect(json_response['labels']).to include 'label_bar'
      expect(json_response['labels']).to include 'label/bar'
475
    end
J
jubianchi 已提交
476 477 478 479

    it 'should return 400 if title is too long' do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
          title: 'g' * 256
480 481
      expect(response.status).to eq(400)
      expect(json_response['message']['title']).to eq([
J
jubianchi 已提交
482
        'is too long (maximum is 255 characters)'
483
      ])
J
jubianchi 已提交
484
    end
A
Andrew8xx8 已提交
485 486 487 488 489 490
  end

  describe "PUT /projects/:id/issues/:issue_id to update state and label" do
    it "should update a project issue" do
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
        labels: 'label2', state_event: "close"
491
      expect(response.status).to eq(200)
A
Andrew8xx8 已提交
492

493 494
      expect(json_response['labels']).to include 'label2'
      expect(json_response['state']).to eq "closed"
N
Nihad Abbasov 已提交
495
    end
496 497 498 499 500 501 502 503 504 505 506 507

    context 'when an admin or owner makes the request' do
      it 'accepts the update date to be set' do
        update_time = 2.weeks.ago
        put api("/projects/#{project.id}/issues/#{issue.id}", user),
          labels: 'label3', state_event: 'close', updated_at: update_time
        expect(response.status).to eq(200)

        expect(json_response['labels']).to include 'label3'
        expect(Time.parse(json_response['updated_at'])).to be_within(1.second).of(update_time)
      end
    end
N
Nihad Abbasov 已提交
508 509 510
  end

  describe "DELETE /projects/:id/issues/:issue_id" do
511
    it "rejects a non member from deleting an issue" do
512 513
      delete api("/projects/#{project.id}/issues/#{issue.id}", non_member)
      expect(response.status).to be(403)
Z
Zeger-Jan van de Weg 已提交
514 515
    end

516
    it "rejects a developer from deleting an issue" do
517 518 519
      delete api("/projects/#{project.id}/issues/#{issue.id}", author)
      expect(response.status).to be(403)
    end
Z
Zeger-Jan van de Weg 已提交
520

521 522 523 524 525 526 527 528 529
    context "when the user is project owner" do
      let(:owner)     { create(:user) }
      let(:project)   { create(:project, namespace: owner.namespace) }

      it "deletes the issue if an admin requests it" do
        delete api("/projects/#{project.id}/issues/#{issue.id}", owner)
        expect(response.status).to eq(200)
        expect(json_response['state']).to eq 'opened'
      end
N
Nihad Abbasov 已提交
530 531
    end
  end
R
Robert Schilling 已提交
532 533 534 535 536 537 538

  describe '/projects/:id/issues/:issue_id/move' do
    let!(:target_project) { create(:project, path: 'project2', creator_id: user.id, namespace: user.namespace ) }
    let!(:target_project2) { create(:project, creator_id: non_member.id, namespace: non_member.namespace ) }

    it 'moves an issue' do
      post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
539
               to_project_id: target_project.id
R
Robert Schilling 已提交
540 541 542 543 544

      expect(response.status).to eq(201)
      expect(json_response['project_id']).to eq(target_project.id)
    end

545 546 547 548
    context 'when source and target projects are the same' do
      it 'returns 400 when trying to move an issue' do
        post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
                 to_project_id: project.id
R
Robert Schilling 已提交
549

550 551 552
        expect(response.status).to eq(400)
        expect(json_response['message']).to eq('Cannot move issue to project it originates from!')
      end
R
Robert Schilling 已提交
553 554
    end

555 556 557 558
    context 'when the user does not have the permission to move issues' do
      it 'returns 400 when trying to move an issue' do
        post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
                 to_project_id: target_project2.id
R
Robert Schilling 已提交
559

560 561 562
        expect(response.status).to eq(400)
        expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!')
      end
R
Robert Schilling 已提交
563 564 565 566
    end

    it 'moves the issue to another namespace if I am admin' do
      post api("/projects/#{project.id}/issues/#{issue.id}/move", admin),
567
               to_project_id: target_project2.id
R
Robert Schilling 已提交
568 569 570 571 572

      expect(response.status).to eq(201)
      expect(json_response['project_id']).to eq(target_project2.id)
    end

573 574 575 576
    context 'when issue does not exist' do
      it 'returns 404 when trying to move an issue' do
        post api("/projects/#{project.id}/issues/123/move", user),
                 to_project_id: target_project.id
R
Robert Schilling 已提交
577

578 579
        expect(response.status).to eq(404)
      end
R
Robert Schilling 已提交
580 581
    end

582 583 584 585
    context 'when source project does not exist' do
      it 'returns 404 when trying to move an issue' do
        post api("/projects/123/issues/#{issue.id}/move", user),
                 to_project_id: target_project.id
R
Robert Schilling 已提交
586

587 588 589 590 591 592 593 594 595 596 597
        expect(response.status).to eq(404)
      end
    end

    context 'when target project does not exist' do
      it 'returns 404 when trying to move an issue' do
        post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
                 to_project_id: 123

        expect(response.status).to eq(404)
      end
R
Robert Schilling 已提交
598 599
    end
  end
600

601
  describe 'POST :id/issues/:issue_id/subscription' do
602
    it 'subscribes to an issue' do
603
      post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
604 605 606 607 608 609

      expect(response.status).to eq(201)
      expect(json_response['subscribed']).to eq(true)
    end

    it 'returns 304 if already subscribed' do
610
      post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
611 612 613

      expect(response.status).to eq(304)
    end
614 615 616 617 618 619

    it 'returns 404 if the issue is not found' do
      post api("/projects/#{project.id}/issues/123/subscription", user)

      expect(response.status).to eq(404)
    end
620 621
  end

622
  describe 'DELETE :id/issues/:issue_id/subscription' do
623
    it 'unsubscribes from an issue' do
624
      delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user)
625

626
      expect(response.status).to eq(200)
627 628 629 630
      expect(json_response['subscribed']).to eq(false)
    end

    it 'returns 304 if not subscribed' do
631
      delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2)
632 633 634

      expect(response.status).to eq(304)
    end
635 636

    it 'returns 404 if the issue is not found' do
637
      delete api("/projects/#{project.id}/issues/123/subscription", user)
638 639 640

      expect(response.status).to eq(404)
    end
641
  end
N
Nihad Abbasov 已提交
642
end