redmine_crm 0.0.38 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/doc/CHANGELOG +6 -0
- data/lib/redmine_crm.rb +3 -0
- data/lib/redmine_crm/acts_as_draftable/rcrm_acts_as_draftable.rb +31 -16
- data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +5 -5
- data/lib/redmine_crm/compatibility/application_controller_patch.rb +29 -0
- data/lib/redmine_crm/currency/loader.rb +4 -5
- data/lib/redmine_crm/liquid/drops/issues_drop.rb +105 -1
- data/lib/redmine_crm/liquid/drops/projects_drop.rb +1 -1
- data/lib/redmine_crm/liquid/drops/time_entries_drop.rb +64 -0
- data/lib/redmine_crm/money_helper.rb +2 -2
- data/lib/redmine_crm/version.rb +1 -1
- data/test/acts_as_draftable/draft_test.rb +3 -3
- data/test/acts_as_draftable/rcrm_acts_as_draftable_test.rb +34 -40
- data/test/schema.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cec54924c890caa40b9affa944a8cf4186e4ca7c
|
4
|
+
data.tar.gz: 1b0b5395bc2f1e5f2c03ee4504725a6cbb153b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cbb08c06c06fa75356b93d25a23483f776b1c96a9f505f1ace7a54ae6123057dc1972145a93dd0632cf3ac8c8260c88513ec9d333f5912d4c39653d5a1c7406
|
7
|
+
data.tar.gz: 29c51f79b3d048c7d4ad59ff48be8f2757c85230fb1b5aa082fa4d07033d867142f3331d804363c10567d0f7aadfca404f273570f0056eb6ae440d7cb6291e60
|
data/README.md
CHANGED
@@ -73,7 +73,7 @@ puts message.save_draft
|
|
73
73
|
# => true
|
74
74
|
|
75
75
|
# You can also save draft linked to a particular user.
|
76
|
-
Message.new(subject: 'baz').save_draft(current_user)
|
76
|
+
Message.new(subject: 'baz').save_draft(user: current_user)
|
77
77
|
|
78
78
|
# And restore message from some user's draft.
|
79
79
|
user_draft = Message.drafts(current_user).last
|
@@ -94,9 +94,15 @@ user_message.save!
|
|
94
94
|
puts Message.drafts(current_user).count
|
95
95
|
# => 0
|
96
96
|
|
97
|
-
#
|
98
|
-
puts
|
97
|
+
# Drafts will be saved only for new (not persisted) or changed instances.
|
98
|
+
puts Message.new.save_draft
|
99
|
+
# => true
|
100
|
+
persisted = Message.last
|
101
|
+
puts persisted.save_draft
|
99
102
|
# => false
|
103
|
+
persisted.subject = 'other subject'
|
104
|
+
puts persisted.save_draft
|
105
|
+
# => true
|
100
106
|
```
|
101
107
|
|
102
108
|
### Tags
|
data/doc/CHANGELOG
CHANGED
@@ -4,6 +4,12 @@ Redmine crm gem - general functions for plugins (tags, vote, viewing, currency)
|
|
4
4
|
Copyright (C) 2011-2018 RedmineUP
|
5
5
|
https://www.redmineup.com/
|
6
6
|
|
7
|
+
== 2018-09-28 v0.0.40
|
8
|
+
|
9
|
+
* acts_as_draftable adopted for Redmine projects
|
10
|
+
* New Liquid Drops: JournalsDrop, JournalDrop, TimeEntriesDrop, TimeEntryDrop
|
11
|
+
* New liquid properties for issues: done_ratio, estimated_hours, spent_hours, total_spent_hours, total_estimated_hours, is_private, closed_on, assignee, tracker, status, priority, category, version, time_entries, parent, project, subtasks, notes, journals
|
12
|
+
|
7
13
|
== 2018-03-28 v0.0.37
|
8
14
|
|
9
15
|
* Added rcrm_acts_as_draftable
|
data/lib/redmine_crm.rb
CHANGED
@@ -27,11 +27,14 @@ require 'redmine_crm/liquid/drops/issues_drop'
|
|
27
27
|
require 'redmine_crm/liquid/drops/news_drop'
|
28
28
|
require 'redmine_crm/liquid/drops/projects_drop'
|
29
29
|
require 'redmine_crm/liquid/drops/users_drop'
|
30
|
+
require 'redmine_crm/liquid/drops/time_entries_drop'
|
30
31
|
|
31
32
|
require 'redmine_crm/helpers/external_assets_helper'
|
32
33
|
require 'redmine_crm/helpers/form_tag_helper'
|
33
34
|
require 'redmine_crm/assets_manager'
|
34
35
|
|
36
|
+
require 'redmine_crm/compatibility/application_controller_patch'
|
37
|
+
|
35
38
|
module RedmineCrm
|
36
39
|
GEM_NAME = 'redmine_crm'.freeze
|
37
40
|
end
|
@@ -55,7 +55,7 @@ module RedmineCrm
|
|
55
55
|
end
|
56
56
|
|
57
57
|
attr_accessor :draft_id
|
58
|
-
|
58
|
+
before_save :clear_draft
|
59
59
|
|
60
60
|
extend RedmineCrm::ActsAsDraftable::ClassMethods
|
61
61
|
include RedmineCrm::ActsAsDraftable::InstanceMethods
|
@@ -74,39 +74,56 @@ module RedmineCrm
|
|
74
74
|
target = draft.target_type.constantize.new
|
75
75
|
target.load_from_draft(draft.data)
|
76
76
|
|
77
|
-
target.send("#{draft_parent}=", draft.parent) if draft_parent
|
78
77
|
target.draft_id = draft.id
|
79
78
|
target
|
80
79
|
end
|
81
80
|
|
82
81
|
def drafts(user)
|
83
|
-
Draft.where(
|
82
|
+
Draft.where(user_id: user.id, target_type: name)
|
84
83
|
end
|
85
84
|
end # ClassMethods
|
86
85
|
|
87
86
|
module InstanceMethods
|
88
|
-
def save_draft
|
89
|
-
return false unless
|
90
|
-
|
91
|
-
draft = Draft.find_by_id(self.draft_id) || Draft.new
|
87
|
+
def save_draft
|
88
|
+
return false unless new_record? || changed?
|
92
89
|
|
90
|
+
draft = self.draft || Draft.new
|
93
91
|
draft.data = dump_to_draft
|
92
|
+
draft.user_id = User.current.try(:id)
|
93
|
+
draft.parent = parent_for_draft
|
94
94
|
draft.target_type = self.class.name
|
95
|
-
draft.user = user
|
96
|
-
draft.parent = self.send(self.class.draft_parent) if self.class.draft_parent
|
97
95
|
|
98
96
|
result = draft.save
|
99
97
|
self.draft_id = draft.id if result
|
100
98
|
result
|
101
99
|
end
|
102
100
|
|
103
|
-
def update_draft(
|
101
|
+
def update_draft(attributes)
|
104
102
|
with_transaction_returning_status do
|
105
103
|
assign_attributes(attributes)
|
106
|
-
save_draft
|
104
|
+
save_draft
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
108
|
+
def draft
|
109
|
+
Draft.find_by_id(draft_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
def parent_for_draft
|
113
|
+
return self if id.present?
|
114
|
+
|
115
|
+
self.class.draft_parent.present? ? send(self.class.draft_parent) : self
|
116
|
+
end
|
117
|
+
|
118
|
+
def last_draft
|
119
|
+
@last_draft ||= RedmineCrm::ActsAsDraftable::Draft.where(
|
120
|
+
target_type: self.class.name,
|
121
|
+
parent_type: parent_for_draft.try(:class).try(:to_s),
|
122
|
+
parent_id: parent_for_draft.try(:id),
|
123
|
+
user_id: User.current.try(:id)
|
124
|
+
).last
|
125
|
+
end
|
126
|
+
|
110
127
|
def dump_to_draft
|
111
128
|
Marshal.dump(instance_values)
|
112
129
|
end
|
@@ -119,11 +136,9 @@ module RedmineCrm
|
|
119
136
|
end
|
120
137
|
end
|
121
138
|
|
122
|
-
private
|
123
|
-
|
124
139
|
def clear_draft
|
125
|
-
if
|
126
|
-
self.draft_id = nil
|
140
|
+
if last_draft && last_draft.destroy
|
141
|
+
self.draft_id = nil
|
127
142
|
end
|
128
143
|
end
|
129
144
|
end # InstanceMethods
|
@@ -135,7 +150,7 @@ module RedmineCrm
|
|
135
150
|
connection.create_table :drafts do |t|
|
136
151
|
t.string :target_type, limit: 150, null: false
|
137
152
|
t.references :user
|
138
|
-
t.references :parent, polymorphic: true
|
153
|
+
t.references :parent, polymorphic: true
|
139
154
|
t.binary :data, limit: 16777215, null: false
|
140
155
|
t.datetime :updated_at, null: false
|
141
156
|
end
|
@@ -104,8 +104,8 @@ module RedmineCrm
|
|
104
104
|
self.acts_as_viewed_options = { :viewing_class => viewing_class,
|
105
105
|
:viewer_class => viewer_class }
|
106
106
|
class_eval do
|
107
|
-
has_many :viewings, :
|
108
|
-
has_many
|
107
|
+
has_many :viewings, as: :viewed, dependent: :delete_all, class_name: viewing_class.to_s
|
108
|
+
has_many :viewers, through: :viewings, class_name: viewer_class.to_s
|
109
109
|
|
110
110
|
before_create :init_viewing_fields
|
111
111
|
end
|
@@ -113,9 +113,9 @@ module RedmineCrm
|
|
113
113
|
# Add to the User (or whatever the viewer is) a has_many viewings
|
114
114
|
viewer_as_class = viewer_class.constantize
|
115
115
|
return if viewer_as_class.instance_methods.include?('find_in_viewings')
|
116
|
-
viewer_as_class.class_eval
|
117
|
-
has_many :viewings, foreign_key: :viewer_id, class_name:
|
118
|
-
|
116
|
+
viewer_as_class.class_eval do
|
117
|
+
has_many :viewings, foreign_key: :viewer_id, class_name: viewing_class.to_s, dependent: :delete_all
|
118
|
+
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RedmineCrm
|
2
|
+
module Patches
|
3
|
+
module ApplicationControllerPatch
|
4
|
+
def self.included(base) # :nodoc:
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
base.class_eval do
|
7
|
+
unloadable # Send unloadable so it will not be unloaded in development
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def before_action(*filters, &block)
|
13
|
+
before_filter(*filters, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def skip_before_action(*filters, &block)
|
17
|
+
skip_before_filter(*filters, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
unless ActionController::Base.methods.include?(:before_action)
|
25
|
+
ActionController::Base.send(
|
26
|
+
:include,
|
27
|
+
RedmineCrm::Patches::ApplicationControllerPatch
|
28
|
+
)
|
29
|
+
end
|
@@ -3,13 +3,12 @@ module RedmineCrm
|
|
3
3
|
module Loader
|
4
4
|
DATA_PATH = File.expand_path("../../../../config", __FILE__)
|
5
5
|
|
6
|
-
# Loads and returns the currencies stored in JSON files
|
6
|
+
# Loads and returns the currencies stored in JSON files
|
7
|
+
# in the config directory.
|
7
8
|
#
|
8
9
|
# @return [Hash]
|
9
10
|
def load_currencies
|
10
|
-
|
11
|
-
# currencies.merge! parse_currency_file("currency_non_iso.json")
|
12
|
-
# currencies.merge! parse_currency_file("currency_backwards_compatible.json")
|
11
|
+
parse_currency_file('currency_iso.json')
|
13
12
|
end
|
14
13
|
|
15
14
|
private
|
@@ -17,7 +16,7 @@ module RedmineCrm
|
|
17
16
|
def parse_currency_file(filename)
|
18
17
|
json = File.read("#{DATA_PATH}/#{filename}")
|
19
18
|
json.force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
|
20
|
-
JSON.parse(json, :
|
19
|
+
JSON.parse(json, symbolize_names: true)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
@@ -16,6 +16,10 @@ module RedmineCrm
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def visible
|
20
|
+
@visible ||= @all.select(&:visible?)
|
21
|
+
end
|
22
|
+
|
19
23
|
def each(&block)
|
20
24
|
all.each(&block)
|
21
25
|
end
|
@@ -36,7 +40,13 @@ module RedmineCrm
|
|
36
40
|
:start_date,
|
37
41
|
:due_date,
|
38
42
|
:overdue?,
|
39
|
-
:
|
43
|
+
:done_ratio,
|
44
|
+
:estimated_hours,
|
45
|
+
:spent_hours,
|
46
|
+
:total_spent_hours,
|
47
|
+
:total_estimated_hours,
|
48
|
+
:is_private?,
|
49
|
+
:closed_on,
|
40
50
|
:updated_on,
|
41
51
|
:created_on,
|
42
52
|
:to => :@issue
|
@@ -57,10 +67,104 @@ module RedmineCrm
|
|
57
67
|
@user ||= UserDrop.new(@issue.author)
|
58
68
|
end
|
59
69
|
|
70
|
+
def assignee
|
71
|
+
@assignee ||= UserDrop.new(@issue.assigned_to)
|
72
|
+
end
|
73
|
+
|
74
|
+
def tracker
|
75
|
+
@tracker ||= @issue.tracker && @issue.tracker.name
|
76
|
+
end
|
77
|
+
|
78
|
+
def status
|
79
|
+
@status ||= @issue.status && @issue.status.name
|
80
|
+
end
|
81
|
+
|
82
|
+
def priority
|
83
|
+
@priority ||= @issue.priority && @issue.priority.name
|
84
|
+
end
|
85
|
+
|
86
|
+
def category
|
87
|
+
@category ||= @issue.category && @issue.category.name
|
88
|
+
end
|
89
|
+
|
90
|
+
def version
|
91
|
+
@version ||= @issue.fixed_version && @issue.fixed_version.name
|
92
|
+
end
|
93
|
+
|
94
|
+
def time_entries
|
95
|
+
@time_entries ||= TimeEntriesDrop.new @issue.time_entries
|
96
|
+
end
|
97
|
+
|
98
|
+
def parent
|
99
|
+
@parent ||= IssueDrop.new @issue.parent if @issue.parent
|
100
|
+
end
|
101
|
+
|
102
|
+
def project
|
103
|
+
@project ||= ProjectDrop.new @issue.project if @issue.project
|
104
|
+
end
|
105
|
+
|
106
|
+
def subtasks
|
107
|
+
@subtasks ||= IssuesDrop.new @issue.children
|
108
|
+
end
|
109
|
+
|
110
|
+
def notes
|
111
|
+
@notes ||= @issue.journals.where("#{Journal.table_name}.notes IS NOT ?", nil).order(:created_on).map(&:notes)
|
112
|
+
end
|
113
|
+
|
114
|
+
def journals
|
115
|
+
@journals ||= JournalsDrop.new @issue.journals.where("#{Journal.table_name}.notes IS NOT ?", nil)
|
116
|
+
end
|
117
|
+
|
60
118
|
def custom_field_values
|
61
119
|
@issue.custom_field_values
|
62
120
|
end
|
63
121
|
|
64
122
|
end
|
123
|
+
|
124
|
+
class JournalsDrop < ::Liquid::Drop
|
125
|
+
def initialize(journals)
|
126
|
+
@journals = journals
|
127
|
+
end
|
128
|
+
|
129
|
+
def all
|
130
|
+
@all ||= @journals.map do |journal|
|
131
|
+
JournalDrop.new journal
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def visible
|
136
|
+
@visible ||= @all.select(&:visible?)
|
137
|
+
end
|
138
|
+
|
139
|
+
def each(&block)
|
140
|
+
all.each(&block)
|
141
|
+
end
|
142
|
+
|
143
|
+
def size
|
144
|
+
@journals.size
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class JournalDrop < ::Liquid::Drop
|
149
|
+
delegate :id,
|
150
|
+
:notes,
|
151
|
+
:created_on,
|
152
|
+
:private_notes,
|
153
|
+
:to => :@journal
|
154
|
+
|
155
|
+
def initialize(journal)
|
156
|
+
@journal = journal
|
157
|
+
end
|
158
|
+
|
159
|
+
def user
|
160
|
+
@user ||= UserDrop.new(@journal.user)
|
161
|
+
end
|
162
|
+
|
163
|
+
def issue
|
164
|
+
@issue ||= IssueDrop.new @journal.issue if @journal.issue
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
65
169
|
end
|
66
170
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module RedmineCrm
|
2
|
+
module Liquid
|
3
|
+
class TimeEntriesDrop < ::Liquid::Drop
|
4
|
+
def initialize(time_entries)
|
5
|
+
@time_entries = time_entries
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
@all ||= @time_entries.map do |time_entry|
|
10
|
+
TimeEntryDrop.new time_entry
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def visible
|
15
|
+
@visible ||= @all.select(&:visible?)
|
16
|
+
end
|
17
|
+
|
18
|
+
def each(&block)
|
19
|
+
all.each(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def size
|
23
|
+
@time_entries.size
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TimeEntryDrop < ::Liquid::Drop
|
28
|
+
include ActionView::Helpers::UrlHelper
|
29
|
+
|
30
|
+
delegate :id,
|
31
|
+
:hours,
|
32
|
+
:comments,
|
33
|
+
:spent_on,
|
34
|
+
:tyear,
|
35
|
+
:tmonth,
|
36
|
+
:tweek,
|
37
|
+
:visible?,
|
38
|
+
:updated_on,
|
39
|
+
:created_on,
|
40
|
+
:to => :@time_entry
|
41
|
+
|
42
|
+
def initialize(time_entry)
|
43
|
+
@time_entry = time_entry
|
44
|
+
end
|
45
|
+
|
46
|
+
def user
|
47
|
+
@user ||= UserDrop.new(@time_entry.user)
|
48
|
+
end
|
49
|
+
|
50
|
+
def issue
|
51
|
+
@issue ||= IssueDrop.new(@time_entry.issue)
|
52
|
+
end
|
53
|
+
|
54
|
+
def activity
|
55
|
+
@activity ||= @time_entry.activity && @time_entry.activity.name
|
56
|
+
end
|
57
|
+
|
58
|
+
def custom_field_values
|
59
|
+
@time_entry.custom_field_values
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -39,9 +39,9 @@ module RedmineCrm
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def all_currencies
|
42
|
-
Currency.table.inject([]) do |array, (
|
42
|
+
Currency.table.inject([]) do |array, (_, attributes)|
|
43
43
|
array ||= []
|
44
|
-
array << [
|
44
|
+
array << [attributes[:name].to_s + (attributes[:symbol].blank? ? '' : " (#{attributes[:symbol]})"), attributes[:iso_code]]
|
45
45
|
array
|
46
46
|
end.sort{|x, y| x[0] <=> y[0]}
|
47
47
|
end
|
data/lib/redmine_crm/version.rb
CHANGED
@@ -4,7 +4,7 @@ class DraftTest < ActiveSupport::TestCase
|
|
4
4
|
def test_restore
|
5
5
|
issue = Issue.new(subject: 'some subject', description: 'some description')
|
6
6
|
|
7
|
-
issue.save_draft
|
7
|
+
issue.save_draft
|
8
8
|
restored_issue = RedmineCrm::ActsAsDraftable::Draft.find(issue.draft_id).restore
|
9
9
|
|
10
10
|
assert_equal issue.subject, restored_issue.subject
|
@@ -13,9 +13,9 @@ class DraftTest < ActiveSupport::TestCase
|
|
13
13
|
|
14
14
|
def test_restore_all
|
15
15
|
first_issue = Issue.new(subject: 'first subject')
|
16
|
-
first_issue.save_draft
|
16
|
+
first_issue.save_draft
|
17
17
|
second_issue = Issue.new(subject: 'second subject')
|
18
|
-
second_issue.save_draft
|
18
|
+
second_issue.save_draft
|
19
19
|
|
20
20
|
restored_issues = RedmineCrm::ActsAsDraftable::Draft.restore_all
|
21
21
|
assert_equal [first_issue.subject, second_issue.subject], restored_issues.map(&:subject).sort
|
@@ -34,16 +34,18 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_drafts
|
37
|
+
Issue.rcrm_acts_as_draftable parent: :project
|
37
38
|
issue = Issue.new
|
38
|
-
issue.save_draft
|
39
|
+
issue.save_draft
|
39
40
|
|
40
41
|
assert_equal 1, Issue.drafts(current_user).count
|
41
42
|
assert_equal RedmineCrm::ActsAsDraftable::Draft, Issue.drafts(current_user).first.class
|
42
43
|
end
|
43
44
|
|
44
45
|
def test_from_draft
|
46
|
+
Issue.rcrm_acts_as_draftable parent: :project
|
45
47
|
issue = Issue.new(subject: 'subject')
|
46
|
-
issue.save_draft
|
48
|
+
issue.save_draft
|
47
49
|
|
48
50
|
issue_from_draft = Issue.from_draft(issue.draft_id)
|
49
51
|
|
@@ -56,11 +58,11 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
56
58
|
|
57
59
|
def test_draft_deleted_after_save
|
58
60
|
issue = Issue.new(subject: 'subject')
|
59
|
-
issue.save_draft
|
61
|
+
issue.save_draft
|
60
62
|
|
61
63
|
issue_from_draft = Issue.from_draft(issue.draft_id)
|
62
64
|
|
63
|
-
assert_difference 'Issue.count'
|
65
|
+
assert_difference 'Issue.count' do
|
64
66
|
assert_difference 'RedmineCrm::ActsAsDraftable::Draft.count', -1 do
|
65
67
|
issue_from_draft.save!
|
66
68
|
end
|
@@ -78,7 +80,7 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
78
80
|
Project.rcrm_acts_as_draftable
|
79
81
|
|
80
82
|
project = Project.new
|
81
|
-
project.save_draft
|
83
|
+
project.save_draft
|
82
84
|
|
83
85
|
assert_raises do
|
84
86
|
Issue.from_draft(project.draft_id)
|
@@ -89,7 +91,7 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
89
91
|
assert_equal String, Issue.new.dump_to_draft.class
|
90
92
|
end
|
91
93
|
|
92
|
-
def
|
94
|
+
def test_load_from_draft
|
93
95
|
attributes = {subject: 'subject', description: 'description'}
|
94
96
|
draft = Issue.new(attributes).dump_to_draft
|
95
97
|
|
@@ -101,17 +103,17 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def test_save_draft
|
104
|
-
|
106
|
+
Issue.rcrm_acts_as_draftable parent: :project
|
107
|
+
attributes = { subject: 'subject' }
|
105
108
|
issue = Issue.new(attributes)
|
106
109
|
|
107
|
-
|
108
|
-
assert_difference 'RedmineCrm::ActsAsDraftable::Draft.count'
|
109
|
-
result = issue.save_draft
|
110
|
+
assert_no_difference 'Issue.count' do
|
111
|
+
assert_difference 'RedmineCrm::ActsAsDraftable::Draft.count' do
|
112
|
+
result = issue.save_draft
|
110
113
|
assert_equal true, result
|
111
114
|
end
|
112
115
|
end
|
113
|
-
|
114
|
-
|
116
|
+
assert_not_nil issue.draft_id
|
115
117
|
|
116
118
|
draft = RedmineCrm::ActsAsDraftable::Draft.find(issue.draft_id)
|
117
119
|
assert_equal 'Issue', draft.target_type
|
@@ -119,36 +121,24 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
119
121
|
assert_equal attributes[:subject], draft.restore.subject
|
120
122
|
end
|
121
123
|
|
122
|
-
def test_save_draft_without_user
|
123
|
-
issue = Issue.new
|
124
|
-
|
125
|
-
assert_difference 'Issue.count', 0 do
|
126
|
-
assert_difference 'RedmineCrm::ActsAsDraftable::Draft.count', 1 do
|
127
|
-
result = issue.save_draft
|
128
|
-
assert_equal true, result
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
draft = RedmineCrm::ActsAsDraftable::Draft.find(issue.draft_id)
|
133
|
-
assert_nil draft.user_id
|
134
|
-
end
|
135
|
-
|
136
124
|
def test_save_draft_with_associations
|
125
|
+
Issue.rcrm_acts_as_draftable parent: :project
|
137
126
|
issue = Issue.new(project: projects(:second_project))
|
138
|
-
issue.save_draft
|
127
|
+
issue.save_draft
|
139
128
|
|
140
129
|
draft = RedmineCrm::ActsAsDraftable::Draft.find(issue.draft_id)
|
141
130
|
assert_equal issue.project.name, draft.restore.project.name
|
142
131
|
end
|
143
132
|
|
144
133
|
def test_save_draft_updates_existing_draft
|
134
|
+
Issue.rcrm_acts_as_draftable parent: :project
|
145
135
|
issue = Issue.new
|
146
|
-
issue.save_draft
|
136
|
+
issue.save_draft
|
147
137
|
|
148
138
|
issue.subject = 'changed subject'
|
149
|
-
|
150
|
-
|
151
|
-
issue.save_draft
|
139
|
+
assert_no_difference 'Issue.count' do
|
140
|
+
assert_no_difference 'RedmineCrm::ActsAsDraftable::Draft.count' do
|
141
|
+
issue.save_draft
|
152
142
|
end
|
153
143
|
end
|
154
144
|
|
@@ -156,20 +146,24 @@ class RcrmActsAsDraftableTest < ActiveSupport::TestCase
|
|
156
146
|
assert_equal issue.subject, draft.restore.subject
|
157
147
|
end
|
158
148
|
|
159
|
-
def
|
160
|
-
issue =
|
161
|
-
issue.save_draft
|
162
|
-
|
163
|
-
|
149
|
+
def test_save_draft_does_not_save_persisted_object
|
150
|
+
issue = issues(:second_issue)
|
151
|
+
assert_equal false, issue.save_draft
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_save_draft_saves_persisted_but_changed_object
|
155
|
+
issue = issues(:second_issue)
|
156
|
+
issue.subject = 'changed subject'
|
157
|
+
assert_equal true, issue.save_draft
|
164
158
|
end
|
165
159
|
|
166
160
|
def test_update_draft
|
167
161
|
issue = Issue.new(subject: 'subject')
|
168
|
-
issue.save_draft
|
162
|
+
issue.save_draft
|
169
163
|
|
170
|
-
|
171
|
-
|
172
|
-
issue.update_draft(
|
164
|
+
assert_no_difference 'Issue.count' do
|
165
|
+
assert_no_difference 'RedmineCrm::ActsAsDraftable::Draft.count' do
|
166
|
+
issue.update_draft(subject: 'updated_subject')
|
173
167
|
end
|
174
168
|
end
|
175
169
|
|
data/test/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.40
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RedmineUP
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/redmine_crm/acts_as_votable/vote.rb
|
112
112
|
- lib/redmine_crm/acts_as_votable/voter.rb
|
113
113
|
- lib/redmine_crm/assets_manager.rb
|
114
|
+
- lib/redmine_crm/compatibility/application_controller_patch.rb
|
114
115
|
- lib/redmine_crm/currency.rb
|
115
116
|
- lib/redmine_crm/currency/formatting.rb
|
116
117
|
- lib/redmine_crm/currency/heuristics.rb
|
@@ -122,6 +123,7 @@ files:
|
|
122
123
|
- lib/redmine_crm/liquid/drops/issues_drop.rb
|
123
124
|
- lib/redmine_crm/liquid/drops/news_drop.rb
|
124
125
|
- lib/redmine_crm/liquid/drops/projects_drop.rb
|
126
|
+
- lib/redmine_crm/liquid/drops/time_entries_drop.rb
|
125
127
|
- lib/redmine_crm/liquid/drops/users_drop.rb
|
126
128
|
- lib/redmine_crm/liquid/filters/arrays.rb
|
127
129
|
- lib/redmine_crm/liquid/filters/base.rb
|