qalam_merit 4.5.01 → 4.5.06

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a062b61ba12835e8cc9ea7eeed4eb6b94eccaa7fdd4323cdc8efd226e5331aa7
4
- data.tar.gz: b91428baa833ca06913fe27c2c54623db498e5a0a051c368fc3b3cb509e18971
3
+ metadata.gz: d32a4d56924a23f24741b8aa276cd54f32767ad51d8c04df8d138f4c82d2c427
4
+ data.tar.gz: 5202cdc4c9c90323f07dffe90eb1db4a6690df92dce156fb7466f30526482bf5
5
5
  SHA512:
6
- metadata.gz: 2a3e6f2eceff7d5971e4e8ebfc71a71d7cc553e76ca7bb07c5c51e071bbeeefe782fe7d6be7c27ccab85fb514a7de83a2cf1246bd081246d6ddda5c79ab0e79a
7
- data.tar.gz: dff4b30e28a4f91bbc49f661fbc55aee612ab8ae849e429f545089690b582e533c993b39f3b01ef0f9a2d41283c290660007ffb383feb0f94f1d39f62b52377b
6
+ metadata.gz: 3a64775d9aa10271625631b8bbad64482a3fc09c1776652a7fba52bdafb3a78da0a87ea5c1a7b3fd6d8f4c20dace827087c2c4790578fcd4eeb1d2634608e031
7
+ data.tar.gz: 73a2d727db358c669dccdf8e9f73212410c563ce50262e20052ab6b8cd73111f932cfb09aa1ae8fdc00edeaa68018278d0a99baaf9421d62492b5a8fa26679f4
@@ -16,7 +16,7 @@ module Merit
16
16
 
17
17
  # Delegate methods from meritable models to their sash
18
18
  def _merit_delegate_methods_to_sash
19
- methods = %w(badge_ids badges points add_badge rm_badge
19
+ methods = %w(badge_ids badges points add_badge add_qalam_badge rm_badge
20
20
  add_points subtract_points score_points)
21
21
  methods.each { |method| delegate method, to: :_sash }
22
22
  end
@@ -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, " belongs_to :sash, foreign_key: 'sash_id', class_name: 'Merit::Sash'\n")
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
@@ -6,6 +6,7 @@ module Merit::Models::ActiveRecord
6
6
  has_many :activity_logs,
7
7
  class_name: 'Merit::ActivityLog',
8
8
  as: :related_change
9
+ belongs_to :course, foreign_key: "course_id", class_name: 'Course'
9
10
 
10
11
  validates_presence_of :badge_id, :sash
11
12
  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::MeritScore'
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::MeritScore::Point
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::MeritScore::Point.new
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::MeritScore.create
51
+ scores << Merit::QalamScore.create
52
52
  end
53
53
  end
54
54
  end
@@ -8,16 +8,27 @@ module Merit::Models
8
8
  badges_sashes.map(&:badge_id)
9
9
  end
10
10
 
11
- def add_badge(badge_id)
12
- bs = Merit::BadgesSash.new(badge_id: badge_id.to_i)
13
- badges_sashes << bs
14
- bs
11
+ def add_badge(badge_id, options = {})
12
+ if (course_id = options[:course_id])
13
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i, course_id: course_id.to_i)
14
+ else
15
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i)
16
+ end
17
+ badges_sashes << bs
18
+ bs
15
19
  end
16
20
 
17
21
  def rm_badge(badge_id)
18
22
  badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy)
19
23
  end
20
24
 
25
+ ########################QALAM_DEV#########################
26
+ def add_qalam_badge(badge_id, course_id)
27
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i, course_id: course_id.to_i)
28
+ badges_sashes << bs
29
+ bs
30
+ end
31
+ ########################END###################################
21
32
  # Retrieve the number of points from a category
22
33
  # By default all points are summed up
23
34
  # @param category [String] The category
@@ -31,7 +42,7 @@ module Merit::Models
31
42
  end
32
43
 
33
44
  def add_points(num_points, options = {})
34
- point = Merit::MeritScore::Point.new
45
+ point = Merit::QalamScore::Point.new
35
46
  point.num_points = num_points
36
47
  scores
37
48
  .where(category: options[:category] || 'default')
@@ -47,7 +58,7 @@ module Merit::Models
47
58
  private
48
59
 
49
60
  def create_scores
50
- scores << Merit::MeritScore.create
61
+ scores << Merit::QalamScore.create
51
62
  end
52
63
  end
53
64
  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.01'
9
+ s.version = '4.5.06'
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::MeritScore::Point.count
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::MeritScore::Point.count
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::Score do
3
+ describe Merit::QalamScore do
4
4
  it 'Point#sash_id delegates to Score' do
5
- score = Merit::MeritScore.new
5
+ score = Merit::QalamScore.new
6
6
  score.sash_id = 33
7
7
 
8
- point = Merit::MeritScore::Point.new
8
+ point = Merit::QalamScore::Point.new
9
9
  point.score = score
10
10
 
11
11
  _(point.sash_id).must_be :==, score.sash_id
@@ -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::MeritScore.last
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::MeritScore::Point.count", 1) do
22
+ assert_difference("Merit::QalamScore::Point.count", 1) do
23
23
  @sash.add_points 5
24
24
  end
25
- score = Merit::MeritScore.last
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::MeritScore.last
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::MeritScore::Point.count", 1) do
46
+ assert_difference("Merit::QalamScore::Point.count", 1) do
47
47
  @sash.subtract_points 5
48
48
  end
49
- score = Merit::MeritScore.last
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.01
4
+ version: 4.5.06
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-02-24 00:00:00.000000000 Z
12
+ date: 2021-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk
@@ -158,7 +158,7 @@ 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/merit_score.rb
161
+ - lib/merit/models/active_record/qalam_score.rb
162
162
  - lib/merit/models/active_record/sash.rb
163
163
  - lib/merit/models/badges_sash_concern.rb
164
164
  - lib/merit/models/base/badges_sash.rb
@@ -246,8 +246,8 @@ files:
246
246
  - test/test_helper.rb
247
247
  - test/unit/action_test.rb
248
248
  - test/unit/base_target_finder_test.rb
249
- - test/unit/merit_score_test.rb
250
249
  - test/unit/merit_unit_test.rb
250
+ - test/unit/qalam_score_test.rb
251
251
  - test/unit/rule_unit_test.rb
252
252
  - test/unit/rules_matcher_test.rb
253
253
  - test/unit/sash_finder_test.rb
@@ -351,8 +351,8 @@ test_files:
351
351
  - test/test_helper.rb
352
352
  - test/unit/action_test.rb
353
353
  - test/unit/base_target_finder_test.rb
354
- - test/unit/merit_score_test.rb
355
354
  - test/unit/merit_unit_test.rb
355
+ - test/unit/qalam_score_test.rb
356
356
  - test/unit/rule_unit_test.rb
357
357
  - test/unit/rules_matcher_test.rb
358
358
  - test/unit/sash_finder_test.rb
@@ -1,25 +0,0 @@
1
- module Merit::Models::ActiveRecord
2
- class MeritScore < ActiveRecord::Base
3
- self.table_name = :merit_scores
4
- belongs_to :sash
5
- has_many :score_points,
6
- dependent: :destroy,
7
- class_name: 'Merit::MeritScore::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::MeritScore < Merit::Models::ActiveRecord::Score; end
25
- class Merit::MeritScore::Point < Merit::Models::ActiveRecord::Score::Point; end