redmine_crm 0.0.23 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/doc/CHANGELOG +4 -0
  4. data/lib/redmine_crm.rb +28 -20
  5. data/lib/redmine_crm/{rcrm_acts_as_taggable.rb → acts_as_taggable/rcrm_acts_as_taggable.rb} +93 -87
  6. data/lib/redmine_crm/acts_as_taggable/tag.rb +81 -0
  7. data/lib/redmine_crm/acts_as_taggable/tag_list.rb +111 -0
  8. data/lib/redmine_crm/acts_as_taggable/tagging.rb +16 -0
  9. data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
  10. data/lib/redmine_crm/{rcrm_acts_as_votable.rb → acts_as_votable/rcrm_acts_as_votable.rb} +8 -11
  11. data/lib/redmine_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
  12. data/lib/redmine_crm/{votable.rb → acts_as_votable/votable.rb} +36 -47
  13. data/lib/redmine_crm/{vote.rb → acts_as_votable/vote.rb} +7 -10
  14. data/lib/redmine_crm/{voter.rb → acts_as_votable/voter.rb} +29 -34
  15. data/lib/redmine_crm/currency/formatting.rb +0 -3
  16. data/lib/redmine_crm/currency/heuristics.rb +1 -1
  17. data/lib/redmine_crm/currency/loader.rb +1 -1
  18. data/lib/redmine_crm/helpers/tags_helper.rb +1 -3
  19. data/lib/redmine_crm/helpers/vote_helper.rb +29 -32
  20. data/lib/redmine_crm/liquid/drops/issues_drop.rb +66 -0
  21. data/lib/redmine_crm/liquid/drops/news_drop.rb +54 -0
  22. data/lib/redmine_crm/liquid/drops/projects_drop.rb +86 -0
  23. data/lib/redmine_crm/liquid/drops/users_drop.rb +72 -0
  24. data/lib/redmine_crm/liquid/filters/arrays.rb +178 -0
  25. data/lib/redmine_crm/liquid/filters/base.rb +208 -0
  26. data/lib/redmine_crm/version.rb +1 -1
  27. data/redmine_crm.gemspec +1 -1
  28. data/test/{acts_as_taggable_test.rb → acts_as_taggable/rcrm_acts_as_taggable_test.rb} +114 -151
  29. data/test/acts_as_taggable/tag_list_test.rb +38 -0
  30. data/test/acts_as_taggable/tag_test.rb +74 -0
  31. data/test/acts_as_taggable/tagging_test.rb +15 -0
  32. data/test/{viewed_test.rb → acts_as_viewed/rcrm_acts_as_viewed_test.rb} +17 -15
  33. data/test/{votable_test.rb → acts_as_votable/rcrm_acts_as_votable_test.rb} +3 -3
  34. data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +12 -0
  35. data/test/{votable_model_test.rb → acts_as_votable/votable_test.rb} +4 -4
  36. data/test/{voter_model_test.rb → acts_as_votable/voter_test.rb} +7 -7
  37. data/test/currency_test.rb +10 -10
  38. data/test/fixtures/issue.rb +6 -2
  39. data/test/fixtures/issues.yml +13 -1
  40. data/test/fixtures/news.rb +3 -0
  41. data/test/fixtures/news.yml +8 -0
  42. data/test/fixtures/project.rb +8 -0
  43. data/test/fixtures/projects.yml +10 -0
  44. data/test/fixtures/user.rb +5 -1
  45. data/test/fixtures/users.yml +3 -2
  46. data/test/fixtures/vote_classes.rb +2 -3
  47. data/test/liquid/drops/issues_drop_test.rb +34 -0
  48. data/test/liquid/drops/liquid_test.rb +52 -0
  49. data/test/liquid/drops/news_drop_test.rb +38 -0
  50. data/test/liquid/drops/projects_drop_test.rb +44 -0
  51. data/test/liquid/drops/uses_drop_test.rb +36 -0
  52. data/test/liquid/filters/arrays_filter_test.rb +24 -0
  53. data/test/liquid/filters/base_filter_test.rb +63 -0
  54. data/test/liquid/liquid_helper.rb +32 -0
  55. data/test/money_helper_test.rb +5 -5
  56. data/test/schema.rb +21 -9
  57. data/test/test_helper.rb +26 -25
  58. metadata +76 -28
  59. data/lib/redmine_crm/rcrm_acts_as_viewed.rb +0 -287
  60. data/lib/redmine_crm/rcrm_acts_as_voter.rb +0 -27
  61. data/lib/redmine_crm/tag.rb +0 -81
  62. data/lib/redmine_crm/tag_list.rb +0 -112
  63. data/lib/redmine_crm/tagging.rb +0 -20
  64. data/test/tag_test.rb +0 -64
  65. data/test/tagging_test.rb +0 -14
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module RedmineCrm
4
+ module ActsAsTaggable
5
+ class TagListTest < ActiveSupport::TestCase
6
+ def setup
7
+ @tag_list = TagList.new(%w(error bug))
8
+ end
9
+
10
+ def test_from
11
+ assert_equal %w(one two three), TagList.from('one, two, two, three, three, three')
12
+ end
13
+
14
+ def test_add
15
+ @tag_list.add(['new_tag'])
16
+ assert_equal %w(error bug new_tag), @tag_list
17
+ end
18
+
19
+ def test_remove
20
+ @tag_list.remove(['old_tag'])
21
+ assert_equal %w(error bug), @tag_list
22
+ @tag_list.remove(['error'])
23
+ assert_equal %w(bug), @tag_list
24
+ end
25
+
26
+ def test_toggle
27
+ @tag_list.toggle(['new_tag'])
28
+ assert_equal %w(error bug new_tag), @tag_list
29
+ @tag_list.toggle(['error'])
30
+ assert_equal %w(bug new_tag), @tag_list
31
+ end
32
+
33
+ def test_to_s
34
+ assert_equal 'error, bug', @tag_list.to_s
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module RedmineCrm
4
+ module ActsAsTaggable
5
+ class TagTest < ActiveSupport::TestCase
6
+ def test_find_or_create_with_like_by_name
7
+ assert_no_difference 'RedmineCrm::ActsAsTaggable::Tag.count' do
8
+ Tag.find_or_create_with_like_by_name('error')
9
+ end
10
+
11
+ assert_difference 'RedmineCrm::ActsAsTaggable::Tag.count', 1 do
12
+ Tag.find_or_create_with_like_by_name('new_tag')
13
+ end
14
+ end
15
+
16
+ def test_name_required
17
+ t = Tag.create
18
+ assert_match /blank/, t.errors[:name].to_s
19
+ end
20
+
21
+ def test_name_unique
22
+ t = Tag.create!(:name => 'My tag')
23
+ duplicate = t.dup
24
+ assert !duplicate.save
25
+ assert_match /not uniq/, duplicate.errors[:name].to_s
26
+ end
27
+
28
+ def test_taggings
29
+ assert_equivalent [taggings(:tag_for_error), taggings(:tag_for_error1), taggings(:tag_for_error2)], tags(:error).taggings
30
+ assert_equivalent [taggings(:tag_for_question1), taggings(:tag_for_question2), taggings(:tag_for_question3)], tags(:question).taggings
31
+ end
32
+
33
+ def test_to_s
34
+ assert_equal tags(:error).name, tags(:error).to_s
35
+ end
36
+
37
+ def test_equality
38
+ assert_equal tags(:error), tags(:error)
39
+ assert_equal Tag.find(tags(:error).id), Tag.find(tags(:error).id)
40
+ assert_equal Tag.new(:name => 'A'), Tag.new(:name => 'A')
41
+ assert_not_equal Tag.new(:name => 'A'), Tag.new(:name => 'B')
42
+ end
43
+
44
+ def test_taggings_removed_when_tag_destroyed
45
+ assert_difference("Tagging.count", -Tagging.where(:tag_id => tags(:error).id).count) do
46
+ assert tags(:error).destroy
47
+ end
48
+ end
49
+
50
+ def test_all_counts
51
+ assert_tag_counts Tag.counts, :error => 3, :feature => 1, :bug => 1, :question => 3
52
+ end
53
+
54
+ def test_all_counts_with_string_conditions
55
+ assert_tag_counts Tag.counts(:conditions => 'taggings.created_at >= \'2015-01-01\''),
56
+ :question => 3, :error => 2, :feature => 1, :bug => 1
57
+ end
58
+
59
+ def test_all_counts_with_array_conditions
60
+ assert_tag_counts Tag.counts(:conditions => ['taggings.created_at >= ?', '2015-01-01']),
61
+ :question => 3, :error => 2, :feature => 1, :bug => 1
62
+ end
63
+
64
+ def test_all_counts_with_hash_conditions
65
+ tag_counts = Tag.counts(
66
+ :conditions => {
67
+ :taggings => { :created_at => (DateTime.parse('2014-12-31 23:59') .. DateTime.parse('4000-01-01')) }
68
+ }
69
+ )
70
+ assert_tag_counts tag_counts, :question => 3, :error => 2, :feature => 1, :bug => 1
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module RedmineCrm
4
+ module ActsAsTaggable
5
+ class TaggingTest < ActiveSupport::TestCase
6
+ def test_tag
7
+ assert_equal tags(:error), taggings(:tag_for_error).tag
8
+ end
9
+
10
+ def test_taggable
11
+ assert_equal issues(:first_issue), taggings(:tag_for_error).taggable
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class VotableTest < ActiveSupport::TestCase
3
+ class RcrmActsAsVotableTest < ActiveSupport::TestCase
4
4
  def test_not_be_votable
5
5
  assert !NotVotable.votable?, false
6
6
  end
@@ -14,4 +14,4 @@ class VotableTest < ActiveSupport::TestCase
14
14
  assert VotableCache.create(:name => 'voting model with cache')
15
15
  assert VotableVoter.create(:name => 'i can vote too!')
16
16
  end
17
- end
17
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RcrmActsAsVoterTest < ActiveSupport::TestCase
4
+ def test_not_be_votable
5
+ assert !NotVoter.voter?, false
6
+ end
7
+
8
+ def test_be_voter
9
+ assert Voter.voter?, true
10
+ assert VotableVoter.voter?, true
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class VotableTest < ActiveSupport::TestCase
2
4
 
3
- class VotableModelTest < ActiveSupport::TestCase
4
-
5
5
  def votable
6
6
  votables(:votable)
7
7
  end
@@ -475,4 +475,4 @@ class VotableModelTest < ActiveSupport::TestCase
475
475
  end
476
476
 
477
477
 
478
- end
478
+ 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
@@ -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
@@ -1,14 +1,18 @@
1
1
  class Issue < ActiveRecord::Base
2
2
  rcrm_acts_as_taggable
3
3
  rcrm_acts_as_viewed
4
- # default_scope {where(:closed => false)}
4
+
5
+ belongs_to :project
5
6
  belongs_to :user
7
+ belongs_to :author, :class_name => 'User'
6
8
  validates_presence_of :description
7
9
 
10
+ scope :visible, lambda { where('1=1') }
11
+
8
12
  def save_without_validation
9
13
  save
10
14
  end
11
15
  end
12
16
 
13
17
  class SpecialIssue < Issue
14
- end
18
+ end
@@ -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: sam
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,3 @@
1
+ class News < ActiveRecord::Base
2
+ belongs_to :author, :class_name => 'User'
3
+ end
@@ -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,8 @@
1
+ class Project < ActiveRecord::Base
2
+ STATUS_ACTIVE = 1
3
+ has_many :issues, :dependent => :destroy
4
+
5
+ def active?
6
+ status == STATUS_ACTIVE
7
+ end
8
+ end
@@ -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,7 +1,11 @@
1
1
  class User < ActiveRecord::Base
2
2
  has_many :issues
3
3
 
4
+ def self.current
5
+ User.first
6
+ end
7
+
4
8
  def anonymous?
5
9
  false
6
10
  end
7
- end
11
+ end