merit 2.4.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +3 -35
- data/NEWS.md +31 -0
- data/README.md +15 -3
- data/RELEASING.md +16 -0
- data/Rakefile +13 -1
- data/app/models/merit/badge.rb +2 -19
- data/lib/merit.rb +13 -35
- data/lib/merit/{rules_badge_methods.rb → badge_rules_methods.rb} +0 -0
- data/lib/merit/base_target_finder.rb +1 -6
- data/lib/merit/{model_additions.rb → class_methods.rb} +2 -19
- data/lib/merit/controller_extensions.rb +13 -30
- data/lib/{generators → merit/generators}/active_record/install_generator.rb +12 -8
- data/lib/{generators → merit/generators}/active_record/merit_generator.rb +7 -3
- data/lib/{generators → merit/generators}/active_record/remove_generator.rb +9 -5
- data/lib/{generators/active_record/templates/add_merit_fields_to_model.rb → merit/generators/active_record/templates/add_merit_fields_to_model.erb} +1 -1
- data/lib/{generators/active_record/templates/create_badges_sashes.rb → merit/generators/active_record/templates/create_badges_sashes.erb} +1 -1
- data/lib/{generators/active_record/templates/create_merit_actions.rb → merit/generators/active_record/templates/create_merit_actions.erb} +2 -2
- data/lib/{generators/active_record/templates/create_merit_activity_logs.rb → merit/generators/active_record/templates/create_merit_activity_logs.erb} +1 -1
- data/lib/merit/generators/active_record/templates/create_sashes.erb +7 -0
- data/lib/{generators/active_record/templates/create_scores_and_points.rb → merit/generators/active_record/templates/create_scores_and_points.erb} +2 -2
- data/lib/{generators/active_record/templates/remove_merit_fields_from_model.rb → merit/generators/active_record/templates/remove_merit_fields_from_model.erb} +1 -1
- data/lib/{generators/active_record/templates/remove_merit_tables.rb → merit/generators/active_record/templates/remove_merit_tables.erb} +1 -1
- data/lib/merit/generators/install_generator.rb +18 -0
- data/lib/{generators/merit → merit/generators}/merit_generator.rb +3 -1
- data/lib/{generators/merit → merit/generators}/remove_generator.rb +3 -1
- data/lib/{generators/merit/templates/merit.rb → merit/generators/templates/merit.erb} +0 -3
- data/lib/{generators/merit/templates/merit_badge_rules.rb → merit/generators/templates/merit_badge_rules.erb} +0 -0
- data/lib/{generators/merit/templates/merit_point_rules.rb → merit/generators/templates/merit_point_rules.erb} +0 -0
- data/lib/{generators/merit/templates/merit_rank_rules.rb → merit/generators/templates/merit_rank_rules.erb} +0 -0
- data/{app/models/merit/action.rb → lib/merit/models/action_concern.rb} +12 -10
- data/lib/merit/models/active_record/action.rb +11 -0
- data/lib/merit/models/active_record/{merit/activity_log.rb → activity_log.rb} +4 -6
- data/lib/merit/models/active_record/{merit/badges_sash.rb → badges_sash.rb} +4 -4
- data/lib/merit/models/active_record/{merit/sash.rb → sash.rb} +5 -2
- data/lib/merit/models/active_record/{merit/score.rb → score.rb} +4 -1
- data/lib/merit/models/badges_sash_concern.rb +13 -0
- data/lib/merit/models/base/badges_sash.rb +1 -1
- data/lib/merit/models/base/sash.rb +1 -1
- data/lib/merit/models/sash_concern.rb +53 -0
- data/lib/merit/{rules_points_methods.rb → point_rules_methods.rb} +0 -0
- data/lib/merit/{rules_rank_methods.rb → rank_rules_methods.rb} +3 -18
- data/merit.gemspec +7 -5
- 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/address.rb +1 -12
- data/test/dummy/app/models/comment.rb +3 -25
- data/test/dummy/app/models/user.rb +1 -18
- data/test/dummy/config/application.rb +8 -10
- data/test/dummy/config/application_api_only.rb +28 -0
- data/test/dummy/config/environment_api_only.rb +7 -0
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/new_framework_defaults.rb +3 -0
- data/test/dummy/db/migrate/20110421191249_create_users.rb +2 -2
- data/test/dummy/db/migrate/20110421191250_create_comments.rb +2 -2
- data/test/dummy/db/migrate/20120318022220_add_fields_to_users.rb +1 -1
- data/test/dummy/db/migrate/20130321082817_add_fields_to_comments.rb +1 -1
- data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -2
- data/test/dummy/db/migrate/20130329224407_create_merit_activity_logs.rb +1 -1
- data/test/dummy/db/migrate/20130329224408_create_sashes.rb +2 -2
- data/test/dummy/db/migrate/20130329224409_create_badges_sashes.rb +1 -1
- data/test/dummy/db/migrate/20130329224410_create_scores_and_points.rb +1 -1
- data/test/dummy/db/migrate/20140211144001_create_addresses.rb +1 -1
- data/test/dummy/db/migrate/20140819133931_add_target_data_to_merit_actions.rb +1 -1
- data/test/dummy/db/schema.rb +55 -59
- data/test/integration/navigation_test.rb +2 -2
- data/test/test_helper.rb +11 -12
- data/test/unit/base_target_finder_test.rb +7 -26
- data/test/unit/merit_unit_test.rb +13 -17
- data/test/unit/rule_unit_test.rb +15 -8
- data/test/unit/rules_matcher_test.rb +9 -6
- data/test/unit/sash_finder_test.rb +5 -5
- data/test/unit/score_test.rb +1 -1
- data/test/unit/target_finder_test.rb +13 -13
- metadata +61 -70
- data/UPGRADING.md +0 -256
- data/lib/generators/active_record/templates/add_target_data_to_merit_actions.rb +0 -5
- data/lib/generators/active_record/templates/create_sashes.rb +0 -7
- data/lib/generators/active_record/upgrade_generator.rb +0 -36
- data/lib/generators/merit/install_generator.rb +0 -16
- data/lib/generators/merit/upgrade_generator.rb +0 -7
- data/lib/merit/models/active_record/merit/action.rb +0 -12
- data/lib/merit/models/mongoid/merit/action.rb +0 -18
- data/lib/merit/models/mongoid/merit/activity_log.rb +0 -11
- data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -22
- data/lib/merit/models/mongoid/merit/sash.rb +0 -30
- data/lib/merit/models/mongoid/merit/score.rb +0 -45
- data/test/dummy/db/migrate/20140906225844_create_players.rb +0 -8
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -191
- data/test/orm/active_record.rb +0 -2
- data/test/orm/mongoid.rb +0 -6
- data/test/orm_models/active_record.rb +0 -11
- data/test/orm_models/mongoid.rb +0 -15
@@ -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
|
@@ -1,14 +1,3 @@
|
|
1
|
-
|
2
|
-
when :active_record
|
3
|
-
class Address < ActiveRecord::Base
|
4
|
-
end
|
5
|
-
when :mongoid
|
6
|
-
class Address
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Timestamps
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Address
|
1
|
+
class Address < ActiveRecord::Base
|
13
2
|
belongs_to :user
|
14
3
|
end
|
@@ -1,34 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def friend
|
5
|
-
User.find_by_name('friend')
|
6
|
-
end
|
1
|
+
class Comment < ActiveRecord::Base
|
2
|
+
def friend
|
3
|
+
User.find_by_name('friend')
|
7
4
|
end
|
8
|
-
when :mongoid
|
9
|
-
class Comment
|
10
|
-
include Mongoid::Document
|
11
|
-
include Mongoid::Timestamps
|
12
5
|
|
13
|
-
field :name, :type => String
|
14
|
-
field :comment, :type => String
|
15
|
-
field :votes, :type => Integer, :default => 0
|
16
|
-
|
17
|
-
def friend
|
18
|
-
User.find_by(name: 'friend')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Comment
|
24
6
|
has_merit
|
25
7
|
|
26
8
|
belongs_to :user
|
27
9
|
|
28
|
-
if show_attr_accessible?
|
29
|
-
attr_accessible :name, :comment, :user_id, :votes
|
30
|
-
end
|
31
|
-
|
32
10
|
validates :name, :comment, :user_id, :presence => true
|
33
11
|
|
34
12
|
delegate :comments, :to => :user, :prefix => true
|
@@ -1,26 +1,9 @@
|
|
1
|
-
|
2
|
-
when :active_record
|
3
|
-
class User < ActiveRecord::Base
|
4
|
-
end
|
5
|
-
when :mongoid
|
6
|
-
class User
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Timestamps
|
9
|
-
|
10
|
-
field :name, :type => String
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class User
|
1
|
+
class User < ActiveRecord::Base
|
15
2
|
has_merit
|
16
3
|
|
17
4
|
has_many :addresses
|
18
5
|
has_many :comments
|
19
6
|
|
20
|
-
if show_attr_accessible?
|
21
|
-
attr_accessible :name
|
22
|
-
end
|
23
|
-
|
24
7
|
def model_with_no_reputation
|
25
8
|
addresses.first || addresses.create
|
26
9
|
end
|
@@ -10,19 +10,17 @@ Bundler.require
|
|
10
10
|
require "merit"
|
11
11
|
|
12
12
|
module Dummy
|
13
|
-
class Application < Rails::Application
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# config.active_record.whitelist_attributes = true
|
13
|
+
class Application < ::Rails::Application
|
14
|
+
if Rails.version.match? "5.2.+"
|
15
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
if Rails.version.match? "6.0.+"
|
19
|
+
config.load_defaults "6.0"
|
20
|
+
end
|
21
21
|
|
22
|
-
|
22
|
+
config.i18n.enforce_available_locales = true
|
23
23
|
config.encoding = "utf-8"
|
24
|
-
|
25
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
26
24
|
config.filter_parameters += [:password]
|
27
25
|
end
|
28
26
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "boot"
|
4
|
+
|
5
|
+
require "rails"
|
6
|
+
# Pick the frameworks you want:
|
7
|
+
require "active_model/railtie"
|
8
|
+
require "active_record/railtie"
|
9
|
+
require "action_controller/railtie"
|
10
|
+
require "action_view/railtie"
|
11
|
+
require "action_mailer/railtie"
|
12
|
+
|
13
|
+
# require "sprockets/railtie"
|
14
|
+
require "rails/test_unit/railtie"
|
15
|
+
|
16
|
+
# Require the gems listed in Gemfile, including any gems
|
17
|
+
# you've limited to :test, :development, or :production.
|
18
|
+
Bundler.require
|
19
|
+
require "merit"
|
20
|
+
|
21
|
+
module Dummy
|
22
|
+
class Application < ::Rails::Application
|
23
|
+
config.load_defaults 5.2 if ENV["RAILS_VERSION"] =~ /^5.2/
|
24
|
+
config.api_only = true
|
25
|
+
config.i18n.enforce_available_locales = true
|
26
|
+
config.encoding = "utf-8"
|
27
|
+
end
|
28
|
+
end
|
@@ -32,5 +32,5 @@ Dummy::Application.configure do
|
|
32
32
|
# Print deprecation notices to the stderr
|
33
33
|
config.active_support.deprecation = :stderr
|
34
34
|
|
35
|
-
config.eager_load =
|
35
|
+
config.eager_load = false
|
36
36
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateComments < ActiveRecord::Migration
|
1
|
+
class CreateComments < ActiveRecord::Migration[5.0]
|
2
2
|
def self.up
|
3
3
|
create_table :comments do |t|
|
4
4
|
t.string :name
|
@@ -6,7 +6,7 @@ class CreateComments < ActiveRecord::Migration
|
|
6
6
|
t.integer :user_id
|
7
7
|
t.integer :votes, :default => 0
|
8
8
|
|
9
|
-
t.timestamps
|
9
|
+
t.timestamps null: false
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateMeritActions < ActiveRecord::Migration
|
1
|
+
class CreateMeritActions < ActiveRecord::Migration[5.0]
|
2
2
|
def self.up
|
3
3
|
create_table :merit_actions do |t|
|
4
4
|
t.integer :user_id # source
|
@@ -8,7 +8,7 @@ class CreateMeritActions < ActiveRecord::Migration
|
|
8
8
|
t.string :target_model
|
9
9
|
t.integer :target_id
|
10
10
|
t.boolean :processed, :default => false
|
11
|
-
t.timestamps
|
11
|
+
t.timestamps null: false
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/test/dummy/db/schema.rb
CHANGED
@@ -1,93 +1,89 @@
|
|
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_08_19_133931) 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:
|
71
|
-
t.integer "sash_id"
|
72
|
-
t.string "category", default: "default"
|
73
|
-
end
|
74
|
-
|
75
|
-
create_table "players", force: true do |t|
|
70
|
+
create_table "merit_scores", force: :cascade do |t|
|
76
71
|
t.integer "sash_id"
|
77
|
-
t.
|
72
|
+
t.string "category", default: "default"
|
73
|
+
t.index ["sash_id"], name: "index_merit_scores_on_sash_id"
|
78
74
|
end
|
79
75
|
|
80
|
-
create_table "sashes", force:
|
76
|
+
create_table "sashes", force: :cascade do |t|
|
81
77
|
t.datetime "created_at", null: false
|
82
78
|
t.datetime "updated_at", null: false
|
83
79
|
end
|
84
80
|
|
85
|
-
create_table "users", force:
|
86
|
-
t.string
|
87
|
-
t.datetime "created_at",
|
88
|
-
t.datetime "updated_at",
|
89
|
-
t.integer
|
90
|
-
t.integer
|
81
|
+
create_table "users", force: :cascade do |t|
|
82
|
+
t.string "name"
|
83
|
+
t.datetime "created_at", null: false
|
84
|
+
t.datetime "updated_at", null: false
|
85
|
+
t.integer "sash_id"
|
86
|
+
t.integer "level", default: 0
|
91
87
|
end
|
92
88
|
|
93
89
|
end
|
@@ -305,8 +305,8 @@ class NavigationTest < ActionDispatch::IntegrationTest
|
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
|
-
comment_1.reload.points.must_be :==, 2
|
309
|
-
comment_2.reload.points.must_be :==, 2
|
308
|
+
_(comment_1.reload.points).must_be :==, 2
|
309
|
+
_(comment_2.reload.points).must_be :==, 2
|
310
310
|
end
|
311
311
|
|
312
312
|
test 'api/comments#show should grant 1 point to user' do
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configure Rails Envinronment
|
2
2
|
ENV['RAILS_ENV'] = 'test'
|
3
|
-
RUBYOPT="-w $RUBYOPT"
|
3
|
+
RUBYOPT = "-w $RUBYOPT".freeze
|
4
4
|
|
5
5
|
if ENV["COVERAGE"]
|
6
6
|
require 'coveralls'
|
@@ -13,16 +13,21 @@ 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'
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
require
|
23
|
-
|
24
|
-
require
|
25
|
-
|
22
|
+
if ARGV.include?("-api-only")
|
23
|
+
require File.expand_path("dummy/config/environment_api_only.rb", __dir__)
|
24
|
+
else
|
25
|
+
require File.expand_path("dummy/config/environment.rb", __dir__)
|
26
|
+
end
|
27
|
+
|
28
|
+
require "rails/test_help"
|
29
|
+
require "minitest/rails"
|
30
|
+
require "mocha/minitest"
|
26
31
|
|
27
32
|
Rails.backtrace_cleaner.remove_silencers!
|
28
33
|
|
@@ -33,9 +38,3 @@ Capybara.default_selector = :css
|
|
33
38
|
|
34
39
|
# Load support files
|
35
40
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
36
|
-
|
37
|
-
Merit.orm = :active_record if Merit.orm.nil?
|
38
|
-
|
39
|
-
def active_record_orm?
|
40
|
-
Merit.orm == :active_record
|
41
|
-
end
|