Revision 1297:0a574315af3e .svn/pristine/ca

View differences:

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

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

  
20
class RoutingJournalsTest < ActionController::IntegrationTest
21
  def test_journals
22
    assert_routing(
23
        { :method => 'post', :path => "/issues/1/quoted" },
24
        { :controller => 'journals', :action => 'new', :id => '1' }
25
      )
26
    assert_routing(
27
        { :method => 'get', :path => "/issues/changes" },
28
        { :controller => 'journals', :action => 'index' }
29
      )
30
    assert_routing(
31
        { :method => 'get', :path => "/journals/diff/1" },
32
        { :controller => 'journals', :action => 'diff', :id => '1' }
33
      )
34
    ["get", "post"].each do |method|
35
      assert_routing(
36
          { :method => method, :path => "/journals/edit/1" },
37
          { :controller => 'journals', :action => 'edit', :id => '1' }
38
        )
39
    end
40
  end
41
end
.svn/pristine/ca/ca6a83d87a789a365f28655b1d414ca917f8787b.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

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

  
20
class Redmine::Hook::ManagerTest < ActionView::TestCase
21
  fixtures :projects, :users, :members, :member_roles, :roles,
22
           :groups_users,
23
           :trackers, :projects_trackers,
24
           :enabled_modules,
25
           :versions,
26
           :issue_statuses, :issue_categories, :issue_relations, :workflows,
27
           :enumerations,
28
           :issues
29

  
30
  # Some hooks that are manually registered in these tests
31
  class TestHook < Redmine::Hook::ViewListener; end
32

  
33
  class TestHook1 < TestHook
34
    def view_layouts_base_html_head(context)
35
      'Test hook 1 listener.'
36
    end
37
  end
38

  
39
  class TestHook2 < TestHook
40
    def view_layouts_base_html_head(context)
41
      'Test hook 2 listener.'
42
    end
43
  end
44

  
45
  class TestHook3 < TestHook
46
    def view_layouts_base_html_head(context)
47
      "Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}."
48
    end
49
  end
50

  
51
  class TestLinkToHook < TestHook
52
    def view_layouts_base_html_head(context)
53
      link_to('Issues', :controller => 'issues')
54
    end
55
  end
56

  
57
  class TestHookHelperController < ActionController::Base
58
    include Redmine::Hook::Helper
59
  end
60

  
61
  class TestHookHelperView < ActionView::Base
62
    include Redmine::Hook::Helper
63
  end
64

  
65
  Redmine::Hook.clear_listeners
66

  
67
  def setup
68
    @hook_module = Redmine::Hook
69
  end
70

  
71
  def teardown
72
    @hook_module.clear_listeners
73
  end
74

  
75
  def test_clear_listeners
76
    assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
77
    @hook_module.add_listener(TestHook1)
78
    @hook_module.add_listener(TestHook2)
79
    assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size
80

  
81
    @hook_module.clear_listeners
82
    assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
83
  end
84

  
85
  def test_add_listener
86
    assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
87
    @hook_module.add_listener(TestHook1)
88
    assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size
89
  end
90

  
91
  def test_call_hook
92
    @hook_module.add_listener(TestHook1)
93
    assert_equal ['Test hook 1 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)
94
  end
95

  
96
  def test_call_hook_with_context
97
    @hook_module.add_listener(TestHook3)
98
    assert_equal ['Context keys: bar, controller, foo, hook_caller, project, request.'],
99
                 hook_helper.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a')
100
  end
101

  
102
  def test_call_hook_with_multiple_listeners
103
    @hook_module.add_listener(TestHook1)
104
    @hook_module.add_listener(TestHook2)
105
    assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)
106
  end
107

  
108
  # Context: Redmine::Hook::Helper.call_hook default_url
109
  def test_call_hook_default_url_options
110
    @hook_module.add_listener(TestLinkToHook)
111

  
112
    assert_equal ['<a href="/issues">Issues</a>'], hook_helper.call_hook(:view_layouts_base_html_head)
113
  end
114

  
115
  # Context: Redmine::Hook::Helper.call_hook
116
  def test_call_hook_with_project_added_to_context
117
    @hook_module.add_listener(TestHook3)
118
    assert_match /project/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
119
  end
120

  
121
  def test_call_hook_from_controller_with_controller_added_to_context
122
    @hook_module.add_listener(TestHook3)
123
    assert_match /controller/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
124
  end
125

  
126
  def test_call_hook_from_controller_with_request_added_to_context
127
    @hook_module.add_listener(TestHook3)
128
    assert_match /request/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
129
  end
130

  
131
  def test_call_hook_from_view_with_project_added_to_context
132
    @hook_module.add_listener(TestHook3)
133
    assert_match /project/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
134
  end
135

  
136
  def test_call_hook_from_view_with_controller_added_to_context
137
    @hook_module.add_listener(TestHook3)
138
    assert_match /controller/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
139
  end
140

  
141
  def test_call_hook_from_view_with_request_added_to_context
142
    @hook_module.add_listener(TestHook3)
143
    assert_match /request/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
144
  end
145

  
146
  def test_call_hook_from_view_should_join_responses_with_a_space
147
    @hook_module.add_listener(TestHook1)
148
    @hook_module.add_listener(TestHook2)
149
    assert_equal 'Test hook 1 listener. Test hook 2 listener.',
150
                 view_hook_helper.call_hook(:view_layouts_base_html_head)
151
  end
152

  
153
  def test_call_hook_should_not_change_the_default_url_for_email_notifications
154
    issue = Issue.find(1)
155

  
156
    ActionMailer::Base.deliveries.clear
157
    Mailer.issue_add(issue).deliver
158
    mail = ActionMailer::Base.deliveries.last
159

  
160
    @hook_module.add_listener(TestLinkToHook)
161
    hook_helper.call_hook(:view_layouts_base_html_head)
162

  
163
    ActionMailer::Base.deliveries.clear
164
    Mailer.issue_add(issue).deliver
165
    mail2 = ActionMailer::Base.deliveries.last
166

  
167
    assert_equal mail_body(mail), mail_body(mail2)
168
  end
169

  
170
  def hook_helper
171
    @hook_helper ||= TestHookHelperController.new
172
  end
173

  
174
  def view_hook_helper
175
    @view_hook_helper ||= TestHookHelperView.new(Rails.root.to_s + '/app/views')
176
  end
177
end
178

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

  
18
class WikiContentObserver < ActiveRecord::Observer
19
  def after_create(wiki_content)
20
    Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added')
21
  end
22

  
23
  def after_update(wiki_content)
24
    if wiki_content.text_changed?
25
      Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated')
26
    end
27
  end
28
end
.svn/pristine/ca/ca9a94f4269bc05500b823a9f42b210c9322360b.svn-base
1
require File.expand_path('../../test_helper', __FILE__)
2
require 'search_controller'
3

  
4
# Re-raise errors caught by the controller.
5
class SearchController; def rescue_action(e) raise e end; end
6

  
7
class SearchControllerTest < ActionController::TestCase
8
  fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
9
           :issues, :trackers, :issue_statuses, :enumerations,
10
           :custom_fields, :custom_values,
11
           :repositories, :changesets
12

  
13
  def setup
14
    @controller = SearchController.new
15
    @request    = ActionController::TestRequest.new
16
    @response   = ActionController::TestResponse.new
17
    User.current = nil
18
  end
19

  
20
  def test_search_for_projects
21
    get :index
22
    assert_response :success
23
    assert_template 'index'
24

  
25
    get :index, :q => "cook"
26
    assert_response :success
27
    assert_template 'index'
28
    assert assigns(:results).include?(Project.find(1))
29
  end
30

  
31
  def test_search_all_projects
32
    get :index, :q => 'recipe subproject commit', :all_words => ''
33
    assert_response :success
34
    assert_template 'index'
35

  
36
    assert assigns(:results).include?(Issue.find(2))
37
    assert assigns(:results).include?(Issue.find(5))
38
    assert assigns(:results).include?(Changeset.find(101))
39
    assert_tag :dt, :attributes => { :class => /issue/ },
40
                    :child => { :tag => 'a',  :content => /Add ingredients categories/ },
41
                    :sibling => { :tag => 'dd', :content => /should be classified by categories/ }
42

  
43
    assert assigns(:results_by_type).is_a?(Hash)
44
    assert_equal 5, assigns(:results_by_type)['changesets']
45
    assert_tag :a, :content => 'Changesets (5)'
46
  end
47

  
48
  def test_search_issues
49
    get :index, :q => 'issue', :issues => 1
50
    assert_response :success
51
    assert_template 'index'
52

  
53
    assert_equal true, assigns(:all_words)
54
    assert_equal false, assigns(:titles_only)
55
    assert assigns(:results).include?(Issue.find(8))
56
    assert assigns(:results).include?(Issue.find(5))
57
    assert_tag :dt, :attributes => { :class => /issue closed/ },
58
                    :child => { :tag => 'a',  :content => /Closed/ }
59
  end
60

  
61
  def test_search_issues_should_search_notes
62
    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
63

  
64
    get :index, :q => 'searchkeyword', :issues => 1
65
    assert_response :success
66
    assert_include Issue.find(2), assigns(:results)
67
  end
68

  
69
  def test_search_issues_with_multiple_matches_in_journals_should_return_issue_once
70
    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
71
    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
72

  
73
    get :index, :q => 'searchkeyword', :issues => 1
74
    assert_response :success
75
    assert_include Issue.find(2), assigns(:results)
76
    assert_equal 1, assigns(:results).size
77
  end
78

  
79
  def test_search_issues_should_search_private_notes_with_permission_only
80
    Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
81
    @request.session[:user_id] = 2
82

  
83
    Role.find(1).add_permission! :view_private_notes
84
    get :index, :q => 'searchkeyword', :issues => 1
85
    assert_response :success
86
    assert_include Issue.find(2), assigns(:results)
87

  
88
    Role.find(1).remove_permission! :view_private_notes
89
    get :index, :q => 'searchkeyword', :issues => 1
90
    assert_response :success
91
    assert_not_include Issue.find(2), assigns(:results)
92
  end
93

  
94
  def test_search_all_projects_with_scope_param
95
    get :index, :q => 'issue', :scope => 'all'
96
    assert_response :success
97
    assert_template 'index'
98
    assert assigns(:results).present?
99
  end
100

  
101
  def test_search_my_projects
102
    @request.session[:user_id] = 2
103
    get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
104
    assert_response :success
105
    assert_template 'index'
106
    assert assigns(:results).include?(Issue.find(1))
107
    assert !assigns(:results).include?(Issue.find(5))
108
  end
109

  
110
  def test_search_my_projects_without_memberships
111
    # anonymous user has no memberships
112
    get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
113
    assert_response :success
114
    assert_template 'index'
115
    assert assigns(:results).empty?
116
  end
117

  
118
  def test_search_project_and_subprojects
119
    get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
120
    assert_response :success
121
    assert_template 'index'
122
    assert assigns(:results).include?(Issue.find(1))
123
    assert assigns(:results).include?(Issue.find(5))
124
  end
125

  
126
  def test_search_without_searchable_custom_fields
127
    CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
128

  
129
    get :index, :id => 1
130
    assert_response :success
131
    assert_template 'index'
132
    assert_not_nil assigns(:project)
133

  
134
    get :index, :id => 1, :q => "can"
135
    assert_response :success
136
    assert_template 'index'
137
  end
138

  
139
  def test_search_with_searchable_custom_fields
140
    get :index, :id => 1, :q => "stringforcustomfield"
141
    assert_response :success
142
    results = assigns(:results)
143
    assert_not_nil results
144
    assert_equal 1, results.size
145
    assert results.include?(Issue.find(7))
146
  end
147

  
148
  def test_search_all_words
149
    # 'all words' is on by default
150
    get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
151
    assert_equal true, assigns(:all_words)
152
    results = assigns(:results)
153
    assert_not_nil results
154
    assert_equal 1, results.size
155
    assert results.include?(Issue.find(3))
156
  end
157

  
158
  def test_search_one_of_the_words
159
    get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
160
    assert_equal false, assigns(:all_words)
161
    results = assigns(:results)
162
    assert_not_nil results
163
    assert_equal 3, results.size
164
    assert results.include?(Issue.find(3))
165
  end
166

  
167
  def test_search_titles_only_without_result
168
    get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
169
    results = assigns(:results)
170
    assert_not_nil results
171
    assert_equal 0, results.size
172
  end
173

  
174
  def test_search_titles_only
175
    get :index, :id => 1, :q => 'recipe', :titles_only => '1'
176
    assert_equal true, assigns(:titles_only)
177
    results = assigns(:results)
178
    assert_not_nil results
179
    assert_equal 2, results.size
180
  end
181

  
182
  def test_search_content
183
    Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
184

  
185
    get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
186
    assert_equal false, assigns(:titles_only)
187
    results = assigns(:results)
188
    assert_not_nil results
189
    assert_equal 1, results.size
190
  end
191

  
192
  def test_search_with_offset
193
    get :index, :q => 'coo', :offset => '20080806073000'
194
    assert_response :success
195
    results = assigns(:results)
196
    assert results.any?
197
    assert results.map(&:event_datetime).max < '20080806T073000'.to_time
198
  end
199

  
200
  def test_search_previous_with_offset
201
    get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
202
    assert_response :success
203
    results = assigns(:results)
204
    assert results.any?
205
    assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
206
  end
207

  
208
  def test_search_with_invalid_project_id
209
    get :index, :id => 195, :q => 'recipe'
210
    assert_response 404
211
    assert_nil assigns(:results)
212
  end
213

  
214
  def test_quick_jump_to_issue
215
    # issue of a public project
216
    get :index, :q => "3"
217
    assert_redirected_to '/issues/3'
218

  
219
    # issue of a private project
220
    get :index, :q => "4"
221
    assert_response :success
222
    assert_template 'index'
223
  end
224

  
225
  def test_large_integer
226
    get :index, :q => '4615713488'
227
    assert_response :success
228
    assert_template 'index'
229
  end
230

  
231
  def test_tokens_with_quotes
232
    get :index, :id => 1, :q => '"good bye" hello "bye bye"'
233
    assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
234
  end
235

  
236
  def test_results_should_be_escaped_once
237
    assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once')
238
    get :index, :q => 'escaped_once'
239
    assert_response :success
240
    assert_select '#search-results' do
241
      assert_select 'dt.issue a', :text => /&lt;subject&gt;/
242
      assert_select 'dd', :text => /&lt;description&gt;/
243
    end
244
  end
245

  
246
  def test_keywords_should_be_highlighted
247
    assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted')
248
    get :index, :q => 'highlighted'
249
    assert_response :success
250
    assert_select '#search-results' do
251
      assert_select 'dt.issue a span.highlight', :text => 'highlighted'
252
      assert_select 'dd span.highlight', :text => 'highlighted'
253
    end
254
  end
255
end
.svn/pristine/ca/cae05f836fa0aba3f92054c65c73c78f356b7faf.svn-base
1
begin
2
  require "rubygems"
3
  require "bundler"
4
rescue LoadError
5
  $stderr.puts "Redmine requires Bundler. Please install it with `gem install bundler`."
6
  exit 1
7
end
8

  
9
if Gem::Version.new(Bundler::VERSION) < Gem::Version.new("1.0.21")
10
  $stderr.puts "Redmine requires Bundler 1.0.21 (you're using #{Bundler::VERSION}).\nPlease install a newer version with `gem install bundler`."
11
  exit 1
12
end
13

  
14
begin
15
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
16
  Bundler.setup
17
rescue Bundler::GemNotFound
18
  $stderr.puts "Some gems may need to be installed or updated.\nPlease run `bundle install --without development test`."
19
  exit 1
20
end

Also available in: Unified diff