redmine_crm 0.0.23 → 0.0.53

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/README.md +166 -33
  4. data/Rakefile +3 -12
  5. data/app/controllers/redmine_crm_controller.rb +26 -0
  6. data/app/views/redmine_crm/_money.html.erb +44 -0
  7. data/app/views/redmine_crm/settings.html.erb +10 -0
  8. data/bitbucket-pipelines.yml +54 -0
  9. data/config/currency_iso.json +12 -0
  10. data/config/locales/en.yml +13 -0
  11. data/config/locales/ru.yml +13 -0
  12. data/config/routes.rb +5 -0
  13. data/doc/CHANGELOG +123 -2
  14. data/lib/redmine_crm/acts_as_draftable/draft.rb +40 -0
  15. data/lib/redmine_crm/acts_as_draftable/rcrm_acts_as_draftable.rb +172 -0
  16. data/lib/redmine_crm/acts_as_list/list.rb +282 -0
  17. data/lib/redmine_crm/{rcrm_acts_as_taggable.rb → acts_as_taggable/rcrm_acts_as_taggable.rb} +112 -93
  18. data/lib/redmine_crm/acts_as_taggable/tag.rb +81 -0
  19. data/lib/redmine_crm/acts_as_taggable/tag_list.rb +111 -0
  20. data/lib/redmine_crm/acts_as_taggable/tagging.rb +16 -0
  21. data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
  22. data/lib/redmine_crm/{rcrm_acts_as_votable.rb → acts_as_votable/rcrm_acts_as_votable.rb} +15 -14
  23. data/lib/redmine_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
  24. data/lib/redmine_crm/{votable.rb → acts_as_votable/votable.rb} +54 -65
  25. data/lib/redmine_crm/{vote.rb → acts_as_votable/vote.rb} +6 -8
  26. data/lib/redmine_crm/{voter.rb → acts_as_votable/voter.rb} +29 -34
  27. data/lib/redmine_crm/assets_manager.rb +43 -0
  28. data/lib/redmine_crm/colors_helper.rb +192 -0
  29. data/lib/redmine_crm/compatibility/application_controller_patch.rb +33 -0
  30. data/lib/redmine_crm/currency/formatting.rb +5 -8
  31. data/lib/redmine_crm/currency/heuristics.rb +1 -1
  32. data/lib/redmine_crm/currency/loader.rb +5 -6
  33. data/lib/redmine_crm/currency.rb +28 -17
  34. data/lib/redmine_crm/engine.rb +4 -0
  35. data/lib/redmine_crm/helpers/external_assets_helper.rb +19 -0
  36. data/lib/redmine_crm/helpers/form_tag_helper.rb +76 -0
  37. data/lib/redmine_crm/helpers/tags_helper.rb +1 -3
  38. data/lib/redmine_crm/helpers/vote_helper.rb +29 -32
  39. data/lib/redmine_crm/hooks/views_layouts_hook.rb +11 -0
  40. data/lib/redmine_crm/liquid/drops/issues_drop.rb +191 -0
  41. data/lib/redmine_crm/liquid/drops/news_drop.rb +54 -0
  42. data/lib/redmine_crm/liquid/drops/projects_drop.rb +86 -0
  43. data/lib/redmine_crm/liquid/drops/time_entries_drop.rb +65 -0
  44. data/lib/redmine_crm/liquid/drops/users_drop.rb +68 -0
  45. data/lib/redmine_crm/liquid/filters/arrays.rb +187 -0
  46. data/lib/redmine_crm/liquid/filters/base.rb +217 -0
  47. data/lib/redmine_crm/liquid/filters/colors.rb +31 -0
  48. data/lib/redmine_crm/money_helper.rb +17 -18
  49. data/lib/redmine_crm/settings/money.rb +46 -0
  50. data/lib/redmine_crm/settings.rb +53 -0
  51. data/lib/redmine_crm/version.rb +1 -1
  52. data/lib/redmine_crm.rb +60 -21
  53. data/redmine_crm.gemspec +12 -6
  54. data/test/acts_as_draftable/draft_test.rb +29 -0
  55. data/test/acts_as_draftable/rcrm_acts_as_draftable_test.rb +178 -0
  56. data/test/{acts_as_taggable_test.rb → acts_as_taggable/rcrm_acts_as_taggable_test.rb} +117 -156
  57. data/test/acts_as_taggable/tag_list_test.rb +34 -0
  58. data/test/acts_as_taggable/tag_test.rb +72 -0
  59. data/test/acts_as_taggable/tagging_test.rb +15 -0
  60. data/test/{viewed_test.rb → acts_as_viewed/rcrm_acts_as_viewed_test.rb} +17 -15
  61. data/test/acts_as_votable/rcrm_acts_as_votable_test.rb +19 -0
  62. data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +14 -0
  63. data/test/{votable_model_test.rb → acts_as_votable/votable_test.rb} +34 -5
  64. data/test/{voter_model_test.rb → acts_as_votable/voter_test.rb} +8 -8
  65. data/test/currency_test.rb +10 -10
  66. data/test/database.yml +14 -14
  67. data/test/fixtures/issues.yml +13 -1
  68. data/test/fixtures/news.yml +8 -0
  69. data/test/fixtures/projects.yml +10 -0
  70. data/test/fixtures/users.yml +6 -2
  71. data/test/liquid/drops/issues_drop_test.rb +34 -0
  72. data/test/liquid/drops/news_drop_test.rb +38 -0
  73. data/test/liquid/drops/projects_drop_test.rb +44 -0
  74. data/test/liquid/drops/uses_drop_test.rb +36 -0
  75. data/test/liquid/filters/arrays_filter_test.rb +31 -0
  76. data/test/liquid/filters/base_filter_test.rb +63 -0
  77. data/test/liquid/filters/colors_filter_test.rb +33 -0
  78. data/test/liquid/liquid_helper.rb +34 -0
  79. data/test/models/issue.rb +14 -0
  80. data/test/models/news.rb +3 -0
  81. data/test/models/project.rb +8 -0
  82. data/test/{fixtures → models}/user.rb +5 -1
  83. data/test/{fixtures → models}/vote_classes.rb +0 -21
  84. data/test/money_helper_test.rb +5 -5
  85. data/test/schema.rb +33 -10
  86. data/test/test_helper.rb +20 -72
  87. data/vendor/assets/images/money.png +0 -0
  88. data/vendor/assets/images/vcard.png +0 -0
  89. data/vendor/assets/javascripts/Chart.bundle.min.js +16 -0
  90. data/vendor/assets/javascripts/select2.js +2 -0
  91. data/vendor/assets/javascripts/select2_helpers.js +192 -0
  92. data/vendor/assets/stylesheets/money.css +3 -0
  93. data/vendor/assets/stylesheets/select2.css +424 -0
  94. metadata +190 -40
  95. data/lib/redmine_crm/rcrm_acts_as_viewed.rb +0 -287
  96. data/lib/redmine_crm/rcrm_acts_as_voter.rb +0 -27
  97. data/lib/redmine_crm/tag.rb +0 -81
  98. data/lib/redmine_crm/tag_list.rb +0 -112
  99. data/lib/redmine_crm/tagging.rb +0 -20
  100. data/test/fixtures/issue.rb +0 -14
  101. data/test/tag_test.rb +0 -64
  102. data/test/tagging_test.rb +0 -14
  103. data/test/votable_test.rb +0 -17
@@ -1,26 +1,24 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class ViewedTest < ActiveSupport::TestCase
4
-
3
+ class RcrmActsAsViewedTest < ActiveSupport::TestCase
5
4
  def user
6
- user = users(:jonathan)
5
+ users(:jonathan)
7
6
  end
8
7
 
9
8
  def issue
10
- issue = issues(:first_issue)
9
+ issues(:first_issue)
11
10
  end
12
-
13
-
11
+
14
12
  def test_zero_of_view_count
15
- assert_equal issue.view_count, "0(0)"
13
+ assert_equal issue.view_count, '0(0)'
16
14
  end
17
-
15
+
18
16
  def test_can_view
19
17
  issue.view '127.0.0.1', user
20
- assert_equal issue.view_count, "1(1)"
18
+ assert_equal issue.view_count, '1(1)'
21
19
  # second view change only total count
22
20
  issue.view '127.0.0.1', user
23
- assert_equal issue.view_count, "2(1)"
21
+ assert_equal issue.view_count, '2(1)'
24
22
  end
25
23
 
26
24
  def test_viewed_by
@@ -32,14 +30,18 @@ class ViewedTest < ActiveSupport::TestCase
32
30
  def test_twice_view
33
31
  issue.view '127.0.0.1', user
34
32
  issue.view '127.0.0.1', user
35
- assert_equal "2(1)", issue.view_count
33
+ assert_equal '2(1)', issue.view_count
36
34
  end
37
-
35
+
38
36
  def test_viewed?
39
37
  assert !issue.viewed?
40
38
  issue.view '127.0.0.1', user
41
39
  assert issue.viewed?
42
40
  end
43
41
 
44
-
45
- end
42
+ def test_find_viewed_by
43
+ assert_equal [], Issue.find_viewed_by(user)
44
+ issue.view '127.0.0.1', user
45
+ assert_equal [issue], Issue.find_viewed_by(user)
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RcrmActsAsVotableTest < ActiveSupport::TestCase
4
+
5
+ class NotVotable < ActiveRecord::Base; end
6
+ def test_that_votable_returns_false_unless_included
7
+ assert_equal NotVotable.votable?, false
8
+ end
9
+
10
+ def test_that_votable_returns_true_if_included
11
+ assert_equal Votable.votable?, true
12
+ end
13
+
14
+ def test_behaves_like_votable_model
15
+ assert Voter.create(:name => 'i can vote!')
16
+ assert VotableCache.create(:name => 'voting model with cache')
17
+ assert VotableVoter.create(:name => 'i can vote too!')
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RcrmActsAsVoterTest < ActiveSupport::TestCase
4
+
5
+ class NotVoter < ActiveRecord::Base; end
6
+ def test_that_voter_returns_false_unless_included
7
+ assert_equal NotVoter.voter?, false
8
+ end
9
+
10
+ def test_that_voter_returns_true_if_included
11
+ assert_equal Voter.voter?, true
12
+ assert_equal VotableVoter.voter?, true
13
+ end
14
+ end
@@ -1,7 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class VotableModelTest < ActiveSupport::TestCase
4
-
3
+ class VotableTest < ActiveSupport::TestCase
5
4
  def votable
6
5
  votables(:votable)
7
6
  end
@@ -15,6 +14,36 @@ class VotableModelTest < ActiveSupport::TestCase
15
14
  assert_equal votable.votes_for.size, 1
16
15
  end
17
16
 
17
+ def test_have_vote_when_saved_by_id
18
+ votable.vote_by(:voter => voters(:voter), :vote => "yes", :vote_ip => '127.0.0.1')
19
+ assert_equal votable.votes_for.size, 1
20
+ assert_equal votable.votes_for.last.vote_ip, '127.0.0.1'
21
+ end
22
+
23
+ def test_voted_twice_by_one_ip
24
+ votable.vote_by(:voter => voters(:voter), :vote => "yes", :vote_ip => '127.0.0.1', :vote_by_ip => true)
25
+ votable.vote_by(:voter => voters(:voter), :vote => "no", :vote_ip => '127.0.0.1', :vote_by_ip => true)
26
+ assert_equal votable.votes_for.size, 1
27
+ end
28
+
29
+ def test_voted_twice_by_one_ip_with_duplicate_params
30
+ votable.vote_by(:voter => voters(:voter), :vote => "yes", :vote_ip => '127.0.0.1', :vote_by_ip => true)
31
+ votable.vote_by(:voter => voters(:voter), :vote => "no", :vote_ip => '127.0.0.1', :vote_by_ip => true, :duplicate => true)
32
+ assert_equal votable.votes_for.size, 2
33
+ end
34
+
35
+ def test_one_scoped_vote_by_ip_when_using_scope_by_same_person
36
+ votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'rank', :vote_ip => '127.0.0.1', :vote_by_ip => true)
37
+ votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'rank', :vote_ip => '127.0.0.1', :vote_by_ip => true)
38
+ assert_equal votable.find_votes_for(:vote_scope => 'rank').size, 1
39
+ end
40
+
41
+ def test_two_votes_for_when_voting_on_two_diff_scopes
42
+ votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'weekly_rank', :vote_ip => '127.0.0.1', :vote_by_ip => true)
43
+ votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'monthly_rank', :vote_ip => '127.0.0.1', :vote_by_ip => true)
44
+ assert_equal votable.votes_for.size, 2
45
+ end
46
+
18
47
  def test_voted_twice_by_same_person
19
48
  votable.vote_by(:voter => voters(:voter), :vote => "yes")
20
49
  votable.vote_by(:voter => voters(:voter), :vote => "no")
@@ -82,7 +111,7 @@ class VotableModelTest < ActiveSupport::TestCase
82
111
  assert votable.vote_registered?
83
112
  end
84
113
 
85
- def test_not_count_the_vote_as_being_registered_if_that_voter_has_alredy_voted_and_voted_has_not_chanded
114
+ def test_not_count_the_vote_as_being_registered_if_that_voter_has_already_voted_and_voted_has_not_changed
86
115
  votable.vote_by(:voter => voters(:voter), :vote => true)
87
116
  votable.vote_by(:voter => voters(:voter), :vote => 'yes')
88
117
  assert !votable.vote_registered?
@@ -475,4 +504,4 @@ class VotableModelTest < ActiveSupport::TestCase
475
504
  end
476
505
 
477
506
 
478
- end
507
+ end
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class VoterModelTest < ActiveSupport::TestCase
3
+ class VoterTest < ActiveSupport::TestCase
4
4
  def votable
5
5
  votables(:votable)
6
6
  end
@@ -59,12 +59,12 @@ class VoterModelTest < ActiveSupport::TestCase
59
59
  end
60
60
 
61
61
  def test_be_voted_as_nil_when_a_voter_has_never_voted
62
- assert_equal voter.voted_as_when_voting_on(votable), nil
62
+ assert_nil voter.voted_as_when_voting_on(votable)
63
63
  end
64
64
 
65
65
  def test_be_voted_as_nil_when_a_voter_has_never_voted_under_the_scope
66
66
  votable.vote_by :voter => voter, :vote => false, :vote_scope => 'rank'
67
- assert_equal voter.voted_as_when_voting_on(votable), nil
67
+ assert_nil voter.voted_as_when_voting_on(votable)
68
68
  end
69
69
 
70
70
  def test_return_true_if_voter_has_voted_true
@@ -138,7 +138,7 @@ class VoterModelTest < ActiveSupport::TestCase
138
138
 
139
139
  def test_get_all_of_the_voters_up_votes_for_a_class
140
140
  votable.vote_by(:voter => voter)
141
- votables(:votable2).vote_by( :voter => voter, :vote => false)
141
+ votables(:votable2).vote_by(:voter => voter, :vote => false)
142
142
  assert_equal voter.find_up_votes_for_class(votable_klass).size, 1
143
143
  assert_equal voter.votes.up.for_type(votable_klass).count, 1
144
144
  end
@@ -158,7 +158,7 @@ class VoterModelTest < ActiveSupport::TestCase
158
158
  end
159
159
 
160
160
  # describe '#find_voted_items
161
-
161
+
162
162
  def test_returns_objects_that_a_user_has_upvoted_for
163
163
  votable.vote_by(:voter => voter)
164
164
  votables(:votable2).vote_by(:voter => voters(:voter2))
@@ -215,7 +215,7 @@ class VoterModelTest < ActiveSupport::TestCase
215
215
  end
216
216
 
217
217
  # describe '#find_down_voted_items
218
-
218
+
219
219
  def test_does_not_return_objects_that_a_user_has_upvoted_for
220
220
  votable.vote_by :voter => voter
221
221
  assert_equal voter.find_down_voted_items.size, 0
@@ -293,4 +293,4 @@ class VoterModelTest < ActiveSupport::TestCase
293
293
  assert get_down_voted.include? votable
294
294
  assert_equal get_down_voted.size, 1
295
295
  end
296
- end
296
+ end
@@ -30,9 +30,9 @@ module RedmineCrm
30
30
  end
31
31
 
32
32
  def test_nil_unless_matching_given_id
33
- assert_equal nil, Currency.find("ZZZ")
33
+ assert_nil Currency.find("ZZZ")
34
34
  end
35
-
35
+
36
36
  class Mock
37
37
  def to_s
38
38
  '208'
@@ -49,8 +49,8 @@ module RedmineCrm
49
49
  end
50
50
 
51
51
  def test_nil_if_no_currency_has_the_given_num_code
52
- assert_equal Currency.find_by_iso_numeric("non iso 4217 numeric code"), nil
53
- assert_equal Currency.find_by_iso_numeric(0), nil
52
+ assert_nil Currency.find_by_iso_numeric("non iso 4217 numeric code")
53
+ assert_nil Currency.find_by_iso_numeric(0)
54
54
  end
55
55
 
56
56
  # .all
@@ -58,7 +58,7 @@ module RedmineCrm
58
58
  assert Currency.all.include?(Currency.new(:usd))
59
59
  end
60
60
 
61
- def test_include_register_currencies
61
+ def test_include_register_currencies
62
62
  register_foo
63
63
  assert Currency.all.include?(Currency.new(:foo))
64
64
  unregister_foo
@@ -91,7 +91,7 @@ module RedmineCrm
91
91
  Currency.unregister(iso_code: "XXX")
92
92
  end
93
93
 
94
- def test_present_iso_code
94
+ def test_present_iso_code
95
95
  assert_raises KeyError do
96
96
  Currency.register(name: "New currency")
97
97
  end
@@ -102,7 +102,7 @@ module RedmineCrm
102
102
  Currency.register(iso_code: "XXX")
103
103
  assert_not_equal nil, Currency.find("XXX")
104
104
  Currency.unregister(iso_code: "XXX")
105
- assert_equal nil, Currency.find("XXX")
105
+ assert_nil Currency.find("XXX")
106
106
  end
107
107
 
108
108
  def test_exitred_currency
@@ -116,10 +116,10 @@ module RedmineCrm
116
116
  Currency.register(iso_code: "YYZ")
117
117
  #test with string
118
118
  Currency.unregister("XXX")
119
- assert_equal nil, Currency.find("XXX")
119
+ assert_nil Currency.find("XXX")
120
120
  #test with symbol
121
121
  Currency.unregister(:yyz)
122
- assert_equal nil, Currency.find(:yyz)
122
+ assert_nil Currency.find(:yyz)
123
123
  end
124
124
 
125
125
  # .each
@@ -289,4 +289,4 @@ module RedmineCrm
289
289
  unregister_foo
290
290
  end
291
291
  end
292
- end
292
+ end
data/test/database.yml CHANGED
@@ -1,17 +1,17 @@
1
- mysql:
2
- :adapter: mysql2
3
- :host: localhost
4
- :username: root
5
- :password: 1
6
- :database: rails_plugin_test
1
+ sqlite:
2
+ adapter: sqlite3
3
+ database: ':memory:'
7
4
 
8
- sqlite3:
9
- :adapter: sqlite3
10
- :database: ':memory:'
5
+ mysql:
6
+ adapter: mysql2
7
+ database: redmine_crm_test
8
+ username: root
9
+ password: password
10
+ host: 127.0.0.1
11
11
 
12
12
  postgresql:
13
- :adapter: postgresql
14
- :database: rails_plugin_test
15
- :user: container
16
- :password: 1
17
- :host: localhost
13
+ adapter: postgresql
14
+ database: redmine_crm_test
15
+ user: postgres
16
+ password: password
17
+ host: 127.0.0.1
@@ -1,12 +1,24 @@
1
1
  first_issue:
2
+ subject: Issue 1 subject
2
3
  description: Some description for the issue
3
4
  user: jonathan
5
+ author: jonathan
6
+ project: first_project
4
7
  second_issue:
8
+ subject: Issue 2 subject
5
9
  description: Second issue
6
10
  user: jonathan
11
+ author: jonathan
12
+ project: first_project
7
13
  third_issue:
14
+ subject: Issue 3 subject
8
15
  description: Third issue
9
16
  user: sam
17
+ author: homer
18
+ project: second_project
10
19
  fourth_issue:
20
+ subject: Issue 4 subject
11
21
  description: Fourth issue
12
- user: sam
22
+ user: sam
23
+ author: sam
24
+ project: second_project
@@ -0,0 +1,8 @@
1
+ first_news:
2
+ title: News 1 title
3
+ description: Some description for the news 1
4
+ author: jonathan
5
+ second_news:
6
+ title: News 2 title
7
+ description: Some description for the news 2
8
+ author: sam
@@ -0,0 +1,10 @@
1
+ first_project:
2
+ name: Project 1
3
+ description: Some description for the project 1
4
+ identifier: project1
5
+ status: 1
6
+ second_project:
7
+ name: Project 2
8
+ description: Some description for the project 2
9
+ identifier: project2
10
+ status: 5
@@ -1,5 +1,9 @@
1
1
  jonathan:
2
2
  name: Jonathan
3
-
3
+ language: 'EN'
4
4
  sam:
5
- name: Sam
5
+ name: Sam
6
+ language: 'RU'
7
+ homer:
8
+ name: Homer
9
+ language: 'CH'
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class IssuesDropTest < ActiveSupport::TestCase
6
+ def setup
7
+ @issue = Issue.first
8
+ @user = User.first
9
+ @liquid_render = LiquidRender.new('user' => Liquid::UserDrop.new(@user),
10
+ 'issue' => Liquid::IssueDrop.new(@issue),
11
+ 'issues' => Liquid::IssuesDrop.new(Issue.all))
12
+ end
13
+
14
+ def test_issues_all
15
+ issues_text = @liquid_render.render('{% for issue in issues.all %} {{issue.subject }} {% endfor %}')
16
+ Issue.all.map(&:subject).each do |subject|
17
+ assert_match subject, issues_text
18
+ end
19
+ end
20
+
21
+ def test_issues_size
22
+ assert_equal '4', @liquid_render.render('{{ issues.size }}')
23
+ end
24
+
25
+ def test_issue_author
26
+ assert_equal @user.name, @liquid_render.render('{{ issue.author.name }}')
27
+ end
28
+
29
+ def test_issue_delegated
30
+ assert_equal [@issue.id, @issue.subject, @issue.description].join('|'),
31
+ @liquid_render.render('{{ issue.id }}|{{ issue.subject }}|{{ issue.description }}')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class NewsDropTest < ActiveSupport::TestCase
6
+ def setup
7
+ @news = News.first
8
+ @user = User.first
9
+ @liquid_render = LiquidRender.new('user' => Liquid::UserDrop.new(@user),
10
+ 'news' => Liquid::NewsDrop.new(@news),
11
+ 'newss' => Liquid::NewssDrop.new(News.all))
12
+ end
13
+
14
+ def test_newss_all
15
+ newss_text = @liquid_render.render('{% for news in newss.all %} {{news.title }} {% endfor %}')
16
+ News.all.map(&:title).each do |title|
17
+ assert_match title, newss_text
18
+ end
19
+ end
20
+
21
+ def test_newss_last
22
+ assert_equal News.last.title, @liquid_render.render('{{ newss.last.title }}')
23
+ end
24
+
25
+ def test_newss_size
26
+ assert_equal '2', @liquid_render.render('{{ newss.size }}')
27
+ end
28
+
29
+ def test_news_author
30
+ assert_equal @user.name, @liquid_render.render('{{ news.author.name }}')
31
+ end
32
+
33
+ def test_issue_delegated
34
+ assert_equal [@news.id, @news.title, @news.description].join('|'),
35
+ @liquid_render.render('{{ news.id }}|{{ news.title }}|{{ news.description }}')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class ProjectsDropTest < ActiveSupport::TestCase
6
+ def setup
7
+ @project = Project.first
8
+ @user = User.first
9
+ @liquid_render = LiquidRender.new('user' => Liquid::UserDrop.new(@user),
10
+ 'project' => Liquid::ProjectDrop.new(@project),
11
+ 'projects' => Liquid::ProjectsDrop.new(Project.all))
12
+ end
13
+
14
+ def test_projects_all
15
+ projects_text = @liquid_render.render('{% for project in projects.all %} {{project.identifier }} {% endfor %}')
16
+ Project.all.map(&:identifier).each do |identifier|
17
+ assert_match identifier, projects_text
18
+ end
19
+ end
20
+
21
+ def test_projects_active
22
+ projects_text = @liquid_render.render('{% for project in projects.active %} {{project.identifier }} {% endfor %}')
23
+ Project.where(:status => 1).map(&:identifier).each do |identifier|
24
+ assert_match identifier, projects_text
25
+ end
26
+ end
27
+
28
+ def test_projects_size
29
+ assert_equal '2', @liquid_render.render('{{ projects.size }}')
30
+ end
31
+
32
+ def test_project_issues
33
+ issues_text = @liquid_render.render('{% for issue in project.issues %} {{issue.subject }} {% endfor %}')
34
+ Project.first.issues.each do |issue|
35
+ assert_match issue.subject, issues_text
36
+ end
37
+ end
38
+
39
+ def test_project_delegated
40
+ assert_equal [@project.id, @project.identifier, @project.description].join('|'),
41
+ @liquid_render.render('{{ project.id }}|{{ project.identifier }}|{{ project.description }}')
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class UsersDropTest < ActiveSupport::TestCase
6
+ def setup
7
+ @user = User.first
8
+ @liquid_render = LiquidRender.new('user' => Liquid::UserDrop.new(@user),
9
+ 'users' => Liquid::UsersDrop.new(User.all))
10
+ end
11
+
12
+ def test_users_all
13
+ users_text = @liquid_render.render('{% for user in users.all %} {{user.name }} {% endfor %}')
14
+ User.all.map(&:name).each do |name|
15
+ assert_match name, users_text
16
+ end
17
+ end
18
+
19
+ def test_users_current
20
+ assert_equal User.first.name, @liquid_render.render('{{ users.current.name }}')
21
+ end
22
+
23
+ def test_users_size
24
+ assert_equal '3', @liquid_render.render('{{ users.size }}')
25
+ end
26
+
27
+ def test_user_name
28
+ assert_equal @user.name, @liquid_render.render('{{ user.name }}')
29
+ end
30
+
31
+ def test_user_delegated
32
+ assert_equal [@user.name, @user.language].join('|'),
33
+ @liquid_render.render('{{ user.name }}|{{ user.language }}')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class ArraysFilterTest < ActiveSupport::TestCase
6
+ def setup
7
+ @liquid_render = LiquidRender.new
8
+ @array = '6,7,8,9,1,2,3,4,5'
9
+ end
10
+
11
+ def test_first_filter
12
+ assert_match '1', @liquid_render.render("{{ '#{@array}' | split: ',' | first: 5 | last }}")
13
+ end
14
+
15
+ def test_sort_filter
16
+ assert_match '123456789', @liquid_render.render("{{ '#{@array}' | split: ',' | sort }}")
17
+ end
18
+
19
+ def test_where_filter
20
+ assert_match '{"name"=>"two", "value"=>5}', @liquid_render.render("{{ objects_arr | where: 'name', 'two' }}")
21
+ assert_match '{"name"=>"one", "value"=>10}', @liquid_render.render("{{ objects_arr | where: 'value', 6, '>' }}")
22
+ assert_match '{"name"=>"one", "value"=>10}', @liquid_render.render("{{ objects_arr | where: 'name', 'on', 'match' }}")
23
+ assert_match '3', @liquid_render.render("{{ objects_arr | where: 'value', '', 'any' | size }}")
24
+ assert_match '1', @liquid_render.render("{{ objects_arr | where: 'value', '', 'none' | size }}")
25
+ assert_match '2', @liquid_render.render("{{ issues.all | where: 'author.name', 'Jonathan', '==' | size }}")
26
+ assert_match '1', @liquid_render.render("{{ issues.all | where: 'author.language', 'CH', '==' | size }}")
27
+ assert_match '0', @liquid_render.render("{{ issues.all | where: 'author.name', '', 'none' | size }}")
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class BaseFilterTest < ActiveSupport::TestCase
6
+ def setup
7
+ @liquid_render = LiquidRender.new
8
+ end
9
+
10
+ def test_underscore_filter
11
+ assert_match 'some_text', @liquid_render.render("{{ 'some text' | underscore }}")
12
+ end
13
+
14
+ def test_dasherize_filter
15
+ assert_match 'some-text', @liquid_render.render("{{ 'some text' | dasherize }}")
16
+ end
17
+
18
+ def test_random_filter
19
+ assert @liquid_render.render("{{ random: 10 }}").to_i <= 10
20
+ end
21
+
22
+ def test_encode_filter
23
+ assert_equal 'http%3A%3A%2F%2Fwww.test.com%3Fkey%3Dtest+test+test',
24
+ @liquid_render.render("{{ 'http:://www.test.com?key=test test test' | encode }}")
25
+ end
26
+
27
+ def test_plus_days_filter
28
+ assert_match (Date.today + 3.days).strftime(date_format), @liquid_render.render("{{today | plus_days: 3 | date: '#{date_format}'}}")
29
+ end
30
+
31
+ def test_date_range_filter
32
+ assert_equal '10', @liquid_render.render("{{today | date_range: '#{Date.today - 10.days}'}}")
33
+ end
34
+
35
+ def test_today_filter
36
+ assert_match Date.today.strftime(date_format), @liquid_render.render('{{today}}')
37
+ end
38
+
39
+ def test_utc_filter
40
+ assert_match '2017-01-01 10:13:13 UTC', @liquid_render.render("{{'San, 01 Jan 2017 13:13:13 MSK +03:00' | utc}}")
41
+ end
42
+
43
+ def test_modulo_filter
44
+ assert_equal '3', @liquid_render.render("{{24 | modulo: 7}}")
45
+ end
46
+
47
+ def test_round_filter
48
+ assert_equal '24.12', @liquid_render.render("{{24.12345 | round: 2}}")
49
+ end
50
+
51
+ def test_ceil_filter
52
+ assert_equal '25', @liquid_render.render("{{24.11 | ceil }}")
53
+ end
54
+
55
+ def test_floor_filter
56
+ assert_equal '24', @liquid_render.render("{{24.99 | floor }}")
57
+ end
58
+
59
+ def test_currency_filter
60
+ assert_equal '99,99 RUB', @liquid_render.render("{{99.99 | currency: 'RUB' }}")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../liquid_helper'
2
+ include LiquidHelperMethods
3
+
4
+ module RedmineCrm
5
+ class ColorsFilterTest < ActiveSupport::TestCase
6
+
7
+ def setup
8
+ @liquid_render = LiquidRender.new
9
+ end
10
+
11
+ def test_hex_color
12
+ assert_match '#ff0000', @liquid_render.render("{{ 'red' | hex_color }}")
13
+ end
14
+
15
+ def test_darken_color
16
+ assert_match '#000066', @liquid_render.render("{{ 'blue' | darken_color }}")
17
+ end
18
+
19
+ def test_lighten_color
20
+ assert_match '#9999ff', @liquid_render.render("{{ 'blue' | lighten_color }}")
21
+ end
22
+
23
+ def test_contrasting_text_color
24
+ assert_match '#9999ff', @liquid_render.render("{{ 'blue' | contrasting_text_color }}")
25
+ end
26
+
27
+ def test_convert_to_brightness_value
28
+ assert_match '15', @liquid_render.render("{{ 'blue' | convert_to_brightness_value }}")
29
+ end
30
+
31
+
32
+ end
33
+ end