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
@@ -1,5 +1,6 @@
1
1
  jonathan:
2
2
  name: Jonathan
3
-
3
+ language: 'EN'
4
4
  sam:
5
- name: Sam
5
+ name: Sam
6
+ language: 'RU'
@@ -3,7 +3,7 @@ class Voter < ActiveRecord::Base
3
3
  end
4
4
 
5
5
  class NotVoter < ActiveRecord::Base
6
-
6
+
7
7
  end
8
8
 
9
9
  class Votable < ActiveRecord::Base
@@ -45,10 +45,9 @@ class ABoringClass
45
45
  end
46
46
  end
47
47
 
48
-
49
48
  # def clean_database
50
49
  # models = [ActsAsVotable::Vote, Voter, NotVoter, Votable, NotVotable, VotableCache]
51
50
  # models.each do |model|
52
51
  # ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
53
52
  # end
54
- # end
53
+ # end
@@ -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,52 @@
1
+ # require File.dirname(__FILE__) + '/../liquid_helper'
2
+
3
+ # module RedmineCrm
4
+ # class LiquidTest < ActiveSupport::TestCase
5
+
6
+ # def test_user_drop
7
+ # user = User.first
8
+ # assert_match user.name, render("{{ user.name }}")
9
+ # end
10
+
11
+ # def test_users_drop
12
+ # users_name = User.all.map(&:name)
13
+ # rendered_text = render("{% for user in users %} {{user.name }} {% endfor %}")
14
+ # users_name.each do |name|
15
+ # assert_match name, rendered_text
16
+ # end
17
+ # end
18
+
19
+ # def test_issue_drop
20
+ # assert_match Issue.first.description, render("{{ issue.description }}")
21
+ # end
22
+
23
+ # def test_default_filter
24
+ # user = User.first
25
+ # user.name = nil
26
+ # user.save
27
+ # assert_match 'user', render("{{ user.name | default: 'user' }}")
28
+ # end
29
+
30
+ # private
31
+
32
+ # def render(content)
33
+ # assigns = {}
34
+ # assigns['now'] = Time.now
35
+ # assigns['today'] = Date.today.strftime(date_format)
36
+ # assigns['user'] = Liquid::UserDrop.new(User.first)
37
+ # assigns['users'] = Liquid::UsersDrop.new(User.all)
38
+ # assigns['issue'] = Liquid::IssueDrop.new(Issue.first)
39
+
40
+ # registers = {}
41
+ # begin
42
+ # ::Liquid::Template.parse(content).render(::Liquid::Context.new({}, assigns, registers)).html_safe
43
+ # rescue => e
44
+ # e.message
45
+ # end
46
+ # end
47
+
48
+ # def date_format
49
+ # '%d.%m.%Y'
50
+ # end
51
+ # end
52
+ # 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 '2', @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,24 @@
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
+ end
22
+
23
+ end
24
+ 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,32 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class LiquidRender
4
+
5
+ def initialize(drops = {})
6
+ @objects_hash = [
7
+ {'name' => 'one', "value" => 10},
8
+ {'name' => 'two', "value" => 5},
9
+ {'name' => 'three', "value" => 6}
10
+ ]
11
+ @registers = {}
12
+ @assigns = {}
13
+ @assigns['objects_arr'] = @objects_hash
14
+ @assigns['now'] = Time.now
15
+ @assigns['today'] = Date.today.strftime(date_format)
16
+ drops.each do |key, drop|
17
+ @assigns[key] = drop
18
+ end
19
+ end
20
+
21
+ def render(content)
22
+ ::Liquid::Template.parse(content).render(::Liquid::Context.new({}, @assigns, @registers)).html_safe
23
+ rescue => e
24
+ e.message
25
+ end
26
+ end
27
+
28
+ module LiquidHelperMethods
29
+ def date_format
30
+ '%d.%m.%Y'
31
+ end
32
+ end
@@ -4,9 +4,9 @@ class MoneyHelperTest < ActiveSupport::TestCase
4
4
  include RedmineCrm::MoneyHelper
5
5
 
6
6
  def test_price_to_currency
7
- assert_equal '$3,265.65', price_to_currency(3265.65, "USD")
8
- assert_equal "3.265,65 ₽", price_to_currency(3265.65, "RUB")
9
- assert_equal "3,200.0", price_to_currency(3200, "")
10
- assert_equal "3,200.0", price_to_currency(3200, "Foo")
7
+ assert_equal '$3,265.65', price_to_currency(3265.65, 'USD')
8
+ assert_equal '3.265,65 RUB', price_to_currency(3265.65, 'RUB')
9
+ assert_equal '3,200.0', price_to_currency(3200, '')
10
+ assert_equal '3,200.0', price_to_currency(3200, 'Foo')
11
11
  end
12
- end
12
+ end
data/test/schema.rb CHANGED
@@ -1,26 +1,30 @@
1
1
  ActiveRecord::Schema.define :version => 0 do
2
-
2
+
3
3
  create_table "tags", :force => true do |t|
4
4
  t.column "name", :string
5
5
  end
6
-
6
+
7
7
  create_table "taggings", :force => true do |t|
8
8
  t.column "tag_id", :integer
9
9
  t.column "taggable_id", :integer
10
10
  t.column "taggable_type", :string
11
11
  t.column "created_at", :datetime
12
12
  end
13
-
13
+
14
14
 
15
15
  create_table "users", :force => true do |t|
16
16
  t.column "name", :string
17
+ t.column "language", :string
17
18
  end
18
-
19
+
19
20
  create_table "issues", :force => true do |t|
21
+ t.integer "project_id"
22
+ t.column "subject", :string
20
23
  t.column "description", :string
21
24
  t.column "closed", :boolean
22
25
  t.column "cached_tag_list", :string
23
26
  t.column "user_id", :integer
27
+ t.column "author_id", :integer
24
28
  t.column "views", :integer, :default => 0
25
29
  t.column "total_views", :integer, :default => 0
26
30
  end
@@ -36,10 +40,18 @@ ActiveRecord::Schema.define :version => 0 do
36
40
  t.timestamps
37
41
  end
38
42
 
39
- # add_index :votes, [:votable_id, :votable_type]
40
- # add_index :votes, [:voter_id, :voter_type]
41
- # add_index :votes, [:voter_id, :voter_type, :vote_scope]
42
- # add_index :votes, [:votable_id, :votable_type, :vote_scope]
43
+ create_table "news", :force => true do |t|
44
+ t.string "title"
45
+ t.text "description"
46
+ t.integer "author_id"
47
+ end
48
+
49
+ create_table "projects", :force => true do |t|
50
+ t.string "name"
51
+ t.text "description"
52
+ t.string "identifier"
53
+ t.integer "status"
54
+ end
43
55
 
44
56
  create_table :voters, :force => true do |t|
45
57
  t.string :name
@@ -97,4 +109,4 @@ ActiveRecord::Schema.define :version => 0 do
97
109
  t.column :ip, :string, :limit => '24'
98
110
  t.column :created_at, :datetime
99
111
  end
100
- end
112
+ end