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