merit 2.2.0 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bceef6c4f4123e4b5aa45f35c90f51779803eccb
4
- data.tar.gz: f64bea2e08e184c8b413e5410c02424f51b44c35
3
+ metadata.gz: b7d2cd9366ca515998303997aa8b9f30d7ab3e9f
4
+ data.tar.gz: 7be13cb7255f3d90760360827f07f6d57a2b1376
5
5
  SHA512:
6
- metadata.gz: 22924df6b8915eb8dde70a0360141d2551eaf42d21cc8c45fbd8375354ff5897bd8e68433963cf426265be38eac3adfe4487c7c95376739b43f93d7d297bc075
7
- data.tar.gz: 9d1324c2c32759030bb54e7aa9b37face51cf7e82da3ab53462b818a200e1efbb9d05d83fb896345cb112dfab21047c38bcd1c348e7175de72337df67b6f4007
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.1'
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.beta1"
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.png?branch=master)](http://travis-ci.org/tute/merit)
7
- [![Coverage
8
- Status](https://coveralls.io/repos/tute/merit/badge.png?branch=master)](https://coveralls.io/r/tute/merit?branch=master)
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` corresponds to the `:name` of the 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', badge: 'relevant-commenter', to: :user do |comment|
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 self.up
2
+ def change
3
3
  add_column :<%= table_name %>, :sash_id, :integer
4
- add_column :<%= table_name %>, :level, :integer, :default => 0
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 self.up
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 self.up
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,11 +1,7 @@
1
1
  class CreateSashes < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_table :sashes do |t|
4
4
  t.timestamps
5
5
  end
6
6
  end
7
-
8
- def self.down
9
- drop_table :sashes
10
- end
11
7
  end
@@ -1,5 +1,5 @@
1
1
  class CreateScoresAndPoints < ActiveRecord::Migration
2
- def self.up
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
- # grant_on 'users#create', badge: 'just-registered', to: :itself
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|
@@ -30,7 +30,7 @@ module Merit
30
30
  end
31
31
 
32
32
  def target_data_hash
33
- if Merit::Action.new.respond_to? :target_data
33
+ if Merit::Action.new.respond_to?(:target_data)
34
34
  { target_data: target_object.to_yaml }
35
35
  else
36
36
  Merit.upgrade_target_data_warning
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
- @badge ||= Merit::Badge.find_by_name_and_level(badge_name, level)
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
@@ -7,6 +7,7 @@ module Merit
7
7
  actions = Array.wrap(actions)
8
8
 
9
9
  rule = Rule.new
10
+ rule.badge_id = options[:badge_id]
10
11
  rule.badge_name = options[:badge]
11
12
  rule.level = options[:level]
12
13
  rule.to = options[:to] || :action_user
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.2.0'
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', badge: 'commenter', level: 10 do |comment|
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
@@ -21,6 +21,7 @@ end
21
21
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
22
22
  require 'rails/test_help'
23
23
  require 'minitest/rails'
24
+ require 'mocha/mini_test'
24
25
  require "orm/#{Merit.orm}"
25
26
 
26
27
  Rails.backtrace_cleaner.remove_silencers!
@@ -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
- badge = Merit::Badge.create(id: 98, name: 'test-badge-98')
40
- @rule.badge_name = badge.name
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.2.0
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-09-14 00:00:00.000000000 Z
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.4.1
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: