-
Notifications
You must be signed in to change notification settings - Fork 34
/
question_journal_hooks_test.rb
155 lines (123 loc) · 5.22 KB
/
question_journal_hooks_test.rb
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
require File.dirname(__FILE__) + '/../../../test_helper'
class QuestionJournalHooksTest < ActionController::IntegrationTest
include Redmine::Hook::Helper
def setup
Setting.gravatar_enabled = '1'
@user1 = User.generate!(:firstname => 'Test', :lastname => 'one', :login => 'existing', :password => 'existing', :password_confirmation => 'existing')
@user2 = User.generate!(:firstname => 'Test', :lastname => 'two')
@project = Project.generate!.reload
@issue = Issue.generate_for_project!(@project)
@journal = Journal.generate!(:issue => @issue, :notes => 'A note')
User.add_to_project(@user1, @project, Role.generate!(:permissions => [:view_issues, :add_issues, :edit_issues, :edit_issue_notes]))
end
context '#views_journals_notes_form_after_notes' do
context 'should render a text field' do
setup do
login_as
@question = Question.generate!(:issue => @issue, :journal => @journal, :assigned_to => @user2, :opened => true)
visit "/journals/edit/#{@journal.id}" # RJS
end
should 'with the selected users login' do
assert response.body.match(/#{@user2.reload.login}/)
end
should 'with an area for the autocomplete choices' do
assert response.body.match 'question_assigned_to_choices'
end
should 'with the autocomplete JavaScript' do
assert response.body.match(/Autocompleter/)
end
end
end
context '#controller_journals_edit_post' do
setup do
login_as
end
context 'with an empty question' do
should 'should do nothing' do
assert_no_difference('Journal.count') do
assert_no_difference('Question.count') do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => 'New notes'
end
end
end
end
context 'with a new question for anyone' do
setup do
assert_no_difference('Journal.count') do
assert_difference('Question.count') do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => 'New notes', :question => { :assigned_to => 'anyone'}
end
end
end
should 'should create a new question' do
question = Question.last
assert_equal nil, question.assigned_to
end
should 'should add the CSS class of "question" to the journal div' do
assert response.body.match(/addClassName\('question'\)/)
end
should 'should remove all existing question lines using RJS' do
assert response.body.match(/question-line.*remove/)
end
should 'should add the generated HTML to the top of the side div' do
assert response.body.match(/insert.*top/)
end
end
context 'with a new question for a user' do
should 'should create a new question' do
assert_no_difference('Journal.count') do
assert_difference('Question.count') do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => 'New notes', :question => { :assigned_to => @user2.reload.login}
end
end
question = Question.last
assert_equal @user2, question.assigned_to
end
end
context 'with a reassigned question' do
should 'should change the assignment of the question' do
@question = Question.generate!(:issue => @issue, :journal => @journal, :assigned_to => @user2, :opened => true)
assert_no_difference('Journal.count') do
assert_no_difference('Question.count') do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => 'New notes', :question => { :assigned_to => @user1.reload.login}
end
end
question = Question.last
assert_equal @user1, question.assigned_to
end
end
context 'with a removed question' do
setup do
@question = Question.generate!(:issue => @issue, :journal => @journal, :assigned_to => @user2, :opened => true)
assert_no_difference('Journal.count') do
assert_difference('Question.count', -1) do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => 'New notes', :question => { :assigned_to => ''}
end
end
end
should 'should destroy the question' do
assert_equal nil, Question.find_by_id(@question.id)
end
should 'should remove the CSS class of "question" from the journal div' do
assert response.body.match(/removeClassName\('question'\)/)
end
should 'should remove all existing question lines using RJS' do
assert response.body.match(/question-line.*remove/)
end
end
context 'with a removed journal by clearing the notes' do
setup do
@question = Question.generate!(:issue => @issue, :journal => @journal, :assigned_to => @user2, :opened => true)
assert_difference('Journal.count',-1) do
assert_difference('Question.count', -1) do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => '', :question => { :assigned_to => ''}
assert_response :success
end
end
end
should 'should destroy the question' do
assert_equal nil, Question.find_by_id(@question.id)
end
end
end
end