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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +7 -18
  4. data/README.md +74 -153
  5. data/Rakefile +1 -1
  6. data/app/assets/images/icons.svg +9 -0
  7. data/app/assets/javascripts/consumer.js +37 -50
  8. data/app/assets/javascripts/consumer_worker.js +219 -0
  9. data/app/assets/javascripts/jquery.colorPicker.min.js +26 -0
  10. data/app/assets/javascripts/select2_helpers.js +12 -0
  11. data/app/assets/stylesheets/calendars.css +0 -3
  12. data/app/assets/stylesheets/redmineup.css +520 -0
  13. data/app/assets/stylesheets/select2.css +2 -2
  14. data/app/views/redmineup/_additional_assets.html.erb +1 -0
  15. data/app/views/redmineup/journals/_history.html.erb +33 -0
  16. data/config/locales/ar.yml +13 -0
  17. data/config/locales/az.yml +13 -0
  18. data/config/locales/bg.yml +13 -0
  19. data/config/locales/bs.yml +13 -0
  20. data/config/locales/ca.yml +13 -0
  21. data/config/locales/cs.yml +1 -0
  22. data/config/locales/da.yml +13 -0
  23. data/config/locales/de.yml +1 -0
  24. data/config/locales/el.yml +13 -0
  25. data/config/locales/en-GB.yml +14 -0
  26. data/config/locales/en.yml +1 -0
  27. data/config/locales/es-PA.yml +14 -0
  28. data/config/locales/es.yml +1 -0
  29. data/config/locales/et.yml +13 -0
  30. data/config/locales/eu.yml +13 -0
  31. data/config/locales/fa.yml +13 -0
  32. data/config/locales/fi.yml +13 -0
  33. data/config/locales/fr.yml +13 -0
  34. data/config/locales/gl.yml +13 -0
  35. data/config/locales/he.yml +13 -0
  36. data/config/locales/hr.yml +13 -0
  37. data/config/locales/hu.yml +13 -0
  38. data/config/locales/id.yml +13 -0
  39. data/config/locales/it.yml +13 -0
  40. data/config/locales/ja.yml +13 -0
  41. data/config/locales/ko.yml +13 -0
  42. data/config/locales/lt.yml +13 -0
  43. data/config/locales/lv.yml +13 -0
  44. data/config/locales/mk.yml +13 -0
  45. data/config/locales/mn.yml +13 -0
  46. data/config/locales/nl.yml +13 -0
  47. data/config/locales/no.yml +13 -0
  48. data/config/locales/pl.yml +13 -0
  49. data/config/locales/pt-BR.yml +13 -0
  50. data/config/locales/pt.yml +13 -0
  51. data/config/locales/ro.yml +13 -0
  52. data/config/locales/ru.yml +2 -1
  53. data/config/locales/sk.yml +13 -0
  54. data/config/locales/sl.yml +13 -0
  55. data/config/locales/sq.yml +13 -0
  56. data/config/locales/sr-YU.yml +13 -0
  57. data/config/locales/sr.yml +13 -0
  58. data/config/locales/sv.yml +13 -0
  59. data/config/locales/ta-IN.yml +13 -0
  60. data/config/locales/th.yml +13 -0
  61. data/config/locales/tr.yml +13 -0
  62. data/config/locales/uk.yml +13 -0
  63. data/config/locales/vi.yml +13 -0
  64. data/config/locales/zh-TW.yml +13 -0
  65. data/config/locales/zh.yml +13 -0
  66. data/config/routes.rb +4 -0
  67. data/doc/CHANGELOG +119 -24
  68. data/doc/active-record-mixins.md +156 -0
  69. data/doc/assets-money-and-utilities.md +71 -0
  70. data/doc/tagging-and-select2.md +115 -0
  71. data/lib/action_cable/connection/rup_connection.rb +17 -0
  72. data/lib/action_cable/server/rup_configuration.rb +1 -9
  73. data/lib/action_cable/server/rup_server.rb +8 -0
  74. data/lib/redmineup/acts_as_journalized/hook.rb +16 -0
  75. data/lib/redmineup/acts_as_journalized/journal_event.rb +30 -0
  76. data/lib/redmineup/acts_as_journalized/journal_patch.rb +87 -0
  77. data/lib/redmineup/acts_as_journalized/up_acts_as_journalized.rb +118 -0
  78. data/lib/redmineup/acts_as_taggable/tag.rb +13 -3
  79. data/lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb +36 -28
  80. data/lib/redmineup/acts_as_viewed/up_acts_as_viewed.rb +8 -3
  81. data/lib/redmineup/currency/formatting.rb +1 -0
  82. data/lib/redmineup/engine.rb +14 -2
  83. data/lib/redmineup/helpers/datetime_helper.rb +23 -0
  84. data/lib/redmineup/helpers/external_assets_helper.rb +14 -6
  85. data/lib/redmineup/helpers/form_tag_helper.rb +44 -0
  86. data/lib/redmineup/helpers/journals_helper.rb +53 -0
  87. data/lib/redmineup/helpers/tags_helper.rb +108 -0
  88. data/lib/redmineup/helpers/test_helper.rb +12 -0
  89. data/lib/redmineup/hooks/views_layouts_hook.rb +1 -5
  90. data/lib/redmineup/money_helper.rb +10 -2
  91. data/lib/redmineup/patches/action_cable_base_patch.rb +13 -8
  92. data/lib/redmineup/patches/action_cable_patch.rb +3 -7
  93. data/lib/redmineup/patches/auto_completes_controller_patch.rb +17 -0
  94. data/lib/redmineup/patches/compatibility/routing_mapper_patch.rb +5 -18
  95. data/lib/redmineup/patches/compatibility/sprite_patch.rb +3 -9
  96. data/lib/redmineup/patches/compatibility_patch.rb +0 -6
  97. data/lib/redmineup/patches/liquid_patch.rb +13 -22
  98. data/lib/redmineup/version.rb +1 -1
  99. data/lib/redmineup.rb +38 -41
  100. data/redmineup.gemspec +1 -1
  101. data/test/acts_as_journalized/up_acts_as_journalized_test.rb +106 -0
  102. data/test/acts_as_taggable/tag_test.rb +12 -9
  103. data/test/acts_as_viewed/rup_acts_as_viewed_test.rb +12 -0
  104. data/test/currency_test.rb +7 -0
  105. data/test/locales_test.rb +12 -0
  106. data/test/models/journal.rb +38 -0
  107. data/test/models/journalized_thing.rb +5 -0
  108. data/test/redmine/acts_as_journalized/journalized_redmine_test.rb +264 -0
  109. data/test/schema.rb +18 -1
  110. data/test/tags_helper_view_test.rb +111 -0
  111. data/test/test_helper.rb +13 -12
  112. metadata +74 -5
  113. data/app/assets/stylesheets/money.css +0 -95
  114. data/lib/redmineup/patches/compatibility/application_controller_patch.rb +0 -32
  115. data/lib/redmineup/patches/compatibility/user_patch.rb +0 -21
@@ -9,5 +9,113 @@ module Redmineup
9
9
  yield tag, classes[index]
10
10
  end
11
11
  end
12
+
13
+ def tag_link(url, tag_name, options = {})
14
+ count = options.delete(:count)
15
+ inner = link_to(tag_name, url, options)
16
+ inner << content_tag('span', "(#{count})", class: 'tag-count') if count
17
+ css = monochrome? ? 'tag-label' : 'tag-label-color'
18
+ style = monochrome? ? {} : { style: "background-color: #{Redmineup::ActsAsTaggable::Tag.color_from_name(tag_name)}" }
19
+ content_tag(:span, inner, { class: css }.merge(style))
20
+ end
21
+
22
+ def tag_separator
23
+ ' '
24
+ end
25
+
26
+ def monochrome?
27
+ @monochrome ||= defined?(RedmineupTags) && !RedmineupTags.use_colors?
28
+ end
29
+
30
+ def tag_links(tag_list, options = {}, &url_block)
31
+ return if tag_list.blank?
32
+ content_tag(:span, class: 'tag_list') do
33
+ safe_join(tag_list.map { |tag| tag_link(url_block.call(tag), tag, options.dup) }, tag_separator)
34
+ end
35
+ end
36
+
37
+ # Renders span.tag_list from an array of tag objects (respond to .name and .count).
38
+ # Resolves URL via `{key}_tag_url(name)` in the current view context.
39
+ #
40
+ # tag_cloud_links(contact.available_tags, :contact) # → contact_tag_url(name)
41
+ # tag_cloud_links(tags_cloud, :people) # → people_tag_url(name)
42
+ def tag_cloud_links(tags, key, options = {})
43
+ return if tags.blank?
44
+ url_method = :"#{key}_tag_url"
45
+ raise NoMethodError, "#{url_method} is not defined in view context" unless respond_to?(url_method, true)
46
+ content_tag(:span, class: 'tag_list') do
47
+ safe_join(tags.map { |tag|
48
+ tag_link(send(url_method, tag.name), tag.name, options.merge(count: tag.count).dup)
49
+ }, tag_separator)
50
+ end
51
+ end
52
+
53
+
54
+ def tag_display_mode
55
+ if defined?(RedmineupTags::TagDisplay)
56
+ RedmineupTags::TagDisplay.mode
57
+ elsif defined?(RedmineupTags) && RedmineupTags.respond_to?(:use_colors?)
58
+ RedmineupTags.use_colors? ? 'color' : 'plain'
59
+ else
60
+ 'color'
61
+ end
62
+ end
63
+
64
+ def tag_label_separator
65
+ tag_display_mode == 'link' ? ', ' : ' '
66
+ end
67
+
68
+ def tag_label(inner, color)
69
+ case tag_display_mode
70
+ when 'color' then content_tag(:span, inner, class: 'tag-label tag-label-color', style: "background-color: #{color}")
71
+ when 'plain' then content_tag(:span, inner, class: 'tag-label tag-label-plain')
72
+ else content_tag(:span, inner, class: 'tag-link')
73
+ end
74
+ end
75
+
76
+ def tag_label_link(url, tag_name, options = {})
77
+ options = options.dup
78
+ count = options.delete(:count)
79
+ color = options.delete(:color) || Redmineup::ActsAsTaggable::Tag.color_from_name(tag_name)
80
+ inner = link_to(tag_name, url, options)
81
+ inner << content_tag('span', "(#{count})", class: 'tag-count') if count
82
+ tag_label(inner, color)
83
+ end
84
+
85
+ def tag_label_links(tag_list, options = {}, &url_block)
86
+ return if tag_list.blank?
87
+
88
+ content_tag(:span, class: 'tag_list') do
89
+ safe_join(Array(tag_list).map { |tag| tag_label_link(url_block.call(tag), tag, options) }, tag_label_separator)
90
+ end
91
+ end
92
+
93
+ def tag_sidebar_cloud(tags, key)
94
+ return if tags.blank?
95
+
96
+ settings = defined?(RedmineupTags::TagDisplay) ? RedmineupTags::TagDisplay : nil
97
+ style = settings ? settings.sidebar_style : 'cloud'
98
+ counts = settings ? settings.sidebar_counts? : true
99
+ sort_by, sort_order = settings ? [settings.sort_by, settings.sort_order] : %w[name asc]
100
+
101
+ url_method = :"#{key}_tag_url"
102
+ raise NoMethodError, "#{url_method} is not defined in view context" unless respond_to?(url_method, true)
103
+
104
+ tags = tags.to_a.sort_by { |tag| sort_by == 'count' ? tag.count.to_i : tag.name.downcase }
105
+ tags.reverse! if sort_order == 'desc'
106
+ group_by_letter = style == 'list' && sort_by == 'name'
107
+ groups = group_by_letter ? tags.group_by { |tag| tag.name.downcase.first } : { nil => tags }
108
+ list_el, item_el = style == 'list' ? %w[ul li] : %w[div span]
109
+ separator = style == 'simple_cloud' ? tag_label_separator : ' '
110
+ content = groups.map do |letter, grouped|
111
+ items = []
112
+ tag_cloud(grouped, (1..8).to_a) do |tag, weight|
113
+ items << content_tag(item_el, tag_label_link(send(url_method, tag.name), tag.name, count: (tag.count if counts && tag.count.to_i > 0), color: (tag.color if tag.respond_to?(:color))), class: "tag-nube-#{weight}", style: ('font-size: 1em;' if style == 'simple_cloud'))
114
+ end
115
+ safe_join([(content_tag(item_el, letter.upcase, class: 'letter') if letter), safe_join(items, separator)])
116
+ end
117
+ content_tag(list_el, safe_join(content), class: 'tags-cloud', style: ('text-align: left;' if style == 'simple_cloud'))
118
+ end
119
+
12
120
  end
13
121
  end
@@ -0,0 +1,12 @@
1
+ module Redmineup
2
+ module TestHelper
3
+ module ClassMethods
4
+ def load_plugin_fixtures(plugin_name, *names)
5
+ fixtures_dir = File.join(Redmine::Plugin.find(plugin_name).directory, 'test', 'fixtures')
6
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, names)
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ ActiveSupport::TestCase.extend Redmineup::TestHelper::ClassMethods
@@ -3,11 +3,7 @@
3
3
  module Redmineup
4
4
  module Hooks
5
5
  class ViewsLayoutsHook < Redmine::Hook::ViewListener
6
- def view_layouts_base_html_head(_context = {})
7
- stylesheet_link_tag(:calendars, plugin: 'redmineup') +
8
- stylesheet_link_tag(:money, plugin: 'redmineup') +
9
- javascript_include_tag(:consumer, plugin: 'redmineup')
10
- end
6
+ render_on :view_layouts_base_html_head, partial: 'redmineup/additional_assets'
11
7
  end
12
8
  end
13
9
  end
@@ -8,11 +8,19 @@ module Redmineup
8
8
  price_to_currency(obj.try(price_field), obj.currency, options).to_s if obj.respond_to?(:currency)
9
9
  end
10
10
 
11
- def prices_collection_by_currency(prices_collection, options = {})
11
+ def prices_formatted_collection(prices_collection, options = {})
12
12
  return [] if prices_collection.blank? || prices_collection == 0
13
13
  prices = prices_collection
14
14
  prices.reject!{|k, v| v.to_i == 0} if options[:hide_zeros]
15
- prices.collect{|k, v| content_tag(:span, price_to_currency(v, k, :symbol => true), :style => "white-space: nowrap;")}.compact
15
+ prices.map { |k, v| price_to_currency(v, k, symbol: true) }.compact
16
+ end
17
+
18
+ def prices_collection_by_currency(prices_collection, options = {})
19
+ formatted_prices = prices_formatted_collection(prices_collection, options)
20
+
21
+ formatted_prices.map do |formatted_price|
22
+ content_tag(:span, formatted_price, :style => "white-space: nowrap;")
23
+ end
16
24
  end
17
25
 
18
26
  def deal_currency_icon(currency)
@@ -1,20 +1,25 @@
1
1
  module Redmineup
2
2
  module Patches
3
3
  module ActionCableBasePatch
4
- def self.included(base)
5
- base.send(:extend, ClassMethods)
6
- delegate :rup_broadcast_to, to: :class
4
+ def self.prepended(base)
5
+ base.extend(ClassMethods)
6
+ base.delegate :rup_broadcast_to, to: :class
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def rup_broadcast_to(klass, model, message)
11
- ActionCable.rup_server(klass).broadcast(broadcasting_for(model), message)
10
+ def rup_broadcast_to(*args)
11
+ # TODO: Remove to 2 args after plugins update
12
+ if args.length == 3
13
+ klass, model, message = args
14
+ ActionCable.rup_server(klass).broadcast(broadcasting_for(model), message)
15
+ else
16
+ model, message = args
17
+ ActionCable.rup_server.broadcast(broadcasting_for(model), message)
18
+ end
12
19
  end
13
20
  end
14
21
  end
15
22
  end
16
23
  end
17
24
 
18
- unless ActionCable::Channel::Base.included_modules.include?(Redmineup::Patches::ActionCableBasePatch)
19
- ActionCable::Channel::Base.send(:include, Redmineup::Patches::ActionCableBasePatch)
20
- end
25
+ ActionCable::Channel::Base.prepend(Redmineup::Patches::ActionCableBasePatch)
@@ -1,10 +1,9 @@
1
1
  module Redmineup
2
2
  module Patches
3
3
  module ActionCablePatch
4
-
5
- def self.included(base)
4
+ def self.prepended(base)
6
5
  base.class_eval do
7
- module_function def rup_server(klass = nil)
6
+ module_function def rup_server(klass = 'ActionCable::Connection::RupConnection')
8
7
  @rup_servers ||= {}
9
8
  return @rup_servers[klass] if @rup_servers[klass]
10
9
 
@@ -14,10 +13,7 @@ module Redmineup
14
13
  end
15
14
  end
16
15
  end
17
-
18
16
  end
19
17
  end
20
18
 
21
- unless ActionCable.included_modules.include?(Redmineup::Patches::ActionCablePatch)
22
- ActionCable.send(:include, Redmineup::Patches::ActionCablePatch)
23
- end
19
+ ActionCable.prepend(Redmineup::Patches::ActionCablePatch)
@@ -0,0 +1,17 @@
1
+ module Redmineup
2
+ module Patches
3
+ module AutoCompletesControllerPatch
4
+ DEFAULT_TAGS_LIMIT = 10
5
+
6
+ def taggable_tags
7
+ limit = params.delete(:limit) || DEFAULT_TAGS_LIMIT
8
+ klass = Object.const_get(params[:taggable_type].camelcase) if params[:taggable_type].present?
9
+
10
+ tags = klass && klass.available_tags(params.merge(limit: limit, name_like: params[:q])) || Redmineup::ActsAsTaggable::Tag.limit(limit)
11
+ render json: tags.map { |tag| { id: tag.name, text: tag.name } }
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ AutoCompletesController.prepend(Redmineup::Patches::AutoCompletesControllerPatch)
@@ -2,28 +2,15 @@ module Redmineup
2
2
  module Patches
3
3
  module Compatibility
4
4
  module RoutingMapperPatch
5
- def self.included(base)
6
- base.send(:include, InstanceMethods)
5
+ def constraints(options = {}, &block)
6
+ return super(options, &block) unless options.is_a?(Hash)
7
7
 
8
- base.class_eval do
9
- alias_method :constraints_without_redmineup, :constraints
10
- alias_method :constraints, :constraints_with_redmineup
11
- end
12
- end
13
-
14
- module InstanceMethods
15
- def constraints_with_redmineup(options = {}, &block)
16
- return constraints_without_redmineup(options, &block) unless options.is_a?(Hash)
17
-
18
- options[:object_type] = /.+/ if options[:object_type] && options[:object_type].is_a?(Regexp)
19
- constraints_without_redmineup(options, &block)
20
- end
8
+ options[:object_type] = /.+/ if options[:object_type] && options[:object_type].is_a?(Regexp)
9
+ super(options, &block)
21
10
  end
22
11
  end
23
12
  end
24
13
  end
25
14
  end
26
15
 
27
- unless ActionDispatch::Routing::Mapper.included_modules.include?(Redmineup::Patches::Compatibility::RoutingMapperPatch)
28
- ActionDispatch::Routing::Mapper.send(:include, Redmineup::Patches::Compatibility::RoutingMapperPatch)
29
- end
16
+ ActionDispatch::Routing::Mapper.prepend(Redmineup::Patches::Compatibility::RoutingMapperPatch)
@@ -2,18 +2,12 @@ module Redmineup
2
2
  module Patches
3
3
  module Compatibility
4
4
  module SpritePatch
5
- def self.included(base)
6
- base.class_eval do
7
- def sprite_icon(icon_name, label = nil, icon_only: false, size: '18', css_class: nil, sprite: "icons", plugin: nil, rtl: false)
8
- label
9
- end
10
- end
5
+ def sprite_icon(icon_name, label = '', icon_only: false, size: '18', css_class: nil, sprite: "icons", plugin: nil, rtl: false)
6
+ label
11
7
  end
12
8
  end
13
9
  end
14
10
  end
15
11
  end
16
12
 
17
- unless ApplicationHelper.included_modules.include?(Redmineup::Patches::Compatibility::SpritePatch)
18
- ApplicationHelper.send(:include, Redmineup::Patches::Compatibility::SpritePatch)
19
- end
13
+ ApplicationHelper.prepend(Redmineup::Patches::Compatibility::SpritePatch)
@@ -1,9 +1,3 @@
1
- if Redmine::VERSION.to_s < "4"
2
- require 'redmineup/patches/compatibility/application_controller_patch'
3
- end
4
- if Redmine::VERSION.to_s < "5"
5
- require 'redmineup/patches/compatibility/user_patch'
6
- end
7
1
  if Redmine::VERSION.to_s < "6"
8
2
  require 'redmineup/patches/compatibility/sprite_patch'
9
3
  end
@@ -2,32 +2,23 @@ module Redmineup
2
2
  module Patches
3
3
  module LiquidPatch
4
4
  module StandardFilters
5
+ private
5
6
 
6
- def self.included(base)
7
- base.class_eval do
8
-
9
- private
10
-
11
- def to_number(obj)
12
- case obj
13
- when Float
14
- BigDecimal(obj.to_s)
15
- when Numeric
16
- obj
17
- when String
18
- (obj.strip =~ /^\d+\.\d+$/) ? BigDecimal(obj) : obj.to_i
19
- else
20
- 0
21
- end
22
- end
7
+ def to_number(obj)
8
+ case obj
9
+ when Float
10
+ BigDecimal(obj.to_s)
11
+ when Numeric
12
+ obj
13
+ when String
14
+ (obj.strip =~ /^\d+\.\d+$/) ? BigDecimal(obj) : obj.to_i
15
+ else
16
+ 0
23
17
  end
24
18
  end
25
-
26
19
  end
27
20
  end
28
21
  end
29
22
  end
30
-
31
- unless Liquid::StandardFilters.included_modules.include?(Redmineup::Patches::LiquidPatch::StandardFilters)
32
- Liquid::StandardFilters.send(:include, Redmineup::Patches::LiquidPatch::StandardFilters)
33
- end
23
+
24
+ Liquid::StandardFilters.prepend(Redmineup::Patches::LiquidPatch::StandardFilters)
@@ -1,3 +1,3 @@
1
1
  module Redmineup
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.18'
3
3
  end
data/lib/redmineup.rb CHANGED
@@ -20,6 +20,7 @@ require 'redmineup/acts_as_votable/voter'
20
20
  require 'redmineup/acts_as_draftable/up_acts_as_draftable'
21
21
  require 'redmineup/acts_as_draftable/draft'
22
22
  require 'redmineup/acts_as_priceable/up_acts_as_priceable'
23
+ require 'redmineup/acts_as_journalized/up_acts_as_journalized'
23
24
 
24
25
  require 'redmineup/currency'
25
26
  require 'redmineup/helpers/tags_helper'
@@ -42,8 +43,11 @@ require 'redmineup/liquid/drops/version_drop'
42
43
  require 'redmineup/liquid/drops/custom_field_enumeration_drop'
43
44
 
44
45
  require 'redmineup/helpers/external_assets_helper'
46
+ require 'redmineup/helpers/journals_helper'
45
47
  require 'redmineup/helpers/form_tag_helper'
46
48
  require 'redmineup/helpers/calendars_helper'
49
+ require 'redmineup/helpers/datetime_helper'
50
+ require 'redmineup/helpers/test_helper'
47
51
  require 'redmineup/assets_manager'
48
52
 
49
53
  require 'redmineup/patches/liquid_patch'
@@ -65,6 +69,7 @@ require 'application_record' if !defined?(ApplicationRecord) && Rails.version <
65
69
  if Redmineup.cable_available?
66
70
  require 'action_cable/server/rup_configuration'
67
71
  require 'action_cable/server/rup_server'
72
+ require 'action_cable/connection/rup_connection'
68
73
  require 'redmineup/patches/action_cable_base_patch'
69
74
  require 'redmineup/patches/action_cable_patch'
70
75
  end
@@ -77,13 +82,25 @@ end
77
82
 
78
83
  if defined?(Propshaft::Assembly)
79
84
  Propshaft::Assembly.prepend(Module.new do
80
- def initialize(config)
81
- base_dir = Pathname.new(Redmineup::AssetsManager.base_path)
82
- paths = Redmineup::AssetsManager.assets_paths.map { |path| Pathname.new(path)}
83
- asset_prefix = "plugin_assets/#{Redmineup::GEM_NAME}"
85
+ def self.prepended(base)
86
+ base.class_eval do
87
+ cattr_accessor :redmineup_patched
88
+ end
89
+ end
90
+
91
+ def config
92
+ return super if self.class.redmineup_patched
93
+
94
+ original_config = super
95
+ if defined?(Redmine::AssetPath)
96
+ base_dir = Pathname.new(Redmineup::AssetsManager.base_path)
97
+ paths = Redmineup::AssetsManager.assets_paths.map { |path| Pathname.new(path)}
98
+ asset_prefix = "plugin_assets/#{Redmineup::GEM_NAME}"
84
99
 
85
- config[:redmine_extension_paths] << Redmine::AssetPath.new(base_dir, paths, asset_prefix)
86
- super
100
+ original_config[:redmine_extension_paths] << Redmine::AssetPath.new(base_dir, paths, asset_prefix)
101
+ self.class.redmineup_patched = true
102
+ end
103
+ original_config
87
104
  end
88
105
  end)
89
106
  else
@@ -94,47 +111,27 @@ if defined?(ActionView::Base)
94
111
  ActionView::Base.send :include, Redmineup::CalendarsHelper
95
112
  ActionView::Base.send :include, Redmineup::ExternalAssetsHelper
96
113
  ActionView::Base.send :include, Redmineup::FormTagHelper
114
+ ActionView::Base.send :include, Redmineup::JournalsHelper
115
+ ActionView::Base.send :include, Redmineup::TagsHelper
97
116
  end
98
117
 
99
118
  def requires_redmineup(arg)
100
- def compare_versions(requirement, current)
101
- raise ArgumentError.new('wrong version format') unless check_version_format(requirement)
102
-
103
- requirement = requirement.split('.').collect(&:to_i)
104
- requirement <=> current.slice(0, requirement.size)
105
- end
119
+ arg = { version_or_higher: arg } unless arg.is_a?(Hash)
120
+ arg.assert_valid_keys(:version_or_higher)
106
121
 
107
- def check_version_format(version)
108
- version =~ /^\d+.?\d*.?\d*$/m
122
+ requirement = arg[:version_or_higher]
123
+ unless requirement.is_a?(String)
124
+ raise ArgumentError, ':version_or_higher accepts a version string only'
109
125
  end
110
126
 
111
- arg = { version_or_higher: arg } unless arg.is_a?(Hash)
112
- arg.assert_valid_keys(:version, :version_or_higher)
127
+ current = Gem::Version.new(Redmineup::VERSION)
128
+ required = Gem::Version.new(requirement)
113
129
 
114
- current = Redmineup::VERSION.split('.').map { |x| x.to_i }
115
- arg.each do |k, req|
116
- case k
117
- when :version_or_higher
118
- raise ArgumentError.new(':version_or_higher accepts a version string only') unless req.is_a?(String)
130
+ return true if required <= current
119
131
 
120
- unless compare_versions(req, current) <= 0
121
- Rails.logger.error "\033[31m[ERROR]\033[0m Redmine requires redmineup gem version #{req} or higher (you're using #{Redmineup::VERSION}).\n\033[31m[ERROR]\033[0m Please update with 'bundle update redmineup'." if Rails.logger
122
- abort "\033[31mRedmine requires redmineup gem version #{req} or higher (you're using #{Redmineup::VERSION}).\nPlease update with 'bundle update redmineup'.\033[0m"
123
- end
124
- when :version
125
- req = [req] if req.is_a?(String)
126
- if req.is_a?(Array)
127
- unless req.detect { |ver| compare_versions(ver, current) == 0 }
128
- abort "\033[31mRedmine requires redmineup gem version #{req} (you're using #{Redmineup::VERSION}).\nPlease update with 'bundle update redmineup'.\033[0m"
129
- end
130
- elsif req.is_a?(Range)
131
- unless compare_versions(req.first, current) <= 0 && compare_versions(req.last, current) >= 0
132
- abort "\033[31mRedmine requires redmineup gem version between #{req.first} and #{req.last} (you're using #{Redmineup::VERSION}).\nPlease update with 'bundle update redmineup'.\033[0m"
133
- end
134
- else
135
- raise ArgumentError.new(':version option accepts a version string, an array or a range of versions')
136
- end
137
- end
138
- end
139
- true
132
+ message = "Redmine requires redmineup gem version #{requirement} or higher " \
133
+ "(you're using #{Redmineup::VERSION}).\n" \
134
+ "Please update with 'bundle update redmineup --conservative'."
135
+ Rails.logger&.error("\033[31m[ERROR]\033[0m #{message}")
136
+ abort "\033[31m#{message}\033[0m"
140
137
  end
data/redmineup.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://www.redmineup.com"
14
14
  spec.license = "GPL-2.0"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?("doc/dev/") || %w[AGENTS.md GLOSSARY.md].include?(f) }
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class UpActsAsJournalizedTest < ActiveSupport::TestCase
4
+ def setup
5
+ @user = User.first || User.create!(login: 'journalist')
6
+ @thing = JournalizedThing.create!(name: 'one', status: 'new')
7
+ end
8
+
9
+ def test_attribute_change_is_journaled
10
+ @thing.init_journal(@user, 'why')
11
+ @thing.update!(status: 'done')
12
+
13
+ journal = @thing.journals.last
14
+ assert_equal 'why', journal.notes
15
+ assert_equal [%w(status new done)], journal.details.map { |d| [d.prop_key, d.old_value, d.value] }
16
+ end
17
+
18
+ def test_repeated_edits_keep_every_step
19
+ %w(a b c).each do |status|
20
+ @thing.init_journal(@user)
21
+ @thing.update!(status: status)
22
+ end
23
+
24
+ assert_equal 3, @thing.journals.count
25
+ assert_equal [%w(new a), %w(a b), %w(b c)], @thing.journals.order(:id).map { |j| [j.details.first.old_value, j.details.first.value] }
26
+ end
27
+
28
+ def test_several_changes_make_one_journal
29
+ @thing.init_journal(@user)
30
+ @thing.update!(status: 'done', due_date: Date.new(2026, 1, 1))
31
+
32
+ assert_equal 1, @thing.journals.count
33
+ assert_equal %w(due_date status), @thing.journals.first.details.map(&:prop_key).sort
34
+ end
35
+
36
+ def test_notes_only_journal
37
+ @thing.init_journal(@user, 'just a note')
38
+ @thing.save!
39
+
40
+ assert_equal 1, @thing.journals.count
41
+ assert_empty @thing.journals.first.details
42
+ end
43
+
44
+ def test_unchanged_save_without_notes_makes_no_journal
45
+ @thing.init_journal(@user)
46
+ @thing.save!
47
+
48
+ assert_equal 0, @thing.journals.count
49
+ end
50
+
51
+ def test_no_journal_without_init_journal
52
+ @thing.update!(status: 'done')
53
+
54
+ assert_equal 0, @thing.journals.count
55
+ end
56
+
57
+ def test_rollback_leaves_no_journal
58
+ JournalizedThing.transaction do
59
+ @thing.init_journal(@user, 'x')
60
+ @thing.update!(status: 'done')
61
+ raise ActiveRecord::Rollback
62
+ end
63
+
64
+ assert_equal 0, Journal.where(journalized_type: 'JournalizedThing').count
65
+ end
66
+
67
+ def test_create_is_not_journaled_by_default
68
+ thing = JournalizedThing.new(name: 'two', status: 'new')
69
+ thing.init_journal(@user)
70
+ thing.save!
71
+
72
+ assert_equal 0, thing.journals.count
73
+ end
74
+
75
+ def test_excluded_and_counter_attributes_are_not_tracked
76
+ names = @thing.journalized_attribute_names
77
+
78
+ assert_includes names, 'status'
79
+ assert_not_includes names, 'id'
80
+ assert_not_includes names, 'updated_on'
81
+ assert_not_includes names, 'comments_count'
82
+ end
83
+
84
+ def test_destroy_deletes_journals
85
+ @thing.init_journal(@user, 'x')
86
+ @thing.update!(status: 'done')
87
+
88
+ assert_difference('Journal.count', -1) { @thing.destroy }
89
+ end
90
+
91
+ def test_unknown_option_is_rejected
92
+ assert_raises(ArgumentError) { Class.new(ActiveRecord::Base) { self.table_name = 'journalized_things'; up_acts_as_journalized foo: 1 } }
93
+ end
94
+
95
+ def test_activity_needs_url
96
+ assert_raises(ArgumentError) { Class.new(ActiveRecord::Base) { self.table_name = 'journalized_things'; up_acts_as_journalized activity: {} } }
97
+ end
98
+
99
+ def test_custom_field_values_fallback
100
+ assert_equal [], @thing.custom_field_values
101
+ end
102
+
103
+ def test_registered
104
+ assert_includes Redmineup::ActsAsJournalized.registry, 'JournalizedThing'
105
+ end
106
+ end
@@ -34,16 +34,19 @@ class TagTest < ActiveSupport::TestCase
34
34
  end
35
35
 
36
36
  def test_color
37
- colors = %w(#aaaaaa #bbbbbb)
38
- colorized = [tags(:bug), tags(:feature)]
39
- colorized.each do |tag|
40
- assert_equal colors.include?(tag.color), true
41
- end
37
+ assert_equal '#aaaaaa', tags(:feature).color # 11184810 = 0xaaaaaa
38
+ assert_equal '#bbbbbb', tags(:bug).color # 12303291 = 0xbbbbbb
39
+ # no DB color — falls back to color_from_name, not nil
40
+ assert_equal Redmineup::ActsAsTaggable::Tag.color_from_name('error'), tags(:error).color
41
+ assert_equal Redmineup::ActsAsTaggable::Tag.color_from_name('question'), tags(:question).color
42
+ end
42
43
 
43
- not_colorized = [tags(:error), tags(:question)]
44
- not_colorized.each do |tag|
45
- assert_nil tag.color
46
- end
44
+ def test_color_from_name
45
+ color = Redmineup::ActsAsTaggable::Tag.color_from_name('error')
46
+ assert_match(/\A#[0-9a-f]{6}\z/, color)
47
+ assert_equal color, Redmineup::ActsAsTaggable::Tag.color_from_name('error') # deterministic
48
+ assert_not_equal color, Redmineup::ActsAsTaggable::Tag.color_from_name('other')
49
+ assert_match(/\A#[0-9a-f]{6}\z/, Redmineup::ActsAsTaggable::Tag.color_from_name(nil))
47
50
  end
48
51
 
49
52
  def test_tag_is_equal_to_itself
@@ -44,4 +44,16 @@ class RupActsAsViewedTest < ActiveSupport::TestCase
44
44
  issue.view '127.0.0.1', user
45
45
  assert_equal [issue], Issue.find_viewed_by(user)
46
46
  end
47
+
48
+ def test_viewer_subclass_loaded_before_the_macro_gets_viewings
49
+ Object.const_set(:TmpViewer, Class.new(ActiveRecord::Base) { self.table_name = 'users' })
50
+ Object.const_set(:TmpViewerChild, Class.new(TmpViewer) { has_many :own_issues, class_name: 'Issue', foreign_key: :author_id })
51
+ viewed = Class.new(ActiveRecord::Base) { self.table_name = 'issues'; def self.name; 'TmpViewed'; end }
52
+ viewed.up_acts_as_viewed(viewer_class: 'TmpViewer')
53
+ assert TmpViewer.reflect_on_association(:viewings)
54
+ assert TmpViewerChild.reflect_on_association(:viewings), 'subclass has no viewings association'
55
+ ensure
56
+ Object.send(:remove_const, :TmpViewerChild) if Object.const_defined?(:TmpViewerChild)
57
+ Object.send(:remove_const, :TmpViewer) if Object.const_defined?(:TmpViewer)
58
+ end
47
59
  end
@@ -283,6 +283,13 @@ module Redmineup
283
283
  assert Currency.new(:usd).decimal_places == 2
284
284
  end
285
285
 
286
+ def test_format_zero_decimal_currency_has_no_fraction
287
+ assert_equal '₩3,500,000', Currency.format(3500000, Currency.new(:krw))
288
+ assert_equal '¥1,200', Currency.format(1200, Currency.new(:jpy))
289
+ assert_equal '₫3.500.000', Currency.format(3500000, Currency.new(:vnd))
290
+ assert_equal '$1,234.50', Currency.format(1234.5, Currency.new(:usd))
291
+ end
292
+
286
293
  def test_proper_place_for_custom_currency
287
294
  register_foo
288
295
  assert_equal 2, Currency.new(:foo).decimal_places