dates_helper_test.rb
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require File.dirname(__FILE__) + '/../test_helper'
class DatesHelperTest < Test::Unit::TestCase
include DatesHelper
should 'generate period with two dates' do
date1 = mock
expects(:show_date).with(date1).returns('XXX')
date2 = mock
expects(:show_date).with(date2).returns('YYY')
expects(:_).with('from %s to %s').returns('from %s to %s')
assert_equal 'from XXX to YYY', show_period(date1, date2)
end
should 'generate period with two equal dates' do
date1 = mock
expects(:show_date).with(date1).returns('XXX')
assert_equal 'XXX', show_period(date1, date1)
end
should 'generate period with one date only' do
date1 = mock
expects(:show_date).with(date1).returns('XXX')
assert_equal 'XXX', show_period(date1)
end
should 'show day of week' do
expects(:_).with("Sunday").returns("Domingo")
date = mock
date.expects(:wday).returns(0)
assert_equal "Domingo", show_day_of_week(date)
end
should 'show month' do
expects(:_).with('January').returns('January')
expects(:_).with('%{month} %{year}').returns('%{month} %{year}')
assert_equal 'January 2008', show_month(2008, 1)
end
should 'provide link to previous month' do
expects(:link_to).with('← January 2008', { :year => 2008, :month => 1})
link_to_previous_month('2008', '2')
end
should 'support last year in link to previous month' do
expects(:link_to).with('← December 2007', { :year => 2007, :month => 12})
link_to_previous_month('2008', '1')
end
should 'provide link to next month' do
expects(:link_to).with('March 2008 →', { :year => 2008, :month => 3})
link_to_next_month('2008', '2')
end
should 'support next year in link to next month' do
expects(:link_to).with('January 2009 →', { :year => 2009, :month => 1})
link_to_next_month('2008', '12')
end
should 'get current date when year and month are not informed for next month' do
Date.expects(:today).returns(Date.new(2008,1,1))
expects(:link_to).with('February 2008 →', { :year => 2008, :month => 2})
link_to_next_month(nil, nil)
end
should 'get current date when year and month are not informed for previous month' do
Date.expects(:today).returns(Date.new(2008,1,1))
expects(:link_to).with('← December 2007', { :year => 2007, :month => 12})
link_to_previous_month(nil, nil)
end
end