Revision 1297:0a574315af3e .svn/pristine/3c

View differences:

.svn/pristine/3c/3c182a61315731239b388b13cfd0c9e853524d29.svn-base
1
<% diff = Redmine::UnifiedDiff.new(
2
            diff, :type => diff_type,
3
            :max_lines => Setting.diff_max_lines_displayed.to_i,
4
            :style => diff_style) -%>
5

  
6
<% diff.each do |table_file| -%>
7
<div class="autoscroll">
8
<% if diff.diff_type == 'sbs' -%>
9
<table class="filecontent">
10
<thead>
11
<tr>
12
  <th colspan="4" class="filename">
13
    <%= h(Redmine::CodesetUtil.to_utf8_by_setting(table_file.file_name)) %>
14
  </th>
15
</tr>
16
</thead>
17
<tbody>
18
<% table_file.each_line do |spacing, line| -%>
19
<% if spacing -%>
20
<tr class="spacing">
21
  <th class="line-num">...</th><td></td><th class="line-num">...</th><td></td>
22
</tr>
23
<% end -%>
24
<tr>
25
  <th class="line-num"><%= line.nb_line_left %></th>
26
  <td class="line-code <%= line.type_diff_left %>">
27
    <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line_left).html_safe %></pre>
28
  </td>
29
  <th class="line-num"><%= line.nb_line_right %></th>
30
  <td class="line-code <%= line.type_diff_right %>">
31
    <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line_right).html_safe %></pre>
32
  </td>
33
</tr>
34
<% end -%>
35
</tbody>
36
</table>
37

  
38
<% else -%>
39
<table class="filecontent">
40
<thead>
41
  <tr>
42
    <th colspan="3" class="filename">
43
      <%= h(Redmine::CodesetUtil.to_utf8_by_setting(table_file.file_name)) %>
44
    </th>
45
  </tr>
46
</thead>
47
<tbody>
48
<% table_file.each_line do |spacing, line| %>
49
<% if spacing -%>
50
<tr class="spacing">
51
  <th class="line-num">...</th><th class="line-num">...</th><td></td>
52
</tr>
53
<% end -%>
54
<tr>
55
  <th class="line-num"><%= line.nb_line_left %></th>
56
  <th class="line-num"><%= line.nb_line_right %></th>
57
  <td class="line-code <%= line.type_diff %>">
58
    <pre><%= Redmine::CodesetUtil.to_utf8_by_setting(line.html_line).html_safe %></pre>
59
  </td>
60
</tr>
61
<% end -%>
62
</tbody>
63
</table>
64
<% end -%>
65
</div>
66
<% end -%>
67

  
68
<%= l(:text_diff_truncated) if diff.truncated? %>
.svn/pristine/3c/3c9d342ac8ea509336a4fbcb76da57ef9ad85e78.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::MenuManager::MenuHelperTest < ActionView::TestCase
21

  
22
  include Redmine::MenuManager::MenuHelper
23
  include ERB::Util
24
  fixtures :users, :members, :projects, :enabled_modules, :roles, :member_roles
25

  
26
  def setup
27
    setup_with_controller
28
    # Stub the current menu item in the controller
29
    def current_menu_item
30
      :index
31
    end
32
  end
33

  
34
  context "MenuManager#current_menu_item" do
35
    should "be tested"
36
  end
37

  
38
  context "MenuManager#render_main_menu" do
39
    should "be tested"
40
  end
41

  
42
  context "MenuManager#render_menu" do
43
    should "be tested"
44
  end
45

  
46
  context "MenuManager#menu_item_and_children" do
47
    should "be tested"
48
  end
49

  
50
  context "MenuManager#extract_node_details" do
51
    should "be tested"
52
  end
53

  
54
  def test_render_single_menu_node
55
    node = Redmine::MenuManager::MenuItem.new(:testing, '/test', { })
56
    @output_buffer = render_single_menu_node(node, 'This is a test', node.url, false)
57

  
58
    assert_select("a.testing", "This is a test")
59
  end
60

  
61
  def test_render_menu_node
62
    single_node = Redmine::MenuManager::MenuItem.new(:single_node, '/test', { })
63
    @output_buffer = render_menu_node(single_node, nil)
64

  
65
    assert_select("li") do
66
      assert_select("a.single-node", "Single node")
67
    end
68
  end
69

  
70
  def test_render_menu_node_with_nested_items
71
    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, '/test', { })
72
    parent_node << Redmine::MenuManager::MenuItem.new(:child_one_node, '/test', { })
73
    parent_node << Redmine::MenuManager::MenuItem.new(:child_two_node, '/test', { })
74
    parent_node <<
75
      Redmine::MenuManager::MenuItem.new(:child_three_node, '/test', { }) <<
76
      Redmine::MenuManager::MenuItem.new(:child_three_inner_node, '/test', { })
77

  
78
    @output_buffer = render_menu_node(parent_node, nil)
79

  
80
    assert_select("li") do
81
      assert_select("a.parent-node", "Parent node")
82
      assert_select("ul") do
83
        assert_select("li a.child-one-node", "Child one node")
84
        assert_select("li a.child-two-node", "Child two node")
85
        assert_select("li") do
86
          assert_select("a.child-three-node", "Child three node")
87
          assert_select("ul") do
88
            assert_select("li a.child-three-inner-node", "Child three inner node")
89
          end
90
        end
91
      end
92
    end
93

  
94
  end
95

  
96
  def test_render_menu_node_with_children
97
    User.current = User.find(2)
98

  
99
    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
100
                                                     '/test',
101
                                                     {
102
                                                       :children => Proc.new {|p|
103
                                                         children = []
104
                                                         3.times do |time|
105
                                                           children << Redmine::MenuManager::MenuItem.new("test_child_#{time}",
106
                                                                                                             {:controller => 'issues', :action => 'index'},
107
                                                                                                             {})
108
                                                         end
109
                                                         children
110
                                                       }
111
                                                     })
112
    @output_buffer = render_menu_node(parent_node, Project.find(1))
113

  
114
    assert_select("li") do
115
      assert_select("a.parent-node", "Parent node")
116
      assert_select("ul") do
117
        assert_select("li a.test-child-0", "Test child 0")
118
        assert_select("li a.test-child-1", "Test child 1")
119
        assert_select("li a.test-child-2", "Test child 2")
120
      end
121
    end
122
  end
123

  
124
  def test_render_menu_node_with_nested_items_and_children
125
    User.current = User.find(2)
126

  
127
    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
128
                                                     '/test',
129
                                                     {
130
                                                       :children => Proc.new {|p|
131
                                                         children = []
132
                                                         3.times do |time|
133
                                                           children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", {:controller => 'issues', :action => 'index'}, {})
134
                                                         end
135
                                                         children
136
                                                       }
137
                                                     })
138

  
139
    parent_node << Redmine::MenuManager::MenuItem.new(:child_node,
140
                                                     '/test',
141
                                                     {
142
                                                       :children => Proc.new {|p|
143
                                                         children = []
144
                                                         6.times do |time|
145
                                                            children << Redmine::MenuManager::MenuItem.new("test_dynamic_child_#{time}", {:controller => 'issues', :action => 'index'}, {})
146
                                                         end
147
                                                         children
148
                                                       }
149
                                                     })
150

  
151
    @output_buffer = render_menu_node(parent_node, Project.find(1))
152

  
153
    assert_select("li") do
154
      assert_select("a.parent-node", "Parent node")
155
      assert_select("ul") do
156
        assert_select("li a.child-node", "Child node")
157
        assert_select("ul") do
158
          assert_select("li a.test-dynamic-child-0", "Test dynamic child 0")
159
          assert_select("li a.test-dynamic-child-1", "Test dynamic child 1")
160
          assert_select("li a.test-dynamic-child-2", "Test dynamic child 2")
161
          assert_select("li a.test-dynamic-child-3", "Test dynamic child 3")
162
          assert_select("li a.test-dynamic-child-4", "Test dynamic child 4")
163
          assert_select("li a.test-dynamic-child-5", "Test dynamic child 5")
164
        end
165
        assert_select("li a.test-child-0", "Test child 0")
166
        assert_select("li a.test-child-1", "Test child 1")
167
        assert_select("li a.test-child-2", "Test child 2")
168
      end
169
    end
170
  end
171

  
172
  def test_render_menu_node_with_children_without_an_array
173
    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
174
                                                     '/test',
175
                                                     {
176
                                                       :children => Proc.new {|p| Redmine::MenuManager::MenuItem.new("test_child", "/testing", {})}
177
                                                     })
178

  
179
    assert_raises Redmine::MenuManager::MenuError, ":children must be an array of MenuItems" do
180
      @output_buffer = render_menu_node(parent_node, Project.find(1))
181
    end
182
  end
183

  
184
  def test_render_menu_node_with_incorrect_children
185
    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
186
                                                     '/test',
187
                                                     {
188
                                                       :children => Proc.new {|p| ["a string"] }
189
                                                     })
190

  
191
    assert_raises Redmine::MenuManager::MenuError, ":children must be an array of MenuItems" do
192
      @output_buffer = render_menu_node(parent_node, Project.find(1))
193
    end
194

  
195
  end
196

  
197
  def test_menu_items_for_should_yield_all_items_if_passed_a_block
198
    menu_name = :test_menu_items_for_should_yield_all_items_if_passed_a_block
199
    Redmine::MenuManager.map menu_name do |menu|
200
      menu.push(:a_menu, '/', { })
201
      menu.push(:a_menu_2, '/', { })
202
      menu.push(:a_menu_3, '/', { })
203
    end
204

  
205
    items_yielded = []
206
    menu_items_for(menu_name) do |item|
207
      items_yielded << item
208
    end
209

  
210
    assert_equal 3, items_yielded.size
211
  end
212

  
213
  def test_menu_items_for_should_return_all_items
214
    menu_name = :test_menu_items_for_should_return_all_items
215
    Redmine::MenuManager.map menu_name do |menu|
216
      menu.push(:a_menu, '/', { })
217
      menu.push(:a_menu_2, '/', { })
218
      menu.push(:a_menu_3, '/', { })
219
    end
220

  
221
    items = menu_items_for(menu_name)
222
    assert_equal 3, items.size
223
  end
224

  
225
  def test_menu_items_for_should_skip_unallowed_items_on_a_project
226
    menu_name = :test_menu_items_for_should_skip_unallowed_items_on_a_project
227
    Redmine::MenuManager.map menu_name do |menu|
228
      menu.push(:a_menu, {:controller => 'issues', :action => 'index' }, { })
229
      menu.push(:a_menu_2, {:controller => 'issues', :action => 'index' }, { })
230
      menu.push(:unallowed, {:controller => 'issues', :action => 'unallowed' }, { })
231
    end
232

  
233
    User.current = User.find(2)
234

  
235
    items = menu_items_for(menu_name, Project.find(1))
236
    assert_equal 2, items.size
237
  end
238

  
239
  def test_menu_items_for_should_skip_items_that_fail_the_conditions
240
    menu_name = :test_menu_items_for_should_skip_items_that_fail_the_conditions
241
    Redmine::MenuManager.map menu_name do |menu|
242
      menu.push(:a_menu, {:controller => 'issues', :action => 'index' }, { })
243
      menu.push(:unallowed,
244
                {:controller => 'issues', :action => 'index' },
245
                { :if => Proc.new { false }})
246
    end
247

  
248
    User.current = User.find(2)
249

  
250
    items = menu_items_for(menu_name, Project.find(1))
251
    assert_equal 1, items.size
252
  end
253
end
.svn/pristine/3c/3cbd1a22df619e52f4440d56f4eefc4b5f35d719.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 TimeEntryTest < ActiveSupport::TestCase
21
  fixtures :issues, :projects, :users, :time_entries,
22
           :members, :roles, :member_roles,
23
           :trackers, :issue_statuses,
24
           :projects_trackers,
25
           :journals, :journal_details,
26
           :issue_categories, :enumerations,
27
           :groups_users,
28
           :enabled_modules,
29
           :workflows
30

  
31
  def test_hours_format
32
    assertions = { "2"      => 2.0,
33
                   "21.1"   => 21.1,
34
                   "2,1"    => 2.1,
35
                   "1,5h"   => 1.5,
36
                   "7:12"   => 7.2,
37
                   "10h"    => 10.0,
38
                   "10 h"   => 10.0,
39
                   "45m"    => 0.75,
40
                   "45 m"   => 0.75,
41
                   "3h15"   => 3.25,
42
                   "3h 15"  => 3.25,
43
                   "3 h 15"   => 3.25,
44
                   "3 h 15m"  => 3.25,
45
                   "3 h 15 m" => 3.25,
46
                   "3 hours"  => 3.0,
47
                   "12min"    => 0.2,
48
                   "12 Min"    => 0.2,
49
                  }
50

  
51
    assertions.each do |k, v|
52
      t = TimeEntry.new(:hours => k)
53
      assert_equal v, t.hours, "Converting #{k} failed:"
54
    end
55
  end
56

  
57
  def test_hours_should_default_to_nil
58
    assert_nil TimeEntry.new.hours
59
  end
60

  
61
  def test_spent_on_with_blank
62
    c = TimeEntry.new
63
    c.spent_on = ''
64
    assert_nil c.spent_on
65
  end
66

  
67
  def test_spent_on_with_nil
68
    c = TimeEntry.new
69
    c.spent_on = nil
70
    assert_nil c.spent_on
71
  end
72

  
73
  def test_spent_on_with_string
74
    c = TimeEntry.new
75
    c.spent_on = "2011-01-14"
76
    assert_equal Date.parse("2011-01-14"), c.spent_on
77
  end
78

  
79
  def test_spent_on_with_invalid_string
80
    c = TimeEntry.new
81
    c.spent_on = "foo"
82
    assert_nil c.spent_on
83
  end
84

  
85
  def test_spent_on_with_date
86
    c = TimeEntry.new
87
    c.spent_on = Date.today
88
    assert_equal Date.today, c.spent_on
89
  end
90

  
91
  def test_spent_on_with_time
92
    c = TimeEntry.new
93
    c.spent_on = Time.now
94
    assert_equal Date.today, c.spent_on
95
  end
96

  
97
  def test_validate_time_entry
98
    anon     = User.anonymous
99
    project  = Project.find(1)
100
    issue    = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
101
                         :priority => IssuePriority.all.first, :subject => 'test_create',
102
                         :description => 'IssueTest#test_create', :estimated_hours => '1:30')
103
    assert issue.save
104
    activity = TimeEntryActivity.find_by_name('Design')
105
    te = TimeEntry.create(:spent_on => '2010-01-01',
106
                          :hours    => 100000,
107
                          :issue    => issue,
108
                          :project  => project,
109
                          :user     => anon,
110
                          :activity => activity)
111
    assert_equal 1, te.errors.count
112
  end
113

  
114
  def test_set_project_if_nil
115
    anon     = User.anonymous
116
    project  = Project.find(1)
117
    issue    = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
118
                         :priority => IssuePriority.all.first, :subject => 'test_create',
119
                         :description => 'IssueTest#test_create', :estimated_hours => '1:30')
120
    assert issue.save
121
    activity = TimeEntryActivity.find_by_name('Design')
122
    te = TimeEntry.create(:spent_on => '2010-01-01',
123
                          :hours    => 10,
124
                          :issue    => issue,
125
                          :user     => anon,
126
                          :activity => activity)
127
    assert_equal project.id, te.project.id
128
  end
129
end

Also available in: Unified diff