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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2cbaa14467c3e05f09615f1fccf0fb0b504246ed8e11320245d9c160f2f81c9
4
- data.tar.gz: 940d31167c9bd59cd1ecaa96055cbf87f6e5bf6e7e1fbb3b433215b0d27d3291
3
+ metadata.gz: a847a60ecad264aa85e3118fa9e26a974de2e08142577fe134c12e48c4989faf
4
+ data.tar.gz: 7f219282c0e6c4f33e10f2b77040ef19dbec9874e11140c47cc216fb17c9665b
5
5
  SHA512:
6
- metadata.gz: db2f9a9d70500a9e11985d7dd54d8fc5a891b69a940a72ce8fea8a465d733ae4ab1e197ad1eb11b50f6699321d9d55cffc36f5f1da2ad3c5deebb9d41414380c
7
- data.tar.gz: 9230dda9fe83d1b137dd5105134b4ed41614d2323308a40ae87f98302931f1309e87f00a13c8f893b8dae8c732b4e23e7d22c3ec8353a49a83a465bfd852579c
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
- version = ENV['RAILS_VERSION']
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'
@@ -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).map(&:check_all_rules)
18
+ where(processed: false).find_each(&:check_all_rules)
19
19
  end
20
20
 
21
21
  # Check rules defined for a merit_action
@@ -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 || update_attributes(sash: Sash.create)
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
@@ -7,7 +7,5 @@ module Merit
7
7
  as: :related_change
8
8
 
9
9
  validates_presence_of :badge_id, :sash
10
-
11
- attr_accessible :badge_id if show_attr_accessible?
12
10
  end
13
11
  end
@@ -6,8 +6,6 @@ module Merit
6
6
 
7
7
  field :badge_id, type: Integer
8
8
 
9
- attr_accessible :badge_id if show_attr_accessible?
10
-
11
9
  belongs_to :sash, class_name: 'Merit::Sash'
12
10
  has_many :activity_logs, class_name: 'Merit::ActivityLog', as: :related_change
13
11
 
@@ -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.2'
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.update_attributes(comment_params)
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.update_attributes(user_params)
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
@@ -25,10 +25,6 @@ class Comment
25
25
 
26
26
  belongs_to :user
27
27
 
28
- if show_attr_accessible?
29
- attr_accessible :name, :comment, :user_id, :votes
30
- end
31
-
32
28
  validates :name, :comment, :user_id, :presence => true
33
29
 
34
30
  delegate :comments, :to => :user, :prefix => true
@@ -17,10 +17,6 @@ class User
17
17
  has_many :addresses
18
18
  has_many :comments
19
19
 
20
- if show_attr_accessible?
21
- attr_accessible :name
22
- end
23
-
24
20
  def model_with_no_reputation
25
21
  addresses.first || addresses.create
26
22
  end
@@ -11,7 +11,7 @@ require "merit"
11
11
 
12
12
  module Dummy
13
13
  class Application < Rails::Application
14
- if Rails.version >= "5.2"
14
+ if Rails.version.match? "5.2.+"
15
15
  config.active_record.sqlite3.represent_boolean_as_integer = true
16
16
  end
17
17
 
@@ -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
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
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: 20140906225844) do
13
+ ActiveRecord::Schema.define(version: 2014_09_06_225844) do
15
14
 
16
- create_table "addresses", force: true do |t|
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: true do |t|
21
- t.integer "badge_id"
22
- t.integer "sash_id"
23
- t.boolean "notified_user", default: false
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
- add_index "badges_sashes", ["badge_id", "sash_id"], name: "index_badges_sashes_on_badge_id_and_sash_id"
28
- add_index "badges_sashes", ["badge_id"], name: "index_badges_sashes_on_badge_id"
29
- add_index "badges_sashes", ["sash_id"], name: "index_badges_sashes_on_sash_id"
30
-
31
- create_table "comments", force: true do |t|
32
- t.string "name"
33
- t.text "comment"
34
- t.integer "user_id"
35
- t.integer "votes", default: 0
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: true do |t|
43
- t.integer "user_id"
44
- t.string "action_method"
45
- t.integer "action_value"
46
- t.boolean "had_errors", default: false
47
- t.string "target_model"
48
- t.integer "target_id"
49
- t.boolean "processed", default: false
50
- t.datetime "created_at", null: false
51
- t.datetime "updated_at", null: false
52
- t.text "target_data"
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: true do |t|
56
- t.integer "action_id"
57
- t.string "related_change_type"
58
- t.integer "related_change_id"
59
- t.string "description"
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: true do |t|
64
- t.integer "score_id"
65
- t.integer "num_points", default: 0
66
- t.string "log"
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: true do |t|
70
+ create_table "merit_scores", force: :cascade do |t|
71
71
  t.integer "sash_id"
72
- t.string "category", default: "default"
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: true do |t|
76
+ create_table "players", force: :cascade do |t|
76
77
  t.integer "sash_id"
77
- t.integer "level", default: 0
78
+ t.integer "level", default: 0
78
79
  end
79
80
 
80
- create_table "sashes", force: true do |t|
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: true do |t|
86
- t.string "name"
87
- t.datetime "created_at", null: false
88
- t.datetime "updated_at", null: false
89
- t.integer "sash_id"
90
- t.integer "level", default: 0
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
@@ -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
- if active_record_orm?
18
- test 'unknown ranking raises exception' do
19
- class WeirdRankRules
20
- include Merit::RankRulesMethods
21
- def initialize
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
@@ -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.2
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: 2018-07-23 00:00:00.000000000 Z
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
@@ -1,8 +0,0 @@
1
- # Place orm-dependent test preparation here
2
- migrations = File.expand_path("../../dummy/db/migrate/", __FILE__)
3
-
4
- if Rails.version >= "5.2"
5
- ActiveRecord::MigrationContext.new(migrations).migrate
6
- else
7
- ActiveRecord::Migrator.migrate migrations
8
- end
@@ -1,6 +0,0 @@
1
- # Place orm-dependent test preparation here
2
- class ActiveSupport::TestCase
3
- setup do
4
- Mongoid.purge!
5
- end
6
- end