redmine_crm 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191f70c5ba08d5ecc851be60c8094e17c5578f8b
4
- data.tar.gz: 80038c165458eaa1858f10c360b61b8bc6bbc632
3
+ metadata.gz: 6525848b0cfe3df65dcbf1ea5903e2ec780ba6e2
4
+ data.tar.gz: 9ef776d6118e3998256da878882d7635c798306d
5
5
  SHA512:
6
- metadata.gz: 66e4cc18a95a45af2322642a586a5fe69dd561b7f813fbeb42150f184b39fd604b2d51ce4eb3290216e54f83b4dbf39e89c92e41e81c540d137a9231bc19de67
7
- data.tar.gz: e6324a2cbc82d9e8fa7792102d1bc9e3cc5dc4bb20acab99da79c0982b0a380e0557314b9005f0ffa98b2e1d704f1b817c092ca403c242fddcc4f8d12d9000d9
6
+ metadata.gz: dda3c0995a07c820d329891e3346a713ce561a2810b95cec21faee00457aaba9a068fa4f53df6008ed07ba03d39c929c972bf63f615dd57dacb4cb6eaee74c1f
7
+ data.tar.gz: 122d384d961f9724a3c696caa9178e977138180e4179d802e44bbd9ca685e9c113277deadf400c882421c5e99fd9d2a7a77e6c12c36a0ff60e4ce217e33feb6f
@@ -1,8 +1,16 @@
1
1
  == Redmine CRM gem changelog
2
2
 
3
3
  Redmine crm gem - general functions for plugins (tags, vote, viewing, currency)
4
- Copyright (C) 2011-2016 RedmineUP
5
- http://www.redminecrm.com/
4
+ Copyright (C) 2011-2017 RedmineUP
5
+ https://www.redmineup.com/
6
+
7
+ == 2017-03-13 v0.0.27
8
+
9
+ * Added IP to Votes
10
+
11
+ == 2017-03-10 v0.0.26
12
+
13
+ * Liquid gem with base filters and drops for Redmine objects
6
14
 
7
15
  == 2016-11-12 v0.0.24
8
16
 
@@ -35,6 +35,7 @@ module RedmineCrm
35
35
  t.column :vote_flag, :boolean
36
36
  t.column :vote_scope, :string
37
37
  t.column :vote_weight, :integer
38
+ t.column :vote_ip, :string
38
39
 
39
40
  t.timestamps
40
41
  end
@@ -46,7 +47,8 @@ module RedmineCrm
46
47
  :voter_type => :string,
47
48
  :vote_flag => :boolean,
48
49
  :vote_scope => :string,
49
- :vote_weight => :integer
50
+ :vote_weight => :integer,
51
+ :vote_ip => :string
50
52
  }
51
53
  fields.each do |name, type|
52
54
  if !self.connection.column_exists?(votes_name_table, name)
@@ -57,12 +59,14 @@ module RedmineCrm
57
59
  end
58
60
 
59
61
  if self.parent::VERSION::MAJOR < 4
60
- create_index votes_name_table, [:votable_id, :votable_type]
61
- create_index votes_name_table, [:voter_id, :voter_type]
62
+ create_index votes_name_table, [:votable_id, :votable_type, :vote_ip]
63
+ create_index votes_name_table, [:voter_id, :voter_type, :vote_ip]
62
64
  end
63
65
 
64
66
  create_index votes_name_table, [:voter_id, :voter_type, :vote_scope]
65
67
  create_index votes_name_table, [:votable_id, :votable_type, :vote_scope]
68
+ create_index votes_name_table, [:voter_type, :vote_scope, :vote_ip]
69
+ create_index votes_name_table, [:votable_type, :vote_scope, :vote_ip]
66
70
  end
67
71
 
68
72
  def drop_votable_table(options = {})
@@ -71,16 +71,17 @@ module RedmineCrm
71
71
  return false if options[:voter].nil?
72
72
 
73
73
  # find the vote
74
- votes_for = find_votes_for(:voter_id => options[:voter].id,
75
- :vote_scope => options[:vote_scope],
76
- :voter_type => options[:voter].class.base_class.name)
74
+ vote_conditions = { :vote_scope => options[:vote_scope], :voter_type => options[:voter].class.base_class.name }
75
+ vote_conditions.merge!(options[:vote_by_ip] ? { :vote_ip => options[:vote_ip] } : { :voter_id => options[:voter].id} )
76
+ votes_for = find_votes_for(vote_conditions)
77
77
 
78
78
  if votes_for.count == 0 || options[:duplicate]
79
79
  # this voter has never voted
80
80
  vote = RedmineCrm::ActsAsVotable::Vote.new(
81
81
  :votable => self,
82
82
  :voter => options[:voter],
83
- :vote_scope => options[:vote_scope]
83
+ :vote_scope => options[:vote_scope],
84
+ :vote_ip => options[:vote_ip]
84
85
  )
85
86
  else
86
87
  # this voter is potentially changing his vote
@@ -97,7 +98,7 @@ module RedmineCrm
97
98
  if vote.save
98
99
  self.vote_registered = true if last_update != vote.updated_at
99
100
  update_cached_votes options[:vote_scope]
100
- return true
101
+ return vote
101
102
  else
102
103
  self.vote_registered = false
103
104
  return false
@@ -105,10 +106,10 @@ module RedmineCrm
105
106
  end
106
107
 
107
108
  def unvote(args = {})
108
- return false if args[:voter].nil?
109
- votes_for = find_votes_for(:voter_id => args[:voter].id,
110
- :vote_scope => args[:vote_scope],
111
- :voter_type => args[:voter].class.base_class.name)
109
+ return false if (!args[:vote_by_ip] && args[:voter].nil?) || (args[:vote_by_ip] && args[:vote_ip].nil?)
110
+ vote_conditions = { :vote_scope => args[:vote_scope], :voter_type => args[:voter].class.base_class.name }
111
+ vote_conditions.merge!(args[:vote_by_ip] ? { :vote_ip => args[:vote_ip] } : { :voter_id => args[:voter].id})
112
+ votes_for = find_votes_for(vote_conditions)
112
113
 
113
114
  return true if votes_for.empty?
114
115
  votes_for.each(&:destroy)
@@ -117,16 +118,22 @@ module RedmineCrm
117
118
  true
118
119
  end
119
120
 
120
- def vote_up(voter, options = {})
121
- self.vote_by :voter => voter, :vote => true, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
121
+ def vote_up(voter, options={})
122
+ self.vote_by :voter => voter, :vote => true,
123
+ :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight], :vote_ip => options[:vote_ip],
124
+ :vote_by_ip => options[:vote_by_ip]
122
125
  end
123
126
 
124
- def vote_down(voter, options = {})
125
- self.vote_by :voter => voter, :vote => false, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
127
+ def vote_down(voter, options={})
128
+ self.vote_by :voter => voter, :vote => false,
129
+ :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight], :vote_ip => options[:vote_ip],
130
+ :vote_by_ip => options[:vote_by_ip]
126
131
  end
127
132
 
128
133
  def unvote_by(voter, options = {})
129
- self.unvote :voter => voter, :vote_scope => options[:vote_scope] # Does not need vote_weight since the votes_for are anyway getting destroyed
134
+ # Does not need vote_weight since the votes_for are anyway getting destroyed
135
+ self.unvote :voter => voter, :vote_scope => options[:vote_scope], :vote_ip => options[:vote_ip],
136
+ :vote_by_ip => options[:vote_by_ip]
130
137
  end
131
138
 
132
139
  def scope_cache_field(field, vote_scope)
@@ -7,9 +7,10 @@ module RedmineCrm
7
7
 
8
8
  if defined?(ProtectedAttributes) || ::ActiveRecord::VERSION::MAJOR < 4
9
9
  attr_accessible :votable_id, :votable_type,
10
- :voter_id, :voter_type,
11
- :votable, :voter,
12
- :vote_flag, :vote_scope
10
+ :voter_id, :voter_type,
11
+ :votable, :voter,
12
+ :vote_flag, :vote_scope,
13
+ :vote_ip
13
14
  end
14
15
 
15
16
  belongs_to :votable, :polymorphic => true
@@ -1,3 +1,3 @@
1
1
  module RedmineCrm
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
@@ -6,10 +6,10 @@ require 'redmine_crm/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "redmine_crm"
8
8
  spec.version = RedmineCrm::VERSION
9
- spec.authors = ["RedmineCRM"]
9
+ spec.authors = ["RedmineUP"]
10
10
  spec.email = ["support@redminecrm.com"]
11
- spec.summary = %q{Common libraries for RedmineCRM plugins for Redmine}
12
- spec.description = %q{Common libraries for RedmineCRM plugins for Redmine. Requered Redmine from http://redmine.org}
11
+ spec.summary = %q{Common libraries for RedmineUP plugins for Redmine}
12
+ spec.description = %q{Common libraries for RedmineUP plugins (www.redmineup.com) for Redmine. Requered Redmine from http://redmine.org}
13
13
  spec.homepage = ""
14
14
  spec.license = "GPL2"
15
15
 
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class VotableTest < ActiveSupport::TestCase
4
-
5
4
  def votable
6
5
  votables(:votable)
7
6
  end
@@ -15,6 +14,36 @@ class VotableTest < 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")
@@ -36,6 +36,7 @@ ActiveRecord::Schema.define :version => 0 do
36
36
  t.boolean "vote_flag"
37
37
  t.string "vote_scope"
38
38
  t.integer "vote_weight"
39
+ t.string "vote_ip"
39
40
 
40
41
  t.timestamps
41
42
  end
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.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
- - RedmineCRM
7
+ - RedmineUP
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.6.4
27
- description: Common libraries for RedmineCRM plugins for Redmine. Requered Redmine
28
- from http://redmine.org
27
+ description: Common libraries for RedmineUP plugins (www.redmineup.com) for Redmine.
28
+ Requered Redmine from http://redmine.org
29
29
  email:
30
30
  - support@redminecrm.com
31
31
  executables: []
@@ -126,7 +126,7 @@ rubyforge_project:
126
126
  rubygems_version: 2.4.5.2
127
127
  signing_key:
128
128
  specification_version: 4
129
- summary: Common libraries for RedmineCRM plugins for Redmine
129
+ summary: Common libraries for RedmineUP plugins for Redmine
130
130
  test_files:
131
131
  - test/acts_as_taggable/rcrm_acts_as_taggable_test.rb
132
132
  - test/acts_as_taggable/tag_list_test.rb