@@ -1,39 +1,41 | |||
|
1 | 1 | class CalendarsController < ApplicationController |
|
2 | 2 | menu_item :calendar |
|
3 | 3 | before_filter :find_optional_project |
|
4 | 4 | |
|
5 | 5 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
6 | 6 | |
|
7 | 7 | helper :issues |
|
8 | 8 | helper :projects |
|
9 | 9 | helper :queries |
|
10 | 10 | include QueriesHelper |
|
11 | helper :sort | |
|
12 | include SortHelper | |
|
11 | 13 | |
|
12 | 14 | def show |
|
13 | 15 | if params[:year] and params[:year].to_i > 1900 |
|
14 | 16 | @year = params[:year].to_i |
|
15 | 17 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
16 | 18 | @month = params[:month].to_i |
|
17 | 19 | end |
|
18 | 20 | end |
|
19 | 21 | @year ||= Date.today.year |
|
20 | 22 | @month ||= Date.today.month |
|
21 | 23 | |
|
22 | 24 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
23 | 25 | retrieve_query |
|
24 | 26 | @query.group_by = nil |
|
25 | 27 | if @query.valid? |
|
26 | 28 | events = [] |
|
27 | 29 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
28 | 30 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
29 | 31 | ) |
|
30 | 32 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
31 | 33 | |
|
32 | 34 | @calendar.events = events |
|
33 | 35 | end |
|
34 | 36 | |
|
35 | 37 | render :layout => false if request.xhr? |
|
36 | 38 | end |
|
37 | 39 | |
|
38 | 40 | |
|
39 | 41 | end |
@@ -1,64 +1,74 | |||
|
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
|
2 | 2 | |
|
3 | 3 | class CalendarsControllerTest < ActionController::TestCase |
|
4 | 4 | fixtures :all |
|
5 | 5 | |
|
6 | 6 | def test_calendar |
|
7 | 7 | get :show, :project_id => 1 |
|
8 | 8 | assert_response :success |
|
9 | 9 | assert_template 'calendar' |
|
10 | 10 | assert_not_nil assigns(:calendar) |
|
11 | 11 | end |
|
12 | 12 | |
|
13 | 13 | def test_cross_project_calendar |
|
14 | 14 | get :show |
|
15 | 15 | assert_response :success |
|
16 | 16 | assert_template 'calendar' |
|
17 | 17 | assert_not_nil assigns(:calendar) |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | context "GET :show" do | |
|
21 | should "run custom queries" do | |
|
22 | @query = Query.generate_default! | |
|
23 | ||
|
24 | get :show, :query_id => @query.id | |
|
25 | assert_response :success | |
|
26 | end | |
|
27 | ||
|
28 | end | |
|
29 | ||
|
20 | 30 | def test_week_number_calculation |
|
21 | 31 | Setting.start_of_week = 7 |
|
22 | 32 | |
|
23 | 33 | get :show, :month => '1', :year => '2010' |
|
24 | 34 | assert_response :success |
|
25 | 35 | |
|
26 | 36 | assert_tag :tag => 'tr', |
|
27 | 37 | :descendant => {:tag => 'td', |
|
28 | 38 | :attributes => {:class => 'week-number'}, :content => '53'}, |
|
29 | 39 | :descendant => {:tag => 'td', |
|
30 | 40 | :attributes => {:class => 'odd'}, :content => '27'}, |
|
31 | 41 | :descendant => {:tag => 'td', |
|
32 | 42 | :attributes => {:class => 'even'}, :content => '2'} |
|
33 | 43 | |
|
34 | 44 | assert_tag :tag => 'tr', |
|
35 | 45 | :descendant => {:tag => 'td', |
|
36 | 46 | :attributes => {:class => 'week-number'}, :content => '1'}, |
|
37 | 47 | :descendant => {:tag => 'td', |
|
38 | 48 | :attributes => {:class => 'odd'}, :content => '3'}, |
|
39 | 49 | :descendant => {:tag => 'td', |
|
40 | 50 | :attributes => {:class => 'even'}, :content => '9'} |
|
41 | 51 | |
|
42 | 52 | |
|
43 | 53 | Setting.start_of_week = 1 |
|
44 | 54 | get :show, :month => '1', :year => '2010' |
|
45 | 55 | assert_response :success |
|
46 | 56 | |
|
47 | 57 | assert_tag :tag => 'tr', |
|
48 | 58 | :descendant => {:tag => 'td', |
|
49 | 59 | :attributes => {:class => 'week-number'}, :content => '53'}, |
|
50 | 60 | :descendant => {:tag => 'td', |
|
51 | 61 | :attributes => {:class => 'even'}, :content => '28'}, |
|
52 | 62 | :descendant => {:tag => 'td', |
|
53 | 63 | :attributes => {:class => 'even'}, :content => '3'} |
|
54 | 64 | |
|
55 | 65 | assert_tag :tag => 'tr', |
|
56 | 66 | :descendant => {:tag => 'td', |
|
57 | 67 | :attributes => {:class => 'week-number'}, :content => '1'}, |
|
58 | 68 | :descendant => {:tag => 'td', |
|
59 | 69 | :attributes => {:class => 'even'}, :content => '4'}, |
|
60 | 70 | :descendant => {:tag => 'td', |
|
61 | 71 | :attributes => {:class => 'even'}, :content => '10'} |
|
62 | 72 | |
|
63 | 73 | end |
|
64 | 74 | end |
General Comments 0
You need to be logged in to leave comments.
Login now