To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 41 / 4171661e14f170beefe360373ffc236afc3efe66.svn-base @ 1298:4f746d8966dd

History | View | Annotate | Download (2.81 KB)

1 1295:622f24f53b42 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2013  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 ActivitiesHelperTest < ActionView::TestCase
21
  include ActivitiesHelper
22
23
  class MockEvent
24
    attr_reader :event_datetime, :event_group, :name
25
26
    def initialize(group=nil)
27
      @@count ||= 0
28
      @name = "e#{@@count}"
29
      @event_datetime = Time.now + @@count.hours
30
      @event_group = group || self
31
      @@count += 1
32
    end
33
34
    def self.clear
35
      @@count = 0
36
    end
37
  end
38
39
  def setup
40
    MockEvent.clear
41
  end
42
43
  def test_sort_activity_events_should_sort_by_datetime
44
    events = []
45
    events << MockEvent.new
46
    events << MockEvent.new
47
    events << MockEvent.new
48
49
    assert_equal [
50
        ['e2', false],
51
        ['e1', false],
52
        ['e0', false]
53
      ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
54
  end
55
56
  def test_sort_activity_events_should_group_events
57
    events = []
58
    events << MockEvent.new
59
    events << MockEvent.new(events[0])
60
    events << MockEvent.new(events[0])
61
62
    assert_equal [
63
        ['e2', false],
64
        ['e1', true],
65
        ['e0', true]
66
      ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
67
  end
68
69
  def test_sort_activity_events_with_group_not_in_set_should_group_events
70
    e = MockEvent.new
71
    events = []
72
    events << MockEvent.new(e)
73
    events << MockEvent.new(e)
74
75
    assert_equal [
76
        ['e2', false],
77
        ['e1', true]
78
      ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
79
  end
80
81
  def test_sort_activity_events_should_sort_by_datetime_and_group
82
    events = []
83
    events << MockEvent.new
84
    events << MockEvent.new
85
    events << MockEvent.new
86
    events << MockEvent.new(events[1])
87
    events << MockEvent.new(events[2])
88
    events << MockEvent.new
89
    events << MockEvent.new(events[2])
90
91
    assert_equal [
92
        ['e6', false],
93
        ['e4', true],
94
        ['e2', true],
95
        ['e5', false],
96
        ['e3', false],
97
        ['e1', true],
98
        ['e0', false]
99
      ], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
100
  end
101
end