merit 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +6 -8
- data/lib/generators/active_record/templates/add_fields_to_model.rb +2 -8
- data/lib/generators/active_record/templates/create_merit_actions.rb +1 -5
- data/lib/generators/active_record/templates/create_merit_activity_logs.rb +1 -5
- data/lib/generators/active_record/templates/create_sashes.rb +1 -5
- data/lib/generators/active_record/templates/create_scores_and_points.rb +1 -6
- data/lib/generators/merit/templates/merit_badge_rules.rb +2 -1
- data/lib/merit/controller_extensions.rb +1 -1
- data/lib/merit/rule.rb +6 -2
- data/lib/merit/rules_badge_methods.rb +1 -0
- data/merit.gemspec +1 -1
- data/test/dummy/app/models/merit/badge_rules.rb +2 -2
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/rule_unit_test.rb +9 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7d2cd9366ca515998303997aa8b9f30d7ab3e9f
|
4
|
+
data.tar.gz: 7be13cb7255f3d90760360827f07f6d57a2b1376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ee7dde0226e826d7244c5370ceb9edc8d9bd2d6340a36ba2219c229ea2103e2e891f4fef00708afd9e024bc4b6352fb1a07ba6825a7fc5168385ba18b1abab
|
7
|
+
data.tar.gz: 150e480cb899d7f88ad9ff85f4f7fe4bd19ce2936823454717d27b50ed286809e2a7e6b92b2f0f3fd81600132189f381c8e79ad95aa6e39279537182e392b919
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.3.0
|
4
|
+
|
5
|
+
- [#206] Allow Rule to find Badge by `badge_id`
|
6
|
+
- [#197] SVG badges in favor of PNG in the readme.
|
7
|
+
- [#195] migrations refactor
|
8
|
+
- Tests with Rails 4.2
|
9
|
+
|
3
10
|
## 2.2.0
|
4
11
|
|
5
12
|
- [#181] Rescue `ActiveRecord` only if constant is defined (doesn't trigger
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
version = ENV['RAILS_VERSION'] || '4.
|
5
|
+
version = ENV['RAILS_VERSION'] || '4.2'
|
6
6
|
rails = case version
|
7
7
|
when 'master'
|
8
8
|
{ github: 'rails/rails' }
|
@@ -12,7 +12,7 @@ when '4.0-protected-attributes'
|
|
12
12
|
when /4\.0|4\.1/
|
13
13
|
"~> #{version}.0"
|
14
14
|
when /4\.2/
|
15
|
-
"~> #{version}.0.
|
15
|
+
"~> #{version}.0.rc3"
|
16
16
|
when '3.2'
|
17
17
|
gem 'strong_parameters'
|
18
18
|
"~> #{version}.0"
|
data/README.md
CHANGED
@@ -3,11 +3,9 @@
|
|
3
3
|
Merit adds reputation behavior to Rails apps in the form of Badges, Points,
|
4
4
|
and Rankings.
|
5
5
|
|
6
|
-
[![Build Status](https://travis-ci.org/tute/merit.
|
7
|
-
[![Coverage
|
8
|
-
|
9
|
-
[![Code Climate](https://codeclimate.com/github/tute/merit.png)](https://codeclimate.com/github/tute/merit)
|
10
|
-
|
6
|
+
[![Build Status](https://travis-ci.org/tute/merit.svg?branch=master)](http://travis-ci.org/tute/merit)
|
7
|
+
[![Coverage Status](https://img.shields.io/coveralls/tute/merit.svg)](https://coveralls.io/r/tute/merit?branch=master)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/tute/merit/badges/gpa.svg)](https://codeclimate.com/github/tute/merit)
|
11
9
|
|
12
10
|
# Table of Contents
|
13
11
|
|
@@ -77,8 +75,8 @@ are no longer met).
|
|
77
75
|
Badge rules / conditions are defined in `app/models/merit/badge_rules.rb`
|
78
76
|
`initialize` block by calling `grant_on` with the following parameters:
|
79
77
|
|
80
|
-
* `'controller#action'` a string similar to Rails routes
|
81
|
-
* `:badge`
|
78
|
+
* `'controller#action'` a string similar to Rails routes (required)
|
79
|
+
* `:badge_id` or `:badge` these correspond to the `:id` or `:name` of the badge respectively
|
82
80
|
* `:level` corresponds to the `:level` of the badge
|
83
81
|
* `:to` the object's field to give the badge to. It needs a variable named
|
84
82
|
`@model` in the associated controller action, like `@post` for
|
@@ -105,7 +103,7 @@ Badge rules / conditions are defined in `app/models/merit/badge_rules.rb`
|
|
105
103
|
|
106
104
|
```ruby
|
107
105
|
# app/models/merit/badge_rules.rb
|
108
|
-
grant_on 'comments#vote',
|
106
|
+
grant_on 'comments#vote', badge_id: 5, to: :user do |comment|
|
109
107
|
comment.votes.count == 5
|
110
108
|
end
|
111
109
|
|
@@ -1,12 +1,6 @@
|
|
1
1
|
class AddFieldsTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
add_column :<%= table_name %>, :sash_id, :integer
|
4
|
-
add_column :<%= table_name %>, :level,
|
5
|
-
<%- resource = table_name.singularize -%>
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.down
|
9
|
-
remove_column :<%= table_name %>, :sash_id
|
10
|
-
remove_column :<%= table_name %>, :level
|
4
|
+
add_column :<%= table_name %>, :level, :integer, :default => 0
|
11
5
|
end
|
12
6
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CreateMeritActions < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
create_table :merit_actions do |t|
|
4
4
|
t.integer :user_id
|
5
5
|
t.string :action_method
|
@@ -12,8 +12,4 @@ class CreateMeritActions < ActiveRecord::Migration
|
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
def self.down
|
17
|
-
drop_table :merit_actions
|
18
|
-
end
|
19
15
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CreateMeritActivityLogs < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
create_table :merit_activity_logs do |t|
|
4
4
|
t.integer :action_id
|
5
5
|
t.string :related_change_type
|
@@ -8,8 +8,4 @@ class CreateMeritActivityLogs < ActiveRecord::Migration
|
|
8
8
|
t.datetime :created_at
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
12
|
-
def self.down
|
13
|
-
drop_table :merit_activity_logs
|
14
|
-
end
|
15
11
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CreateScoresAndPoints < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
create_table :merit_scores do |t|
|
4
4
|
t.references :sash
|
5
5
|
t.string :category, default: 'default'
|
@@ -12,9 +12,4 @@ class CreateScoresAndPoints < ActiveRecord::Migration
|
|
12
12
|
t.datetime :created_at
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
def self.down
|
17
|
-
drop_table :merit_scores
|
18
|
-
drop_table :merit_score_points
|
19
|
-
end
|
20
15
|
end
|
@@ -23,7 +23,8 @@ module Merit
|
|
23
23
|
def initialize
|
24
24
|
# If it creates user, grant badge
|
25
25
|
# Should be "current_user" after registration for badge to be granted.
|
26
|
-
#
|
26
|
+
# Find badge by badge_id, badge_id takes presidence over badge
|
27
|
+
# grant_on 'users#create', badge_id: 7, badge: 'just-registered', to: :itself
|
27
28
|
|
28
29
|
# If it has 10 comments, grant commenter-10 badge
|
29
30
|
# grant_on 'comments#create', badge: 'commenter', level: 10 do |comment|
|
data/lib/merit/rule.rb
CHANGED
@@ -3,7 +3,7 @@ module Merit
|
|
3
3
|
# and a temporary option.
|
4
4
|
# Could split this class between badges and rankings functionality
|
5
5
|
class Rule
|
6
|
-
attr_accessor :badge_name, :level, :to, :model_name, :level_name,
|
6
|
+
attr_accessor :badge_id, :badge_name, :level, :to, :model_name, :level_name,
|
7
7
|
:multiple, :temporary, :score, :block, :category
|
8
8
|
|
9
9
|
# Does this rule's condition block apply?
|
@@ -25,7 +25,11 @@ module Merit
|
|
25
25
|
|
26
26
|
# Get rule's related Badge.
|
27
27
|
def badge
|
28
|
-
|
28
|
+
if badge_id
|
29
|
+
Merit::Badge.find(badge_id)
|
30
|
+
else
|
31
|
+
Merit::Badge.find_by_name_and_level(badge_name, level)
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
data/merit.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.homepage = "http://github.com/tute/merit"
|
6
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
7
7
|
s.license = 'MIT'
|
8
|
-
s.version = '2.
|
8
|
+
s.version = '2.3.0'
|
9
9
|
s.authors = ["Tute Costa"]
|
10
10
|
s.email = 'tutecosta@gmail.com'
|
11
11
|
|
@@ -42,8 +42,8 @@ module Merit
|
|
42
42
|
# Example rule for testing badge granting in differently namespaced controllers.
|
43
43
|
grant_on '.*users#index', badge: 'wildcard_badge', multiple: true
|
44
44
|
|
45
|
-
# If it has 10 comments, grant commenter-10 badge
|
46
|
-
grant_on 'comments#create',
|
45
|
+
# If it has 10 comments, grant commenter-10 badge, find badge by badge_id
|
46
|
+
grant_on 'comments#create', badge_id: 1, level: 10 do |comment|
|
47
47
|
comment.user.comments.count >= 10
|
48
48
|
end
|
49
49
|
# Testing badge granting in more than one rule per action with different targets
|
@@ -27,6 +27,8 @@ Dummy::Application.configure do
|
|
27
27
|
# like if you have constraints or database-specific column types
|
28
28
|
# config.active_record.schema_format = :sql
|
29
29
|
|
30
|
+
config.active_support.test_order = :random
|
31
|
+
|
30
32
|
# Print deprecation notices to the stderr
|
31
33
|
config.active_support.deprecation = :stderr
|
32
34
|
|
data/test/test_helper.rb
CHANGED
data/test/unit/rule_unit_test.rb
CHANGED
@@ -35,9 +35,15 @@ describe Merit::Rule do
|
|
35
35
|
-> { @rule.badge }.must_raise Merit::BadgeNotFound
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'finds related badge' do
|
39
|
-
|
40
|
-
@rule.badge_name = badge
|
38
|
+
it 'finds related badge by name' do
|
39
|
+
Merit::Badge.create(id: 98, name: 'test-badge-98')
|
40
|
+
@rule.badge_name = "test-badge-98"
|
41
|
+
@rule.badge.must_be :==, Merit::Badge.find(98)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'finds related badge by name' do
|
45
|
+
Merit::Badge.create(id: 98, name: 'test-badge-98')
|
46
|
+
@rule.badge_id = 98
|
41
47
|
@rule.badge.must_be :==, Merit::Badge.find(98)
|
42
48
|
end
|
43
49
|
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: 2.
|
4
|
+
version: 2.3.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: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ambry
|
@@ -280,8 +280,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
280
|
version: '0'
|
281
281
|
requirements: []
|
282
282
|
rubyforge_project:
|
283
|
-
rubygems_version: 2.
|
283
|
+
rubygems_version: 2.2.2
|
284
284
|
signing_key:
|
285
285
|
specification_version: 4
|
286
286
|
summary: General reputation Rails engine.
|
287
287
|
test_files: []
|
288
|
+
has_rdoc:
|