redmine_extensions 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/redmine_extensions/redmine_extensions.js.orig +648 -0
  3. data/app/views/easy_entity_assignments/_query_index.html.erb.orig +16 -0
  4. data/config/locales/cs.yml +4 -1
  5. data/config/locales/en.yml +1 -0
  6. data/lib/generators/redmine_extensions/entity/templates/context_menu.html.erb.erb +14 -1
  7. data/lib/generators/redmine_extensions/entity/templates/controller.rb.erb +40 -6
  8. data/lib/generators/redmine_extensions/entity/templates/edit.js.erb.erb +5 -5
  9. data/lib/generators/redmine_extensions/entity/templates/index.js.erb.erb +3 -3
  10. data/lib/generators/redmine_extensions/entity/templates/new.js.erb.erb +5 -5
  11. data/lib/generators/redmine_extensions/entity/templates/show.js.erb.erb +3 -3
  12. data/lib/redmine_extensions/easy_query_helpers/outputs.rb +18 -2
  13. data/lib/redmine_extensions/query_output.rb +30 -11
  14. data/lib/redmine_extensions/redmine_patches/controllers/issues_controller_patch.rb +9 -0
  15. data/lib/redmine_extensions/version.rb +1 -1
  16. data/lib/redmine_extensions/version.rb.orig +7 -0
  17. data/spec/redmine/app/controllers/custom_field_enumerations_controller.rb +75 -0
  18. data/spec/redmine/app/controllers/imports_controller.rb +121 -0
  19. data/spec/redmine/app/helpers/imports_helper.rb +47 -0
  20. data/spec/redmine/app/models/custom_field_enumeration.rb +90 -0
  21. data/spec/redmine/app/models/import.rb +249 -0
  22. data/spec/redmine/app/models/import_item.rb +22 -0
  23. data/spec/redmine/app/models/issue_import.rb +186 -0
  24. data/spec/redmine/app/views/attachments/image.html.erb +3 -0
  25. data/spec/redmine/app/views/attachments/other.html.erb +3 -0
  26. data/spec/redmine/app/views/common/_image.html.erb +1 -0
  27. data/spec/redmine/app/views/common/_other.html.erb +1 -0
  28. data/spec/redmine/app/views/custom_field_enumerations/create.js.erb +2 -0
  29. data/spec/redmine/app/views/custom_field_enumerations/destroy.html.erb +14 -0
  30. data/spec/redmine/app/views/custom_field_enumerations/index.html.erb +47 -0
  31. data/spec/redmine/app/views/custom_fields/formats/_enumeration.erb +12 -0
  32. data/spec/redmine/app/views/imports/_fields_mapping.html.erb +90 -0
  33. data/spec/redmine/app/views/imports/mapping.html.erb +52 -0
  34. data/spec/redmine/app/views/imports/mapping.js.erb +1 -0
  35. data/spec/redmine/app/views/imports/new.html.erb +15 -0
  36. data/spec/redmine/app/views/imports/run.html.erb +20 -0
  37. data/spec/redmine/app/views/imports/run.js.erb +11 -0
  38. data/spec/redmine/app/views/imports/settings.html.erb +30 -0
  39. data/spec/redmine/app/views/imports/show.html.erb +38 -0
  40. data/spec/redmine/app/views/layouts/_file.html.erb +15 -0
  41. data/spec/redmine/app/views/mailer/security_notification.html.erb +13 -0
  42. data/spec/redmine/app/views/mailer/security_notification.text.erb +8 -0
  43. data/spec/redmine/app/views/mailer/settings_updated.html.erb +14 -0
  44. data/spec/redmine/app/views/mailer/settings_updated.text.erb +12 -0
  45. data/spec/redmine/app/views/queries/_query_form.html.erb +62 -0
  46. data/spec/redmine/app/views/repositories/_changeset.html.erb +40 -0
  47. data/spec/redmine/app/views/search/index.api.rsb +12 -0
  48. data/spec/redmine/app/views/settings/_api.html.erb +10 -0
  49. data/spec/redmine/app/views/settings/_attachments.html.erb +21 -0
  50. data/spec/redmine/app/views/wiki/_new_modal.html.erb +21 -0
  51. data/spec/redmine/app/views/wiki/new.html.erb +17 -0
  52. data/spec/redmine/app/views/wiki/new.js.erb +2 -0
  53. data/spec/redmine/appveyor.yml +36 -0
  54. data/spec/redmine/db/migrate/20150725112753_insert_allowed_statuses_for_new_issues.rb +23 -0
  55. data/spec/redmine/db/migrate/20150730122707_create_imports.rb +13 -0
  56. data/spec/redmine/db/migrate/20150730122735_create_import_items.rb +10 -0
  57. data/spec/redmine/db/migrate/20150921204850_change_time_entries_comments_limit_to_1024.rb +9 -0
  58. data/spec/redmine/db/migrate/20150921210243_change_wiki_contents_comments_limit_to_1024.rb +11 -0
  59. data/spec/redmine/db/migrate/20151020182334_change_attachments_filesize_limit_to_8.rb +9 -0
  60. data/spec/redmine/db/migrate/20151020182731_fix_comma_in_user_format_setting_value.rb +13 -0
  61. data/spec/redmine/db/migrate/20151021184614_change_issue_categories_name_limit_to_60.rb +9 -0
  62. data/spec/redmine/db/migrate/20151021185456_change_auth_sources_filter_to_text.rb +9 -0
  63. data/spec/redmine/db/migrate/20151021190616_change_user_preferences_hide_mail_default_to_true.rb +9 -0
  64. data/spec/redmine/db/migrate/20151024082034_add_tokens_updated_on.rb +10 -0
  65. data/spec/redmine/db/migrate/20151025072118_create_custom_field_enumerations.rb +10 -0
  66. data/spec/redmine/db/migrate/20151031095005_add_projects_default_version_id.rb +12 -0
  67. data/spec/redmine/db/migrate/20160404080304_force_password_reset_during_setup.rb +9 -0
  68. data/spec/redmine/db/migrate/20160416072926_remove_position_defaults.rb +13 -0
  69. data/spec/redmine/db/migrate/20160529063352_add_roles_settings.rb +5 -0
  70. data/spec/redmine/lib/redmine/acts/positioned.rb +118 -0
  71. data/spec/redmine/lib/redmine/helpers/url.rb +35 -0
  72. data/spec/redmine/lib/redmine/hook/listener.rb +32 -0
  73. data/spec/redmine/lib/redmine/hook/view_listener.rb +78 -0
  74. data/spec/redmine/log/test.log +2 -0
  75. data/spec/redmine/plugins/dummy_plugin/Gemfile +1 -0
  76. data/spec/redmine/plugins/dummy_plugin/app/controllers/dummy_autocompletes_controller.rb +4 -0
  77. data/spec/redmine/plugins/dummy_plugin/app/views/dummy_autocompletes/index.html.erb +3 -0
  78. data/spec/redmine/plugins/dummy_plugin/config/locales/en.yml +2 -0
  79. data/spec/redmine/plugins/dummy_plugin/config/routes.rb +1 -0
  80. data/spec/redmine/plugins/dummy_plugin/init.rb +34 -0
  81. data/spec/redmine/plugins/dummy_plugin/lib/dummy_plugin/easy_patch/redmine/controllers/issues_controller_patch.example +30 -0
  82. data/spec/redmine/plugins/dummy_plugin/lib/dummy_plugin/easy_patch/redmine/helpers/issues_helper_patch.example +30 -0
  83. data/spec/redmine/plugins/dummy_plugin/lib/dummy_plugin/easy_patch/redmine/models/issue_patch.example +30 -0
  84. data/spec/redmine/plugins/dummy_plugin/lib/dummy_plugin/hooks.rb +5 -0
  85. data/spec/redmine/plugins/dummy_plugin/lib/dummy_plugin/internals.rb +4 -0
  86. data/spec/redmine/public/images/jstoolbar/bt_precode.png +0 -0
  87. data/spec/redmine/public/images/reorder.png +0 -0
  88. data/spec/redmine/public/javascripts/jquery-1.11.1-ui-1.11.0-ujs-3.1.4.js +21 -0
  89. data/spec/redmine/public/javascripts/redmine_extensions/application.js +13 -0
  90. data/spec/redmine/public/javascripts/redmine_extensions/easy_togglers.js +58 -0
  91. data/spec/redmine/public/javascripts/redmine_extensions/jquery.entityarray.js +130 -0
  92. data/spec/redmine/public/javascripts/redmine_extensions/redmine_extensions.js +642 -0
  93. data/spec/redmine/public/javascripts/responsive.js +83 -0
  94. data/spec/redmine/public/stylesheets/responsive.css +799 -0
  95. data/spec/redmine/test/fixtures/files/import_dates.csv +4 -0
  96. data/spec/redmine/test/fixtures/files/import_iso8859-1.csv +3 -0
  97. data/spec/redmine/test/fixtures/files/import_issues.csv +4 -0
  98. data/spec/redmine/test/fixtures/ldap/slapd.centos6.conf +24 -0
  99. data/spec/redmine/test/fixtures/ldap/slapd.ubuntu.12.04.conf +23 -0
  100. data/spec/redmine/test/fixtures/mail_handler/issue_update_with_cc.eml +19 -0
  101. data/spec/redmine/test/fixtures/mail_handler/ticket_on_project_given_by_to_header.eml +60 -0
  102. data/spec/redmine/test/fixtures/mail_handler/ticket_with_text_attachment_iso-8859-2.eml +31 -0
  103. data/spec/redmine/test/functional/custom_field_enumerations_controller_test.rb +115 -0
  104. data/spec/redmine/test/functional/imports_controller_test.rb +205 -0
  105. data/spec/redmine/test/functional/sessions_controller_test.rb +138 -0
  106. data/spec/redmine/test/integration/api_test/search_test.rb +92 -0
  107. data/spec/redmine/test/integration/routing/imports_test.rb +36 -0
  108. data/spec/redmine/test/integration/sessions_test.rb +97 -0
  109. data/spec/redmine/test/ui/custom_fields_test_ui.rb +38 -0
  110. data/spec/redmine/test/unit/attachment_transaction_test.rb +76 -0
  111. data/spec/redmine/test/unit/helpers/journals_helper_test.rb +48 -0
  112. data/spec/redmine/test/unit/helpers/wiki_helper_test.rb +45 -0
  113. data/spec/redmine/test/unit/issue_import_test.rb +178 -0
  114. data/spec/redmine/test/unit/lib/redmine/acts/positioned_with_scope_test.rb +53 -0
  115. data/spec/redmine/test/unit/lib/redmine/acts/positioned_without_scope_test.rb +55 -0
  116. data/spec/redmine/test/unit/lib/redmine/field_format/enumeration_format_test.rb +91 -0
  117. data/spec/support/easy_queries_helpers.rb +0 -0
  118. metadata +216 -10
@@ -0,0 +1,48 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../../test_helper', __FILE__)
19
+
20
+ class JournalsHelperTest < Redmine::HelperTest
21
+ include JournalsHelper
22
+
23
+ fixtures :projects, :trackers, :issue_statuses, :issues,
24
+ :enumerations, :issue_categories,
25
+ :projects_trackers,
26
+ :users, :roles, :member_roles, :members,
27
+ :enabled_modules,
28
+ :custom_fields,
29
+ :attachments,
30
+ :versions
31
+
32
+ def test_journal_thumbnail_attachments_should_return_thumbnailable_attachments
33
+ issue = Issue.generate!
34
+
35
+ journal = new_record(Journal) do
36
+ issue.init_journal(User.find(1))
37
+ issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'image.png'), :author => User.find(1))
38
+ issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'foo'), :author => User.find(1))
39
+ issue.save
40
+ end
41
+ assert_equal 2, journal.details.count
42
+
43
+ thumbnails = journal_thumbnail_attachments(journal)
44
+ assert_equal 1, thumbnails.count
45
+ assert_kind_of Attachment, thumbnails.first
46
+ assert_equal 'image.png', thumbnails.first.filename
47
+ end
48
+ end
@@ -0,0 +1,45 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../../test_helper', __FILE__)
19
+
20
+ class WikiHelperTest < Redmine::HelperTest
21
+ include WikiHelper
22
+ include Rails.application.routes.url_helpers
23
+
24
+ fixtures :projects, :users,
25
+ :roles, :member_roles, :members,
26
+ :enabled_modules, :wikis, :wiki_pages
27
+
28
+ def test_wiki_page_edit_cancel_path_for_new_page_without_parent_should_be_wiki_index
29
+ wiki = Wiki.find(1)
30
+ page = WikiPage.new(:wiki => wiki)
31
+ assert_equal '/projects/ecookbook/wiki/index', wiki_page_edit_cancel_path(page)
32
+ end
33
+
34
+ def test_wiki_page_edit_cancel_path_for_new_page_with_parent_should_be_parent
35
+ wiki = Wiki.find(1)
36
+ page = WikiPage.new(:wiki => wiki, :parent => wiki.find_page('Another_page'))
37
+ assert_equal '/projects/ecookbook/wiki/Another_page', wiki_page_edit_cancel_path(page)
38
+ end
39
+
40
+ def test_wiki_page_edit_cancel_path_for_existing_page_should_be_the_page
41
+ wiki = Wiki.find(1)
42
+ page = wiki.find_page('Child_1')
43
+ assert_equal '/projects/ecookbook/wiki/Child_1', wiki_page_edit_cancel_path(page)
44
+ end
45
+ end
@@ -0,0 +1,178 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../test_helper', __FILE__)
19
+
20
+ class IssueImportTest < ActiveSupport::TestCase
21
+ fixtures :projects, :enabled_modules,
22
+ :users, :email_addresses,
23
+ :roles, :members, :member_roles,
24
+ :issues, :issue_statuses,
25
+ :trackers, :projects_trackers,
26
+ :versions,
27
+ :issue_categories,
28
+ :enumerations,
29
+ :workflows,
30
+ :custom_fields,
31
+ :custom_values,
32
+ :custom_fields_projects,
33
+ :custom_fields_trackers
34
+
35
+ include Redmine::I18n
36
+
37
+ def setup
38
+ set_language_if_valid 'en'
39
+ end
40
+
41
+ def test_create_versions_should_create_missing_versions
42
+ import = generate_import_with_mapping
43
+ import.mapping.merge!('fixed_version' => '9', 'create_versions' => '1')
44
+ import.save!
45
+
46
+ version = new_record(Version) do
47
+ assert_difference 'Issue.count', 3 do
48
+ import.run
49
+ end
50
+ end
51
+ assert_equal '2.1', version.name
52
+ end
53
+
54
+ def test_create_categories_should_create_missing_categories
55
+ import = generate_import_with_mapping
56
+ import.mapping.merge!('category' => '10', 'create_categories' => '1')
57
+ import.save!
58
+
59
+ category = new_record(IssueCategory) do
60
+ assert_difference 'Issue.count', 3 do
61
+ import.run
62
+ end
63
+ end
64
+ assert_equal 'New category', category.name
65
+ end
66
+
67
+ def test_mapping_with_fixed_tracker
68
+ import = generate_import_with_mapping
69
+ import.mapping.merge!('tracker' => 'value:2')
70
+ import.save!
71
+
72
+ issues = new_records(Issue, 3) { import.run }
73
+ assert_equal [2], issues.map(&:tracker_id).uniq
74
+ end
75
+
76
+ def test_mapping_with_mapped_tracker
77
+ import = generate_import_with_mapping
78
+ import.mapping.merge!('tracker' => '13')
79
+ import.save!
80
+
81
+ issues = new_records(Issue, 3) { import.run }
82
+ assert_equal [1, 2, 1], issues.map(&:tracker_id)
83
+ end
84
+
85
+ def test_should_not_import_with_default_tracker_when_tracker_is_invalid
86
+ Tracker.find_by_name('Feature request').update!(:name => 'Feature')
87
+
88
+ import = generate_import_with_mapping
89
+ import.mapping.merge!('tracker' => '13')
90
+ import.save!
91
+ import.run
92
+
93
+ assert_equal 1, import.unsaved_items.count
94
+ item = import.unsaved_items.first
95
+ assert_include "Tracker cannot be blank", item.message
96
+ end
97
+
98
+ def test_status_should_be_set
99
+ import = generate_import_with_mapping
100
+ import.mapping.merge!('status' => '14')
101
+ import.save!
102
+
103
+ issues = new_records(Issue, 3) { import.run }
104
+ assert_equal ['New', 'New', 'Assigned'], issues.map(&:status).map(&:name)
105
+ end
106
+
107
+ def test_parent_should_be_set
108
+ import = generate_import_with_mapping
109
+ import.mapping.merge!('parent_issue_id' => '5')
110
+ import.save!
111
+
112
+ issues = new_records(Issue, 3) { import.run }
113
+ assert_nil issues[0].parent
114
+ assert_equal issues[0].id, issues[1].parent_id
115
+ assert_equal 2, issues[2].parent_id
116
+ end
117
+
118
+ def test_assignee_should_be_set
119
+ import = generate_import_with_mapping
120
+ import.mapping.merge!('assigned_to' => '11')
121
+ import.save!
122
+
123
+ issues = new_records(Issue, 3) { import.run }
124
+ assert_equal [User.find(3), nil, nil], issues.map(&:assigned_to)
125
+ end
126
+
127
+ def test_user_custom_field_should_be_set
128
+ field = IssueCustomField.generate!(:field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
129
+ import = generate_import_with_mapping
130
+ import.mapping.merge!("cf_#{field.id}" => '11')
131
+ import.save!
132
+
133
+ issues = new_records(Issue, 3) { import.run }
134
+ assert_equal '3', issues.first.custom_field_value(field)
135
+ end
136
+
137
+ def test_is_private_should_be_set_based_on_user_locale
138
+ import = generate_import_with_mapping
139
+ import.mapping.merge!('is_private' => '6')
140
+ import.save!
141
+
142
+ issues = new_records(Issue, 3) { import.run }
143
+ assert_equal [false, true, false], issues.map(&:is_private)
144
+ end
145
+
146
+ def test_dates_should_be_parsed_using_date_format_setting
147
+ field = IssueCustomField.generate!(:field_format => 'date', :is_for_all => true, :trackers => Tracker.all)
148
+ import = generate_import_with_mapping('import_dates.csv')
149
+ import.settings.merge!('date_format' => Import::DATE_FORMATS[1])
150
+ import.mapping.merge!('tracker' => 'value:1', 'subject' => '0', 'start_date' => '1', 'due_date' => '2', "cf_#{field.id}" => '3')
151
+ import.save!
152
+
153
+ issue = new_record(Issue) { import.run } # only 1 valid issue
154
+ assert_equal "Valid dates", issue.subject
155
+ assert_equal Date.parse('2015-07-10'), issue.start_date
156
+ assert_equal Date.parse('2015-08-12'), issue.due_date
157
+ assert_equal '2015-07-14', issue.custom_field_value(field)
158
+ end
159
+
160
+ def test_date_format_should_default_to_user_language
161
+ user = User.generate!(:language => 'fr')
162
+ import = Import.new
163
+ import.user = user
164
+ assert_nil import.settings['date_format']
165
+
166
+ import.set_default_settings
167
+ assert_equal '%d/%m/%Y', import.settings['date_format']
168
+ end
169
+
170
+ def test_run_should_remove_the_file
171
+ import = generate_import_with_mapping
172
+ file_path = import.filepath
173
+ assert File.exists?(file_path)
174
+
175
+ import.run
176
+ assert !File.exists?(file_path)
177
+ end
178
+ end
@@ -0,0 +1,53 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../../../../test_helper', __FILE__)
19
+
20
+ class Redmine::Acts::PositionedWithScopeTest < ActiveSupport::TestCase
21
+ fixtures :projects, :boards
22
+
23
+ def test_create_should_default_to_last_position
24
+ b = Board.generate!(:project_id => 1)
25
+ assert_equal 3, b.reload.position
26
+
27
+ b = Board.generate!(:project_id => 3)
28
+ assert_equal 1, b.reload.position
29
+ end
30
+
31
+ def test_create_should_insert_at_given_position
32
+ b = Board.generate!(:project_id => 1, :position => 2)
33
+
34
+ assert_equal 2, b.reload.position
35
+ assert_equal [1, 3, 1, 2], Board.order(:id).pluck(:position)
36
+ end
37
+
38
+ def test_destroy_should_remove_position
39
+ b = Board.generate!(:project_id => 1, :position => 2)
40
+ b.destroy
41
+
42
+ assert_equal [1, 2, 1], Board.order(:id).pluck(:position)
43
+ end
44
+
45
+ def test_update_should_update_positions
46
+ b = Board.generate!(:project_id => 1)
47
+ assert_equal 3, b.position
48
+
49
+ b.position = 2
50
+ b.save!
51
+ assert_equal [1, 3, 1, 2], Board.order(:id).pluck(:position)
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../../../../test_helper', __FILE__)
19
+
20
+ class Redmine::Acts::PositionedWithoutScopeTest < ActiveSupport::TestCase
21
+ fixtures :trackers, :issue_statuses
22
+
23
+ def test_create_should_default_to_last_position
24
+ t = Tracker.generate
25
+ t.save!
26
+
27
+ assert_equal 4, t.reload.position
28
+ end
29
+
30
+ def test_create_should_insert_at_given_position
31
+ t = Tracker.generate
32
+ t.position = 2
33
+ t.save!
34
+
35
+ assert_equal 2, t.reload.position
36
+ assert_equal [1, 3, 4, 2], Tracker.order(:id).pluck(:position)
37
+ end
38
+
39
+ def test_destroy_should_remove_position
40
+ t = Tracker.generate!
41
+ Tracker.generate!
42
+ t.destroy
43
+
44
+ assert_equal [1, 2, 3, 4], Tracker.order(:id).pluck(:position)
45
+ end
46
+
47
+ def test_update_should_update_positions
48
+ t = Tracker.generate!
49
+ assert_equal 4, t.position
50
+
51
+ t.position = 2
52
+ t.save!
53
+ assert_equal [1, 3, 4, 2], Tracker.order(:id).pluck(:position)
54
+ end
55
+ end
@@ -0,0 +1,91 @@
1
+ # Redmine - project management software
2
+ # Copyright (C) 2006-2016 Jean-Philippe Lang
3
+ #
4
+ # This program is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License
6
+ # as published by the Free Software Foundation; either version 2
7
+ # of the License, or (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+ require File.expand_path('../../../../../test_helper', __FILE__)
19
+ require 'redmine/field_format'
20
+
21
+ class Redmine::EnumerationFieldFormatTest < ActionView::TestCase
22
+ include ApplicationHelper
23
+
24
+ def setup
25
+ set_language_if_valid 'en'
26
+ @field = IssueCustomField.create!(:name => 'List', :field_format => 'enumeration', :is_required => false)
27
+ @foo = CustomFieldEnumeration.new(:name => 'Foo')
28
+ @bar = CustomFieldEnumeration.new(:name => 'Bar')
29
+ @field.enumerations << @foo
30
+ @field.enumerations << @bar
31
+ end
32
+
33
+ def test_edit_tag_should_contain_possible_values
34
+ value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new)
35
+
36
+ tag = @field.format.edit_tag(self, 'id', 'name', value)
37
+ assert_select_in tag, 'select' do
38
+ assert_select 'option', 3
39
+ assert_select 'option[value=""]'
40
+ assert_select 'option[value=?]', @foo.id.to_s, :text => 'Foo'
41
+ assert_select 'option[value=?]', @bar.id.to_s, :text => 'Bar'
42
+ end
43
+ end
44
+
45
+ def test_edit_tag_should_select_current_value
46
+ value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new, :value => @bar.id.to_s)
47
+
48
+ tag = @field.format.edit_tag(self, 'id', 'name', value)
49
+ assert_select_in tag, 'select' do
50
+ assert_select 'option[selected=selected]', 1
51
+ assert_select 'option[value=?][selected=selected]', @bar.id.to_s, :text => 'Bar'
52
+ end
53
+ end
54
+
55
+ def test_edit_tag_with_multiple_should_select_current_values
56
+ @field.multiple = true
57
+ @field.save!
58
+ value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new, :value => [@foo.id.to_s, @bar.id.to_s])
59
+
60
+ tag = @field.format.edit_tag(self, 'id', 'name', value)
61
+ assert_select_in tag, 'select[multiple=multiple]' do
62
+ assert_select 'option[selected=selected]', 2
63
+ assert_select 'option[value=?][selected=selected]', @foo.id.to_s, :text => 'Foo'
64
+ assert_select 'option[value=?][selected=selected]', @bar.id.to_s, :text => 'Bar'
65
+ end
66
+ end
67
+
68
+ def test_edit_tag_with_check_box_style_should_contain_possible_values
69
+ @field.edit_tag_style = 'check_box'
70
+ @field.save!
71
+ value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new)
72
+
73
+ tag = @field.format.edit_tag(self, 'id', 'name', value)
74
+ assert_select_in tag, 'span' do
75
+ assert_select 'input[type=radio]', 3
76
+ assert_select 'label', :text => '(none)' do
77
+ assert_select 'input[value=""]'
78
+ end
79
+ assert_select 'label', :text => 'Foo' do
80
+ assert_select 'input[value=?]', @foo.id.to_s
81
+ end
82
+ assert_select 'label', :text => 'Bar' do
83
+ assert_select 'input[value=?]', @bar.id.to_s
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_value_from_keyword_should_return_enumeration_id
89
+ assert_equal @foo.id, @field.value_from_keyword('foo', nil)
90
+ end
91
+ end