summaryrefslogtreecommitdiffstats
path: root/test/functional/activities_controller_test.rb
blob: 13f44a108f36c67aebc7f1a706d124a184555cdc (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require File.expand_path('../../test_helper', __FILE__)

class ActivitiesControllerTest < ActionController::TestCase
  fixtures :projects, :trackers, :issue_statuses, :issues,
           :enumerations, :users, :issue_categories,
           :projects_trackers,
           :roles,
           :member_roles,
           :members,
           :groups_users,
           :enabled_modules,
           :workflows,
           :journals, :journal_details


  def test_project_index
    get :index, :id => 1, :with_subprojects => 0
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:events_by_day)

    assert_tag :tag => "h3",
               :content => /#{2.days.ago.to_date.day}/,
               :sibling => { :tag => "dl",
                 :child => { :tag => "dt",
                   :attributes => { :class => /issue-edit/ },
                   :child => { :tag => "a",
                     :content => /(#{IssueStatus.find(2).name})/,
                   }
                 }
               }
  end

  def test_project_index_with_invalid_project_id_should_respond_404
    get :index, :id => 299
    assert_response 404
  end

  def test_previous_project_index
    get :index, :id => 1, :from => 3.days.ago.to_date
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:events_by_day)

    assert_tag :tag => "h3",
               :content => /#{3.day.ago.to_date.day}/,
               :sibling => { :tag => "dl",
                 :child => { :tag => "dt",
                   :attributes => { :class => /issue/ },
                   :child => { :tag => "a",
                     :content => /Can&#x27;t print recipes/,
                   }
                 }
               }
  end

  def test_global_index
    @request.session[:user_id] = 1
    get :index
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:events_by_day)

    i5 = Issue.find(5)
    d5 = User.find(1).time_to_date(i5.created_on)
    assert_tag :tag => "h3",
               :content => /#{d5.day}/,
               :sibling => { :tag => "dl",
                 :child => { :tag => "dt",
                   :attributes => { :class => /issue/ },
                   :child => { :tag => "a",
                     :content => /Subproject issue/,
                   }
                 }
               }
  end

  def test_user_index
    @request.session[:user_id] = 1
    get :index, :user_id => 2
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:events_by_day)

    assert_select 'h2 a[href=/users/2]', :text => 'John Smith'

    i1 = Issue.find(1)
    d1 = User.find(1).time_to_date(i1.created_on)

    assert_tag :tag => "h3",
               :content => /#{d1.day}/,
               :sibling => { :tag => "dl",
                 :child => { :tag => "dt",
                   :attributes => { :class => /issue/ },
                   :child => { :tag => "a",
                     :content => /Can&#x27;t print recipes/,
                   }
                 }
               }
  end

  def test_user_index_with_invalid_user_id_should_respond_404
    get :index, :user_id => 299
    assert_response 404
  end

  def test_index_atom_feed
    get :index, :format => 'atom', :with_subprojects => 0
    assert_response :success
    assert_template 'common/feed'

    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
        :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
        :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}

    assert_tag :tag => 'entry', :child => {
      :tag => 'link',
      :attributes => {:href => 'http://test.host/issues/11'}}
  end

  def test_index_atom_feed_with_explicit_selection
    get :index, :format => 'atom', :with_subprojects => 0,
      :show_changesets => 1,
      :show_documents => 1,
      :show_files => 1,
      :show_issues => 1,
      :show_messages => 1,
      :show_news => 1,
      :show_time_entries => 1,
      :show_wiki_edits => 1

    assert_response :success
    assert_template 'common/feed'

    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
        :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
    assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
        :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}

    assert_tag :tag => 'entry', :child => {
      :tag => 'link',
      :attributes => {:href => 'http://test.host/issues/11'}}
  end

  def test_index_atom_feed_with_one_item_type
    get :index, :format => 'atom', :show_issues => '1'
    assert_response :success
    assert_template 'common/feed'
    assert_tag :tag => 'title', :content => /Issues/
  end
end