merit 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (1.1.2)
4
+ merit (1.2.0)
5
5
  ambry (~> 0.3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -51,7 +51,13 @@ grant_on ['users#create', 'users#update'], :badge => 'autobiographer', :temporar
51
51
  end
52
52
  ```
53
53
 
54
- ## Grant manually
54
+ ### Check granted badges
55
+
56
+ ```ruby
57
+ current_user.badges # Returns an array of badges
58
+ ```
59
+
60
+ ### Grant manually
55
61
 
56
62
  You may also grant badges "by hand":
57
63
 
@@ -96,7 +102,13 @@ score 20, :on => [
96
102
  score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
97
103
  ```
98
104
 
99
- ## Score manually
105
+ ### Check awarded points
106
+
107
+ ```ruby
108
+ current_user.points # Returns an integer
109
+ ```
110
+
111
+ ### Score manually
100
112
 
101
113
  You may also change user points "by hand":
102
114
 
@@ -1,6 +1,6 @@
1
1
  # Upgrading
2
2
 
3
- ## to 1.2.0 (unreleased)
3
+ ## to 1.2.0
4
4
 
5
5
  * `Badge#grant_to(meritable_object)` no longer exists. Use
6
6
  `meritable_object.add_badge(badge_id)` (may add badges more than once).
@@ -49,9 +49,9 @@ module Merit
49
49
  end
50
50
 
51
51
  ActiveSupport.on_load(:action_controller) do
52
- # Load application defined rules
53
- ::Merit::AppBadgeRules = BadgeRules.new.defined_rules
54
- ::Merit::AppPointRules = PointRules.new.defined_rules
52
+ # Load application defined rules on application boot up
53
+ ::Merit::AppBadgeRules = ::Merit::BadgeRules.new.defined_rules
54
+ ::Merit::AppPointRules = ::Merit::PointRules.new.defined_rules
55
55
 
56
56
  include Merit::ControllerExtensions
57
57
  end
@@ -30,7 +30,7 @@ module Merit
30
30
  end
31
31
 
32
32
  def had_errors?
33
- target_object.try(:errors).try(:present?) || false
33
+ target_object.respond_to?(:errors) && target_object.errors.try(:present?)
34
34
  end
35
35
 
36
36
  def target_object
@@ -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 = '1.1.2'
7
+ s.version = '1.2.0'
8
8
  s.authors = ["Tute Costa"]
9
9
  s.email = 'tutecosta@gmail.com'
10
10
  s.add_dependency 'ambry', '~> 0.3.0'
@@ -7,27 +7,27 @@ class NavigationTest < ActiveSupport::IntegrationCase
7
7
  click_button('Create User')
8
8
 
9
9
  user = User.where(:name => 'Jack').first
10
- assert_equal [Badge.by_name('just-registered').first], user.badges.to_a
10
+ assert_equal [Badge.by_name('just-registered').first], user.badges
11
11
  end
12
12
 
13
13
  test 'User#add_badge should add one badge, #rm_badge should delete one' do
14
14
  user = User.create(:name => 'test-user')
15
- assert_equal [], user.badges.to_a
15
+ assert_equal [], user.badges
16
16
 
17
17
  badge = Badge.first
18
18
  user.add_badge badge.id
19
19
  user.add_badge badge.id
20
- assert_equal [badge, badge], user.badges.to_a
20
+ assert_equal [badge, badge], user.badges
21
21
 
22
22
  user.rm_badge badge.id
23
- assert_equal [badge], user.reload.badges.to_a
23
+ assert_equal [badge], user.reload.badges
24
24
  end
25
25
 
26
26
  test 'Remove inexistent badge should do nothing' do
27
27
  user = User.create(:name => 'test-user')
28
- assert_equal [], user.badges.to_a
28
+ assert_equal [], user.badges
29
29
  user.rm_badge 1
30
- assert_equal [], user.badges.to_a
30
+ assert_equal [], user.badges
31
31
  end
32
32
 
33
33
  test 'users#index should grant badge multiple times' do
@@ -70,8 +70,8 @@ class NavigationTest < ActiveSupport::IntegrationCase
70
70
  fill_in 'User', :with => user.id
71
71
  click_button('Create Comment')
72
72
 
73
- assert_equal [Badge.by_name('commenter').by_level(10).first], user.reload.badges.to_a
74
- assert_equal [Badge.by_name('has_commenter_friend').first], friend.reload.badges.to_a
73
+ assert_equal [Badge.by_name('commenter').by_level(10).first], user.reload.badges
74
+ assert_equal [Badge.by_name('has_commenter_friend').first], friend.reload.badges
75
75
 
76
76
  # Vote (to 5) a user's comment, assert relevant-commenter badge granted
77
77
  relevant_comment = user.comments.where(:votes => 8).first
@@ -81,13 +81,13 @@ class NavigationTest < ActiveSupport::IntegrationCase
81
81
  end
82
82
 
83
83
  relevant_badge = Badge.by_name('relevant-commenter').first
84
- user_badges = User.where(:name => 'test-user').first.badges.to_a
84
+ user_badges = User.where(:name => 'test-user').first.badges
85
85
  assert user_badges.include?(relevant_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain relevant-commenter badge."
86
86
 
87
87
  # Edit user's name by long name
88
88
  # tests ruby code in grant_on is being executed, and gives badge
89
89
  user = User.where(:name => 'test-user').first
90
- user_badges = user.badges.to_a
90
+ user_badges = user.badges
91
91
 
92
92
  visit "/users/#{user.id}/edit"
93
93
  fill_in 'Name', :with => 'long_name!'
@@ -95,7 +95,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
95
95
 
96
96
  user = User.where(:name => 'long_name!').first
97
97
  autobiographer_badge = Badge.by_name('autobiographer').first
98
- assert user.badges.to_a.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain autobiographer badge."
98
+ assert user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain autobiographer badge."
99
99
 
100
100
  # Edit user's name by short name
101
101
  # tests ruby code in grant_on is being executed, and removes badge
@@ -104,7 +104,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
104
104
  click_button('Update User')
105
105
 
106
106
  user = User.where(:name => 'abc').first
107
- assert !user.badges.to_a.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should remove autobiographer badge."
107
+ assert !user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should remove autobiographer badge."
108
108
  end
109
109
 
110
110
  test 'user workflow should add up points at some times' do
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: 1.1.2
4
+ version: 1.2.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-12-04 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ambry
@@ -321,9 +321,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
321
  version: '0'
322
322
  requirements: []
323
323
  rubyforge_project:
324
- rubygems_version: 1.8.24
324
+ rubygems_version: 1.8.23
325
325
  signing_key:
326
326
  specification_version: 3
327
327
  summary: General reputation Rails engine.
328
328
  test_files: []
329
- has_rdoc: