Revision 1297:0a574315af3e .svn/pristine/69

View differences:

.svn/pristine/69/6904e863535549693b29c5f01931c820124ef164.svn-base
1
$('#tab-content-wiki').html('<%= escape_javascript(render :partial => 'projects/settings/wiki') %>');
.svn/pristine/69/69263d2dc0d479e58420859c9a2d96157091cbd5.svn-base
1
api.array :versions, api_meta(:total_count => @versions.size) do
2
  @versions.each do |version|
3
    api.version do
4
      api.id version.id
5
      api.project(:id => version.project_id, :name => version.project.name) unless version.project.nil?
6

  
7
      api.name        version.name
8
      api.description version.description
9
      api.status      version.status
10
      api.due_date    version.effective_date
11
      api.sharing     version.sharing
12

  
13
      render_api_custom_values version.custom_field_values, api
14

  
15
      api.created_on version.created_on
16
      api.updated_on version.updated_on
17
    end
18
  end
19
end
.svn/pristine/69/6928f5ba5fc17fb66a0a7ba070cce99ed775980c.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 RoutingTimelogsTest < ActionController::IntegrationTest
21
  def test_timelogs_global
22
    assert_routing(
23
        { :method => 'get', :path => "/time_entries" },
24
        { :controller => 'timelog', :action => 'index' }
25
      )
26
    assert_routing(
27
        { :method => 'get', :path => "/time_entries.csv" },
28
        { :controller => 'timelog', :action => 'index', :format => 'csv' }
29
      )
30
    assert_routing(
31
        { :method => 'get', :path => "/time_entries.atom" },
32
        { :controller => 'timelog', :action => 'index', :format => 'atom' }
33
      )
34
    assert_routing(
35
        { :method => 'get', :path => "/time_entries/new" },
36
        { :controller => 'timelog', :action => 'new' }
37
      )
38
    assert_routing(
39
        { :method => 'get', :path => "/time_entries/22/edit" },
40
        { :controller => 'timelog', :action => 'edit', :id => '22' }
41
      )
42
    assert_routing(
43
        { :method => 'post', :path => "/time_entries" },
44
        { :controller => 'timelog', :action => 'create' }
45
      )
46
    assert_routing(
47
        { :method => 'put', :path => "/time_entries/22" },
48
        { :controller => 'timelog', :action => 'update', :id => '22' }
49
      )
50
    assert_routing(
51
        { :method => 'delete', :path => "/time_entries/55" },
52
        { :controller => 'timelog', :action => 'destroy', :id => '55' }
53
      )
54
  end
55

  
56
  def test_timelogs_scoped_under_project
57
    assert_routing(
58
        { :method => 'get', :path => "/projects/567/time_entries" },
59
        { :controller => 'timelog', :action => 'index', :project_id => '567' }
60
      )
61
    assert_routing(
62
        { :method => 'get', :path => "/projects/567/time_entries.csv" },
63
        { :controller => 'timelog', :action => 'index', :project_id => '567',
64
          :format => 'csv' }
65
      )
66
    assert_routing(
67
        { :method => 'get', :path => "/projects/567/time_entries.atom" },
68
        { :controller => 'timelog', :action => 'index', :project_id => '567',
69
          :format => 'atom' }
70
      )
71
    assert_routing(
72
        { :method => 'get', :path => "/projects/567/time_entries/new" },
73
        { :controller => 'timelog', :action => 'new', :project_id => '567' }
74
      )
75
    assert_routing(
76
        { :method => 'get', :path => "/projects/567/time_entries/22/edit" },
77
        { :controller => 'timelog', :action => 'edit',
78
          :id => '22', :project_id => '567' }
79
      )
80
    assert_routing(
81
        { :method => 'post', :path => "/projects/567/time_entries" },
82
        { :controller => 'timelog', :action => 'create',
83
          :project_id => '567' }
84
      )
85
    assert_routing(
86
        { :method => 'put', :path => "/projects/567/time_entries/22" },
87
        { :controller => 'timelog', :action => 'update',
88
          :id => '22', :project_id => '567' }
89
      )
90
    assert_routing(
91
        { :method => 'delete', :path => "/projects/567/time_entries/55" },
92
        { :controller => 'timelog', :action => 'destroy',
93
          :id => '55', :project_id => '567' }
94
      )
95
  end
96

  
97
  def test_timelogs_scoped_under_issues
98
    assert_routing(
99
        { :method => 'get', :path => "/issues/234/time_entries" },
100
        { :controller => 'timelog', :action => 'index', :issue_id => '234' }
101
      )
102
    assert_routing(
103
        { :method => 'get', :path => "/issues/234/time_entries.csv" },
104
        { :controller => 'timelog', :action => 'index', :issue_id => '234',
105
          :format => 'csv' }
106
      )
107
    assert_routing(
108
        { :method => 'get', :path => "/issues/234/time_entries.atom" },
109
        { :controller => 'timelog', :action => 'index', :issue_id => '234',
110
          :format => 'atom' }
111
      )
112
    assert_routing(
113
        { :method => 'get', :path => "/issues/234/time_entries/new" },
114
        { :controller => 'timelog', :action => 'new', :issue_id => '234' }
115
      )
116
    assert_routing(
117
        { :method => 'get', :path => "/issues/234/time_entries/22/edit" },
118
        { :controller => 'timelog', :action => 'edit', :id => '22',
119
          :issue_id => '234' }
120
      )
121
    assert_routing(
122
        { :method => 'post', :path => "/issues/234/time_entries" },
123
        { :controller => 'timelog', :action => 'create', :issue_id => '234' }
124
      )
125
    assert_routing(
126
        { :method => 'put', :path => "/issues/234/time_entries/22" },
127
        { :controller => 'timelog', :action => 'update', :id => '22',
128
          :issue_id => '234' }
129
      )
130
    assert_routing(
131
        { :method => 'delete', :path => "/issues/234/time_entries/55" },
132
        { :controller => 'timelog', :action => 'destroy', :id => '55',
133
          :issue_id => '234' }
134
      )
135
  end
136

  
137
  def test_timelogs_scoped_under_project_and_issues
138
    assert_routing(
139
        { :method => 'get',
140
          :path => "/projects/ecookbook/issues/234/time_entries" },
141
        { :controller => 'timelog', :action => 'index',
142
          :issue_id => '234', :project_id => 'ecookbook' }
143
      )
144
    assert_routing(
145
        { :method => 'get',
146
          :path => "/projects/ecookbook/issues/234/time_entries.csv" },
147
        { :controller => 'timelog', :action => 'index',
148
          :issue_id => '234', :project_id => 'ecookbook', :format => 'csv' }
149
      )
150
    assert_routing(
151
        { :method => 'get',
152
          :path => "/projects/ecookbook/issues/234/time_entries.atom" },
153
        { :controller => 'timelog', :action => 'index',
154
          :issue_id => '234', :project_id => 'ecookbook', :format => 'atom' }
155
      )
156
    assert_routing(
157
        { :method => 'get',
158
          :path => "/projects/ecookbook/issues/234/time_entries/new" },
159
        { :controller => 'timelog', :action => 'new',
160
          :issue_id => '234', :project_id => 'ecookbook' }
161
      )
162
    assert_routing(
163
        { :method => 'get',
164
          :path => "/projects/ecookbook/issues/234/time_entries/22/edit" },
165
        { :controller => 'timelog', :action => 'edit', :id => '22',
166
          :issue_id => '234', :project_id => 'ecookbook' }
167
      )
168
    assert_routing(
169
        { :method => 'post',
170
          :path => "/projects/ecookbook/issues/234/time_entries" },
171
        { :controller => 'timelog', :action => 'create',
172
          :issue_id => '234', :project_id => 'ecookbook' }
173
      )
174
    assert_routing(
175
        { :method => 'put',
176
          :path => "/projects/ecookbook/issues/234/time_entries/22" },
177
        { :controller => 'timelog', :action => 'update', :id => '22',
178
          :issue_id => '234', :project_id => 'ecookbook' }
179
      )
180
    assert_routing(
181
        { :method => 'delete',
182
          :path => "/projects/ecookbook/issues/234/time_entries/55" },
183
        { :controller => 'timelog', :action => 'destroy', :id => '55',
184
          :issue_id => '234', :project_id => 'ecookbook' }
185
      )
186
  end
187

  
188
  def test_timelogs_report
189
    assert_routing(
190
        { :method => 'get',
191
          :path => "/time_entries/report" },
192
        { :controller => 'timelog', :action => 'report' }
193
      )
194
    assert_routing(
195
        { :method => 'get',
196
          :path => "/time_entries/report.csv" },
197
        { :controller => 'timelog', :action => 'report', :format => 'csv' }
198
      )
199
    assert_routing(
200
        { :method => 'get',
201
          :path => "/issues/234/time_entries/report" },
202
        { :controller => 'timelog', :action => 'report', :issue_id => '234' }
203
      )
204
    assert_routing(
205
        { :method => 'get',
206
          :path => "/issues/234/time_entries/report.csv" },
207
        { :controller => 'timelog', :action => 'report', :issue_id => '234',
208
          :format => 'csv' }
209
      )
210
    assert_routing(
211
        { :method => 'get',
212
          :path => "/projects/567/time_entries/report" },
213
        { :controller => 'timelog', :action => 'report', :project_id => '567' }
214
      )
215
    assert_routing(
216
        { :method => 'get',
217
          :path => "/projects/567/time_entries/report.csv" },
218
        { :controller => 'timelog', :action => 'report', :project_id => '567',
219
          :format => 'csv' }
220
      )
221
  end
222

  
223
  def test_timelogs_bulk_edit
224
    assert_routing(
225
        { :method => 'delete',
226
          :path => "/time_entries/destroy" },
227
        { :controller => 'timelog', :action => 'destroy' }
228
      )
229
    assert_routing(
230
        { :method => 'post',
231
          :path => "/time_entries/bulk_update" },
232
        { :controller => 'timelog', :action => 'bulk_update' }
233
      )
234
    assert_routing(
235
        { :method => 'get',
236
          :path => "/time_entries/bulk_edit" },
237
        { :controller => 'timelog', :action => 'bulk_edit' }
238
      )
239
  end
240
end
.svn/pristine/69/693231f9e49b340c1c563f401aa7c54ec7a66549.svn-base
1
# -*- encoding: utf-8 -*-
2
lib = File.expand_path('../lib/', __FILE__)
3
$:.unshift lib unless $:.include?(lib)
4
require 'awesome_nested_set/version'
5

  
6
Gem::Specification.new do |s|
7
  s.name = %q{awesome_nested_set}
8
  s.version = ::AwesomeNestedSet::VERSION
9
  s.authors = ["Brandon Keepers", "Daniel Morrison", "Philip Arndt"]
10
  s.description = %q{An awesome nested set implementation for Active Record}
11
  s.email = %q{info@collectiveidea.com}
12
  s.extra_rdoc_files = [
13
    "README.rdoc"
14
  ]
15
  s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.rdoc CHANGELOG)
16
  s.homepage = %q{http://github.com/collectiveidea/awesome_nested_set}
17
  s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
18
  s.require_paths = ["lib"]
19
  s.rubygems_version = %q{1.3.6}
20
  s.summary = %q{An awesome nested set implementation for Active Record}
21
  s.add_runtime_dependency 'activerecord', '>= 3.0.0'
22
end
.svn/pristine/69/694cd2c99623d577c90a26a298a76c97fefa807e.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
require 'wiki_controller'
20

  
21
# Re-raise errors caught by the controller.
22
class WikiController; def rescue_action(e) raise e end; end
23

  
24
class WikiControllerTest < ActionController::TestCase
25
  fixtures :projects, :users, :roles, :members, :member_roles,
26
           :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
27
           :wiki_content_versions, :attachments
28

  
29
  def setup
30
    @controller = WikiController.new
31
    @request    = ActionController::TestRequest.new
32
    @response   = ActionController::TestResponse.new
33
    User.current = nil
34
  end
35

  
36
  def test_show_start_page
37
    get :show, :project_id => 'ecookbook'
38
    assert_response :success
39
    assert_template 'show'
40
    assert_tag :tag => 'h1', :content => /CookBook documentation/
41

  
42
    # child_pages macro
43
    assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
44
               :child => { :tag => 'li',
45
                           :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
46
                                                    :content => 'Page with an inline image' } }
47
  end
48
  
49
  def test_export_link
50
    Role.anonymous.add_permission! :export_wiki_pages
51
    get :show, :project_id => 'ecookbook'
52
    assert_response :success
53
    assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
54
  end
55

  
56
  def test_show_page_with_name
57
    get :show, :project_id => 1, :id => 'Another_page'
58
    assert_response :success
59
    assert_template 'show'
60
    assert_tag :tag => 'h1', :content => /Another page/
61
    # Included page with an inline image
62
    assert_tag :tag => 'p', :content => /This is an inline image/
63
    assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
64
                                               :alt => 'This is a logo' }
65
  end
66

  
67
  def test_show_old_version
68
    get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
69
    assert_response :success
70
    assert_template 'show'
71

  
72
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
73
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
74
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
75
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
76
  end
77

  
78
  def test_show_old_version_without_permission_should_be_denied
79
    Role.anonymous.remove_permission! :view_wiki_edits
80

  
81
    get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
82
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
83
  end
84

  
85
  def test_show_first_version
86
    get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'
87
    assert_response :success
88
    assert_template 'show'
89

  
90
    assert_select 'a', :text => /Previous/, :count => 0
91
    assert_select 'a', :text => /diff/, :count => 0
92
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
93
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
94
  end
95

  
96
  def test_show_redirected_page
97
    WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
98

  
99
    get :show, :project_id => 'ecookbook', :id => 'Old_title'
100
    assert_redirected_to '/projects/ecookbook/wiki/Another_page'
101
  end
102

  
103
  def test_show_with_sidebar
104
    page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
105
    page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
106
    page.save!
107

  
108
    get :show, :project_id => 1, :id => 'Another_page'
109
    assert_response :success
110
    assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
111
                              :content => /Side bar content for test_show_with_sidebar/
112
  end
113
  
114
  def test_show_should_display_section_edit_links
115
    @request.session[:user_id] = 2
116
    get :show, :project_id => 1, :id => 'Page with sections'
117
    assert_no_tag 'a', :attributes => {
118
      :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1'
119
    }
120
    assert_tag 'a', :attributes => {
121
      :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
122
    }
123
    assert_tag 'a', :attributes => {
124
      :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
125
    }
126
  end
127

  
128
  def test_show_current_version_should_display_section_edit_links
129
    @request.session[:user_id] = 2
130
    get :show, :project_id => 1, :id => 'Page with sections', :version => 3
131

  
132
    assert_tag 'a', :attributes => {
133
      :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
134
    }
135
  end
136

  
137
  def test_show_old_version_should_not_display_section_edit_links
138
    @request.session[:user_id] = 2
139
    get :show, :project_id => 1, :id => 'Page with sections', :version => 2
140

  
141
    assert_no_tag 'a', :attributes => {
142
      :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
143
    }
144
  end
145

  
146
  def test_show_unexistent_page_without_edit_right
147
    get :show, :project_id => 1, :id => 'Unexistent page'
148
    assert_response 404
149
  end
150

  
151
  def test_show_unexistent_page_with_edit_right
152
    @request.session[:user_id] = 2
153
    get :show, :project_id => 1, :id => 'Unexistent page'
154
    assert_response :success
155
    assert_template 'edit'
156
  end
157

  
158
  def test_show_unexistent_page_with_parent_should_preselect_parent
159
    @request.session[:user_id] = 2
160
    get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
161
    assert_response :success
162
    assert_template 'edit'
163
    assert_tag 'select', :attributes => {:name => 'wiki_page[parent_id]'},
164
      :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}}
165
  end
166

  
167
  def test_show_should_not_show_history_without_permission
168
    Role.anonymous.remove_permission! :view_wiki_edits
169
    get :show, :project_id => 1, :id => 'Page with sections', :version => 2
170

  
171
    assert_response 302
172
  end
173

  
174
  def test_create_page
175
    @request.session[:user_id] = 2
176
    assert_difference 'WikiPage.count' do
177
      assert_difference 'WikiContent.count' do
178
        put :update, :project_id => 1,
179
                    :id => 'New page',
180
                    :content => {:comments => 'Created the page',
181
                                 :text => "h1. New page\n\nThis is a new page",
182
                                 :version => 0}
183
      end
184
    end
185
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
186
    page = Project.find(1).wiki.find_page('New page')
187
    assert !page.new_record?
188
    assert_not_nil page.content
189
    assert_nil page.parent
190
    assert_equal 'Created the page', page.content.comments
191
  end
192

  
193
  def test_create_page_with_attachments
194
    @request.session[:user_id] = 2
195
    assert_difference 'WikiPage.count' do
196
      assert_difference 'Attachment.count' do
197
        put :update, :project_id => 1,
198
                    :id => 'New page',
199
                    :content => {:comments => 'Created the page',
200
                                 :text => "h1. New page\n\nThis is a new page",
201
                                 :version => 0},
202
                    :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
203
      end
204
    end
205
    page = Project.find(1).wiki.find_page('New page')
206
    assert_equal 1, page.attachments.count
207
    assert_equal 'testfile.txt', page.attachments.first.filename
208
  end
209

  
210
  def test_create_page_with_parent
211
    @request.session[:user_id] = 2
212
    assert_difference 'WikiPage.count' do
213
      put :update, :project_id => 1, :id => 'New page',
214
        :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
215
        :wiki_page => {:parent_id => 2}
216
    end
217
    page = Project.find(1).wiki.find_page('New page')
218
    assert_equal WikiPage.find(2), page.parent
219
  end
220

  
221
  def test_edit_page
222
    @request.session[:user_id] = 2
223
    get :edit, :project_id => 'ecookbook', :id => 'Another_page'
224

  
225
    assert_response :success
226
    assert_template 'edit'
227

  
228
    assert_tag 'textarea',
229
      :attributes => { :name => 'content[text]' },
230
      :content => "\n"+WikiPage.find_by_title('Another_page').content.text
231
  end
232

  
233
  def test_edit_section
234
    @request.session[:user_id] = 2
235
    get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
236

  
237
    assert_response :success
238
    assert_template 'edit'
239
    
240
    page = WikiPage.find_by_title('Page_with_sections')
241
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
242

  
243
    assert_tag 'textarea',
244
      :attributes => { :name => 'content[text]' },
245
      :content => "\n"+section
246
    assert_tag 'input',
247
      :attributes => { :name => 'section', :type => 'hidden', :value => '2' }
248
    assert_tag 'input',
249
      :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash }
250
  end
251

  
252
  def test_edit_invalid_section_should_respond_with_404
253
    @request.session[:user_id] = 2
254
    get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
255

  
256
    assert_response 404
257
  end
258

  
259
  def test_update_page
260
    @request.session[:user_id] = 2
261
    assert_no_difference 'WikiPage.count' do
262
      assert_no_difference 'WikiContent.count' do
263
        assert_difference 'WikiContent::Version.count' do
264
          put :update, :project_id => 1,
265
            :id => 'Another_page',
266
            :content => {
267
              :comments => "my comments",
268
              :text => "edited",
269
              :version => 1
270
            }
271
        end
272
      end
273
    end
274
    assert_redirected_to '/projects/ecookbook/wiki/Another_page'
275

  
276
    page = Wiki.find(1).pages.find_by_title('Another_page')
277
    assert_equal "edited", page.content.text
278
    assert_equal 2, page.content.version
279
    assert_equal "my comments", page.content.comments
280
  end
281

  
282
  def test_update_page_with_parent
283
    @request.session[:user_id] = 2
284
    assert_no_difference 'WikiPage.count' do
285
      assert_no_difference 'WikiContent.count' do
286
        assert_difference 'WikiContent::Version.count' do
287
          put :update, :project_id => 1,
288
            :id => 'Another_page',
289
            :content => {
290
              :comments => "my comments",
291
              :text => "edited",
292
              :version => 1
293
            },
294
            :wiki_page => {:parent_id => '1'}
295
        end
296
      end
297
    end
298
    assert_redirected_to '/projects/ecookbook/wiki/Another_page'
299

  
300
    page = Wiki.find(1).pages.find_by_title('Another_page')
301
    assert_equal "edited", page.content.text
302
    assert_equal 2, page.content.version
303
    assert_equal "my comments", page.content.comments
304
    assert_equal WikiPage.find(1), page.parent
305
  end
306

  
307
  def test_update_page_with_failure
308
    @request.session[:user_id] = 2
309
    assert_no_difference 'WikiPage.count' do
310
      assert_no_difference 'WikiContent.count' do
311
        assert_no_difference 'WikiContent::Version.count' do
312
          put :update, :project_id => 1,
313
            :id => 'Another_page',
314
            :content => {
315
              :comments => 'a' * 300,  # failure here, comment is too long
316
              :text => 'edited',
317
              :version => 1
318
            }
319
          end
320
        end
321
      end
322
    assert_response :success
323
    assert_template 'edit'
324

  
325
    assert_error_tag :descendant => {:content => /Comment is too long/}
326
    assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => "\nedited"
327
    assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
328
  end
329

  
330
  def test_update_page_with_parent_change_only_should_not_create_content_version
331
    @request.session[:user_id] = 2
332
    assert_no_difference 'WikiPage.count' do
333
      assert_no_difference 'WikiContent.count' do
334
        assert_no_difference 'WikiContent::Version.count' do
335
          put :update, :project_id => 1,
336
            :id => 'Another_page',
337
            :content => {
338
              :comments => '',
339
              :text => Wiki.find(1).find_page('Another_page').content.text,
340
              :version => 1
341
            },
342
            :wiki_page => {:parent_id => '1'}
343
        end
344
      end
345
    end
346
    page = Wiki.find(1).pages.find_by_title('Another_page')
347
    assert_equal 1, page.content.version
348
    assert_equal WikiPage.find(1), page.parent
349
  end
350

  
351
  def test_update_page_with_attachments_only_should_not_create_content_version
352
    @request.session[:user_id] = 2
353
    assert_no_difference 'WikiPage.count' do
354
      assert_no_difference 'WikiContent.count' do
355
        assert_no_difference 'WikiContent::Version.count' do
356
          assert_difference 'Attachment.count' do
357
            put :update, :project_id => 1,
358
              :id => 'Another_page',
359
              :content => {
360
                :comments => '',
361
                :text => Wiki.find(1).find_page('Another_page').content.text,
362
                :version => 1
363
              },
364
              :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
365
          end
366
        end
367
      end
368
    end
369
    page = Wiki.find(1).pages.find_by_title('Another_page')
370
    assert_equal 1, page.content.version
371
  end
372

  
373
  def test_update_stale_page_should_not_raise_an_error
374
    @request.session[:user_id] = 2
375
    c = Wiki.find(1).find_page('Another_page').content
376
    c.text = 'Previous text'
377
    c.save!
378
    assert_equal 2, c.version
379

  
380
    assert_no_difference 'WikiPage.count' do
381
      assert_no_difference 'WikiContent.count' do
382
        assert_no_difference 'WikiContent::Version.count' do
383
          put :update, :project_id => 1,
384
            :id => 'Another_page',
385
            :content => {
386
              :comments => 'My comments',
387
              :text => 'Text should not be lost',
388
              :version => 1
389
            }
390
        end
391
      end
392
    end
393
    assert_response :success
394
    assert_template 'edit'
395
    assert_tag :div,
396
      :attributes => { :class => /error/ },
397
      :content => /Data has been updated by another user/
398
    assert_tag 'textarea',
399
      :attributes => { :name => 'content[text]' },
400
      :content => /Text should not be lost/
401
    assert_tag 'input',
402
      :attributes => { :name => 'content[comments]', :value => 'My comments' }
403

  
404
    c.reload
405
    assert_equal 'Previous text', c.text
406
    assert_equal 2, c.version
407
  end
408

  
409
  def test_update_section
410
    @request.session[:user_id] = 2
411
    page = WikiPage.find_by_title('Page_with_sections')
412
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
413
    text = page.content.text
414

  
415
    assert_no_difference 'WikiPage.count' do
416
      assert_no_difference 'WikiContent.count' do
417
        assert_difference 'WikiContent::Version.count' do
418
          put :update, :project_id => 1, :id => 'Page_with_sections',
419
            :content => {
420
              :text => "New section content",
421
              :version => 3
422
            },
423
            :section => 2,
424
            :section_hash => hash
425
        end
426
      end
427
    end
428
    assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
429
    assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
430
  end
431

  
432
  def test_update_section_should_allow_stale_page_update
433
    @request.session[:user_id] = 2
434
    page = WikiPage.find_by_title('Page_with_sections')
435
    section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
436
    text = page.content.text
437

  
438
    assert_no_difference 'WikiPage.count' do
439
      assert_no_difference 'WikiContent.count' do
440
        assert_difference 'WikiContent::Version.count' do
441
          put :update, :project_id => 1, :id => 'Page_with_sections',
442
            :content => {
443
              :text => "New section content",
444
              :version => 2 # Current version is 3
445
            },
446
            :section => 2,
447
            :section_hash => hash
448
        end
449
      end
450
    end
451
    assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
452
    page.reload
453
    assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
454
    assert_equal 4, page.content.version
455
  end
456

  
457
  def test_update_section_should_not_allow_stale_section_update
458
    @request.session[:user_id] = 2
459

  
460
    assert_no_difference 'WikiPage.count' do
461
      assert_no_difference 'WikiContent.count' do
462
        assert_no_difference 'WikiContent::Version.count' do
463
          put :update, :project_id => 1, :id => 'Page_with_sections',
464
            :content => {
465
              :comments => 'My comments',
466
              :text => "Text should not be lost",
467
              :version => 3
468
            },
469
            :section => 2,
470
            :section_hash => Digest::MD5.hexdigest("wrong hash")
471
        end
472
      end
473
    end
474
    assert_response :success
475
    assert_template 'edit'
476
    assert_tag :div,
477
      :attributes => { :class => /error/ },
478
      :content => /Data has been updated by another user/
479
    assert_tag 'textarea',
480
      :attributes => { :name => 'content[text]' },
481
      :content => /Text should not be lost/
482
    assert_tag 'input',
483
      :attributes => { :name => 'content[comments]', :value => 'My comments' }
484
  end
485

  
486
  def test_preview
487
    @request.session[:user_id] = 2
488
    xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
489
                                   :content => { :comments => '',
490
                                                 :text => 'this is a *previewed text*',
491
                                                 :version => 3 }
492
    assert_response :success
493
    assert_template 'common/_preview'
494
    assert_tag :tag => 'strong', :content => /previewed text/
495
  end
496

  
497
  def test_preview_new_page
498
    @request.session[:user_id] = 2
499
    xhr :post, :preview, :project_id => 1, :id => 'New page',
500
                                   :content => { :text => 'h1. New page',
501
                                                 :comments => '',
502
                                                 :version => 0 }
503
    assert_response :success
504
    assert_template 'common/_preview'
505
    assert_tag :tag => 'h1', :content => /New page/
506
  end
507

  
508
  def test_history
509
    @request.session[:user_id] = 2
510
    get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation'
511
    assert_response :success
512
    assert_template 'history'
513
    assert_not_nil assigns(:versions)
514
    assert_equal 3, assigns(:versions).size
515

  
516
    assert_select "input[type=submit][name=commit]"
517
    assert_select 'td' do
518
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
519
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
520
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
521
    end
522
  end
523

  
524
  def test_history_with_one_version
525
    @request.session[:user_id] = 2
526
    get :history, :project_id => 'ecookbook', :id => 'Another_page'
527
    assert_response :success
528
    assert_template 'history'
529
    assert_not_nil assigns(:versions)
530
    assert_equal 1, assigns(:versions).size
531
    assert_select "input[type=submit][name=commit]", false
532
    assert_select 'td' do
533
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
534
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
535
      assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
536
    end
537
  end
538

  
539
  def test_diff
540
    content = WikiPage.find(1).content
541
    assert_difference 'WikiContent::Version.count', 2 do
542
      content.text = "Line removed\nThis is a sample text for testing diffs"
543
      content.save!
544
      content.text = "This is a sample text for testing diffs\nLine added"
545
      content.save!
546
    end
547

  
548
    get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1)
549
    assert_response :success
550
    assert_template 'diff'
551
    assert_select 'span.diff_out', :text => 'Line removed'
552
    assert_select 'span.diff_in', :text => 'Line added'
553
  end
554

  
555
  def test_diff_with_invalid_version_should_respond_with_404
556
    get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
557
    assert_response 404
558
  end
559

  
560
  def test_diff_with_invalid_version_from_should_respond_with_404
561
    get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
562
    assert_response 404
563
  end
564

  
565
  def test_annotate
566
    get :annotate, :project_id => 1, :id =>  'CookBook_documentation', :version => 2
567
    assert_response :success
568
    assert_template 'annotate'
569

  
570
    # Line 1
571
    assert_tag :tag => 'tr', :child => {
572
      :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
573
        :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
574
          :tag => 'td', :content => /h1\. CookBook documentation/
575
        }
576
      }
577
    }
578

  
579
    # Line 5
580
    assert_tag :tag => 'tr', :child => {
581
      :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
582
        :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
583
          :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
584
        }
585
      }
586
    }
587
  end
588

  
589
  def test_annotate_with_invalid_version_should_respond_with_404
590
    get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
591
    assert_response 404
592
  end
593

  
594
  def test_get_rename
595
    @request.session[:user_id] = 2
596
    get :rename, :project_id => 1, :id => 'Another_page'
597
    assert_response :success
598
    assert_template 'rename'
599
    assert_tag 'option',
600
      :attributes => {:value => ''},
601
      :content => '',
602
      :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
603
    assert_no_tag 'option',
604
      :attributes => {:selected => 'selected'},
605
      :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
606
  end
607

  
608
  def test_get_rename_child_page
609
    @request.session[:user_id] = 2
610
    get :rename, :project_id => 1, :id => 'Child_1'
611
    assert_response :success
612
    assert_template 'rename'
613
    assert_tag 'option',
614
      :attributes => {:value => ''},
615
      :content => '',
616
      :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
617
    assert_tag 'option',
618
      :attributes => {:value => '2', :selected => 'selected'},
619
      :content => /Another page/,
620
      :parent => {
621
        :tag => 'select',
622
        :attributes => {:name => 'wiki_page[parent_id]'}
623
      }
624
  end
625

  
626
  def test_rename_with_redirect
627
    @request.session[:user_id] = 2
628
    post :rename, :project_id => 1, :id => 'Another_page',
629
                            :wiki_page => { :title => 'Another renamed page',
630
                                            :redirect_existing_links => 1 }
631
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
632
    wiki = Project.find(1).wiki
633
    # Check redirects
634
    assert_not_nil wiki.find_page('Another page')
635
    assert_nil wiki.find_page('Another page', :with_redirect => false)
636
  end
637

  
638
  def test_rename_without_redirect
639
    @request.session[:user_id] = 2
640
    post :rename, :project_id => 1, :id => 'Another_page',
641
                            :wiki_page => { :title => 'Another renamed page',
642
                                            :redirect_existing_links => "0" }
643
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
644
    wiki = Project.find(1).wiki
645
    # Check that there's no redirects
646
    assert_nil wiki.find_page('Another page')
647
  end
648

  
649
  def test_rename_with_parent_assignment
650
    @request.session[:user_id] = 2
651
    post :rename, :project_id => 1, :id => 'Another_page',
652
      :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
653
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
654
    assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
655
  end
656

  
657
  def test_rename_with_parent_unassignment
658
    @request.session[:user_id] = 2
659
    post :rename, :project_id => 1, :id => 'Child_1',
660
      :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
661
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
662
    assert_nil WikiPage.find_by_title('Child_1').parent
663
  end
664

  
665
  def test_destroy_a_page_without_children_should_not_ask_confirmation
666
    @request.session[:user_id] = 2
667
    delete :destroy, :project_id => 1, :id => 'Child_2'
668
    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
669
  end
670

  
671
  def test_destroy_parent_should_ask_confirmation
672
    @request.session[:user_id] = 2
673
    assert_no_difference('WikiPage.count') do
674
      delete :destroy, :project_id => 1, :id => 'Another_page'
675
    end
676
    assert_response :success
677
    assert_template 'destroy'
678
    assert_select 'form' do
679
      assert_select 'input[name=todo][value=nullify]'
680
      assert_select 'input[name=todo][value=destroy]'
681
      assert_select 'input[name=todo][value=reassign]'
682
    end
683
  end
684

  
685
  def test_destroy_parent_with_nullify_should_delete_parent_only
686
    @request.session[:user_id] = 2
687
    assert_difference('WikiPage.count', -1) do
688
      delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
689
    end
690
    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
691
    assert_nil WikiPage.find_by_id(2)
692
  end
693

  
694
  def test_destroy_parent_with_cascade_should_delete_descendants
695
    @request.session[:user_id] = 2
696
    assert_difference('WikiPage.count', -4) do
697
      delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
698
    end
699
    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
700
    assert_nil WikiPage.find_by_id(2)
701
    assert_nil WikiPage.find_by_id(5)
702
  end
703

  
704
  def test_destroy_parent_with_reassign
705
    @request.session[:user_id] = 2
706
    assert_difference('WikiPage.count', -1) do
707
      delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
708
    end
709
    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
710
    assert_nil WikiPage.find_by_id(2)
711
    assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
712
  end
713

  
714
  def test_destroy_version
715
    @request.session[:user_id] = 2
716
    assert_difference 'WikiContent::Version.count', -1 do
717
      assert_no_difference 'WikiContent.count' do
718
        assert_no_difference 'WikiPage.count' do
719
          delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2
720
          assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
721
        end
722
      end
723
    end
724
  end
725

  
726
  def test_index
727
    get :index, :project_id => 'ecookbook'
728
    assert_response :success
729
    assert_template 'index'
730
    pages = assigns(:pages)
731
    assert_not_nil pages
732
    assert_equal Project.find(1).wiki.pages.size, pages.size
733
    assert_equal pages.first.content.updated_on, pages.first.updated_on
734

  
735
    assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
736
                    :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
737
                                              :content => 'CookBook documentation' },
738
                                :child => { :tag => 'ul',
739
                                            :child => { :tag => 'li',
740
                                                        :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
741
                                                                                 :content => 'Page with an inline image' } } } },
742
                    :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
743
                                                                       :content => 'Another page' } }
744
  end
745

  
746
  def test_index_should_include_atom_link
747
    get :index, :project_id => 'ecookbook'
748
    assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
749
  end
750

  
751
  def test_export_to_html
752
    @request.session[:user_id] = 2
753
    get :export, :project_id => 'ecookbook'
754

  
755
    assert_response :success
756
    assert_not_nil assigns(:pages)
757
    assert assigns(:pages).any?
758
    assert_equal "text/html", @response.content_type
759

  
760
    assert_select "a[name=?]", "CookBook_documentation"
761
    assert_select "a[name=?]", "Another_page"
762
    assert_select "a[name=?]", "Page_with_an_inline_image"
763
  end
764

  
765
  def test_export_to_pdf
766
    @request.session[:user_id] = 2
767
    get :export, :project_id => 'ecookbook', :format => 'pdf'
768

  
769
    assert_response :success
770
    assert_not_nil assigns(:pages)
771
    assert assigns(:pages).any?
772
    assert_equal 'application/pdf', @response.content_type
773
    assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition']
774
    assert @response.body.starts_with?('%PDF')
775
  end
776

  
777
  def test_export_without_permission_should_be_denied
778
    @request.session[:user_id] = 2
779
    Role.find_by_name('Manager').remove_permission! :export_wiki_pages
780
    get :export, :project_id => 'ecookbook'
781

  
782
    assert_response 403
783
  end
784

  
785
  def test_date_index
786
    get :date_index, :project_id => 'ecookbook'
787

  
788
    assert_response :success
789
    assert_template 'date_index'
790
    assert_not_nil assigns(:pages)
791
    assert_not_nil assigns(:pages_by_date)
792

  
793
    assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
794
  end
795

  
796
  def test_not_found
797
    get :show, :project_id => 999
798
    assert_response 404
799
  end
800

  
801
  def test_protect_page
802
    page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
803
    assert !page.protected?
804
    @request.session[:user_id] = 2
805
    post :protect, :project_id => 1, :id => page.title, :protected => '1'
806
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
807
    assert page.reload.protected?
808
  end
809

  
810
  def test_unprotect_page
811
    page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
812
    assert page.protected?
813
    @request.session[:user_id] = 2
814
    post :protect, :project_id => 1, :id => page.title, :protected => '0'
815
    assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
816
    assert !page.reload.protected?
817
  end
818

  
819
  def test_show_page_with_edit_link
820
    @request.session[:user_id] = 2
821
    get :show, :project_id => 1
822
    assert_response :success
823
    assert_template 'show'
824
    assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
825
  end
826

  
827
  def test_show_page_without_edit_link
828
    @request.session[:user_id] = 4
829
    get :show, :project_id => 1
830
    assert_response :success
831
    assert_template 'show'
832
    assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
833
  end
834

  
835
  def test_show_pdf
836
    @request.session[:user_id] = 2
837
    get :show, :project_id => 1, :format => 'pdf'
838
    assert_response :success
839
    assert_not_nil assigns(:page)
840
    assert_equal 'application/pdf', @response.content_type
841
    assert_equal 'attachment; filename="CookBook_documentation.pdf"',
842
                  @response.headers['Content-Disposition']
843
  end
844

  
845
  def test_show_html
846
    @request.session[:user_id] = 2
847
    get :show, :project_id => 1, :format => 'html'
848
    assert_response :success
849
    assert_not_nil assigns(:page)
850
    assert_equal 'text/html', @response.content_type
851
    assert_equal 'attachment; filename="CookBook_documentation.html"',
852
                  @response.headers['Content-Disposition']
853
    assert_tag 'h1', :content => 'CookBook documentation'
854
  end
855

  
856
  def test_show_versioned_html
857
    @request.session[:user_id] = 2
858
    get :show, :project_id => 1, :format => 'html', :version => 2
859
    assert_response :success
860
    assert_not_nil assigns(:content)
861
    assert_equal 2, assigns(:content).version
862
    assert_equal 'text/html', @response.content_type
863
    assert_equal 'attachment; filename="CookBook_documentation.html"',
864
                  @response.headers['Content-Disposition']
865
    assert_tag 'h1', :content => 'CookBook documentation'
866
  end
867

  
868
  def test_show_txt
869
    @request.session[:user_id] = 2
870
    get :show, :project_id => 1, :format => 'txt'
871
    assert_response :success
872
    assert_not_nil assigns(:page)
873
    assert_equal 'text/plain', @response.content_type
874
    assert_equal 'attachment; filename="CookBook_documentation.txt"',
875
                  @response.headers['Content-Disposition']
876
    assert_include 'h1. CookBook documentation', @response.body
877
  end
878

  
879
  def test_show_versioned_txt
880
    @request.session[:user_id] = 2
881
    get :show, :project_id => 1, :format => 'txt', :version => 2
882
    assert_response :success
883
    assert_not_nil assigns(:content)
884
    assert_equal 2, assigns(:content).version
885
    assert_equal 'text/plain', @response.content_type
886
    assert_equal 'attachment; filename="CookBook_documentation.txt"',
887
                  @response.headers['Content-Disposition']
888
    assert_include 'h1. CookBook documentation', @response.body
889
  end
890

  
891
  def test_edit_unprotected_page
892
    # Non members can edit unprotected wiki pages
893
    @request.session[:user_id] = 4
894
    get :edit, :project_id => 1, :id => 'Another_page'
895
    assert_response :success
896
    assert_template 'edit'
897
  end
898

  
899
  def test_edit_protected_page_by_nonmember
900
    # Non members can't edit protected wiki pages
901
    @request.session[:user_id] = 4
902
    get :edit, :project_id => 1, :id => 'CookBook_documentation'
903
    assert_response 403
904
  end
905

  
906
  def test_edit_protected_page_by_member
907
    @request.session[:user_id] = 2
908
    get :edit, :project_id => 1, :id => 'CookBook_documentation'
909
    assert_response :success
910
    assert_template 'edit'
911
  end
912

  
913
  def test_history_of_non_existing_page_should_return_404
914
    get :history, :project_id => 1, :id => 'Unknown_page'
915
    assert_response 404
916
  end
917

  
918
  def test_add_attachment
919
    @request.session[:user_id] = 2
920
    assert_difference 'Attachment.count' do
921
      post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
922
        :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
923
    end
924
    attachment = Attachment.first(:order => 'id DESC')
925
    assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
926
  end
927
end
.svn/pristine/69/69880768f41d60c3194963e6b90500b6be6affe7.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 GanttsController < ApplicationController
19
  menu_item :gantt
20
  before_filter :find_optional_project
21

  
22
  rescue_from Query::StatementInvalid, :with => :query_statement_invalid
23

  
24
  helper :gantt
25
  helper :issues
26
  helper :projects
27
  helper :queries
28
  include QueriesHelper
29
  helper :sort
30
  include SortHelper
31
  include Redmine::Export::PDF
32

  
33
  def show
34
    @gantt = Redmine::Helpers::Gantt.new(params)
35
    @gantt.project = @project
36
    retrieve_query
37
    @query.group_by = nil
38
    @gantt.query = @query if @query.valid?
39

  
40
    basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
41

  
42
    respond_to do |format|
43
      format.html { render :action => "show", :layout => !request.xhr? }
44
      format.png  { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
45
      format.pdf  { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
46
    end
47
  end
48
end
.svn/pristine/69/69920dcbdbcd687ac4b06555af482a8e6a1caf3a.svn-base
1
<%= error_messages_for @document %>
2

  
3
<div class="box tabular">
4
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
5
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
6
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
7
</div>
8

  
9
<%= wikitoolbar_for 'document_description' %>
10

  
11
<% if @document.new_record? %>
12
<div class="box tabular">
13
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form', :locals => {:container => @document} %></p>
14
</div>
15
<% end %>

Also available in: Unified diff