Redmine 3.4.4
This commit is contained in:
commit
64924a6376
2112 changed files with 259028 additions and 0 deletions
102
test/unit/helpers/activities_helper_test.rb
Normal file
102
test/unit/helpers/activities_helper_test.rb
Normal file
|
@ -0,0 +1,102 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class ActivitiesHelperTest < Redmine::HelperTest
|
||||
include ActivitiesHelper
|
||||
|
||||
class MockEvent
|
||||
attr_reader :event_datetime, :event_group, :name
|
||||
|
||||
def initialize(group=nil)
|
||||
@@count ||= 0
|
||||
@name = "e#{@@count}"
|
||||
@event_datetime = Time.now + @@count.hours
|
||||
@event_group = group || self
|
||||
@@count += 1
|
||||
end
|
||||
|
||||
def self.clear
|
||||
@@count = 0
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
super
|
||||
MockEvent.clear
|
||||
end
|
||||
|
||||
def test_sort_activity_events_should_sort_by_datetime
|
||||
events = []
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new
|
||||
|
||||
assert_equal [
|
||||
['e2', false],
|
||||
['e1', false],
|
||||
['e0', false]
|
||||
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
|
||||
end
|
||||
|
||||
def test_sort_activity_events_should_group_events
|
||||
events = []
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new(events[0])
|
||||
events << MockEvent.new(events[0])
|
||||
|
||||
assert_equal [
|
||||
['e2', false],
|
||||
['e1', true],
|
||||
['e0', true]
|
||||
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
|
||||
end
|
||||
|
||||
def test_sort_activity_events_with_group_not_in_set_should_group_events
|
||||
e = MockEvent.new
|
||||
events = []
|
||||
events << MockEvent.new(e)
|
||||
events << MockEvent.new(e)
|
||||
|
||||
assert_equal [
|
||||
['e2', false],
|
||||
['e1', true]
|
||||
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
|
||||
end
|
||||
|
||||
def test_sort_activity_events_should_sort_by_datetime_and_group
|
||||
events = []
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new(events[1])
|
||||
events << MockEvent.new(events[2])
|
||||
events << MockEvent.new
|
||||
events << MockEvent.new(events[2])
|
||||
|
||||
assert_equal [
|
||||
['e6', false],
|
||||
['e4', true],
|
||||
['e2', true],
|
||||
['e5', false],
|
||||
['e3', false],
|
||||
['e1', true],
|
||||
['e0', false]
|
||||
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
|
||||
end
|
||||
end
|
1611
test/unit/helpers/application_helper_test.rb
Normal file
1611
test/unit/helpers/application_helper_test.rb
Normal file
File diff suppressed because it is too large
Load diff
89
test/unit/helpers/custom_fields_helper_test.rb
Normal file
89
test/unit/helpers/custom_fields_helper_test.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class CustomFieldsHelperTest < Redmine::HelperTest
|
||||
include ApplicationHelper
|
||||
include CustomFieldsHelper
|
||||
include ERB::Util
|
||||
|
||||
def test_format_boolean_value
|
||||
I18n.locale = 'en'
|
||||
assert_equal 'Yes', format_value('1', CustomField.new(:field_format => 'bool'))
|
||||
assert_equal 'No', format_value('0', CustomField.new(:field_format => 'bool'))
|
||||
end
|
||||
|
||||
def test_label_tag_should_include_description_as_span_title_if_present
|
||||
field = CustomField.new(:field_format => 'string', :description => 'This is the description')
|
||||
tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in tag, 'label span[title=?]', 'This is the description'
|
||||
end
|
||||
|
||||
def test_label_tag_should_not_include_title_if_description_is_blank
|
||||
field = CustomField.new(:field_format => 'string')
|
||||
tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in tag, 'label span[title]', 0
|
||||
end
|
||||
|
||||
def test_label_tag_should_include_for_attribute_for_select_tag
|
||||
field = CustomField.new(:name => 'Foo', :field_format => 'list')
|
||||
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in s, 'label[for]'
|
||||
end
|
||||
|
||||
def test_label_tag_should_not_include_for_attribute_for_checkboxes
|
||||
field = CustomField.new(:name => 'Foo', :field_format => 'list', :edit_tag_style => 'check_box')
|
||||
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in s, 'label:not([for])'
|
||||
end
|
||||
|
||||
def test_label_tag_should_include_for_attribute_for_bool_as_select_tag
|
||||
field = CustomField.new(:name => 'Foo', :field_format => 'bool')
|
||||
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in s, 'label[for]'
|
||||
end
|
||||
|
||||
def test_label_tag_should_include_for_attribute_for_bool_as_checkbox
|
||||
field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'check_box')
|
||||
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in s, 'label[for]'
|
||||
end
|
||||
|
||||
def test_label_tag_should_not_include_for_attribute_for_bool_as_radio
|
||||
field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'radio')
|
||||
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
|
||||
assert_select_in s, 'label:not([for])'
|
||||
end
|
||||
|
||||
def test_unknow_field_format_should_be_edited_as_string
|
||||
field = CustomField.new(:field_format => 'foo')
|
||||
value = CustomValue.new(:value => 'bar', :custom_field => field)
|
||||
field.id = 52
|
||||
|
||||
assert_select_in custom_field_tag('object', value),
|
||||
'input[type=text][value=bar][name=?]', 'object[custom_field_values][52]'
|
||||
end
|
||||
|
||||
def test_unknow_field_format_should_be_bulk_edited_as_string
|
||||
field = CustomField.new(:field_format => 'foo')
|
||||
field.id = 52
|
||||
|
||||
assert_select_in custom_field_tag_for_bulk_edit('object', field),
|
||||
'input[type=text][value=""][name=?]', 'object[custom_field_values][52]'
|
||||
end
|
||||
end
|
42
test/unit/helpers/groups_helper_test.rb
Normal file
42
test/unit/helpers/groups_helper_test.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class GroupsHelperTest < Redmine::HelperTest
|
||||
include ERB::Util
|
||||
include GroupsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :users
|
||||
|
||||
def test_render_principals_for_new_group_users
|
||||
group = Group.generate!
|
||||
|
||||
result = render_principals_for_new_group_users(group)
|
||||
assert_select_in result, 'input[name=?][value="2"]', 'user_ids[]'
|
||||
end
|
||||
|
||||
def test_render_principals_for_new_group_users_with_limited_results_should_paginate
|
||||
group = Group.generate!
|
||||
|
||||
result = render_principals_for_new_group_users(group, 3)
|
||||
assert_select_in result, 'span.pagination'
|
||||
assert_select_in result, 'span.pagination li.current span', :text => '1'
|
||||
assert_select_in result, 'a[href=?]', "/groups/#{group.id}/autocomplete_for_user.js?page=2", :text => '2'
|
||||
end
|
||||
end
|
332
test/unit/helpers/issues_helper_test.rb
Normal file
332
test/unit/helpers/issues_helper_test.rb
Normal file
|
@ -0,0 +1,332 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class IssuesHelperTest < Redmine::HelperTest
|
||||
include IssuesHelper
|
||||
include CustomFieldsHelper
|
||||
include ERB::Util
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :projects, :trackers, :issue_statuses, :issues,
|
||||
:enumerations, :users, :issue_categories,
|
||||
:projects_trackers,
|
||||
:roles,
|
||||
:member_roles,
|
||||
:members,
|
||||
:enabled_modules,
|
||||
:custom_fields,
|
||||
:attachments,
|
||||
:versions
|
||||
|
||||
def test_issue_heading
|
||||
assert_equal "Bug #1", issue_heading(Issue.find(1))
|
||||
end
|
||||
|
||||
def test_issues_destroy_confirmation_message_with_one_root_issue
|
||||
assert_equal l(:text_issues_destroy_confirmation),
|
||||
issues_destroy_confirmation_message(Issue.find(1))
|
||||
end
|
||||
|
||||
def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
|
||||
assert_equal l(:text_issues_destroy_confirmation),
|
||||
issues_destroy_confirmation_message(Issue.find([1, 2]))
|
||||
end
|
||||
|
||||
def test_issues_destroy_confirmation_message_with_one_parent_issue
|
||||
Issue.find(2).update! :parent_issue_id => 1
|
||||
assert_equal l(:text_issues_destroy_confirmation) + "\n" +
|
||||
l(:text_issues_destroy_descendants_confirmation, :count => 1),
|
||||
issues_destroy_confirmation_message(Issue.find(1))
|
||||
end
|
||||
|
||||
def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
|
||||
Issue.find(2).update! :parent_issue_id => 1
|
||||
assert_equal l(:text_issues_destroy_confirmation),
|
||||
issues_destroy_confirmation_message(Issue.find([1, 2]))
|
||||
end
|
||||
|
||||
def test_issues_destroy_confirmation_message_with_issues_that_share_descendants
|
||||
root = Issue.generate!
|
||||
child = Issue.generate!(:parent_issue_id => root.id)
|
||||
Issue.generate!(:parent_issue_id => child.id)
|
||||
|
||||
assert_equal l(:text_issues_destroy_confirmation) + "\n" +
|
||||
l(:text_issues_destroy_descendants_confirmation, :count => 1),
|
||||
issues_destroy_confirmation_message([root.reload, child.reload])
|
||||
end
|
||||
|
||||
test 'show_detail with no_html should show a changing attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
|
||||
:value => '100', :prop_key => 'done_ratio')
|
||||
assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail with no_html should show a new attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
|
||||
:value => '100', :prop_key => 'done_ratio')
|
||||
assert_equal "% Done set to 100", show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail with no_html should show a deleted attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
|
||||
:value => nil, :prop_key => 'done_ratio')
|
||||
assert_equal "% Done deleted (50)", show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail with html should show a changing attribute with HTML highlights' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
|
||||
:value => '100', :prop_key => 'done_ratio')
|
||||
html = show_detail(detail, false)
|
||||
assert_include '<strong>% Done</strong>', html
|
||||
assert_include '<i>40</i>', html
|
||||
assert_include '<i>100</i>', html
|
||||
end
|
||||
|
||||
test 'show_detail with html should show a new attribute with HTML highlights' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
|
||||
:value => '100', :prop_key => 'done_ratio')
|
||||
html = show_detail(detail, false)
|
||||
assert_include '<strong>% Done</strong>', html
|
||||
assert_include '<i>100</i>', html
|
||||
end
|
||||
|
||||
test 'show_detail with html should show a deleted attribute with HTML highlights' do
|
||||
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
|
||||
:value => nil, :prop_key => 'done_ratio')
|
||||
html = show_detail(detail, false)
|
||||
assert_include '<strong>% Done</strong>', html
|
||||
assert_include '<del><i>50</i></del>', html
|
||||
end
|
||||
|
||||
test 'show_detail with a start_date attribute should format the dates' do
|
||||
detail = JournalDetail.new(
|
||||
:property => 'attr',
|
||||
:old_value => '2010-01-01',
|
||||
:value => '2010-01-31',
|
||||
:prop_key => 'start_date'
|
||||
)
|
||||
with_settings :date_format => '%m/%d/%Y' do
|
||||
assert_match "01/31/2010", show_detail(detail, true)
|
||||
assert_match "01/01/2010", show_detail(detail, true)
|
||||
end
|
||||
end
|
||||
|
||||
test 'show_detail with a due_date attribute should format the dates' do
|
||||
detail = JournalDetail.new(
|
||||
:property => 'attr',
|
||||
:old_value => '2010-01-01',
|
||||
:value => '2010-01-31',
|
||||
:prop_key => 'due_date'
|
||||
)
|
||||
with_settings :date_format => '%m/%d/%Y' do
|
||||
assert_match "01/31/2010", show_detail(detail, true)
|
||||
assert_match "01/01/2010", show_detail(detail, true)
|
||||
end
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a project attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match 'eCookbook', show_detail(detail, true)
|
||||
assert_match 'OnlineStore', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a issue status attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match 'New', show_detail(detail, true)
|
||||
assert_match 'Assigned', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a tracker attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match 'Bug', show_detail(detail, true)
|
||||
assert_match 'Feature request', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a assigned to attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match 'Redmine Admin', show_detail(detail, true)
|
||||
assert_match 'John Smith', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a priority attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
|
||||
:old_value => 4, :value => 5)
|
||||
assert_match 'Low', show_detail(detail, true)
|
||||
assert_match 'Normal', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a category attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match 'Printing', show_detail(detail, true)
|
||||
assert_match 'Recipes', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a fixed version attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
|
||||
:old_value => 1, :value => 2)
|
||||
assert_match '0.1', show_detail(detail, true)
|
||||
assert_match '1.0', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a estimated hours attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
|
||||
:old_value => '5', :value => '6.3')
|
||||
assert_match '5.00', show_detail(detail, true)
|
||||
assert_match '6.30', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should not show values with a description attribute' do
|
||||
detail = JournalDetail.new(:property => 'attr', :prop_key => 'description',
|
||||
:old_value => 'Foo', :value => 'Bar')
|
||||
assert_equal 'Description updated', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show old and new values with a custom field' do
|
||||
detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
|
||||
:old_value => 'MySQL', :value => 'PostgreSQL')
|
||||
assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should not show values with a long text custom field' do
|
||||
field = IssueCustomField.create!(:name => "Long field", :field_format => 'text')
|
||||
detail = JournalDetail.new(:property => 'cf', :prop_key => field.id,
|
||||
:old_value => 'Foo', :value => 'Bar')
|
||||
assert_equal 'Long field updated', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show added file' do
|
||||
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
|
||||
:old_value => nil, :value => 'error281.txt')
|
||||
assert_match 'error281.txt', show_detail(detail, true)
|
||||
end
|
||||
|
||||
test 'show_detail should show removed file' do
|
||||
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
|
||||
:old_value => 'error281.txt', :value => nil)
|
||||
assert_match 'error281.txt', show_detail(detail, true)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_added
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:value => 1)
|
||||
assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true)
|
||||
str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes)
|
||||
assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added",
|
||||
show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_added_with_inexistant_issue
|
||||
inexistant_issue_number = 9999
|
||||
assert_nil Issue.find_by_id(inexistant_issue_number)
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:value => inexistant_issue_number)
|
||||
assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
|
||||
assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
|
||||
issue = Issue.generate!(:is_private => true)
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:value => issue.id)
|
||||
|
||||
assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
|
||||
assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_deleted
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:old_value => 1)
|
||||
assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true)
|
||||
str = link_to("Bug #1",
|
||||
"/issues/1",
|
||||
:class => Issue.find(1).css_classes)
|
||||
assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)",
|
||||
show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_deleted_with_inexistant_issue
|
||||
inexistant_issue_number = 9999
|
||||
assert_nil Issue.find_by_id(inexistant_issue_number)
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:old_value => inexistant_issue_number)
|
||||
assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
|
||||
assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
|
||||
issue = Issue.generate!(:is_private => true)
|
||||
detail = JournalDetail.new(:property => 'relation',
|
||||
:prop_key => 'precedes',
|
||||
:old_value => issue.id)
|
||||
|
||||
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
|
||||
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
|
||||
end
|
||||
|
||||
def test_details_to_strings_with_multiple_values_removed_from_custom_field
|
||||
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
|
||||
details = []
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '1', :value => nil)
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil)
|
||||
|
||||
assert_equal ["User deleted (Dave Lopper, Redmine Admin)"], details_to_strings(details, true)
|
||||
assert_equal ["<strong>User</strong> deleted (<del><i>Dave Lopper, Redmine Admin</i></del>)"], details_to_strings(details, false)
|
||||
end
|
||||
|
||||
def test_details_to_strings_with_multiple_values_added_to_custom_field
|
||||
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
|
||||
details = []
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1')
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '3')
|
||||
|
||||
assert_equal ["User Dave Lopper, Redmine Admin added"], details_to_strings(details, true)
|
||||
assert_equal ["<strong>User</strong> <i>Dave Lopper, Redmine Admin</i> added"], details_to_strings(details, false)
|
||||
end
|
||||
|
||||
def test_details_to_strings_with_multiple_values_added_and_removed_from_custom_field
|
||||
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
|
||||
details = []
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1')
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '2', :value => nil)
|
||||
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil)
|
||||
|
||||
assert_equal [
|
||||
"User Redmine Admin added",
|
||||
"User deleted (Dave Lopper, John Smith)"
|
||||
], details_to_strings(details, true)
|
||||
assert_equal [
|
||||
"<strong>User</strong> <i>Redmine Admin</i> added",
|
||||
"<strong>User</strong> deleted (<del><i>Dave Lopper, John Smith</i></del>)"
|
||||
], details_to_strings(details, false)
|
||||
end
|
||||
|
||||
def test_find_name_by_reflection_should_return_nil_for_missing_record
|
||||
assert_nil find_name_by_reflection('status', 99)
|
||||
end
|
||||
end
|
48
test/unit/helpers/journals_helper_test.rb
Normal file
48
test/unit/helpers/journals_helper_test.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class JournalsHelperTest < Redmine::HelperTest
|
||||
include JournalsHelper
|
||||
|
||||
fixtures :projects, :trackers, :issue_statuses, :issues,
|
||||
:enumerations, :issue_categories,
|
||||
:projects_trackers,
|
||||
:users, :roles, :member_roles, :members,
|
||||
:enabled_modules,
|
||||
:custom_fields,
|
||||
:attachments,
|
||||
:versions
|
||||
|
||||
def test_journal_thumbnail_attachments_should_return_thumbnailable_attachments
|
||||
issue = Issue.generate!
|
||||
|
||||
journal = new_record(Journal) do
|
||||
issue.init_journal(User.find(1))
|
||||
issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'image.png'), :author => User.find(1))
|
||||
issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'foo'), :author => User.find(1))
|
||||
issue.save
|
||||
end
|
||||
assert_equal 2, journal.details.count
|
||||
|
||||
thumbnails = journal_thumbnail_attachments(journal)
|
||||
assert_equal 1, thumbnails.count
|
||||
assert_kind_of Attachment, thumbnails.first
|
||||
assert_equal 'image.png', thumbnails.first.filename
|
||||
end
|
||||
end
|
43
test/unit/helpers/members_helper_test.rb
Normal file
43
test/unit/helpers/members_helper_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class MembersHelperTest < Redmine::HelperTest
|
||||
include ERB::Util
|
||||
include MembersHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :projects, :users, :members, :member_roles,
|
||||
:trackers, :issue_statuses
|
||||
|
||||
def test_render_principals_for_new_members
|
||||
project = Project.generate!
|
||||
|
||||
result = render_principals_for_new_members(project)
|
||||
assert_select_in result, 'input[name=?][value="2"]', 'membership[user_ids][]'
|
||||
end
|
||||
|
||||
def test_render_principals_for_new_members_with_limited_results_should_paginate
|
||||
project = Project.generate!
|
||||
|
||||
result = render_principals_for_new_members(project, 3)
|
||||
assert_select_in result, 'span.pagination'
|
||||
assert_select_in result, 'span.pagination li.current span', :text => '1'
|
||||
assert_select_in result, 'a[href=?]', "/projects/#{project.identifier}/memberships/autocomplete.js?page=2", :text => '2'
|
||||
end
|
||||
end
|
78
test/unit/helpers/projects_helper_test.rb
Normal file
78
test/unit/helpers/projects_helper_test.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class ProjectsHelperTest < Redmine::HelperTest
|
||||
include ApplicationHelper
|
||||
include ProjectsHelper
|
||||
include ERB::Util
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :projects, :trackers, :issue_statuses, :issues,
|
||||
:enumerations, :users, :issue_categories,
|
||||
:versions,
|
||||
:projects_trackers,
|
||||
:member_roles,
|
||||
:members,
|
||||
:groups_users,
|
||||
:enabled_modules
|
||||
|
||||
def test_link_to_version_within_project
|
||||
@project = Project.find(2)
|
||||
User.current = User.find(1)
|
||||
assert_equal '<a title="07/01/2006" href="/versions/5">Alpha</a>', link_to_version(Version.find(5))
|
||||
end
|
||||
|
||||
def test_link_to_version
|
||||
User.current = User.find(1)
|
||||
assert_equal '<a title="07/01/2006" href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5))
|
||||
end
|
||||
|
||||
def test_link_to_version_without_effective_date
|
||||
User.current = User.find(1)
|
||||
version = Version.find(5)
|
||||
version.effective_date = nil
|
||||
assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(version)
|
||||
end
|
||||
|
||||
def test_link_to_private_version
|
||||
assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5))
|
||||
end
|
||||
|
||||
def test_link_to_version_invalid_version
|
||||
assert_equal '', link_to_version(Object)
|
||||
end
|
||||
|
||||
def test_format_version_name_within_project
|
||||
@project = Project.find(1)
|
||||
assert_equal "0.1", format_version_name(Version.find(1))
|
||||
end
|
||||
|
||||
def test_format_version_name
|
||||
assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
|
||||
end
|
||||
|
||||
def test_format_version_name_for_system_version
|
||||
assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7))
|
||||
end
|
||||
|
||||
def test_version_options_for_select_with_no_versions
|
||||
assert_equal '', version_options_for_select([])
|
||||
assert_equal '', version_options_for_select([], Version.find(1))
|
||||
end
|
||||
end
|
96
test/unit/helpers/queries_helper_test.rb
Normal file
96
test/unit/helpers/queries_helper_test.rb
Normal file
|
@ -0,0 +1,96 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class QueriesHelperTest < Redmine::HelperTest
|
||||
include QueriesHelper
|
||||
|
||||
fixtures :projects, :enabled_modules, :users, :members,
|
||||
:member_roles, :roles, :trackers, :issue_statuses,
|
||||
:issue_categories, :enumerations, :issues,
|
||||
:watchers, :custom_fields, :custom_values, :versions,
|
||||
:queries,
|
||||
:projects_trackers,
|
||||
:custom_fields_trackers
|
||||
|
||||
def test_filters_options_for_select_should_have_a_blank_option
|
||||
options = filters_options_for_select(IssueQuery.new)
|
||||
assert_select_in options, 'option[value=""]'
|
||||
end
|
||||
|
||||
def test_filters_options_for_select_should_not_group_regular_filters
|
||||
with_locale 'en' do
|
||||
options = filters_options_for_select(IssueQuery.new)
|
||||
assert_select_in options, 'optgroup option[value=status_id]', 0
|
||||
assert_select_in options, 'option[value=status_id]', :text => 'Status'
|
||||
end
|
||||
end
|
||||
|
||||
def test_filters_options_for_select_should_group_date_filters
|
||||
with_locale 'en' do
|
||||
options = filters_options_for_select(IssueQuery.new)
|
||||
assert_select_in options, 'optgroup[label=?]', 'Date', 1
|
||||
assert_select_in options, 'optgroup > option[value=due_date]', :text => 'Due date'
|
||||
end
|
||||
end
|
||||
|
||||
def test_filters_options_for_select_should_not_group_only_one_date_filter
|
||||
with_locale 'en' do
|
||||
options = filters_options_for_select(TimeEntryQuery.new)
|
||||
assert_select_in options, 'option[value=spent_on]'
|
||||
assert_select_in options, 'optgroup[label=?]', 'Date', 0
|
||||
assert_select_in options, 'optgroup option[value=spent_on]', 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_filters_options_for_select_should_group_relations_filters
|
||||
with_locale 'en' do
|
||||
options = filters_options_for_select(IssueQuery.new)
|
||||
assert_select_in options, 'optgroup[label=?]', 'Relations', 1
|
||||
assert_select_in options, 'optgroup[label=?] > option', 'Relations', 11
|
||||
assert_select_in options, 'optgroup > option[value=relates]', :text => 'Related to'
|
||||
end
|
||||
end
|
||||
|
||||
def test_filters_options_for_select_should_group_associations_filters
|
||||
CustomField.delete_all
|
||||
cf1 = ProjectCustomField.create!(:name => 'Foo', :field_format => 'string', :is_filter => true)
|
||||
cf2 = ProjectCustomField.create!(:name => 'Bar', :field_format => 'string', :is_filter => true)
|
||||
|
||||
with_locale 'en' do
|
||||
options = filters_options_for_select(IssueQuery.new)
|
||||
assert_select_in options, 'optgroup[label=?]', 'Project', 1
|
||||
assert_select_in options, 'optgroup[label=?] > option', 'Project', 2
|
||||
assert_select_in options, 'optgroup > option[value=?]', "project.cf_#{cf1.id}", :text => "Project's Foo"
|
||||
end
|
||||
end
|
||||
|
||||
def test_query_to_csv_should_translate_boolean_custom_field_values
|
||||
f = IssueCustomField.generate!(:field_format => 'bool', :name => 'Boolean', :is_for_all => true, :trackers => Tracker.all)
|
||||
issues = [
|
||||
Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '0'}),
|
||||
Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '1'})
|
||||
]
|
||||
|
||||
with_locale 'fr' do
|
||||
csv = query_to_csv(issues, IssueQuery.new(:column_names => ['id', "cf_#{f.id}"]))
|
||||
assert_include "Oui", csv
|
||||
assert_include "Non", csv
|
||||
end
|
||||
end
|
||||
end
|
43
test/unit/helpers/routes_helper_test.rb
Normal file
43
test/unit/helpers/routes_helper_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class RoutesHelperTest < Redmine::HelperTest
|
||||
fixtures :projects, :issues
|
||||
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def test_time_entries_path
|
||||
assert_equal '/projects/ecookbook/time_entries', _time_entries_path(Project.find(1), nil)
|
||||
assert_equal '/time_entries', _time_entries_path(nil, nil)
|
||||
end
|
||||
|
||||
def test_report_time_entries_path
|
||||
assert_equal '/projects/ecookbook/time_entries/report', _report_time_entries_path(Project.find(1), nil)
|
||||
assert_equal '/time_entries/report', _report_time_entries_path(nil, nil)
|
||||
end
|
||||
|
||||
def test_new_time_entry_path
|
||||
assert_equal '/projects/ecookbook/time_entries/new', _new_time_entry_path(Project.find(1), nil)
|
||||
assert_equal '/issues/1/time_entries/new', _new_time_entry_path(Project.find(1), Issue.find(1))
|
||||
assert_equal '/issues/1/time_entries/new', _new_time_entry_path(nil, Issue.find(1))
|
||||
assert_equal '/time_entries/new', _new_time_entry_path(nil, nil)
|
||||
end
|
||||
end
|
48
test/unit/helpers/search_helper_test.rb
Normal file
48
test/unit/helpers/search_helper_test.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class SearchHelperTest < Redmine::HelperTest
|
||||
include SearchHelper
|
||||
include ERB::Util
|
||||
|
||||
def test_highlight_single_token
|
||||
assert_equal 'This is a <span class="highlight token-0">token</span>.',
|
||||
highlight_tokens('This is a token.', %w(token))
|
||||
end
|
||||
|
||||
def test_highlight_multiple_tokens
|
||||
assert_equal 'This is a <span class="highlight token-0">token</span> and <span class="highlight token-1">another</span> <span class="highlight token-0">token</span>.',
|
||||
highlight_tokens('This is a token and another token.', %w(token another))
|
||||
end
|
||||
|
||||
def test_highlight_should_not_exceed_maximum_length
|
||||
s = (('1234567890' * 100) + ' token ') * 100
|
||||
r = highlight_tokens(s, %w(token))
|
||||
assert r.include?('<span class="highlight token-0">token</span>')
|
||||
assert r.length <= 1300
|
||||
end
|
||||
|
||||
def test_highlight_multibyte
|
||||
s = ('й' * 200) + ' token ' + ('й' * 200)
|
||||
r = highlight_tokens(s, %w(token))
|
||||
assert_equal ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45), r
|
||||
end
|
||||
end
|
30
test/unit/helpers/settings_helper_test.rb
Normal file
30
test/unit/helpers/settings_helper_test.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class SettingsHelperTest < Redmine::HelperTest
|
||||
include SettingsHelper
|
||||
include ERB::Util
|
||||
|
||||
def test_date_format_setting_options_should_include_human_readable_format
|
||||
Date.stubs(:today).returns(Date.parse("2015-07-14"))
|
||||
|
||||
options = date_format_setting_options('en')
|
||||
assert_include ["2015-07-14 (yyyy-mm-dd)", "%Y-%m-%d"], options
|
||||
end
|
||||
end
|
109
test/unit/helpers/sort_helper_test.rb
Normal file
109
test/unit/helpers/sort_helper_test.rb
Normal file
|
@ -0,0 +1,109 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class SortHelperTest < Redmine::HelperTest
|
||||
include SortHelper
|
||||
include ERB::Util
|
||||
|
||||
def setup
|
||||
super
|
||||
@session = nil
|
||||
@sort_param = nil
|
||||
end
|
||||
|
||||
def test_default_sort_clause_with_array
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update(['attr1', 'attr2'])
|
||||
|
||||
assert_equal ['attr1 DESC'], sort_clause
|
||||
end
|
||||
|
||||
def test_default_sort_clause_with_hash
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||||
|
||||
assert_equal ['table1.attr1 DESC'], sort_clause
|
||||
end
|
||||
|
||||
def test_default_sort_clause_with_multiple_columns
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
|
||||
|
||||
assert_equal ['table1.attr1 DESC', 'table1.attr2 DESC'], sort_clause
|
||||
end
|
||||
|
||||
def test_params_sort
|
||||
@sort_param = 'attr1,attr2:desc'
|
||||
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||||
|
||||
assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
|
||||
assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
|
||||
end
|
||||
|
||||
def test_invalid_params_sort
|
||||
@sort_param = 'invalid_key'
|
||||
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||||
|
||||
assert_nil sort_clause
|
||||
assert_equal 'invalid_key', @session['foo_bar_sort']
|
||||
end
|
||||
|
||||
def test_invalid_order_params_sort
|
||||
@sort_param = 'attr1:foo:bar,attr2'
|
||||
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
||||
|
||||
assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
|
||||
assert_equal 'attr1,attr2', @session['foo_bar_sort']
|
||||
end
|
||||
|
||||
def test_sort_css_without_params_should_use_default_sort
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update(['attr1', 'attr2'])
|
||||
|
||||
assert_equal 'sort-by-attr1 sort-desc', sort_css_classes
|
||||
end
|
||||
|
||||
def test_sort_css_should_use_params
|
||||
@sort_param = 'attr2,attr1'
|
||||
sort_init 'attr1', 'desc'
|
||||
sort_update(['attr1', 'attr2'])
|
||||
|
||||
assert_equal 'sort-by-attr2 sort-asc', sort_css_classes
|
||||
end
|
||||
|
||||
def test_sort_css_should_dasherize_sort_name
|
||||
sort_init 'foo_bar'
|
||||
sort_update(['foo_bar'])
|
||||
|
||||
assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def controller_name; 'foo'; end
|
||||
def action_name; 'bar'; end
|
||||
def params; {:sort => @sort_param}; end
|
||||
def session; @session ||= {}; end
|
||||
end
|
53
test/unit/helpers/timelog_helper_test.rb
Normal file
53
test/unit/helpers/timelog_helper_test.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class TimelogHelperTest < Redmine::HelperTest
|
||||
include TimelogHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ActionView::Helpers::DateHelper
|
||||
include ERB::Util
|
||||
|
||||
fixtures :projects, :roles, :enabled_modules, :users,
|
||||
:repositories, :changesets,
|
||||
:trackers, :issue_statuses, :issues, :versions, :documents,
|
||||
:wikis, :wiki_pages, :wiki_contents,
|
||||
:boards, :messages,
|
||||
:attachments,
|
||||
:enumerations
|
||||
|
||||
def test_activities_collection_for_select_options_should_return_array_of_activity_names_and_ids
|
||||
activities = activity_collection_for_select_options
|
||||
assert activities.include?(["Design", 9])
|
||||
assert activities.include?(["Development", 10])
|
||||
end
|
||||
|
||||
def test_activities_collection_for_select_options_should_not_include_inactive_activities
|
||||
activities = activity_collection_for_select_options
|
||||
assert !activities.include?(["Inactive Activity", 14])
|
||||
end
|
||||
|
||||
def test_activities_collection_for_select_options_should_use_the_projects_override
|
||||
project = Project.find(1)
|
||||
override_activity = TimeEntryActivity.create!({:name => "Design override", :parent => TimeEntryActivity.find_by_name("Design"), :project => project})
|
||||
|
||||
activities = activity_collection_for_select_options(nil, project)
|
||||
assert !activities.include?(["Design", 9]), "System activity found in: " + activities.inspect
|
||||
assert activities.include?(["Design override", override_activity.id]), "Override activity not found in: " + activities.inspect
|
||||
end
|
||||
end
|
54
test/unit/helpers/version_helper_test.rb
Normal file
54
test/unit/helpers/version_helper_test.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class VersionsHelperTest < Redmine::HelperTest
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :projects, :versions
|
||||
|
||||
def test_version_filtered_issues_path_sharing_none
|
||||
version = Version.new(:name => 'test', :sharing => 'none')
|
||||
version.project = Project.find(5)
|
||||
assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
|
||||
end
|
||||
|
||||
def test_version_filtered_issues_path_sharing_descendants
|
||||
version = Version.new(:name => 'test', :sharing => 'descendants')
|
||||
version.project = Project.find(5)
|
||||
assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
|
||||
end
|
||||
|
||||
def test_version_filtered_issues_path_sharing_hierarchy
|
||||
version = Version.new(:name => 'test', :sharing => 'hierarchy')
|
||||
version.project = Project.find(5)
|
||||
assert_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
|
||||
end
|
||||
|
||||
def test_version_filtered_issues_path_sharing_tree
|
||||
version = Version.new(:name => 'test', :sharing => 'tree')
|
||||
version.project = Project.find(5)
|
||||
assert_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
|
||||
end
|
||||
|
||||
def test_version_filtered_issues_path_sharing_system
|
||||
version = Version.new(:name => 'test', :sharing => 'system')
|
||||
version.project = Project.find(5)
|
||||
assert_match /^\/issues\?/, version_filtered_issues_path(version)
|
||||
end
|
||||
end
|
67
test/unit/helpers/watchers_helper_test.rb
Normal file
67
test/unit/helpers/watchers_helper_test.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class WatchersHelperTest < Redmine::HelperTest
|
||||
include WatchersHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :users, :issues
|
||||
|
||||
test '#watcher_link with a non-watched object' do
|
||||
expected = link_to(
|
||||
"Watch",
|
||||
"/watchers/watch?object_id=1&object_type=issue",
|
||||
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
|
||||
)
|
||||
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
|
||||
end
|
||||
|
||||
test '#watcher_link with a single objet array' do
|
||||
expected = link_to(
|
||||
"Watch",
|
||||
"/watchers/watch?object_id=1&object_type=issue",
|
||||
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
|
||||
)
|
||||
assert_equal expected, watcher_link([Issue.find(1)], User.find(1))
|
||||
end
|
||||
|
||||
test '#watcher_link with a multiple objets array' do
|
||||
expected = link_to(
|
||||
"Watch",
|
||||
"/watchers/watch?object_id%5B%5D=1&object_id%5B%5D=3&object_type=issue",
|
||||
:remote => true, :method => 'post', :class => "issue-bulk-watcher icon icon-fav-off"
|
||||
)
|
||||
assert_equal expected, watcher_link([Issue.find(1), Issue.find(3)], User.find(1))
|
||||
end
|
||||
|
||||
def test_watcher_link_with_nil_should_return_empty_string
|
||||
assert_equal '', watcher_link(nil, User.find(1))
|
||||
end
|
||||
|
||||
test '#watcher_link with a watched object' do
|
||||
Watcher.create!(:watchable => Issue.find(1), :user => User.find(1))
|
||||
|
||||
expected = link_to(
|
||||
"Unwatch",
|
||||
"/watchers/watch?object_id=1&object_type=issue",
|
||||
:remote => true, :method => 'delete', :class => "issue-1-watcher icon icon-fav"
|
||||
)
|
||||
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
|
||||
end
|
||||
end
|
45
test/unit/helpers/wiki_helper_test.rb
Normal file
45
test/unit/helpers/wiki_helper_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class WikiHelperTest < Redmine::HelperTest
|
||||
include WikiHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
fixtures :projects, :users,
|
||||
:roles, :member_roles, :members,
|
||||
:enabled_modules, :wikis, :wiki_pages
|
||||
|
||||
def test_wiki_page_edit_cancel_path_for_new_page_without_parent_should_be_wiki_index
|
||||
wiki = Wiki.find(1)
|
||||
page = WikiPage.new(:wiki => wiki)
|
||||
assert_equal '/projects/ecookbook/wiki/index', wiki_page_edit_cancel_path(page)
|
||||
end
|
||||
|
||||
def test_wiki_page_edit_cancel_path_for_new_page_with_parent_should_be_parent
|
||||
wiki = Wiki.find(1)
|
||||
page = WikiPage.new(:wiki => wiki, :parent => wiki.find_page('Another_page'))
|
||||
assert_equal '/projects/ecookbook/wiki/Another_page', wiki_page_edit_cancel_path(page)
|
||||
end
|
||||
|
||||
def test_wiki_page_edit_cancel_path_for_existing_page_should_be_the_page
|
||||
wiki = Wiki.find(1)
|
||||
page = wiki.find_page('Child_1')
|
||||
assert_equal '/projects/ecookbook/wiki/Child_1', wiki_page_edit_cancel_path(page)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue