merit 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -7
- data/NEWS.md +7 -0
- data/Rakefile +5 -1
- data/app/models/merit/action.rb +1 -1
- data/app/models/merit/badge.rb +1 -10
- data/lib/merit/model_additions.rb +1 -7
- data/lib/merit/models/active_record/merit/action.rb +0 -5
- data/lib/merit/models/active_record/merit/activity_log.rb +0 -4
- data/lib/merit/models/active_record/merit/badges_sash.rb +0 -2
- data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -2
- data/merit.gemspec +1 -1
- data/test/dummy/app/controllers/comments_controller.rb +1 -1
- data/test/dummy/app/controllers/registrations_controller.rb +1 -1
- data/test/dummy/app/models/comment.rb +0 -4
- data/test/dummy/app/models/user.rb +0 -4
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/schema.rb +57 -56
- data/test/test_helper.rb +1 -5
- data/test/unit/merit_unit_test.rb +8 -10
- data/test/unit/rule_unit_test.rb +8 -1
- metadata +3 -7
- data/test/orm/active_record.rb +0 -8
- data/test/orm/mongoid.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a847a60ecad264aa85e3118fa9e26a974de2e08142577fe134c12e48c4989faf
|
4
|
+
data.tar.gz: 7f219282c0e6c4f33e10f2b77040ef19dbec9874e11140c47cc216fb17c9665b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b2714cb9b1c672ba79a1d1034ac6f53bf66c544d568d358c2fe98f3a42801589db9a1213c7eb36abe03a51f8392b4929d52db06549d8786d6b7bfe125e48486
|
7
|
+
data.tar.gz: 2c062006a8352ad9bc7bce01db34851a30e4b7b8fce7de19c6dc4377366e743832ad0507e88b498ba1ed9f6f498e787ebddbb6f2c27577d1870c2dd08d0e6679
|
data/Gemfile
CHANGED
@@ -2,12 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
if version =~ /^5.2/
|
7
|
-
gem 'rails', github: "rails/rails", branch: "5-2-stable"
|
8
|
-
else
|
9
|
-
gem 'rails', version
|
10
|
-
end
|
5
|
+
gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', 6.0)}"
|
11
6
|
|
12
7
|
case ENV['ORM']
|
13
8
|
when 'active_record'
|
@@ -18,7 +13,7 @@ end
|
|
18
13
|
|
19
14
|
group :development, :test do
|
20
15
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
|
21
|
-
gem 'sqlite3'
|
16
|
+
gem 'sqlite3', '~> 1.4'
|
22
17
|
end
|
23
18
|
|
24
19
|
gem 'coveralls', require: false
|
data/NEWS.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
User-visible changes worth mentioning.
|
4
4
|
|
5
|
+
## 3.0.3
|
6
|
+
|
7
|
+
- Test against Ruby 2.6 and Rails 6
|
8
|
+
- Use `find_each` in favor of `map` in `Merit::Action.check_unprocessed`
|
9
|
+
- Allow finding badges defined with symbol names
|
10
|
+
- Remove `Badge#last_granted` method (deprecated in merit <2.0)
|
11
|
+
|
5
12
|
## 3.0.2
|
6
13
|
|
7
14
|
- [#287] Make Sash an optional dependency, fixing issues in Rails 5.1.
|
data/Rakefile
CHANGED
@@ -8,7 +8,11 @@ end
|
|
8
8
|
require 'rake/testtask'
|
9
9
|
|
10
10
|
desc 'Default: run tests for all ORMs.'
|
11
|
-
task default: [:test, :api_test]
|
11
|
+
task default: [:setup, :test, :api_test]
|
12
|
+
|
13
|
+
task :setup do
|
14
|
+
system "cd test/dummy && rake db:migrate && rake db:test:prepare"
|
15
|
+
end
|
12
16
|
|
13
17
|
Rake::TestTask.new(:test) do |t|
|
14
18
|
t.libs << 'lib'
|
data/app/models/merit/action.rb
CHANGED
@@ -15,7 +15,7 @@ require_dependency "merit/models/#{Merit.orm}/merit/action"
|
|
15
15
|
module Merit
|
16
16
|
class Action
|
17
17
|
def self.check_unprocessed
|
18
|
-
where(processed: false).
|
18
|
+
where(processed: false).find_each(&:check_all_rules)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Check rules defined for a merit_action
|
data/app/models/merit/badge.rb
CHANGED
@@ -18,7 +18,7 @@ module Merit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def by_name(name)
|
21
|
-
find { |b| b.name == name.to_s }
|
21
|
+
find { |b| b.name.to_s == name.to_s }
|
22
22
|
end
|
23
23
|
|
24
24
|
def by_level(level)
|
@@ -45,15 +45,6 @@ module Merit
|
|
45
45
|
badge
|
46
46
|
end
|
47
47
|
|
48
|
-
# DEPRECATED: `last_granted` will be removed from merit, please refer to:
|
49
|
-
# https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
|
50
|
-
def last_granted(options = {})
|
51
|
-
warn '[merit] [DEPRECATION] `last_granted` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-last-granted-badges'
|
52
|
-
options[:since_date] ||= 1.month.ago
|
53
|
-
options[:limit] ||= 10
|
54
|
-
BadgesSash.last_granted(options)
|
55
|
-
end
|
56
|
-
|
57
48
|
# Defines Badge#meritable_models method, to get related
|
58
49
|
# entries with certain badge. For instance, Badge.find(3).users
|
59
50
|
# orm-specified
|
@@ -8,7 +8,6 @@ module Merit
|
|
8
8
|
# dependent: destroy as it may raise FK constraint exceptions. See:
|
9
9
|
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1079-belongs_to-dependent-destroy-should-destroy-self-before-assocation
|
10
10
|
belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil, optional: true
|
11
|
-
attr_accessible :sash if show_attr_accessible?
|
12
11
|
|
13
12
|
send :"_merit_#{Merit.orm}_specific_config"
|
14
13
|
_merit_delegate_methods_to_sash
|
@@ -38,11 +37,6 @@ module Merit
|
|
38
37
|
Merit::Badge._define_related_entries_method(meritable_class_name)
|
39
38
|
end
|
40
39
|
|
41
|
-
def show_attr_accessible?
|
42
|
-
defined?(ProtectedAttributes) ||
|
43
|
-
!defined?(ActionController::StrongParameters)
|
44
|
-
end
|
45
|
-
|
46
40
|
# _sash initializes a sash if doesn't have one yet.
|
47
41
|
# From Rails 3.2 we can override association methods to do so
|
48
42
|
# transparently, but merit supports Rails ~> 3.0.0. See:
|
@@ -50,7 +44,7 @@ module Merit
|
|
50
44
|
def _merit_sash_initializer
|
51
45
|
define_method(:_sash) do
|
52
46
|
# TODO: reload.sash is not regression tested
|
53
|
-
sash || reload.sash ||
|
47
|
+
sash || reload.sash || update(sash: Sash.create)
|
54
48
|
sash
|
55
49
|
end
|
56
50
|
end
|
@@ -3,10 +3,5 @@ module Merit
|
|
3
3
|
self.table_name = :merit_actions
|
4
4
|
|
5
5
|
has_many :activity_logs, class_name: 'Merit::ActivityLog'
|
6
|
-
|
7
|
-
if show_attr_accessible?
|
8
|
-
attr_accessible :user_id, :action_method, :action_value, :had_errors,
|
9
|
-
:target_model, :target_id, :processed, :log, :target_data
|
10
|
-
end
|
11
6
|
end
|
12
7
|
end
|
@@ -5,9 +5,5 @@ module Merit
|
|
5
5
|
belongs_to :action, class_name: 'Merit::Action'
|
6
6
|
belongs_to :related_change, polymorphic: true, optional: true
|
7
7
|
has_one :sash, through: :related_change
|
8
|
-
|
9
|
-
if show_attr_accessible?
|
10
|
-
attr_accessible :action_id, :related_change, :description, :created_at
|
11
|
-
end
|
12
8
|
end
|
13
9
|
end
|
data/merit.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
7
7
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
8
8
|
s.license = 'MIT'
|
9
|
-
s.version = '3.0.
|
9
|
+
s.version = '3.0.3'
|
10
10
|
s.authors = ["Tute Costa"]
|
11
11
|
s.email = 'tutecosta@gmail.com'
|
12
12
|
|
@@ -33,7 +33,7 @@ class CommentsController < ApplicationController
|
|
33
33
|
|
34
34
|
def update
|
35
35
|
@comment = Comment.find(params[:id])
|
36
|
-
if @comment.
|
36
|
+
if @comment.update(comment_params)
|
37
37
|
redirect_to(@comment, :notice => 'Comment was successfully updated.')
|
38
38
|
else
|
39
39
|
render "edit"
|
@@ -3,7 +3,7 @@ class RegistrationsController < ApplicationController
|
|
3
3
|
@user = User.find(params[:id])
|
4
4
|
|
5
5
|
respond_to do |format|
|
6
|
-
if @user.
|
6
|
+
if @user.update(user_params)
|
7
7
|
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
|
8
8
|
format.xml { head :ok }
|
9
9
|
else
|
data/test/dummy/db/schema.rb
CHANGED
@@ -1,93 +1,94 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
5
4
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# from scratch.
|
10
|
-
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `rails
|
6
|
+
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
11
10
|
#
|
12
11
|
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2014_09_06_225844) do
|
15
14
|
|
16
|
-
create_table "addresses", force:
|
15
|
+
create_table "addresses", force: :cascade do |t|
|
17
16
|
t.integer "user_id"
|
17
|
+
t.index ["user_id"], name: "index_addresses_on_user_id"
|
18
18
|
end
|
19
19
|
|
20
|
-
create_table "badges_sashes", force:
|
21
|
-
t.integer
|
22
|
-
t.integer
|
23
|
-
t.boolean
|
20
|
+
create_table "badges_sashes", force: :cascade do |t|
|
21
|
+
t.integer "badge_id"
|
22
|
+
t.integer "sash_id"
|
23
|
+
t.boolean "notified_user", default: false
|
24
24
|
t.datetime "created_at"
|
25
|
+
t.index ["badge_id", "sash_id"], name: "index_badges_sashes_on_badge_id_and_sash_id"
|
26
|
+
t.index ["badge_id"], name: "index_badges_sashes_on_badge_id"
|
27
|
+
t.index ["sash_id"], name: "index_badges_sashes_on_sash_id"
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
t.
|
33
|
-
t.
|
34
|
-
t.integer
|
35
|
-
t.integer
|
36
|
-
t.datetime "created_at", null: false
|
37
|
-
t.datetime "updated_at", null: false
|
38
|
-
t.integer "sash_id"
|
39
|
-
t.integer "level", default: 0
|
30
|
+
create_table "comments", force: :cascade do |t|
|
31
|
+
t.string "name"
|
32
|
+
t.text "comment"
|
33
|
+
t.integer "user_id"
|
34
|
+
t.integer "votes", default: 0
|
35
|
+
t.datetime "created_at", null: false
|
36
|
+
t.datetime "updated_at", null: false
|
37
|
+
t.integer "sash_id"
|
38
|
+
t.integer "level", default: 0
|
40
39
|
end
|
41
40
|
|
42
|
-
create_table "merit_actions", force:
|
43
|
-
t.integer
|
44
|
-
t.string
|
45
|
-
t.integer
|
46
|
-
t.boolean
|
47
|
-
t.string
|
48
|
-
t.integer
|
49
|
-
t.boolean
|
50
|
-
t.datetime "created_at",
|
51
|
-
t.datetime "updated_at",
|
52
|
-
t.text
|
41
|
+
create_table "merit_actions", force: :cascade do |t|
|
42
|
+
t.integer "user_id"
|
43
|
+
t.string "action_method"
|
44
|
+
t.integer "action_value"
|
45
|
+
t.boolean "had_errors", default: false
|
46
|
+
t.string "target_model"
|
47
|
+
t.integer "target_id"
|
48
|
+
t.boolean "processed", default: false
|
49
|
+
t.datetime "created_at", null: false
|
50
|
+
t.datetime "updated_at", null: false
|
51
|
+
t.text "target_data"
|
53
52
|
end
|
54
53
|
|
55
|
-
create_table "merit_activity_logs", force:
|
56
|
-
t.integer
|
57
|
-
t.string
|
58
|
-
t.integer
|
59
|
-
t.string
|
54
|
+
create_table "merit_activity_logs", force: :cascade do |t|
|
55
|
+
t.integer "action_id"
|
56
|
+
t.string "related_change_type"
|
57
|
+
t.integer "related_change_id"
|
58
|
+
t.string "description"
|
60
59
|
t.datetime "created_at"
|
61
60
|
end
|
62
61
|
|
63
|
-
create_table "merit_score_points", force:
|
64
|
-
t.integer
|
65
|
-
t.integer
|
66
|
-
t.string
|
62
|
+
create_table "merit_score_points", force: :cascade do |t|
|
63
|
+
t.integer "score_id"
|
64
|
+
t.integer "num_points", default: 0
|
65
|
+
t.string "log"
|
67
66
|
t.datetime "created_at"
|
67
|
+
t.index ["score_id"], name: "index_merit_score_points_on_score_id"
|
68
68
|
end
|
69
69
|
|
70
|
-
create_table "merit_scores", force:
|
70
|
+
create_table "merit_scores", force: :cascade do |t|
|
71
71
|
t.integer "sash_id"
|
72
|
-
t.string
|
72
|
+
t.string "category", default: "default"
|
73
|
+
t.index ["sash_id"], name: "index_merit_scores_on_sash_id"
|
73
74
|
end
|
74
75
|
|
75
|
-
create_table "players", force:
|
76
|
+
create_table "players", force: :cascade do |t|
|
76
77
|
t.integer "sash_id"
|
77
|
-
t.integer "level",
|
78
|
+
t.integer "level", default: 0
|
78
79
|
end
|
79
80
|
|
80
|
-
create_table "sashes", force:
|
81
|
+
create_table "sashes", force: :cascade do |t|
|
81
82
|
t.datetime "created_at", null: false
|
82
83
|
t.datetime "updated_at", null: false
|
83
84
|
end
|
84
85
|
|
85
|
-
create_table "users", force:
|
86
|
-
t.string
|
87
|
-
t.datetime "created_at",
|
88
|
-
t.datetime "updated_at",
|
89
|
-
t.integer
|
90
|
-
t.integer
|
86
|
+
create_table "users", force: :cascade do |t|
|
87
|
+
t.string "name"
|
88
|
+
t.datetime "created_at", null: false
|
89
|
+
t.datetime "updated_at", null: false
|
90
|
+
t.integer "sash_id"
|
91
|
+
t.integer "level", default: 0
|
91
92
|
end
|
92
93
|
|
93
94
|
end
|
data/test/test_helper.rb
CHANGED
@@ -13,6 +13,7 @@ if ENV["COVERAGE"]
|
|
13
13
|
# https://github.com/colszowka/simplecov/pull/104
|
14
14
|
add_group 'Merit', 'lib'
|
15
15
|
add_group 'DummyApp', 'test/dummy'
|
16
|
+
add_filter 'lib/generators'
|
16
17
|
add_filter 'test/dummy/config/initializers'
|
17
18
|
end
|
18
19
|
SimpleCov.start 'rubygem'
|
@@ -27,7 +28,6 @@ end
|
|
27
28
|
require "rails/test_help"
|
28
29
|
require "minitest/rails"
|
29
30
|
require "mocha/minitest"
|
30
|
-
require "orm/#{Merit.orm}"
|
31
31
|
|
32
32
|
Rails.backtrace_cleaner.remove_silencers!
|
33
33
|
|
@@ -40,7 +40,3 @@ Capybara.default_selector = :css
|
|
40
40
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
41
41
|
|
42
42
|
Merit.orm = :active_record if Merit.orm.nil?
|
43
|
-
|
44
|
-
def active_record_orm?
|
45
|
-
Merit.orm == :active_record
|
46
|
-
end
|
@@ -14,18 +14,16 @@ class MeritUnitTest < ActiveSupport::TestCase
|
|
14
14
|
assert Merit::Badge.method_defined?(:players), 'Badge#players should be defined'
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
set_rank level: 1, to: Player, level_name: :clown
|
23
|
-
end
|
24
|
-
end
|
25
|
-
assert_raises Merit::RankAttributeNotDefined do
|
26
|
-
WeirdRankRules.new.check_rank_rules
|
17
|
+
test 'unknown ranking raises exception' do
|
18
|
+
class WeirdRankRules
|
19
|
+
include Merit::RankRulesMethods
|
20
|
+
def initialize
|
21
|
+
set_rank level: 1, to: Player, level_name: :clown
|
27
22
|
end
|
28
23
|
end
|
24
|
+
assert_raises Merit::RankAttributeNotDefined do
|
25
|
+
WeirdRankRules.new.check_rank_rules
|
26
|
+
end
|
29
27
|
end
|
30
28
|
|
31
29
|
test 'Badge#custom_fields_hash saves correctly' do
|
data/test/unit/rule_unit_test.rb
CHANGED
@@ -35,12 +35,19 @@ describe Merit::Rule do
|
|
35
35
|
-> { @rule.badge }.must_raise Merit::BadgeNotFound
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'finds related badge by name' do
|
38
|
+
it 'finds related badge by name, when the name is a string' do
|
39
39
|
Merit::Badge.create(id: 98, name: 'test-badge-98')
|
40
40
|
@rule.badge_name = "test-badge-98"
|
41
41
|
@rule.badge.must_be :==, Merit::Badge.find(98)
|
42
42
|
end
|
43
43
|
|
44
|
+
it 'finds related badge by name, when the name is a symbol' do
|
45
|
+
Merit::Badge.create(id: 100, name: :testbadge)
|
46
|
+
@rule.badge_name = 'testbadge'
|
47
|
+
@rule.badge.must_be :==, Merit::Badge.find(100)
|
48
|
+
@rule.badge
|
49
|
+
end
|
50
|
+
|
44
51
|
it 'finds related badge by name' do
|
45
52
|
Merit::Badge.create(id: 98, name: 'test-badge-98')
|
46
53
|
@rule.badge_id = 98
|
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: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tute Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ambry
|
@@ -250,8 +250,6 @@ files:
|
|
250
250
|
- test/dummy/public/stylesheets/scaffold.css
|
251
251
|
- test/dummy/script/rails
|
252
252
|
- test/integration/navigation_test.rb
|
253
|
-
- test/orm/active_record.rb
|
254
|
-
- test/orm/mongoid.rb
|
255
253
|
- test/orm_models/active_record.rb
|
256
254
|
- test/orm_models/mongoid.rb
|
257
255
|
- test/support/integration_case.rb
|
@@ -285,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
283
|
version: '0'
|
286
284
|
requirements: []
|
287
285
|
rubyforge_project:
|
288
|
-
rubygems_version: 2.7.6
|
286
|
+
rubygems_version: 2.7.6.2
|
289
287
|
signing_key:
|
290
288
|
specification_version: 4
|
291
289
|
summary: Reputation engine for Rails apps
|
@@ -367,8 +365,6 @@ test_files:
|
|
367
365
|
- test/dummy/public/stylesheets/scaffold.css
|
368
366
|
- test/dummy/script/rails
|
369
367
|
- test/integration/navigation_test.rb
|
370
|
-
- test/orm/active_record.rb
|
371
|
-
- test/orm/mongoid.rb
|
372
368
|
- test/orm_models/active_record.rb
|
373
369
|
- test/orm_models/mongoid.rb
|
374
370
|
- test/support/integration_case.rb
|
data/test/orm/active_record.rb
DELETED