redmineup 1.1.1 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +7 -18
- data/README.md +74 -153
- data/Rakefile +1 -1
- data/app/assets/images/icons.svg +9 -0
- data/app/assets/javascripts/consumer.js +37 -50
- data/app/assets/javascripts/consumer_worker.js +219 -0
- data/app/assets/javascripts/jquery.colorPicker.min.js +26 -0
- data/app/assets/javascripts/select2_helpers.js +12 -0
- data/app/assets/stylesheets/calendars.css +0 -3
- data/app/assets/stylesheets/redmineup.css +520 -0
- data/app/assets/stylesheets/select2.css +2 -2
- data/app/views/redmineup/_additional_assets.html.erb +1 -0
- data/app/views/redmineup/journals/_history.html.erb +33 -0
- data/config/locales/ar.yml +13 -0
- data/config/locales/az.yml +13 -0
- data/config/locales/bg.yml +13 -0
- data/config/locales/bs.yml +13 -0
- data/config/locales/ca.yml +13 -0
- data/config/locales/cs.yml +1 -0
- data/config/locales/da.yml +13 -0
- data/config/locales/de.yml +1 -0
- data/config/locales/el.yml +13 -0
- data/config/locales/en-GB.yml +14 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/es-PA.yml +14 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/et.yml +13 -0
- data/config/locales/eu.yml +13 -0
- data/config/locales/fa.yml +13 -0
- data/config/locales/fi.yml +13 -0
- data/config/locales/fr.yml +13 -0
- data/config/locales/gl.yml +13 -0
- data/config/locales/he.yml +13 -0
- data/config/locales/hr.yml +13 -0
- data/config/locales/hu.yml +13 -0
- data/config/locales/id.yml +13 -0
- data/config/locales/it.yml +13 -0
- data/config/locales/ja.yml +13 -0
- data/config/locales/ko.yml +13 -0
- data/config/locales/lt.yml +13 -0
- data/config/locales/lv.yml +13 -0
- data/config/locales/mk.yml +13 -0
- data/config/locales/mn.yml +13 -0
- data/config/locales/nl.yml +13 -0
- data/config/locales/no.yml +13 -0
- data/config/locales/pl.yml +13 -0
- data/config/locales/pt-BR.yml +13 -0
- data/config/locales/pt.yml +13 -0
- data/config/locales/ro.yml +13 -0
- data/config/locales/ru.yml +2 -1
- data/config/locales/sk.yml +13 -0
- data/config/locales/sl.yml +13 -0
- data/config/locales/sq.yml +13 -0
- data/config/locales/sr-YU.yml +13 -0
- data/config/locales/sr.yml +13 -0
- data/config/locales/sv.yml +13 -0
- data/config/locales/ta-IN.yml +13 -0
- data/config/locales/th.yml +13 -0
- data/config/locales/tr.yml +13 -0
- data/config/locales/uk.yml +13 -0
- data/config/locales/vi.yml +13 -0
- data/config/locales/zh-TW.yml +13 -0
- data/config/locales/zh.yml +13 -0
- data/config/routes.rb +4 -0
- data/doc/CHANGELOG +119 -24
- data/doc/active-record-mixins.md +156 -0
- data/doc/assets-money-and-utilities.md +71 -0
- data/doc/tagging-and-select2.md +115 -0
- data/lib/action_cable/connection/rup_connection.rb +17 -0
- data/lib/action_cable/server/rup_configuration.rb +1 -9
- data/lib/action_cable/server/rup_server.rb +8 -0
- data/lib/redmineup/acts_as_journalized/hook.rb +16 -0
- data/lib/redmineup/acts_as_journalized/journal_event.rb +30 -0
- data/lib/redmineup/acts_as_journalized/journal_patch.rb +87 -0
- data/lib/redmineup/acts_as_journalized/up_acts_as_journalized.rb +118 -0
- data/lib/redmineup/acts_as_taggable/tag.rb +13 -3
- data/lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb +36 -28
- data/lib/redmineup/acts_as_viewed/up_acts_as_viewed.rb +8 -3
- data/lib/redmineup/currency/formatting.rb +1 -0
- data/lib/redmineup/engine.rb +14 -2
- data/lib/redmineup/helpers/datetime_helper.rb +23 -0
- data/lib/redmineup/helpers/external_assets_helper.rb +14 -6
- data/lib/redmineup/helpers/form_tag_helper.rb +44 -0
- data/lib/redmineup/helpers/journals_helper.rb +53 -0
- data/lib/redmineup/helpers/tags_helper.rb +108 -0
- data/lib/redmineup/helpers/test_helper.rb +12 -0
- data/lib/redmineup/hooks/views_layouts_hook.rb +1 -5
- data/lib/redmineup/money_helper.rb +10 -2
- data/lib/redmineup/patches/action_cable_base_patch.rb +13 -8
- data/lib/redmineup/patches/action_cable_patch.rb +3 -7
- data/lib/redmineup/patches/auto_completes_controller_patch.rb +17 -0
- data/lib/redmineup/patches/compatibility/routing_mapper_patch.rb +5 -18
- data/lib/redmineup/patches/compatibility/sprite_patch.rb +3 -9
- data/lib/redmineup/patches/compatibility_patch.rb +0 -6
- data/lib/redmineup/patches/liquid_patch.rb +13 -22
- data/lib/redmineup/version.rb +1 -1
- data/lib/redmineup.rb +38 -41
- data/redmineup.gemspec +1 -1
- data/test/acts_as_journalized/up_acts_as_journalized_test.rb +106 -0
- data/test/acts_as_taggable/tag_test.rb +12 -9
- data/test/acts_as_viewed/rup_acts_as_viewed_test.rb +12 -0
- data/test/currency_test.rb +7 -0
- data/test/locales_test.rb +12 -0
- data/test/models/journal.rb +38 -0
- data/test/models/journalized_thing.rb +5 -0
- data/test/redmine/acts_as_journalized/journalized_redmine_test.rb +264 -0
- data/test/schema.rb +18 -1
- data/test/tags_helper_view_test.rb +111 -0
- data/test/test_helper.rb +13 -12
- metadata +74 -5
- data/app/assets/stylesheets/money.css +0 -95
- data/lib/redmineup/patches/compatibility/application_controller_patch.rb +0 -32
- data/lib/redmineup/patches/compatibility/user_patch.rb +0 -21
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
class LocalesTest < ActiveSupport::TestCase
|
|
5
|
+
Dir[File.expand_path('../../config/locales/*.yml', __FILE__)].sort.each do |file|
|
|
6
|
+
name = File.basename(file, '.yml')
|
|
7
|
+
|
|
8
|
+
define_method("test_#{name}_root_key_is_the_locale_name_string") do
|
|
9
|
+
assert_equal [name], YAML.load_file(file).keys
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/test/models/journal.rb
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
|
+
class JournalDetail < ActiveRecord::Base
|
|
2
|
+
belongs_to :journal
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
class Journal < ActiveRecord::Base
|
|
2
6
|
belongs_to :journalized, :polymorphic => true
|
|
3
7
|
belongs_to :issue, :foreign_key => :journalized_id
|
|
4
8
|
|
|
5
9
|
belongs_to :user
|
|
10
|
+
has_many :details, :class_name => 'JournalDetail', :dependent => :delete_all, :inverse_of => :journal
|
|
11
|
+
|
|
12
|
+
attr_accessor :notify
|
|
13
|
+
|
|
14
|
+
def initialize(*args)
|
|
15
|
+
super
|
|
16
|
+
if journalized
|
|
17
|
+
journalized.new_record? ? self.notify = false : start
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def save(*args)
|
|
22
|
+
journalize_changes
|
|
23
|
+
(new_record? && notes.blank? && details.empty?) ? false : super()
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def start
|
|
27
|
+
@attributes_before_change = journalized.journalized_attribute_names.index_with { |name| journalized.send(name) }
|
|
28
|
+
@custom_values_before_change = {}
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def journalize_changes
|
|
33
|
+
if @attributes_before_change
|
|
34
|
+
(journalized.journalized_attribute_names + @attributes_before_change.keys).uniq.each do |name|
|
|
35
|
+
before = @attributes_before_change[name]
|
|
36
|
+
after = journalized.send(name)
|
|
37
|
+
next if before == after || (before.blank? && after.blank?)
|
|
38
|
+
|
|
39
|
+
details << JournalDetail.new(property: 'attr', prop_key: name, old_value: before, value: after)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
start
|
|
43
|
+
end
|
|
6
44
|
end
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
require File.join(Dir.pwd, 'test/test_helper')
|
|
2
|
+
|
|
3
|
+
ActiveRecord::Base.connection.create_table :up_journalized_records, force: true do |t|
|
|
4
|
+
t.references :project
|
|
5
|
+
t.string :name
|
|
6
|
+
t.date :due_date
|
|
7
|
+
t.string :status
|
|
8
|
+
t.integer :comments_count, default: 0
|
|
9
|
+
t.datetime :created_on
|
|
10
|
+
t.datetime :updated_on
|
|
11
|
+
end
|
|
12
|
+
Minitest.after_run { ActiveRecord::Base.connection.drop_table :up_journalized_records, if_exists: true }
|
|
13
|
+
|
|
14
|
+
class UpJournalizedRecordCustomField < CustomField
|
|
15
|
+
def type_name
|
|
16
|
+
:label_project_plural
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class UpJournalizedRecord < (defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base)
|
|
21
|
+
NOTIFIED = []
|
|
22
|
+
|
|
23
|
+
belongs_to :project
|
|
24
|
+
acts_as_customizable
|
|
25
|
+
|
|
26
|
+
scope :visible, lambda { |user = User.current, _options = {}|
|
|
27
|
+
joins(:project).where(Project.allowed_to_condition(user, :view_issues))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def visible?(user = User.current)
|
|
31
|
+
user.allowed_to?(:view_issues, project)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
up_acts_as_journalized(
|
|
35
|
+
notify: ->(journal) { NOTIFIED << journal.id },
|
|
36
|
+
edit_notes_permission: :edit_issues,
|
|
37
|
+
activity: { type: 'up_records', url: ->(journal) { { controller: 'welcome' } }, title: ->(journal) { "Record #{journal.journalized.name}" } }
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
Redmine::Activity.register :up_records, class_name: 'Redmineup::JournalEvent'
|
|
42
|
+
|
|
43
|
+
class UpActsAsJournalizedRedmineTest < ActiveSupport::TestCase
|
|
44
|
+
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :trackers,
|
|
45
|
+
:issue_statuses, :issues, :journals, :journal_details, :enumerations, :custom_fields, :custom_values,
|
|
46
|
+
:projects_trackers, :watchers, :issue_categories, :versions
|
|
47
|
+
|
|
48
|
+
def setup
|
|
49
|
+
User.current = nil
|
|
50
|
+
UpJournalizedRecord::NOTIFIED.clear
|
|
51
|
+
@project = Project.find(1)
|
|
52
|
+
@user = User.find(2)
|
|
53
|
+
@field = UpJournalizedRecordCustomField.create!(
|
|
54
|
+
name: 'Up tags', field_format: 'list', multiple: true, possible_values: %w(a b c), is_for_all: true
|
|
55
|
+
)
|
|
56
|
+
@record = UpJournalizedRecord.create!(project: @project, name: 'rec', status: 'new')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_attribute_and_notes
|
|
60
|
+
@record.init_journal(@user, 'changed')
|
|
61
|
+
@record.update!(status: 'done', due_date: Date.new(2026, 1, 2))
|
|
62
|
+
|
|
63
|
+
journal = @record.journals.last
|
|
64
|
+
assert_equal 'changed', journal.notes
|
|
65
|
+
assert_equal %w(due_date status), journal.details.map(&:prop_key).sort
|
|
66
|
+
assert_equal 'attr', journal.details.first.property
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_multiple_value_custom_field
|
|
70
|
+
@record.reload
|
|
71
|
+
@record.init_journal(@user)
|
|
72
|
+
@record.custom_field_values = { @field.id.to_s => %w(a b) }
|
|
73
|
+
@record.save!
|
|
74
|
+
|
|
75
|
+
@record.reload
|
|
76
|
+
@record.init_journal(@user)
|
|
77
|
+
@record.custom_field_values = { @field.id.to_s => %w(b c) }
|
|
78
|
+
@record.save!
|
|
79
|
+
|
|
80
|
+
details = @record.journals.order(:id).flat_map { |j| j.details.map { |d| [d.property, d.old_value, d.value] } }
|
|
81
|
+
assert_includes details, ['cf', nil, 'a']
|
|
82
|
+
assert_includes details, ['cf', nil, 'b']
|
|
83
|
+
assert_includes details, ['cf', 'a', nil]
|
|
84
|
+
assert_includes details, ['cf', nil, 'c']
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_notes_only
|
|
88
|
+
@record.init_journal(@user, 'only note')
|
|
89
|
+
@record.save!
|
|
90
|
+
|
|
91
|
+
assert_equal ['only note'], @record.journals.map(&:notes)
|
|
92
|
+
assert_empty @record.journals.first.details
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_unchanged_save_without_notes_has_no_journal
|
|
96
|
+
@record.init_journal(@user)
|
|
97
|
+
@record.save!
|
|
98
|
+
|
|
99
|
+
assert_equal 0, @record.journals.count
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_rollback_leaves_no_journal
|
|
103
|
+
UpJournalizedRecord.transaction do
|
|
104
|
+
@record.init_journal(@user, 'x')
|
|
105
|
+
@record.update!(status: 'done')
|
|
106
|
+
raise ActiveRecord::Rollback
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
assert_equal 0, Journal.where(journalized_type: 'UpJournalizedRecord').count
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_create_with_journalize_create
|
|
113
|
+
UpJournalizedRecord.up_journalized_options = UpJournalizedRecord.up_journalized_options.merge(journalize_create: true)
|
|
114
|
+
record = UpJournalizedRecord.new(project: @project, name: 'new', status: 'open')
|
|
115
|
+
record.init_journal(@user)
|
|
116
|
+
record.save!
|
|
117
|
+
|
|
118
|
+
keys = record.journals.first.details.map(&:prop_key)
|
|
119
|
+
assert_includes keys, 'name'
|
|
120
|
+
assert_includes keys, 'status'
|
|
121
|
+
ensure
|
|
122
|
+
UpJournalizedRecord.up_journalized_options = UpJournalizedRecord.up_journalized_options.except(:journalize_create)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_no_watchers_and_no_issue_mail
|
|
126
|
+
ActionMailer::Base.deliveries.clear
|
|
127
|
+
assert_no_difference 'Watcher.count' do
|
|
128
|
+
@record.init_journal(@user, 'x')
|
|
129
|
+
@record.update!(status: 'done')
|
|
130
|
+
end
|
|
131
|
+
assert_empty ActionMailer::Base.deliveries
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_notify_callback_runs_after_commit
|
|
135
|
+
@record.init_journal(@user, 'x')
|
|
136
|
+
@record.update!(status: 'done')
|
|
137
|
+
|
|
138
|
+
assert_equal [@record.journals.last.id], UpJournalizedRecord::NOTIFIED
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_notify_callback_skipped_when_journal_notify_is_false
|
|
142
|
+
@record.init_journal(@user, 'x').notify = false
|
|
143
|
+
@record.update!(status: 'done')
|
|
144
|
+
|
|
145
|
+
assert_empty UpJournalizedRecord::NOTIFIED
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_issue_journals_are_unaffected
|
|
149
|
+
ActionMailer::Base.deliveries.clear
|
|
150
|
+
Setting.notified_events = %w(issue_updated)
|
|
151
|
+
issue = Issue.find(1)
|
|
152
|
+
issue.init_journal(@user, 'issue note')
|
|
153
|
+
issue.update!(subject: 'changed subject')
|
|
154
|
+
|
|
155
|
+
assert_equal 'issue note', issue.journals.last.notes
|
|
156
|
+
assert_equal 'subject', issue.journals.last.details.first.prop_key
|
|
157
|
+
assert_not_empty ActionMailer::Base.deliveries
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_issue_visible_scope_ignores_journals_of_other_types
|
|
161
|
+
@record.init_journal(@user, 'collision')
|
|
162
|
+
@record.save!
|
|
163
|
+
journal = @record.journals.last
|
|
164
|
+
Journal.where(id: journal.id).update_all(journalized_id: 1)
|
|
165
|
+
|
|
166
|
+
assert_not_includes Journal.visible(@user).pluck(:id), journal.id
|
|
167
|
+
assert_includes Journal.visible(@user).pluck(:id), Journal.where(journalized_type: 'Issue', journalized_id: 1).first.id
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def test_history_hides_custom_field_details_of_invisible_fields
|
|
171
|
+
@field.update!(visible: false, role_ids: [])
|
|
172
|
+
@record.reload
|
|
173
|
+
@record.init_journal(@user)
|
|
174
|
+
@record.custom_field_values = { @field.id.to_s => %w(a) }
|
|
175
|
+
@record.save!
|
|
176
|
+
|
|
177
|
+
journal = @record.journals.last
|
|
178
|
+
assert_equal 1, journal.details.size
|
|
179
|
+
assert_empty journal.visible_details(User.find(2))
|
|
180
|
+
assert_equal 1, journal.visible_details(User.find(1)).size
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_visible_for
|
|
184
|
+
hidden = UpJournalizedRecord.create!(project: Project.find(2), name: 'hidden')
|
|
185
|
+
[@record, hidden].each do |record|
|
|
186
|
+
record.init_journal(@user, 'n')
|
|
187
|
+
record.save!
|
|
188
|
+
end
|
|
189
|
+
Project.find(2).update!(is_public: false)
|
|
190
|
+
Member.where(project_id: 2, user_id: @user.id).delete_all
|
|
191
|
+
|
|
192
|
+
ids = Journal.visible_for(@user).pluck(:journalized_id, :journalized_type)
|
|
193
|
+
assert_includes ids, [@record.id, 'UpJournalizedRecord']
|
|
194
|
+
assert_not_includes ids, [hidden.id, 'UpJournalizedRecord']
|
|
195
|
+
assert Journal.visible_for(@user).all? { |j| j.journalized_type == 'UpJournalizedRecord' }
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def test_activity_event
|
|
199
|
+
@record.init_journal(@user, 'visible note')
|
|
200
|
+
@record.save!
|
|
201
|
+
|
|
202
|
+
fetcher = Redmine::Activity::Fetcher.new(@user)
|
|
203
|
+
fetcher.scope = ['up_records']
|
|
204
|
+
event = fetcher.events(Date.today - 1, Date.today + 1).first
|
|
205
|
+
|
|
206
|
+
assert_equal "Record rec", event.event_title
|
|
207
|
+
assert_equal 'visible note', event.event_description
|
|
208
|
+
assert_equal @record, event.event_group
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_activity_is_limited_to_project
|
|
212
|
+
other = UpJournalizedRecord.create!(project: Project.find(2), name: 'other')
|
|
213
|
+
[@record, other].each do |record|
|
|
214
|
+
record.init_journal(@user, 'n')
|
|
215
|
+
record.save!
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
events = Redmineup::JournalEvent.find_events('up_records', User.find(1), nil, nil, project: Project.find(2))
|
|
219
|
+
assert_equal [other], events.map(&:event_group)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def test_activity_only_notes_and_listed_keys
|
|
223
|
+
@record.init_journal(@user)
|
|
224
|
+
@record.update!(status: 'quiet')
|
|
225
|
+
fetcher = Redmine::Activity::Fetcher.new(@user)
|
|
226
|
+
fetcher.scope = ['up_records']
|
|
227
|
+
assert_empty fetcher.events(Date.today - 1, Date.today + 1)
|
|
228
|
+
|
|
229
|
+
UpJournalizedRecord.up_journalized_options = UpJournalizedRecord.up_journalized_options.merge(activity: UpJournalizedRecord.up_journalized_options[:activity].merge(keys: %w(status)))
|
|
230
|
+
@record.init_journal(@user)
|
|
231
|
+
@record.update!(status: 'loud')
|
|
232
|
+
assert_equal 2, fetcher.events(Date.today - 1, Date.today + 1).size
|
|
233
|
+
ensure
|
|
234
|
+
UpJournalizedRecord.up_journalized_options = UpJournalizedRecord.up_journalized_options.merge(activity: UpJournalizedRecord.up_journalized_options[:activity].except(:keys))
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def test_editable_by_and_update_notes
|
|
238
|
+
@record.init_journal(@user, 'old')
|
|
239
|
+
@record.update!(status: 'x')
|
|
240
|
+
journal = @record.journals.last
|
|
241
|
+
|
|
242
|
+
assert journal.editable_by?(User.find(2))
|
|
243
|
+
assert_not journal.editable_by?(User.anonymous)
|
|
244
|
+
assert journal.up_update_notes(@user, 'new')
|
|
245
|
+
assert_equal 'new', journal.reload.notes
|
|
246
|
+
assert_equal @user.id, journal.updated_by_id if journal.has_attribute?(:updated_by_id)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def test_journal_detail_escapes_deleted_custom_field_values
|
|
250
|
+
detail = JournalDetail.new(property: 'cf', prop_key: '999999', old_value: '<b>old</b>', value: '<script>x</script>')
|
|
251
|
+
html = ApplicationController.new.view_context.up_journal_detail(detail, @record.journals.build)
|
|
252
|
+
|
|
253
|
+
assert_no_match(/<script>|<b>/, html)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def test_journal_detail_text
|
|
257
|
+
@record.init_journal(@user)
|
|
258
|
+
@record.update!(status: 'done')
|
|
259
|
+
detail = @record.journals.last.details.first
|
|
260
|
+
|
|
261
|
+
view = ApplicationController.new.view_context
|
|
262
|
+
assert_match(/new/, view.up_journal_detail(detail, @record.journals.last, no_html: true))
|
|
263
|
+
end
|
|
264
|
+
end
|
data/test/schema.rb
CHANGED
|
@@ -34,6 +34,23 @@ ActiveRecord::Schema.define version: 0 do
|
|
|
34
34
|
t.boolean :private_notes, default: false, null: false
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
create_table :journal_details, force: true do |t|
|
|
38
|
+
t.integer :journal_id, default: 0, null: false
|
|
39
|
+
t.string :property, limit: 30, default: '', null: false
|
|
40
|
+
t.string :prop_key, limit: 30, default: '', null: false
|
|
41
|
+
t.text :old_value
|
|
42
|
+
t.text :value
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
create_table :journalized_things, force: true do |t|
|
|
46
|
+
t.string :name
|
|
47
|
+
t.date :due_date
|
|
48
|
+
t.string :status
|
|
49
|
+
t.integer :comments_count, default: 0
|
|
50
|
+
t.datetime :created_on
|
|
51
|
+
t.datetime :updated_on
|
|
52
|
+
end
|
|
53
|
+
|
|
37
54
|
create_table :tags, force: true do |t|
|
|
38
55
|
t.string :name
|
|
39
56
|
t.string :color
|
|
@@ -150,7 +167,7 @@ ActiveRecord::Schema.define version: 0 do
|
|
|
150
167
|
t.column :viewer_id, :integer
|
|
151
168
|
t.column :viewed_id, :integer
|
|
152
169
|
t.column :viewed_type, :string
|
|
153
|
-
t.column :ip, :string, limit: '
|
|
170
|
+
t.column :ip, :string, limit: '45'
|
|
154
171
|
t.column :created_at, :datetime
|
|
155
172
|
end
|
|
156
173
|
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
2
|
+
|
|
3
|
+
class TagsHelperViewTest < ActionView::TestCase
|
|
4
|
+
include Redmineup::TagsHelper
|
|
5
|
+
include Redmineup::FormTagHelper
|
|
6
|
+
|
|
7
|
+
def stub_tag_url(name)
|
|
8
|
+
"/stub_tags/#{name}" # URL stub for tag_cloud_links(tags, :stub)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_tag_link
|
|
12
|
+
result = tag_link('/tags/error', 'error', count: 3)
|
|
13
|
+
assert_includes result, 'tag-label-color'
|
|
14
|
+
assert_includes result, 'background-color: #'
|
|
15
|
+
assert_includes result, '(3)'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_tag_links
|
|
19
|
+
result = tag_links(['error', 'bug']) { |t| "/tags/#{t}" }
|
|
20
|
+
assert_includes result, 'class="tag_list"'
|
|
21
|
+
assert_nil tag_links([]) { |t| "/tags/#{t}" }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_tag_cloud_links
|
|
25
|
+
result = tag_cloud_links(Issue.tag_counts, :stub)
|
|
26
|
+
assert_includes result, 'class="tag_list"'
|
|
27
|
+
assert_includes result, '/stub_tags/'
|
|
28
|
+
assert_nil tag_cloud_links([], :stub)
|
|
29
|
+
assert_raises(NoMethodError) { tag_cloud_links(Issue.tag_counts, :unknown_xyz) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def with_tag_display(mode, style: 'cloud', counts: true)
|
|
33
|
+
settings = Module.new do
|
|
34
|
+
define_singleton_method(:mode) { mode }
|
|
35
|
+
define_singleton_method(:sidebar_style) { style }
|
|
36
|
+
define_singleton_method(:sidebar_counts?) { counts }
|
|
37
|
+
define_singleton_method(:sort_by) { 'name' }
|
|
38
|
+
define_singleton_method(:sort_order) { 'asc' }
|
|
39
|
+
end
|
|
40
|
+
created = !Object.const_defined?(:RedmineupTags)
|
|
41
|
+
Object.const_set(:RedmineupTags, Module.new) if created
|
|
42
|
+
RedmineupTags.const_set(:TagDisplay, settings)
|
|
43
|
+
yield
|
|
44
|
+
ensure
|
|
45
|
+
RedmineupTags.send(:remove_const, :TagDisplay) if RedmineupTags.const_defined?(:TagDisplay, false)
|
|
46
|
+
Object.send(:remove_const, :RedmineupTags) if created
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_tag_label_without_tags_plugin_is_color
|
|
50
|
+
result = tag_label('x', '#112233')
|
|
51
|
+
assert_includes result, 'tag-label tag-label-color'
|
|
52
|
+
assert_includes result, 'background-color: #112233'
|
|
53
|
+
assert_equal ' ', tag_label_separator
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_tag_label_modes
|
|
57
|
+
with_tag_display('plain') do
|
|
58
|
+
assert_includes tag_label('x', '#112233'), 'tag-label tag-label-plain'
|
|
59
|
+
assert_not_includes tag_label('x', '#112233'), 'background-color'
|
|
60
|
+
end
|
|
61
|
+
with_tag_display('link') do
|
|
62
|
+
assert_equal '<span class="tag-link">x</span>', tag_label('x', '#112233')
|
|
63
|
+
assert_equal ', ', tag_label_separator
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_tag_label_link_and_links
|
|
68
|
+
result = tag_label_link('/tags/error', 'error', count: 3, color: '#abcdef', class: 'x')
|
|
69
|
+
assert_includes result, 'background-color: #abcdef'
|
|
70
|
+
assert_includes result, '(3)'
|
|
71
|
+
assert_includes result, 'class="x"'
|
|
72
|
+
links = tag_label_links(%w[a b]) { |t| "/tags/#{t}" }
|
|
73
|
+
assert_includes links, 'class="tag_list"'
|
|
74
|
+
assert_includes links, '/tags/a'
|
|
75
|
+
assert_nil tag_label_links([]) { |t| "/tags/#{t}" }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_tag_sidebar_cloud_styles
|
|
79
|
+
tags = Issue.tag_counts
|
|
80
|
+
assert_nil tag_sidebar_cloud([], :stub)
|
|
81
|
+
assert_includes tag_sidebar_cloud(tags, :stub), 'class="tags-cloud"'
|
|
82
|
+
with_tag_display('plain', style: 'list') do
|
|
83
|
+
result = tag_sidebar_cloud(tags, :stub)
|
|
84
|
+
assert_includes result, '<ul'
|
|
85
|
+
assert_includes result, 'class="letter"'
|
|
86
|
+
end
|
|
87
|
+
with_tag_display('color', counts: false) do
|
|
88
|
+
assert_not_includes tag_sidebar_cloud(tags, :stub), 'tag-count'
|
|
89
|
+
end
|
|
90
|
+
assert_raises(NoMethodError) { tag_sidebar_cloud(tags, :unknown_xyz) }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_tag_list_field_tag
|
|
94
|
+
result = tag_list_field_tag('issue[tag_list]', ['bug'],
|
|
95
|
+
url: '/auto_completes/taggable_tags',
|
|
96
|
+
width: '60%', tags: false,
|
|
97
|
+
placeholder: '+ add tag')
|
|
98
|
+
assert_includes result, 'name="issue[tag_list][]"'
|
|
99
|
+
assert_includes result, 'style="width: 60%;"'
|
|
100
|
+
assert_includes result, '"width":"style"'
|
|
101
|
+
assert_includes result, '"tags":false'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_tag_list_field_tag_with_default_width
|
|
105
|
+
result = tag_list_field_tag('issue[tag_list]', [],
|
|
106
|
+
url: '/auto_completes/taggable_tags',
|
|
107
|
+
placeholder: '+ add tag')
|
|
108
|
+
assert_includes result, 'style="width: 95%;"'
|
|
109
|
+
assert_includes result, '"width":"style"'
|
|
110
|
+
end
|
|
111
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
require 'rails/all'
|
|
2
2
|
require 'redmineup'
|
|
3
3
|
require 'minitest/autorun'
|
|
4
|
+
require 'minitest/mock'
|
|
4
5
|
|
|
5
6
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
6
7
|
ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
|
7
8
|
ActiveRecord::Base.establish_connection(ENV['DB'].try(:to_sym) || :sqlite)
|
|
8
9
|
|
|
9
10
|
load(File.dirname(__FILE__) + '/schema.rb')
|
|
10
|
-
Dir.glob(File.expand_path('
|
|
11
|
+
Dir.glob(File.expand_path('models/*.rb', __dir__)).each { |f| require f }
|
|
11
12
|
|
|
12
|
-
class ActiveSupport::TestCase
|
|
13
|
+
class ActiveSupport::TestCase # :nodoc:
|
|
13
14
|
include ActiveRecord::TestFixtures
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
gem_fixtures_path = File.dirname(__FILE__) + '/fixtures/'
|
|
17
|
+
respond_to?(:fixture_paths=) ? self.fixture_paths = [gem_fixtures_path] : self.fixture_path = gem_fixtures_path
|
|
16
18
|
|
|
17
19
|
self.use_transactional_tests = true if RUBY_VERSION > '1.9.3'
|
|
18
20
|
self.use_instantiated_fixtures = false
|
|
19
|
-
set_fixture_class :
|
|
20
|
-
set_fixture_class :
|
|
21
|
+
set_fixture_class tags: Redmineup::ActsAsTaggable::Tag
|
|
22
|
+
set_fixture_class taggings: Redmineup::ActsAsTaggable::Tagging
|
|
21
23
|
|
|
22
|
-
set_fixture_class :
|
|
24
|
+
set_fixture_class votable_caches: VotableCache
|
|
23
25
|
fixtures :all
|
|
24
26
|
|
|
25
27
|
def assert_equivalent(expected, actual, message = nil)
|
|
@@ -32,9 +34,8 @@ class ActiveSupport::TestCase #:nodoc:
|
|
|
32
34
|
|
|
33
35
|
def assert_tag_counts(tags, expected_values)
|
|
34
36
|
# Map the tag fixture names to real tag names
|
|
35
|
-
expected_values = expected_values.
|
|
37
|
+
expected_values = expected_values.each_with_object({}) do |(tag, count), hash|
|
|
36
38
|
hash[tags(tag).name] = count
|
|
37
|
-
hash
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
tags.each do |tag|
|
|
@@ -44,14 +45,14 @@ class ActiveSupport::TestCase #:nodoc:
|
|
|
44
45
|
assert_equal value, tag.count, "Expected value of #{value} for #{tag.name}, but was #{tag.count}"
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
return if expected_values.empty?
|
|
49
|
+
|
|
50
|
+
assert false, "The following tag counts were not present: #{expected_values.inspect}"
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
# From Rails trunk
|
|
53
54
|
def assert_difference(expressions, difference = 1, message = nil, &block)
|
|
54
|
-
expression_evaluations = [expressions].flatten.collect{ |expression|
|
|
55
|
+
expression_evaluations = [expressions].flatten.collect { |expression| -> { eval(expression, block.binding) } }
|
|
55
56
|
|
|
56
57
|
original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
|
|
57
58
|
yield
|