merit 1.6.2 → 1.7.0

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: 0d0a820341d6408878856c250741dc432cf69e87
4
- data.tar.gz: 5c62d13ececa1fbc100635867a24f1ede459ea7b
3
+ metadata.gz: be995bc6f76b25bcfd157f902124baba46eb05a7
4
+ data.tar.gz: 3905b409c862c55b11e05a892bdad1fca4371653
5
5
  SHA512:
6
- metadata.gz: 8701d647ca74706f02beabb79392e7e35015719b05aef83476a97ae2f86810bace21184065bf1aed45a6f08b40ace8a94e5957a04cd743162e158f0ee433f4b4
7
- data.tar.gz: 321f7574c41b967a5e13af373f387b48b47cc7817397b5777d1c84ef75192edaa97de25cd96ca87b370e2783d59872636fac5fcc1b319a7d5d5a909d02ce70c3
6
+ metadata.gz: 30548a8373a7db2b1a37621bc8dbd08d60e7c2d11bf164b139e5098e245179acfcaec8bde96e4b6bf3a9b0edba238e9b45a65099abed95350bf0aa8d0b9370f5
7
+ data.tar.gz: 1ecac2b778294d30882a0bba7ddcb165b0c328f12f74972cf0dba7dd65a207fa6fb8af151063c1ecd9769f4296bad0712583ab3f003433f8156d850d3652d9ec
data/Gemfile CHANGED
@@ -14,3 +14,15 @@ when '3.2'
14
14
  end
15
15
 
16
16
  gem 'rails', rails
17
+
18
+ group :development, :test do
19
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
20
+ gem 'sqlite3', :platforms => [:ruby, :mswin, :mingw]
21
+ end
22
+
23
+ platforms :rbx do
24
+ gem 'rubysl', '~> 2.0'
25
+ gem 'racc'
26
+ gem 'rubysl-test-unit'
27
+ gem 'rubinius-developer_tools'
28
+ end
data/README.md CHANGED
@@ -112,6 +112,9 @@ action user or to the method(s) defined in the `:to` option. Define rules on
112
112
 
113
113
  `score` accepts:
114
114
 
115
+ * `score`
116
+ * `Integer`
117
+ * `Proc`, or any object that accepts `call` which takes one argument, where the target_object is passed in and the return value is used as the score.
115
118
  * `:on` action as string or array of strings (similar to Rails routes)
116
119
  * `:to` method(s) to send to the target_object (who should be scored?)
117
120
  * `:model_name` (optional) to specify the model name if it cannot be guessed from the controller.
@@ -135,6 +138,9 @@ score 20, on: [
135
138
  ]
136
139
 
137
140
  score 15, on: 'reviews#create', to: [:reviewer, :reviewed]
141
+
142
+ calculate = lambda { |photo| PhotoPointsCalculator.calculate_score_for(photo) }
143
+ score calculate, on: 'photos#create'
138
144
  ```
139
145
 
140
146
  ```ruby
@@ -143,7 +149,7 @@ current_user.points # Returns an integer
143
149
 
144
150
  # Score manually
145
151
  current_user.add_points(20, 'Optional log message')
146
- current_user.substract_points(10)
152
+ current_user.subtract_points(10)
147
153
  ```
148
154
 
149
155
  ```ruby
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  require 'rake'
10
- require 'rdoc/task'
11
10
 
12
11
  require 'rake/testtask'
13
12
 
@@ -20,10 +19,16 @@ end
20
19
 
21
20
  task :default => :test
22
21
 
23
- Rake::RDocTask.new(:rdoc) do |rdoc|
24
- rdoc.rdoc_dir = 'rdoc'
25
- rdoc.title = 'Merit'
26
- rdoc.options << '--line-numbers' << '--inline-source'
27
- rdoc.rdoc_files.include('README.md')
28
- rdoc.rdoc_files.include('lib/**/*.rb')
22
+ begin
23
+ require 'rdoc/task'
24
+
25
+ Rake::RDocTask.new(:rdoc) do |rdoc|
26
+ rdoc.rdoc_dir = 'rdoc'
27
+ rdoc.title = 'Merit'
28
+ rdoc.options << '--line-numbers' << '--inline-source'
29
+ rdoc.rdoc_files.include('README.md')
30
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
+ end
32
+ rescue LoadError
33
+ puts 'This platform does not support RDocTask'
29
34
  end
@@ -1,5 +1,12 @@
1
1
  # Upgrading
2
2
 
3
+ ## 1.7.0
4
+
5
+ * Adds support for dynamic scoring
6
+ * `substract_points` is deprecated in favor of `subtract_points`. Careless
7
+ computers didn't mind my misspellings. ;-)
8
+ * JRuby and Rubinius compatibility
9
+
3
10
  ## 1.6.0
4
11
 
5
12
  * Rails 4 ready.
@@ -26,7 +26,7 @@ module Merit
26
26
  def apply_points
27
27
  return unless rule_applies?
28
28
  @sashes.each do |sash|
29
- point = sash.add_points @rule.score
29
+ point = sash.add_points points
30
30
  notify_observers(@action.id, point)
31
31
  end
32
32
  end
@@ -52,11 +52,22 @@ module Merit
52
52
  !sash.badge_ids.include?(badge.id) || @rule.multiple
53
53
  end
54
54
 
55
+ def rule_object
56
+ BaseTargetFinder.find(@rule, @action)
57
+ end
58
+
55
59
  def rule_applies?
56
- rule_object = BaseTargetFinder.find(@rule, @action)
57
60
  @rule.applies? rule_object
58
61
  end
59
62
 
63
+ def points
64
+ if @rule.score.respond_to?(:call)
65
+ @rule.score.call(rule_object)
66
+ else
67
+ @rule.score
68
+ end
69
+ end
70
+
60
71
  def badge
61
72
  @rule.badge
62
73
  end
@@ -19,7 +19,7 @@ module Merit
19
19
  def _merit_delegate_methods_to_sash
20
20
  methods = %w(badge_ids badges points
21
21
  add_badge rm_badge
22
- add_points substract_points)
22
+ add_points substract_points subtract_points)
23
23
  methods.each { |method| delegate method, to: :_sash }
24
24
  end
25
25
 
@@ -40,7 +40,7 @@ module Merit
40
40
  end
41
41
 
42
42
  def _merit_define_badge_related_entries_method
43
- meritable_class_name = caller[1][/`.*'/][8..-3]
43
+ meritable_class_name = name.demodulize
44
44
  Badge._define_related_entries_method(meritable_class_name)
45
45
  end
46
46
 
@@ -42,7 +42,13 @@ module Merit
42
42
  point
43
43
  end
44
44
 
45
+ # DEPRECATED: Please use <tt>subtract_points</tt> instead.
45
46
  def substract_points(num_points, log = 'Manually granted', category = 'default')
47
+ warn "[DEPRECATION] `substract_points` is deprecated. Please use `subtract_points` instead."
48
+ subtract_points num_points, log, category
49
+ end
50
+
51
+ def subtract_points(num_points, log = 'Manually granted', category = 'default')
46
52
  add_points -num_points, log, category
47
53
  end
48
54
 
@@ -37,7 +37,11 @@ GROUP BY #{options[:table_name]}.id, merit_scores.sash_id
37
37
  ORDER BY sum_points DESC
38
38
  LIMIT #{options[:limit]}
39
39
  SQL
40
- ActiveRecord::Base.connection.execute(sql_query)
40
+ results = ActiveRecord::Base.connection.execute(sql_query)
41
+ results.map do |h|
42
+ h.keep_if { |k, v| (k == alias_id_column) || (k == 'sum_points') }
43
+ end
44
+ results
41
45
  end
42
46
 
43
47
  def points
@@ -7,7 +7,9 @@ module Merit
7
7
  end
8
8
 
9
9
  def select_from(rules)
10
- rules.select { |glob, _| entire_path =~ Regexp.new(glob) }.values.flatten
10
+ rules.select do |glob, _|
11
+ entire_path =~ /^#{Regexp.new(glob)}$/
12
+ end.values.flatten
11
13
  end
12
14
 
13
15
  def any_matching?
@@ -4,15 +4,15 @@ Gem::Specification.new do |s|
4
4
  s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
5
5
  s.homepage = "http://github.com/tute/merit"
6
6
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
7
- s.version = '1.6.2'
7
+ s.license = 'MIT'
8
+ s.version = '1.7.0'
8
9
  s.authors = ["Tute Costa"]
9
10
  s.email = 'tutecosta@gmail.com'
10
11
 
11
12
  s.required_ruby_version = '>= 1.9.2'
12
13
 
13
14
  s.add_dependency 'ambry', '~> 0.3.0'
14
- s.add_development_dependency 'rails', '~> 3.2.0'
15
- s.add_development_dependency 'sqlite3'
15
+ s.add_development_dependency 'rails', '>= 3.2.0'
16
16
  s.add_development_dependency 'capybara'
17
17
  s.add_development_dependency 'simplecov'
18
18
  s.add_development_dependency 'minitest-rails'
@@ -29,6 +29,10 @@ module Merit
29
29
  true
30
30
  end
31
31
  end
32
+
33
+ score lambda { |comment| comment.comment.to_i }, to: :user, on: 'comments#create' do |object|
34
+ object.comment.to_i > 0
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -77,7 +77,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
77
77
  assert_equal 0, Merit::Score::Point.count
78
78
  user.add_points 15
79
79
  assert_equal 15, user.points
80
- user.substract_points 15
80
+ user.subtract_points 15
81
81
  assert_equal 0, user.points
82
82
  assert_equal 2, Merit::Score::Point.count
83
83
 
@@ -172,6 +172,15 @@ class NavigationTest < ActiveSupport::IntegrationCase
172
172
  visit "/comments/#{Comment.last.id}/vote/4"
173
173
  user = User.first
174
174
  assert_equal 46, user.points, 'Voting comments should grant 5 points for voted, and 1 point for voting'
175
+
176
+ visit '/comments/new'
177
+ fill_in 'Name', with: 'Hi'
178
+ fill_in 'Comment', with: '4'
179
+ fill_in 'User', with: user.id
180
+ click_button('Create Comment')
181
+
182
+ user = User.where(name: 'a').first
183
+ assert_equal 50, user.points, 'Commenting should grant the integer in comment points if comment is an integer'
175
184
  end
176
185
 
177
186
  test 'user workflow should grant levels at some times' do
@@ -54,10 +54,10 @@ class MeritUnitTest < ActiveSupport::TestCase
54
54
  sash_2.add_points(5); sash_2.add_points(5)
55
55
 
56
56
  # Test method options
57
- assert_equal [{'sash_id'=>sash_1.id, 'sum_points'=>20, 0=>1, 1=>20},
58
- {'sash_id'=>sash_2.id, 'sum_points'=>10, 0=>2, 1=>10}],
57
+ assert_equal [{'sash_id'=>sash_1.id, 'sum_points'=>20},
58
+ {'sash_id'=>sash_2.id, 'sum_points'=>10}],
59
59
  Merit::Score.top_scored(table_name: :sashes)
60
- assert_equal [{'sash_id'=>sash_1.id, 'sum_points'=>20, 0=>1, 1=>20}],
60
+ assert_equal [{'sash_id'=>sash_1.id, 'sum_points'=>20}],
61
61
  Merit::Score.top_scored(table_name: :sashes, limit: 1)
62
62
  end
63
63
 
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ describe Merit::RulesMatcher do
4
+
5
+ describe 'rules actions are treated as a regexp' do
6
+ it 'selects matching rules (suffix)' do
7
+ matcher = Merit::RulesMatcher.new('comments', 'update')
8
+ matcher.select_from({
9
+ 'comments#update' => 'comments#update',
10
+ 'comments#up' => 'comments#up',
11
+ 'comments#up$' => 'comments#up$',
12
+ 'comments#up.+$' => 'comments#up.+$',
13
+ }).must_be :==, ['comments#update', 'comments#up.+$']
14
+
15
+ matcher = Merit::RulesMatcher.new('comments', 'up')
16
+ matcher.select_from({
17
+ 'comments#update' => 'comments#update',
18
+ 'comments#up' => 'comments#up',
19
+ 'comments#up$' => 'comments#up$',
20
+ 'comments#up.+$' => 'comments#up.+$',
21
+ }).must_be :==, ['comments#up', 'comments#up$']
22
+ end
23
+
24
+ it 'selects matching rules (prefix)' do
25
+ matcher = Merit::RulesMatcher.new('/posts/1/comments', 'create')
26
+ matcher.select_from({
27
+ 'comments#create' => 'comments#create',
28
+ '^comments#create' => '^comments#create',
29
+ '^.*/comments#create' => '^.*/comments#create',
30
+ }).must_be :==, ['^.*/comments#create']
31
+ end
32
+ end
33
+
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tute Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-10 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ambry
@@ -26,32 +26,18 @@ dependencies:
26
26
  version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 3.2.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 3.2.0
41
- - !ruby/object:Gem::Dependency
42
- name: sqlite3
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - '>='
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: 3.2.0
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - '>='
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 3.2.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: capybara
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -284,10 +270,12 @@ files:
284
270
  - test/unit/base_target_finder_test.rb
285
271
  - test/unit/merit_unit_test.rb
286
272
  - test/unit/rule_unit_test.rb
273
+ - test/unit/rules_matcher_test.rb
287
274
  - test/unit/sash_finder_test.rb
288
275
  - test/unit/target_finder_test.rb
289
276
  homepage: http://github.com/tute/merit
290
- licenses: []
277
+ licenses:
278
+ - MIT
291
279
  metadata: {}
292
280
  post_install_message:
293
281
  rdoc_options: []
@@ -305,9 +293,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
293
  version: '0'
306
294
  requirements: []
307
295
  rubyforge_project:
308
- rubygems_version: 2.0.3
296
+ rubygems_version: 2.0.14
309
297
  signing_key:
310
298
  specification_version: 4
311
299
  summary: General reputation Rails engine.
312
300
  test_files: []
313
- has_rdoc: