summaryrefslogtreecommitdiffstats
path: root/test/integration/api_test/journals_test.rb
blob: f637d90f45864d462502bb0eddf65ba8c1f0d3c1 (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
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-2023  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require File.expand_path('../../../test_helper', __FILE__)

class Redmine::ApiTest::JournalTest < Redmine::ApiTest::Base
  fixtures :projects, :issues, :issue_statuses, :journals, :journal_details,
           :issue_relations, :workflows,
           :users, :members, :member_roles, :roles, :enabled_modules,
           :groups_users, :email_addresses,
           :enumerations,
           :projects_trackers, :trackers, :custom_fields

  test "PUT /journals/:id.xml with valid parameters should update the journal notes" do
    put(
      '/journals/1.xml',
      params: {
        journal: { notes: 'changed notes' }
      },
      headers: credentials('admin')
    )

    assert_response :no_content
    assert_equal '', @response.body

    journal = Journal.find(1)
    assert_equal 'changed notes', journal.notes
  end

  test "PUT /journals/:id.json with valid parameters should update the journal notes" do
    put(
      '/journals/1.json',
      params: {
        journal: { notes: 'changed notes' }
      },
      headers: credentials('admin')
    )

    assert_response :no_content
    assert_equal '', @response.body

    journal = Journal.find(1)
    assert_equal 'changed notes', journal.notes
  end

  test "PUT /journals/:id.xml without journal details should destroy journal" do
    journal = Journal.find(5)
    assert_equal [], journal.details
    assert_difference('Journal.count', -1) do
      put(
        "/journals/#{journal.id}.xml",
        params: {
          journal: { notes: '' }
        },
        headers: credentials('admin')
      )
    end
    assert_response :no_content
    assert_equal '', @response.body
    assert_nil Journal.find_by(id: 5)
  end

  test "PUT /journals/:id.json without journal details should destroy journal" do
    journal = Journal.find(5)
    assert_equal [], journal.details
    assert_difference('Journal.count', -1) do
      put(
        "/journals/#{journal.id}.json",
        params: {
          journal: { notes: '' }
        },
        headers: credentials('admin')
      )
    end
    assert_response :no_content
    assert_equal '', @response.body
    assert_nil Journal.find_by(id: 5)
  end
end