summaryrefslogtreecommitdiff
path: root/spec/features/issues/user_uses_slash_commands_spec.rb
blob: bf2b93c92fb68578f1af1f5d90b8449846c2c1cb (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
require 'rails_helper'

feature 'Issues > User uses slash commands', feature: true, js: true do
  include SlashCommandsHelpers
  include WaitForAjax

  it_behaves_like 'issuable record that supports slash commands in its description and notes', :issue do
    let(:issuable) { create(:issue, project: project) }
  end

  describe 'issue-only commands' do
    let(:user) { create(:user) }
    let(:project) { create(:project, :public) }

    before do
      project.team << [user, :master]
      login_with(user)
      visit namespace_project_issue_path(project.namespace, project, issue)
    end

    after do
      wait_for_ajax
    end

    describe 'adding a due date from note' do
      let(:issue) { create(:issue, project: project) }

      context 'when the current user can update the due date' do
        it 'does not create a note, and sets the due date accordingly' do
          write_note("/due 2016-08-28")

          expect(page).not_to have_content '/due 2016-08-28'
          expect(page).to have_content 'Your commands have been executed!'

          issue.reload

          expect(issue.due_date).to eq Date.new(2016, 8, 28)
        end
      end

      context 'when the current user cannot update the due date' do
        let(:guest) { create(:user) }
        before do
          project.team << [guest, :guest]
          logout
          login_with(guest)
          visit namespace_project_issue_path(project.namespace, project, issue)
        end

        it 'does not create a note, and sets the due date accordingly' do
          write_note("/due 2016-08-28")

          expect(page).to have_content '/due 2016-08-28'
          expect(page).not_to have_content 'Your commands have been executed!'

          issue.reload

          expect(issue.due_date).to be_nil
        end
      end
    end

    describe 'removing a due date from note' do
      let(:issue) { create(:issue, project: project, due_date: Date.new(2016, 8, 28)) }

      context 'when the current user can update the due date' do
        it 'does not create a note, and removes the due date accordingly' do
          expect(issue.due_date).to eq Date.new(2016, 8, 28)

          write_note("/remove_due_date")

          expect(page).not_to have_content '/remove_due_date'
          expect(page).to have_content 'Your commands have been executed!'

          issue.reload

          expect(issue.due_date).to be_nil
        end
      end

      context 'when the current user cannot update the due date' do
        let(:guest) { create(:user) }
        before do
          project.team << [guest, :guest]
          logout
          login_with(guest)
          visit namespace_project_issue_path(project.namespace, project, issue)
        end

        it 'does not create a note, and sets the due date accordingly' do
          write_note("/remove_due_date")

          expect(page).to have_content '/remove_due_date'
          expect(page).not_to have_content 'Your commands have been executed!'

          issue.reload

          expect(issue.due_date).to eq Date.new(2016, 8, 28)
        end
      end
    end
  end
end