qalam_merit 4.5.00 → 4.5.05
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/merit/generators/merit_generator.rb +4 -2
- data/lib/merit/models/active_record/qalam_score.rb +31 -0
- data/lib/merit/models/active_record/sash.rb +2 -2
- data/lib/merit/models/base/sash.rb +2 -2
- data/lib/merit/models/sash_concern.rb +2 -2
- data/qalam_merit.gemspec +1 -1
- data/test/integration/navigation_test.rb +2 -2
- data/test/unit/{score_test.rb → qalam_score_test.rb} +3 -3
- data/test/unit/sash_test.rb +6 -6
- metadata +5 -5
- data/lib/merit/models/active_record/score.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36dd98bb62a667ae5b42ca9edb1a6aa9d547a139d268f9da523476937d61d077
|
4
|
+
data.tar.gz: 3d36fe5887fc5844b4e13f342e73216d7fc8ab1f6d70e1a458437c9b86fd247e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b797616130749f3f74ad7b2737dc32461866896547f32f9039d56474f309d20a07113a42f0fa3dd0af105450b511455ff4b769a517d5656885cdfc56194c6780
|
7
|
+
data.tar.gz: 26bc8ce7e1adcee901aaa6f929a0e89d73d22b7088c30cc5321c1369ca4528593417a48336ff6e31b5c03d94505adc6df3701a92bd9f825e1828db0da6d3638b
|
@@ -8,8 +8,10 @@ module Merit
|
|
8
8
|
def inject_merit_content
|
9
9
|
if model_exists?
|
10
10
|
inject_into_class(model_path, class_name, " ### END ###\n\n")
|
11
|
-
inject_into_class(model_path, class_name, " has_many :created_badges, class_name: 'Merit::Badge'\n")
|
12
|
-
inject_into_class(model_path, class_name, "
|
11
|
+
inject_into_class(model_path, class_name, " has_many :created_badges, class_name: 'Merit::Badge', :dependent => :destroy\n")
|
12
|
+
inject_into_class(model_path, class_name, " has_many :assigned_badges, through: :sash, source: :badges, :dependent => :destroy\n")
|
13
|
+
inject_into_class(model_path, class_name, " has_many :badges_sashes, through: :sash, source: :badges_sashes, :dependent => :destroy\n")
|
14
|
+
inject_into_class(model_path, class_name, " belongs_to :sash, foreign_key: 'sash_id', class_name: 'Merit::Sash', :dependent => :destroy\n")
|
13
15
|
inject_into_class(model_path, class_name, " has_merit\n")
|
14
16
|
inject_into_class(model_path, class_name, " ### QALAM_MERIT ###\n")
|
15
17
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Merit::Models::ActiveRecord
|
2
|
+
class QalamScore < ActiveRecord::Base
|
3
|
+
self.table_name = :merit_scores
|
4
|
+
belongs_to :sash,
|
5
|
+
foreign_key: "sash_id",
|
6
|
+
class_name: 'Merit::Sash'
|
7
|
+
has_many :score_points,
|
8
|
+
dependent: :destroy,
|
9
|
+
foreign_key: "score_id",
|
10
|
+
class_name: 'Merit::QalamScore::Point'
|
11
|
+
|
12
|
+
def points
|
13
|
+
score_points.group(:score_id).sum(:num_points).values.first || 0
|
14
|
+
end
|
15
|
+
|
16
|
+
class Point < ActiveRecord::Base
|
17
|
+
self.table_name = :merit_score_points
|
18
|
+
belongs_to :score,
|
19
|
+
foreign_key: "score_id",
|
20
|
+
class_name: 'Merit::QalamScore'
|
21
|
+
has_one :sash, through: :score, source: :sash
|
22
|
+
has_many :activity_logs,
|
23
|
+
class_name: 'Merit::ActivityLog',
|
24
|
+
as: :related_change
|
25
|
+
delegate :sash_id, to: :score
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Merit::QalamScore < Merit::Models::ActiveRecord::QalamScore; end
|
31
|
+
class Merit::QalamScore::Point < Merit::Models::ActiveRecord::QalamScore::Point; end
|
@@ -11,7 +11,7 @@ module Merit::Models::ActiveRecord
|
|
11
11
|
|
12
12
|
has_many :badges_sashes, dependent: :destroy
|
13
13
|
has_many :badges, through: :badges_sashes, source: :badge
|
14
|
-
has_many :scores, dependent: :destroy, class_name: 'Merit::
|
14
|
+
has_many :scores, dependent: :destroy, class_name: 'Merit::QalamScore'
|
15
15
|
|
16
16
|
after_create :create_scores
|
17
17
|
|
@@ -20,7 +20,7 @@ module Merit::Models::ActiveRecord
|
|
20
20
|
# @param category [String] The category
|
21
21
|
# @return [ActiveRecord::Relation] containing the points
|
22
22
|
def score_points(options = {})
|
23
|
-
scope = Merit::
|
23
|
+
scope = Merit::QalamScore::Point
|
24
24
|
.joins(:score)
|
25
25
|
.where('merit_scores.sash_id = ?', id)
|
26
26
|
if (category = options[:category])
|
@@ -32,7 +32,7 @@ module Merit
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_points(num_points, options = {})
|
35
|
-
point = Merit::
|
35
|
+
point = Merit::QalamScore::Point.new
|
36
36
|
point.num_points = num_points
|
37
37
|
scores
|
38
38
|
.where(category: options[:category] || 'default')
|
@@ -48,7 +48,7 @@ module Merit
|
|
48
48
|
private
|
49
49
|
|
50
50
|
def create_scores
|
51
|
-
scores << Merit::
|
51
|
+
scores << Merit::QalamScore.create
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -31,7 +31,7 @@ module Merit::Models
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_points(num_points, options = {})
|
34
|
-
point = Merit::
|
34
|
+
point = Merit::QalamScore::Point.new
|
35
35
|
point.num_points = num_points
|
36
36
|
scores
|
37
37
|
.where(category: options[:category] || 'default')
|
@@ -47,7 +47,7 @@ module Merit::Models
|
|
47
47
|
private
|
48
48
|
|
49
49
|
def create_scores
|
50
|
-
scores << Merit::
|
50
|
+
scores << Merit::QalamScore.create
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/qalam_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 = '4.5.
|
9
|
+
s.version = '4.5.05'
|
10
10
|
s.authors = ["Tute Costa", "Ahmed Abdelhamid"]
|
11
11
|
s.email = ['tutecosta@gmail.com', 'a.hamid@nezam.io']
|
12
12
|
|
@@ -107,12 +107,12 @@ class NavigationTest < ActionDispatch::IntegrationTest
|
|
107
107
|
assert user.badges.empty?, 'Should not have badges'
|
108
108
|
|
109
109
|
assert_equal 0, user.points
|
110
|
-
assert_equal 0, Merit::
|
110
|
+
assert_equal 0, Merit::QalamScore::Point.count
|
111
111
|
user.add_points 15
|
112
112
|
assert_equal 15, user.points
|
113
113
|
user.subtract_points 15
|
114
114
|
assert_equal 0, user.points
|
115
|
-
assert_equal 2, Merit::
|
115
|
+
assert_equal 2, Merit::QalamScore::Point.count
|
116
116
|
|
117
117
|
# Tenth comment with errors doesn't change reputation
|
118
118
|
badges = user.reload.badges
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
describe Merit::
|
3
|
+
describe Merit::QalamScore do
|
4
4
|
it 'Point#sash_id delegates to Score' do
|
5
|
-
score = Merit::
|
5
|
+
score = Merit::QalamScore.new
|
6
6
|
score.sash_id = 33
|
7
7
|
|
8
|
-
point = Merit::
|
8
|
+
point = Merit::QalamScore::Point.new
|
9
9
|
point.score = score
|
10
10
|
|
11
11
|
_(point.sash_id).must_be :==, score.sash_id
|
data/test/unit/sash_test.rb
CHANGED
@@ -10,7 +10,7 @@ class SashTest < ActiveSupport::TestCase
|
|
10
10
|
describe "when category specified" do
|
11
11
|
it "should create a new Point with specified category" do
|
12
12
|
@sash.add_points 5, category: @custom_category
|
13
|
-
score = Merit::
|
13
|
+
score = Merit::QalamScore.last
|
14
14
|
point = score.score_points.last
|
15
15
|
|
16
16
|
assert_equal point.num_points, 5
|
@@ -19,10 +19,10 @@ class SashTest < ActiveSupport::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should create a new Point in category default with specified number of points" do
|
22
|
-
assert_difference("Merit::
|
22
|
+
assert_difference("Merit::QalamScore::Point.count", 1) do
|
23
23
|
@sash.add_points 5
|
24
24
|
end
|
25
|
-
score = Merit::
|
25
|
+
score = Merit::QalamScore.last
|
26
26
|
point = score.score_points.last
|
27
27
|
|
28
28
|
assert_equal point.num_points, 5
|
@@ -34,7 +34,7 @@ class SashTest < ActiveSupport::TestCase
|
|
34
34
|
describe "when category specified" do
|
35
35
|
it "should create a new Point with specified category" do
|
36
36
|
@sash.subtract_points 5, category: @custom_category
|
37
|
-
score = Merit::
|
37
|
+
score = Merit::QalamScore.last
|
38
38
|
point = score.score_points.last
|
39
39
|
|
40
40
|
assert_equal point.num_points, -5
|
@@ -43,10 +43,10 @@ class SashTest < ActiveSupport::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should create a new Point in category default with inverse of specified number of points" do
|
46
|
-
assert_difference("Merit::
|
46
|
+
assert_difference("Merit::QalamScore::Point.count", 1) do
|
47
47
|
@sash.subtract_points 5
|
48
48
|
end
|
49
|
-
score = Merit::
|
49
|
+
score = Merit::QalamScore.last
|
50
50
|
point = score.score_points.last
|
51
51
|
|
52
52
|
assert_equal point.num_points, -5
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qalam_merit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.05
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tute Costa
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|
@@ -158,8 +158,8 @@ files:
|
|
158
158
|
- lib/merit/models/active_record/action.rb
|
159
159
|
- lib/merit/models/active_record/activity_log.rb
|
160
160
|
- lib/merit/models/active_record/badges_sash.rb
|
161
|
+
- lib/merit/models/active_record/qalam_score.rb
|
161
162
|
- lib/merit/models/active_record/sash.rb
|
162
|
-
- lib/merit/models/active_record/score.rb
|
163
163
|
- lib/merit/models/badges_sash_concern.rb
|
164
164
|
- lib/merit/models/base/badges_sash.rb
|
165
165
|
- lib/merit/models/base/sash.rb
|
@@ -247,11 +247,11 @@ files:
|
|
247
247
|
- test/unit/action_test.rb
|
248
248
|
- test/unit/base_target_finder_test.rb
|
249
249
|
- test/unit/merit_unit_test.rb
|
250
|
+
- test/unit/qalam_score_test.rb
|
250
251
|
- test/unit/rule_unit_test.rb
|
251
252
|
- test/unit/rules_matcher_test.rb
|
252
253
|
- test/unit/sash_finder_test.rb
|
253
254
|
- test/unit/sash_test.rb
|
254
|
-
- test/unit/score_test.rb
|
255
255
|
- test/unit/target_finder_test.rb
|
256
256
|
homepage: https://github.com/merit-gem/merit
|
257
257
|
licenses:
|
@@ -352,9 +352,9 @@ test_files:
|
|
352
352
|
- test/unit/action_test.rb
|
353
353
|
- test/unit/base_target_finder_test.rb
|
354
354
|
- test/unit/merit_unit_test.rb
|
355
|
+
- test/unit/qalam_score_test.rb
|
355
356
|
- test/unit/rule_unit_test.rb
|
356
357
|
- test/unit/rules_matcher_test.rb
|
357
358
|
- test/unit/sash_finder_test.rb
|
358
359
|
- test/unit/sash_test.rb
|
359
|
-
- test/unit/score_test.rb
|
360
360
|
- test/unit/target_finder_test.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Merit::Models::ActiveRecord
|
2
|
-
class Score < ActiveRecord::Base
|
3
|
-
self.table_name = :merit_scores
|
4
|
-
belongs_to :sash
|
5
|
-
has_many :score_points,
|
6
|
-
dependent: :destroy,
|
7
|
-
class_name: 'Merit::Score::Point'
|
8
|
-
|
9
|
-
def points
|
10
|
-
score_points.group(:score_id).sum(:num_points).values.first || 0
|
11
|
-
end
|
12
|
-
|
13
|
-
class Point < ActiveRecord::Base
|
14
|
-
belongs_to :score, class_name: 'Merit::Score'
|
15
|
-
has_one :sash, through: :score
|
16
|
-
has_many :activity_logs,
|
17
|
-
class_name: 'Merit::ActivityLog',
|
18
|
-
as: :related_change
|
19
|
-
delegate :sash_id, to: :score
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Merit::Score < Merit::Models::ActiveRecord::Score; end
|
25
|
-
class Merit::Score::Point < Merit::Models::ActiveRecord::Score::Point; end
|