merit 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # TODO: Why do we need them here if they are in .gemspec?
4
- gem 'bson_ext'
5
- gem 'mongoid', '2.4.8'
6
-
7
3
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (0.9.5)
4
+ merit (0.10.0)
5
5
  ambry (~> 0.3.0)
6
6
 
7
7
  GEM
@@ -66,8 +66,8 @@ GEM
66
66
  mime-types (1.18)
67
67
  mongo (1.6.2)
68
68
  bson (~> 1.6.2)
69
- mongoid (2.4.8)
70
- activemodel (~> 3.1)
69
+ mongoid (2.0.2)
70
+ activemodel (~> 3.0)
71
71
  mongo (~> 1.3)
72
72
  tzinfo (~> 0.3.22)
73
73
  multi_json (1.3.6)
@@ -131,7 +131,7 @@ DEPENDENCIES
131
131
  capybara
132
132
  haml
133
133
  merit!
134
- mongoid (= 2.4.8)
134
+ mongoid (~> 2.0.0)
135
135
  rails (~> 3.2.3)
136
136
  simplecov
137
137
  sqlite3
data/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
  5. Define badges you will use in `config/initializers/merit.rb`
16
16
  6. Configure reputation rules for your application in `app/models/merit/*`
17
17
 
18
+ NOTE: Mongoid support is experimental.
19
+
18
20
  ---
19
21
 
20
22
  # Defining badge rules
@@ -1,5 +1,22 @@
1
1
  # Upgrading
2
2
 
3
+ ## to 0.10.0
4
+
5
+ `badges_sashes` table gets a primary key `id` column. Run the following migration:
6
+
7
+ class AddIdToBadgesSashes < ActiveRecord::Migration
8
+ def self.up
9
+ add_column :badges_sashes, :id, :primary_key
10
+ end
11
+
12
+ def self.down
13
+ remove_column :badges_sashes, :id
14
+ end
15
+ end
16
+
17
+ `set_notified!(badge = nil, sash = nil)` no longer exists, just call `set_notified!`
18
+ over the `badge_sash` object, with no parameters.
19
+
3
20
  ## to 0.9.0
4
21
 
5
22
  Adds `allow_multiple` boolean option to `Badge#grant_to` (defaults to
@@ -1,6 +1,6 @@
1
1
  class CreateBadgesSashes < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :badges_sashes, :id => false do |t|
3
+ create_table :badges_sashes do |t|
4
4
  t.integer :badge_id, :sash_id
5
5
  t.boolean :notified_user, :default => false
6
6
  t.datetime :created_at
@@ -3,7 +3,7 @@ module Merit
3
3
 
4
4
  module ClassMethods
5
5
  def has_merit(options = {})
6
- belongs_to :sash
6
+ belongs_to :sash, :dependent => :destroy
7
7
 
8
8
  if Merit.orm == :mongo_mapper
9
9
  plugin Merit
@@ -24,7 +24,7 @@ module Merit
24
24
 
25
25
  def badges
26
26
  create_sash_if_none
27
- sash.badge_ids.collect{|b_id| Badge.find(b_id) }
27
+ sash.badges
28
28
  end
29
29
 
30
30
  # Create sash if doesn't have
@@ -6,10 +6,8 @@ class BadgesSash < ActiveRecord::Base
6
6
  end
7
7
 
8
8
  # To be used in the application, mark badge granting as notified to user
9
- def set_notified!(badge, sash)
10
- # With composite keys ARel complained, had to use SQL
11
- ActiveRecord::Base.connection.execute("UPDATE badges_sashes
12
- SET notified_user = TRUE
13
- WHERE badge_id = #{badge.id} AND sash_id = #{sash.id}")
9
+ def set_notified!
10
+ self.notified_user = true
11
+ save
14
12
  end
15
13
  end
@@ -1,5 +1,9 @@
1
1
  class Sash < ActiveRecord::Base
2
- has_many :badges_sashes
2
+ has_many :badges_sashes, :dependent => :destroy
3
+
4
+ def badges
5
+ badge_ids.collect { |b_id| Badge.find(b_id) }
6
+ end
3
7
 
4
8
  def badge_ids
5
9
  badges_sashes.collect(&:badge_id)
@@ -7,19 +11,11 @@ class Sash < ActiveRecord::Base
7
11
 
8
12
  def add_badge(badge_id)
9
13
  bs = BadgesSash.new
10
- bs.sash_id = self.id
11
14
  bs.badge_id = badge_id
12
- bs.save
15
+ badges_sashes << bs
13
16
  end
17
+
14
18
  def rm_badge(badge_id)
15
- badges_sashes = BadgesSash.where(:badge_id => badge_id, :sash_id => self.id)
16
- # ActiveRecord::Relation#delete|destroy(_all) doesn't work with composite keys.
17
- # Badge is not AR model (Ambry) so can't do self.badges.find(badge_id).delete
18
- badges_sash = badges_sashes.first
19
- badges_sashes.delete_all
20
- # delete doesn't run callbacks, do it by hand
21
- if Object.const_defined?('BadgesSashObserver') && badges_sash.present?
22
- BadgesSashObserver.instance.after_delete(badges_sash)
23
- end
19
+ badges_sashes.find_by_badge_id(badge_id).destroy
24
20
  end
25
21
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
5
5
  s.homepage = "http://github.com/tute/merit"
6
6
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
7
- s.version = "0.9.5"
7
+ s.version = "0.10.0"
8
8
  s.authors = ["Tute Costa"]
9
9
  s.email = 'tutecosta@gmail.com'
10
10
  s.add_dependency 'ambry', '~> 0.3.0'
@@ -1,6 +1,6 @@
1
1
  class CreateBadgesSashes < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :badges_sashes, :id => false do |t|
3
+ create_table :badges_sashes do |t|
4
4
  t.integer :badge_id, :sash_id
5
5
  t.boolean :notified_user, :default => false
6
6
  t.datetime :created_at
@@ -13,7 +13,7 @@
13
13
 
14
14
  ActiveRecord::Schema.define(:version => 20120318022220) do
15
15
 
16
- create_table "badges_sashes", :id => false, :force => true do |t|
16
+ create_table "badges_sashes", :force => true do |t|
17
17
  t.integer "badge_id"
18
18
  t.integer "sash_id"
19
19
  t.boolean "notified_user", :default => false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ambry