Chris@1295: # Redmine - project management software Chris@1295: # Copyright (C) 2006-2013 Jean-Philippe Lang Chris@1295: # Chris@1295: # This program is free software; you can redistribute it and/or Chris@1295: # modify it under the terms of the GNU General Public License Chris@1295: # as published by the Free Software Foundation; either version 2 Chris@1295: # of the License, or (at your option) any later version. Chris@1295: # Chris@1295: # This program is distributed in the hope that it will be useful, Chris@1295: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1295: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1295: # GNU General Public License for more details. Chris@1295: # Chris@1295: # You should have received a copy of the GNU General Public License Chris@1295: # along with this program; if not, write to the Free Software Chris@1295: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1295: Chris@1295: require File.expand_path('../../test_helper', __FILE__) Chris@1295: Chris@1295: class ActivitiesControllerTest < ActionController::TestCase Chris@1295: fixtures :projects, :trackers, :issue_statuses, :issues, Chris@1295: :enumerations, :users, :issue_categories, Chris@1295: :projects_trackers, Chris@1295: :roles, Chris@1295: :member_roles, Chris@1295: :members, Chris@1295: :groups_users, Chris@1295: :enabled_modules, Chris@1295: :journals, :journal_details Chris@1295: Chris@1295: Chris@1295: def test_project_index Chris@1295: get :index, :id => 1, :with_subprojects => 0 Chris@1295: assert_response :success Chris@1295: assert_template 'index' Chris@1295: assert_not_nil assigns(:events_by_day) Chris@1295: Chris@1295: assert_select 'h3', :text => /#{2.days.ago.to_date.day}/ Chris@1295: assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/ Chris@1295: end Chris@1295: Chris@1295: def test_project_index_with_invalid_project_id_should_respond_404 Chris@1295: get :index, :id => 299 Chris@1295: assert_response 404 Chris@1295: end Chris@1295: Chris@1295: def test_previous_project_index Chris@1295: get :index, :id => 1, :from => 2.days.ago.to_date Chris@1295: assert_response :success Chris@1295: assert_template 'index' Chris@1295: assert_not_nil assigns(:events_by_day) Chris@1295: Chris@1295: assert_select 'h3', :text => /#{3.days.ago.to_date.day}/ Chris@1295: assert_select 'dl dt.issue a', :text => /Can't print recipes/ Chris@1295: end Chris@1295: Chris@1295: def test_global_index Chris@1295: @request.session[:user_id] = 1 Chris@1295: get :index Chris@1295: assert_response :success Chris@1295: assert_template 'index' Chris@1295: assert_not_nil assigns(:events_by_day) Chris@1295: Chris@1295: i5 = Issue.find(5) Chris@1295: d5 = User.find(1).time_to_date(i5.created_on) Chris@1295: Chris@1295: assert_select 'h3', :text => /#{d5.day}/ Chris@1295: assert_select 'dl dt.issue a', :text => /Subproject issue/ Chris@1295: end Chris@1295: Chris@1295: def test_user_index Chris@1295: @request.session[:user_id] = 1 Chris@1295: get :index, :user_id => 2 Chris@1295: assert_response :success Chris@1295: assert_template 'index' Chris@1295: assert_not_nil assigns(:events_by_day) Chris@1295: Chris@1295: assert_select 'h2 a[href=/users/2]', :text => 'John Smith' Chris@1295: Chris@1295: i1 = Issue.find(1) Chris@1295: d1 = User.find(1).time_to_date(i1.created_on) Chris@1295: Chris@1295: assert_select 'h3', :text => /#{d1.day}/ Chris@1295: assert_select 'dl dt.issue a', :text => /Can't print recipes/ Chris@1295: end Chris@1295: Chris@1295: def test_user_index_with_invalid_user_id_should_respond_404 Chris@1295: get :index, :user_id => 299 Chris@1295: assert_response 404 Chris@1295: end Chris@1295: Chris@1295: def test_index_atom_feed Chris@1295: get :index, :format => 'atom', :with_subprojects => 0 Chris@1295: assert_response :success Chris@1295: assert_template 'common/feed' Chris@1295: Chris@1295: assert_select 'feed' do Chris@1295: assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0' Chris@1295: assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0' Chris@1295: assert_select 'entry' do Chris@1295: assert_select 'link[href=?]', 'http://test.host/issues/11' Chris@1295: end Chris@1295: end Chris@1295: end Chris@1295: Chris@1295: def test_index_atom_feed_with_explicit_selection Chris@1295: get :index, :format => 'atom', :with_subprojects => 0, Chris@1295: :show_changesets => 1, Chris@1295: :show_documents => 1, Chris@1295: :show_files => 1, Chris@1295: :show_issues => 1, Chris@1295: :show_messages => 1, Chris@1295: :show_news => 1, Chris@1295: :show_time_entries => 1, Chris@1295: :show_wiki_edits => 1 Chris@1295: Chris@1295: assert_response :success Chris@1295: assert_template 'common/feed' Chris@1295: Chris@1295: assert_select 'feed' do Chris@1295: assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?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&with_subprojects=0' Chris@1295: assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?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&with_subprojects=0' Chris@1295: assert_select 'entry' do Chris@1295: assert_select 'link[href=?]', 'http://test.host/issues/11' Chris@1295: end Chris@1295: end Chris@1295: end Chris@1295: Chris@1295: def test_index_atom_feed_with_one_item_type Chris@1295: get :index, :format => 'atom', :show_issues => '1' Chris@1295: assert_response :success Chris@1295: assert_template 'common/feed' Chris@1295: Chris@1295: assert_select 'title', :text => /Issues/ Chris@1295: end Chris@1295: Chris@1295: def test_index_should_show_private_notes_with_permission_only Chris@1295: journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true) Chris@1295: @request.session[:user_id] = 2 Chris@1295: Chris@1295: get :index Chris@1295: assert_response :success Chris@1295: assert_include journal, assigns(:events_by_day).values.flatten Chris@1295: Chris@1295: Role.find(1).remove_permission! :view_private_notes Chris@1295: get :index Chris@1295: assert_response :success Chris@1295: assert_not_include journal, assigns(:events_by_day).values.flatten Chris@1295: end Chris@1295: end