merit 1.2.0 → 1.2.1

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (1.2.0)
4
+ merit (1.2.1)
5
5
  ambry (~> 0.3.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  module Merit
2
2
  # Sets up an app-wide after_filter, and inserts merit_action entries if
3
3
  # there are defined rules (for badges or points) for current
4
- # 'controller_name#action_name'
4
+ # 'controller_path#action_name'
5
5
  module ControllerExtensions
6
6
  def self.included(base)
7
7
  base.after_filter do |controller|
@@ -12,7 +12,7 @@ module Merit
12
12
  :action_method => action_name,
13
13
  :action_value => params[:value],
14
14
  :had_errors => had_errors?,
15
- :target_model => controller_name,
15
+ :target_model => controller_path,
16
16
  :target_id => target_id
17
17
  ).id
18
18
 
@@ -25,7 +25,7 @@ module Merit
25
25
  private
26
26
 
27
27
  def rules_defined?
28
- action = "#{controller_name}\##{action_name}"
28
+ action = "#{controller_path}\##{action_name}"
29
29
  AppBadgeRules[action].present? || AppPointRules[action].present?
30
30
  end
31
31
 
@@ -36,7 +36,7 @@ module Merit
36
36
  def target_object
37
37
  target_obj = instance_variable_get(:"@#{controller_name.singularize}")
38
38
  if target_obj.nil?
39
- Rails.logger.warn("[merit] No object found, maybe you need a '@#{controller_name.singularize}' variable in '#{controller_name}_controller'?")
39
+ Rails.logger.warn("[merit] No object found, maybe you need a '@#{controller_name.singularize}' variable in '#{controller_path}_controller'?")
40
40
  end
41
41
  target_obj
42
42
  end
data/merit.gemspec CHANGED
@@ -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.2.0'
7
+ s.version = '1.2.1'
8
8
  s.authors = ["Tute Costa"]
9
9
  s.email = 'tutecosta@gmail.com'
10
10
  s.add_dependency 'ambry', '~> 0.3.0'
@@ -0,0 +1,9 @@
1
+ class Admin::UsersController < ApplicationController
2
+ def index
3
+ @users = User.all
4
+ respond_to do |format|
5
+ format.html # index.html.erb
6
+ format.xml { render :xml => @users }
7
+ end
8
+ end
9
+ end
@@ -29,6 +29,9 @@ module Merit
29
29
  # Example rule for multiple badge granting
30
30
  grant_on 'users#index', :badge => 'gossip', :multiple => true
31
31
 
32
+ # Example rule for badge granting in namespaced controllers
33
+ grant_on 'admin/users#index', :badge => 'visited_admin'
34
+
32
35
  # If it has 10 comments, grant commenter-10 badge
33
36
  grant_on 'comments#create', :badge => 'commenter', :level => 10 do |comment|
34
37
  comment.user.comments.count >= 10
@@ -0,0 +1,26 @@
1
+ <h1>Listing users from Admin</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>#Comments</th>
7
+ <th>Badges</th>
8
+ <th>Points</th>
9
+ </tr>
10
+
11
+ <% @users.each do |user| %>
12
+ <tr>
13
+ <td><%= user.name %></td>
14
+ <td><%= user.comments.count %></td>
15
+ <td><%= user.show_badges %></td>
16
+ <td><%= user.points %></td>
17
+ <td><%= link_to 'Show', user %>
18
+ - <%= link_to 'Edit', edit_user_path(user) %>
19
+ - <%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
20
+ </tr>
21
+ <% end %>
22
+ </table>
23
+
24
+ <br />
25
+
26
+ <%= link_to 'New User', new_user_path %>
@@ -18,6 +18,10 @@ badge_id = 0
18
18
  :id => (badge_id = badge_id+1),
19
19
  :name => 'commenter',
20
20
  :description => 'You\'ve participated great in our boards!'
21
+ }, {
22
+ :id => (badge_id = badge_id+1),
23
+ :name => 'visited_admin',
24
+ :description => 'You sneaked in!'
21
25
  }, {
22
26
  :id => (badge_id = badge_id+1),
23
27
  :name => 'has_commenter_friend',
@@ -1,4 +1,7 @@
1
1
  Dummy::Application.routes.draw do
2
+ namespace :admin do
3
+ match '/users' => 'users#index'
4
+ end
2
5
  resources :users, :except => :update
3
6
  resources :registrations, :only => :update, :as => :registrations_user
4
7
  resources :comments
@@ -35,8 +35,15 @@ class NavigationTest < ActiveSupport::IntegrationCase
35
35
  visit '/users'
36
36
  visit '/users'
37
37
  visit '/users'
38
- visit '/users'
38
+ gossip = Badge.by_name('gossip').first
39
+ assert_equal 3, User.first.badges.count
40
+ assert_equal [gossip, gossip, gossip], User.first.badges
41
+
42
+ # Testing with namespaced controllers
43
+ visit '/admin/users'
44
+ visited_admin = Badge.by_name('visited_admin').first
39
45
  assert_equal 4, User.first.badges.count
46
+ assert User.first.badges.include?(visited_admin)
40
47
  end
41
48
 
42
49
  test 'user workflow should grant some badges 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.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -238,6 +238,7 @@ files:
238
238
  - test/dummy-mongoid/public/stylesheets/scaffold.css
239
239
  - test/dummy-mongoid/script/rails
240
240
  - test/dummy/Rakefile
241
+ - test/dummy/app/controllers/admin/users_controller.rb
241
242
  - test/dummy/app/controllers/application_controller.rb
242
243
  - test/dummy/app/controllers/comments_controller.rb
243
244
  - test/dummy/app/controllers/registrations_controller.rb
@@ -248,6 +249,7 @@ files:
248
249
  - test/dummy/app/models/merit/point_rules.rb
249
250
  - test/dummy/app/models/merit/rank_rules.rb
250
251
  - test/dummy/app/models/user.rb
252
+ - test/dummy/app/views/admin/users/index.html.erb
251
253
  - test/dummy/app/views/comments/_form.html.erb
252
254
  - test/dummy/app/views/comments/edit.html.erb
253
255
  - test/dummy/app/views/comments/index.html.erb