merit 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (1.3.0)
4
+ merit (1.3.1)
5
5
  ambry (~> 0.3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -61,6 +61,14 @@ current_user.add_badge(badge.id)
61
61
  current_user.rm_badge(badge.id)
62
62
  ```
63
63
 
64
+ ```ruby
65
+ # List 10 badge grants in the last month
66
+ Badge.last_granted
67
+
68
+ # List 20 badge grants in the last week
69
+ Badge.last_granted(since_date: 1.week.ago, limit: 20)
70
+ ```
71
+
64
72
  ---
65
73
 
66
74
  # Defining point rules
@@ -102,6 +110,18 @@ current_user.add_points(20, 'Optional log message')
102
110
  current_user.substract_points(10)
103
111
  ```
104
112
 
113
+ ```ruby
114
+ # List top 10 scored users in the last month
115
+ Merit::Score.top_scored
116
+
117
+ # List top 25 scored lists in the last week
118
+ Merit::Score.top_scored(
119
+ table_name: :lists,
120
+ since_date: 1.week.ago,
121
+ limit: 25
122
+ )
123
+ ```
124
+
105
125
  ---
106
126
 
107
127
  # Defining rank rules
@@ -144,3 +164,4 @@ end
144
164
  # To-do list
145
165
 
146
166
  * Should namespace Badge, BadgesSash and Sash into Merit module.
167
+ * Move level from meritable model into Sash
@@ -4,7 +4,7 @@
4
4
 
5
5
  Adds two methods meant to display a leaderboard.
6
6
 
7
- * `Badge#last_granted(options = {})`. Accepts options:
7
+ * `Badge.last_granted(options = {})`. Accepts options:
8
8
  * `:since_date` (`1.month.ago` by default)
9
9
  * `:limit` (10 by default).
10
10
 
@@ -1,4 +1,4 @@
1
- require "merit/models/#{Merit.orm}/merit/action"
1
+ require_dependency "merit/models/#{Merit.orm}/merit/action"
2
2
 
3
3
  # Merit::Action general schema
4
4
  # ______________________________________________________________
@@ -30,7 +30,7 @@ module Merit
30
30
  end
31
31
 
32
32
  def log_activity(str)
33
- self.update_attribute :log, "#{self.log}#{str}|"
33
+ self.update_attribute :log, "#{self.log}#{str}|"[0,240]
34
34
  end
35
35
 
36
36
  def target_object(model_name = nil)
@@ -16,12 +16,12 @@ module Merit
16
16
 
17
17
  def log_merit_action
18
18
  Merit::Action.create(
19
- :user_id => send(Merit.current_user_method).try(:id),
20
- :action_method => action_name,
21
- :action_value => params[:value],
22
- :had_errors => had_errors?,
23
- :target_model => controller_path,
24
- :target_id => target_id
19
+ user_id: send(Merit.current_user_method).try(:id),
20
+ action_method: action_name,
21
+ action_value: params[:value],
22
+ had_errors: had_errors?,
23
+ target_model: controller_path,
24
+ target_id: target_id
25
25
  ).id
26
26
  end
27
27
 
@@ -44,8 +44,10 @@ module Merit
44
44
 
45
45
  def target_id
46
46
  target_id = params[:id] || target_object.try(:id)
47
- # using friendly_id if id is nil or string but an object was found
48
- if target_object.present? && (target_id.nil? || !(target_id =~ /^[0-9]+$/))
47
+ # If params[:id] is a string (slug, using friendly_id for instance)
48
+ # then object exists but can't store params[:id] as the foreign key.
49
+ # Then we grab object's id.
50
+ if target_object && (target_id.nil? || !(target_id.to_s =~ /^[0-9]+$/))
49
51
  target_id = target_object.id
50
52
  end
51
53
  target_id
@@ -4,7 +4,7 @@ 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.3.0'
7
+ s.version = '1.3.1'
8
8
  s.authors = ["Tute Costa"]
9
9
  s.email = 'tutecosta@gmail.com'
10
10
  s.add_dependency 'ambry', '~> 0.3.0'
@@ -28,6 +28,12 @@ class MeritUnitTest < ActiveSupport::TestCase
28
28
  assert_equal Badge.find(98), rule.badge
29
29
  end
30
30
 
31
+ test "Merit::Action#log_activity doesn't grow larger than 240 chars" do
32
+ m = Merit::Action.create
33
+ m.log_activity('a' * 250)
34
+ assert m.log.length <= 240, 'Log shouldn\'t grow larger than 240 chars'
35
+ end
36
+
31
37
  test "Extends only meritable ActiveRecord models" do
32
38
  class MeritableModel < ActiveRecord::Base
33
39
  def self.columns; @columns ||= []; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ambry