merit 2.3.2 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 781f4040bce17e9983ae237f54bf91c1538ce365
4
- data.tar.gz: c7aeb303a7c9b4378e5b5ecd4ad10de6842d3e64
3
+ metadata.gz: 5d79f50b24ec0f6cf605b5b77fbd9d2b96c41f16
4
+ data.tar.gz: 862c1a7af32018b9344bdccb43d462b97d7339e0
5
5
  SHA512:
6
- metadata.gz: 190bd669ef68c354cc322049f08a77bc68450a2762766be5f322cb84813a029bc74631f94ecbb7d2f1340281f10fb9a8fc5dcf6f243bc8f28adf76b8ce588c04
7
- data.tar.gz: 15155d78b99d36ec84c7124b48e82cbcab1d877ff2d3e370a3aa8d899e09c0f1c99598c448226ff276427b5bf5072760c625831ef94ba391987a33299a17bf26
6
+ metadata.gz: 783a96fce0128b18e34eba63999a84675011576d8ca0031251d5c4fe5d967007488616b0afe07258b0df2ac1b5c3e853e95b10e712b35a3b93f2e943b94e7c65
7
+ data.tar.gz: 0453aa9d1395d6a6d1f86f11276d076ba1d07a2e13b4622b3e07e077cc445e5055c64e99103a5074af555ead4217d05c749f2fc2918d3c9f4e7b264ec1ff04dc
data/NEWS.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  User-visible changes worth mentioning.
4
4
 
5
+ ## 2.3.3
6
+
7
+ - [#215] Bug fix in API where a `BadgeSash` would be created without failures
8
+ with a nil `badge_id`.
9
+ - Add validations to `BadgesSash`
10
+ - Rename generated migration files to explicitly name merit
11
+ - README improvements
12
+
5
13
  ## 2.3.2
6
14
 
7
15
  - [#218] Implement I18n for internationalization support
data/README.md CHANGED
@@ -26,7 +26,9 @@ and Rankings.
26
26
  - [Defining Rules](#defining-rules-2)
27
27
  - [Examples](#examples-2)
28
28
  - [Displaying Rankings](#displaying-rankings)
29
+ - [How merit finds the target object](#how-merit-finds-the-target-object)
29
30
  - [Getting Notifications](#getting-notifications)
31
+ - [I18n](#i18n)
30
32
  - [Uninstalling Merit](#uninstalling-merit)
31
33
 
32
34
 
@@ -135,9 +137,9 @@ badges:
135
137
 
136
138
  ```erb
137
139
  <ul>
138
- <% current_user.badges.each do |badge| %>
139
- <li><%= badge.name %></li>
140
- <% end %>
140
+ <% current_user.badges.each do |badge| %>
141
+ <li><%= badge.name %></li>
142
+ <% end %>
141
143
  </ul>
142
144
  ```
143
145
 
@@ -155,9 +157,9 @@ action user or to the method(s) defined in the `:to` option. Define rules on
155
157
  * `score`
156
158
  * `Integer`
157
159
  * `Proc`, or any object that accepts `call` which takes one argument, where
158
- the target_object is passed in and the return value is used as the score.
160
+ the target object is passed in and the return value is used as the score.
159
161
  * `:on` action as string or array of strings (like `controller#action`, similar to Rails routes)
160
- * `:to` method(s) to send to the target_object (who should be scored?)
162
+ * `:to` method(s) to send to the target object (who should be scored?)
161
163
  * `:model_name` (optional) to specify the model name if it cannot be guessed
162
164
  from the controller. (e.g. `model_name: 'User'` for `RegistrationsController`,
163
165
  or `model_name: 'Comment'` for `Api::CommentsController`)
@@ -258,6 +260,37 @@ end
258
260
  ```
259
261
 
260
262
 
263
+ # How merit finds the target object
264
+
265
+ Merit fetches the rule’s target object (the parameter it receives) from its
266
+ `:model_name` option, or from the controller’s instance variable.
267
+
268
+ To read it from the controller merit searches for the instance variable named
269
+ after the singularized controller name. For example, a rule like:
270
+
271
+ ```ruby
272
+ grant_on 'comments#update', badge_id: 1 do |target_object|
273
+ # target_object would be better named comment in this sample
274
+ end
275
+ ```
276
+
277
+ Would make merit try to find the `@comment` instance variable in the
278
+ `CommentsController#update` action. If the rule had the `:model_name` option
279
+ specified:
280
+
281
+ ```ruby
282
+ grant_on 'comments#update', badge_id: 1, model_name: "Article" do |target_object|
283
+ # target_object would be better named article in this sample
284
+ end
285
+ ```
286
+
287
+ Merit would fetch the `Article` object from the database, found by the `:id`
288
+ param sent in that `update` action.
289
+
290
+ If none of these methods find the target, Merit will log a `no target_obj`
291
+ warning, with a comment to check the configuration for the rule.
292
+
293
+
261
294
  # Getting Notifications
262
295
 
263
296
  You can get observers notified any time merit changes reputation in your
@@ -13,8 +13,8 @@ module ActiveRecord
13
13
  end
14
14
 
15
15
  def copy_migrations_and_model
16
- migration_template 'add_fields_to_model.rb',
17
- "db/migrate/add_fields_to_#{table_name}.rb"
16
+ migration_template 'add_merit_fields_to_model.rb',
17
+ "db/migrate/add_merit_fields_to_#{table_name}.rb"
18
18
  end
19
19
  end
20
20
  end
@@ -16,8 +16,10 @@ module ActiveRecord
16
16
  migration_template 'remove_merit_tables.rb',
17
17
  'db/migrate/remove_merit_tables.rb'
18
18
 
19
- migration_template 'remove_fields_from_model.rb',
20
- "db/migrate/remove_fields_from_#{table_name}.rb"
19
+ migration_template(
20
+ 'remove_merit_fields_from_model.rb',
21
+ "db/migrate/remove_merit_fields_from_#{table_name}.rb"
22
+ )
21
23
  end
22
24
  end
23
25
  end
@@ -1,4 +1,4 @@
1
- class AddFieldsTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class AddMeritFieldsTo<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :<%= table_name %>, :sash_id, :integer
4
4
  add_column :<%= table_name %>, :level, :integer, :default => 0
@@ -1,4 +1,4 @@
1
- class RemoveFieldsFrom<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class RemoveMeritFieldsFrom<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  remove_column :<%= table_name %>, :sash_id
4
4
  remove_column :<%= table_name %>, :level
@@ -1,10 +1,13 @@
1
1
  module Merit
2
2
  class BadgesSash < ActiveRecord::Base
3
3
  include Base::BadgesSash
4
+
4
5
  has_many :activity_logs,
5
6
  class_name: 'Merit::ActivityLog',
6
7
  as: :related_change
7
8
 
9
+ validates_presence_of :badge_id, :sash
10
+
8
11
  attr_accessible :badge_id if show_attr_accessible?
9
12
  end
10
13
  end
@@ -10,13 +10,13 @@ module Merit
10
10
  end
11
11
 
12
12
  def add_badge(badge_id)
13
- bs = Merit::BadgesSash.new(badge_id: badge_id)
13
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i)
14
14
  badges_sashes << bs
15
15
  bs
16
16
  end
17
17
 
18
18
  def rm_badge(badge_id)
19
- badges_sashes.where(badge_id: badge_id).first.try(:destroy)
19
+ badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy)
20
20
  end
21
21
 
22
22
  # Retrieve the number of points from a category
@@ -1,11 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "merit"
3
- s.summary = "General reputation Rails engine."
4
- s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
5
- s.homepage = "http://github.com/tute/merit"
3
+ s.summary = "Reputation engine for Rails apps"
4
+ s.description = "Manage badges, points and rankings (reputation) in your Rails app."
5
+ s.homepage = "https://github.com/merit-gem/merit"
6
6
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
7
+ s.test_files = `git ls-files -- test/*`.split("\n")
7
8
  s.license = 'MIT'
8
- s.version = '2.3.2'
9
+ s.version = '2.3.3'
9
10
  s.authors = ["Tute Costa"]
10
11
  s.email = 'tutecosta@gmail.com'
11
12
 
@@ -36,6 +36,14 @@ class NavigationTest < ActionDispatch::IntegrationTest
36
36
 
37
37
  user.rm_badge badge.id
38
38
  assert_equal [badge], user.reload.badges
39
+
40
+ assert_raise NoMethodError do
41
+ user.add_badge badge
42
+ end
43
+
44
+ assert_raise NoMethodError do
45
+ user.rm_badge badge
46
+ end
39
47
  end
40
48
 
41
49
  test 'Remove inexistent badge should do nothing' do
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: 2.3.2
4
+ version: 2.3.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: 2015-04-19 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ambry
@@ -108,8 +108,7 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.1.0
111
- description: Manage badges, points and rankings (reputation) of resources in a Rails
112
- application.
111
+ description: Manage badges, points and rankings (reputation) in your Rails app.
113
112
  email: tutecosta@gmail.com
114
113
  executables: []
115
114
  extensions: []
@@ -129,14 +128,14 @@ files:
129
128
  - lib/generators/active_record/install_generator.rb
130
129
  - lib/generators/active_record/merit_generator.rb
131
130
  - lib/generators/active_record/remove_generator.rb
132
- - lib/generators/active_record/templates/add_fields_to_model.rb
131
+ - lib/generators/active_record/templates/add_merit_fields_to_model.rb
133
132
  - lib/generators/active_record/templates/add_target_data_to_merit_actions.rb
134
133
  - lib/generators/active_record/templates/create_badges_sashes.rb
135
134
  - lib/generators/active_record/templates/create_merit_actions.rb
136
135
  - lib/generators/active_record/templates/create_merit_activity_logs.rb
137
136
  - lib/generators/active_record/templates/create_sashes.rb
138
137
  - lib/generators/active_record/templates/create_scores_and_points.rb
139
- - lib/generators/active_record/templates/remove_fields_from_model.rb
138
+ - lib/generators/active_record/templates/remove_merit_fields_from_model.rb
140
139
  - lib/generators/active_record/templates/remove_merit_tables.rb
141
140
  - lib/generators/active_record/upgrade_generator.rb
142
141
  - lib/generators/merit/install_generator.rb
@@ -262,7 +261,7 @@ files:
262
261
  - test/unit/sash_test.rb
263
262
  - test/unit/score_test.rb
264
263
  - test/unit/target_finder_test.rb
265
- homepage: http://github.com/tute/merit
264
+ homepage: https://github.com/merit-gem/merit
266
265
  licenses:
267
266
  - MIT
268
267
  metadata: {}
@@ -282,9 +281,97 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
281
  version: '0'
283
282
  requirements: []
284
283
  rubyforge_project:
285
- rubygems_version: 2.4.6
284
+ rubygems_version: 2.5.1
286
285
  signing_key:
287
286
  specification_version: 4
288
- summary: General reputation Rails engine.
289
- test_files: []
290
- has_rdoc:
287
+ summary: Reputation engine for Rails apps
288
+ test_files:
289
+ - test/dummy/Rakefile
290
+ - test/dummy/app/controllers/admin/users_controller.rb
291
+ - test/dummy/app/controllers/api/comments_controller.rb
292
+ - test/dummy/app/controllers/api/users_controller.rb
293
+ - test/dummy/app/controllers/application_controller.rb
294
+ - test/dummy/app/controllers/comments_controller.rb
295
+ - test/dummy/app/controllers/registrations_controller.rb
296
+ - test/dummy/app/controllers/users_controller.rb
297
+ - test/dummy/app/helpers/application_helper.rb
298
+ - test/dummy/app/models/address.rb
299
+ - test/dummy/app/models/comment.rb
300
+ - test/dummy/app/models/dummy_observer.rb
301
+ - test/dummy/app/models/merit/badge_rules.rb
302
+ - test/dummy/app/models/merit/point_rules.rb
303
+ - test/dummy/app/models/merit/rank_rules.rb
304
+ - test/dummy/app/models/user.rb
305
+ - test/dummy/app/views/admin/users/index.html.erb
306
+ - test/dummy/app/views/comments/_form.html.erb
307
+ - test/dummy/app/views/comments/edit.html.erb
308
+ - test/dummy/app/views/comments/index.html.erb
309
+ - test/dummy/app/views/comments/new.html.erb
310
+ - test/dummy/app/views/comments/show.html.erb
311
+ - test/dummy/app/views/layouts/application.html.erb
312
+ - test/dummy/app/views/users/_form.html.erb
313
+ - test/dummy/app/views/users/edit.html.erb
314
+ - test/dummy/app/views/users/index.html.erb
315
+ - test/dummy/app/views/users/new.html.erb
316
+ - test/dummy/app/views/users/show.html.erb
317
+ - test/dummy/config.ru
318
+ - test/dummy/config/application.rb
319
+ - test/dummy/config/boot.rb
320
+ - test/dummy/config/database.yml
321
+ - test/dummy/config/environment.rb
322
+ - test/dummy/config/environments/development.rb
323
+ - test/dummy/config/environments/production.rb
324
+ - test/dummy/config/environments/test.rb
325
+ - test/dummy/config/initializers/backtrace_silencers.rb
326
+ - test/dummy/config/initializers/inflections.rb
327
+ - test/dummy/config/initializers/merit.rb
328
+ - test/dummy/config/initializers/mime_types.rb
329
+ - test/dummy/config/initializers/secret_token.rb
330
+ - test/dummy/config/initializers/session_store.rb
331
+ - test/dummy/config/locales/en.yml
332
+ - test/dummy/config/mongoid.yml
333
+ - test/dummy/config/routes.rb
334
+ - test/dummy/db/migrate/20110421191249_create_users.rb
335
+ - test/dummy/db/migrate/20110421191250_create_comments.rb
336
+ - test/dummy/db/migrate/20120318022220_add_fields_to_users.rb
337
+ - test/dummy/db/migrate/20130321082817_add_fields_to_comments.rb
338
+ - test/dummy/db/migrate/20130329224406_create_merit_actions.rb
339
+ - test/dummy/db/migrate/20130329224407_create_merit_activity_logs.rb
340
+ - test/dummy/db/migrate/20130329224408_create_sashes.rb
341
+ - test/dummy/db/migrate/20130329224409_create_badges_sashes.rb
342
+ - test/dummy/db/migrate/20130329224410_create_scores_and_points.rb
343
+ - test/dummy/db/migrate/20140211144001_create_addresses.rb
344
+ - test/dummy/db/migrate/20140819133931_add_target_data_to_merit_actions.rb
345
+ - test/dummy/db/migrate/20140906225844_create_players.rb
346
+ - test/dummy/db/schema.rb
347
+ - test/dummy/db/seeds.rb
348
+ - test/dummy/public/404.html
349
+ - test/dummy/public/422.html
350
+ - test/dummy/public/500.html
351
+ - test/dummy/public/favicon.ico
352
+ - test/dummy/public/javascripts/application.js
353
+ - test/dummy/public/javascripts/controls.js
354
+ - test/dummy/public/javascripts/dragdrop.js
355
+ - test/dummy/public/javascripts/effects.js
356
+ - test/dummy/public/javascripts/prototype.js
357
+ - test/dummy/public/javascripts/rails.js
358
+ - test/dummy/public/rails.js
359
+ - test/dummy/public/stylesheets/.gitkeep
360
+ - test/dummy/public/stylesheets/scaffold.css
361
+ - test/dummy/script/rails
362
+ - test/integration/navigation_test.rb
363
+ - test/orm/active_record.rb
364
+ - test/orm/mongoid.rb
365
+ - test/orm_models/active_record.rb
366
+ - test/orm_models/mongoid.rb
367
+ - test/support/integration_case.rb
368
+ - test/test_helper.rb
369
+ - test/unit/action_test.rb
370
+ - test/unit/base_target_finder_test.rb
371
+ - test/unit/merit_unit_test.rb
372
+ - test/unit/rule_unit_test.rb
373
+ - test/unit/rules_matcher_test.rb
374
+ - test/unit/sash_finder_test.rb
375
+ - test/unit/sash_test.rb
376
+ - test/unit/score_test.rb
377
+ - test/unit/target_finder_test.rb