merit 2.1.0 → 2.1.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.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/lib/generators/active_record/merit_generator.rb +1 -1
 - data/lib/generators/active_record/remove_generator.rb +1 -1
 - data/lib/generators/merit/merit_generator.rb +1 -1
 - data/lib/generators/merit/remove_generator.rb +1 -1
 - data/lib/merit.rb +2 -1
 - data/lib/merit/controller_extensions.rb +4 -3
 - data/lib/merit/reputation_change_observer.rb +9 -3
 - data/merit.gemspec +1 -1
 - data/test/dummy/app/models/merit/point_rules.rb +3 -1
 - data/test/integration/navigation_test.rb +9 -5
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: fffa4a71100476ce7342d95ec21d9841dcdba506
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 366af39f2fe07ec2eb644a5e7e2710a6fb95abcf
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 766d06b7c33496656d497f3b06a522e9e29f3d4322e500168cfbfcb0deae4ec0502e1ac754108e6545e61c2e16d7f4538cae24d29e65b8bc1fd4789ffae6e646
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 09a1a3dbdc6d61b0acdebb4458fbc043eebcb487f95455bdc913120b97420bee7a4301ae8d34632045b9eb754377ee514fb720cd8a1022b9e6c829bcf7c1fb1d
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/merit.rb
    CHANGED
    
    | 
         @@ -36,7 +36,8 @@ module Merit 
     | 
|
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
              # Define current_user_method
         
     | 
| 
       38 
38 
     | 
    
         
             
              def self.current_user_method
         
     | 
| 
       39 
     | 
    
         
            -
                @config.current_user_method || 
     | 
| 
      
 39 
     | 
    
         
            +
                @config.current_user_method ||
         
     | 
| 
      
 40 
     | 
    
         
            +
                  "current_#{@config.user_model_name.downcase}".to_sym
         
     | 
| 
       40 
41 
     | 
    
         
             
              end
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
43 
     | 
    
         
             
              def self.observers
         
     | 
| 
         @@ -36,9 +36,10 @@ module Merit 
     | 
|
| 
       36 
36 
     | 
    
         
             
                def target_object
         
     | 
| 
       37 
37 
     | 
    
         
             
                  target_obj = instance_variable_get(:"@#{controller_name.singularize}")
         
     | 
| 
       38 
38 
     | 
    
         
             
                  if target_obj.nil?
         
     | 
| 
       39 
     | 
    
         
            -
                    str = '[merit] No object found,  
     | 
| 
       40 
     | 
    
         
            -
                      "'@#{controller_name.singularize}' variable in "  
     | 
| 
       41 
     | 
    
         
            -
                      "'#{controller_path}_controller' 
     | 
| 
      
 39 
     | 
    
         
            +
                    str = '[merit] No object found, you might need a ' \
         
     | 
| 
      
 40 
     | 
    
         
            +
                      "'@#{controller_name.singularize}' variable in " \
         
     | 
| 
      
 41 
     | 
    
         
            +
                      "'#{controller_path}_controller' if no reputation is applied. " \
         
     | 
| 
      
 42 
     | 
    
         
            +
                      'If you are using `model_name` option in the rule this is ok.'
         
     | 
| 
       42 
43 
     | 
    
         
             
                    Rails.logger.warn str
         
     | 
| 
       43 
44 
     | 
    
         
             
                  end
         
     | 
| 
       44 
45 
     | 
    
         
             
                  target_obj
         
     | 
| 
         @@ -1,13 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Merit
         
     | 
| 
       2 
2 
     | 
    
         
             
              class ReputationChangeObserver
         
     | 
| 
       3 
3 
     | 
    
         
             
                def update(changed_data)
         
     | 
| 
       4 
     | 
    
         
            -
                  # TODO: sometimes we recieved true in changed_data[:merit_object]
         
     | 
| 
       5 
     | 
    
         
            -
                  # it should be nil or merit object with activity_logs relation
         
     | 
| 
       6 
4 
     | 
    
         
             
                  ActivityLog.create(
         
     | 
| 
       7 
5 
     | 
    
         
             
                    description:    changed_data[:description],
         
     | 
| 
       8 
     | 
    
         
            -
                    related_change: (changed_data 
     | 
| 
      
 6 
     | 
    
         
            +
                    related_change: related_change(changed_data),
         
     | 
| 
       9 
7 
     | 
    
         
             
                    action_id:      changed_data[:merit_action_id]
         
     | 
| 
       10 
8 
     | 
    
         
             
                  )
         
     | 
| 
       11 
9 
     | 
    
         
             
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                private
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def related_change(data)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  if data[:merit_object].respond_to?(:activity_logs)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    data[:merit_object]
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
       12 
18 
     | 
    
         
             
              end
         
     | 
| 
       13 
19 
     | 
    
         
             
            end
         
     | 
    
        data/merit.gemspec
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       5 
5 
     | 
    
         
             
              s.homepage    = "http://github.com/tute/merit"
         
     | 
| 
       6 
6 
     | 
    
         
             
              s.files       = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.license     = 'MIT'
         
     | 
| 
       8 
     | 
    
         
            -
              s.version     = '2.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version     = '2.1.1'
         
     | 
| 
       9 
9 
     | 
    
         
             
              s.authors     = ["Tute Costa"]
         
     | 
| 
       10 
10 
     | 
    
         
             
              s.email       = 'tutecosta@gmail.com'
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
         @@ -7,7 +7,9 @@ module Merit 
     | 
|
| 
       7 
7 
     | 
    
         
             
                include Merit::PointRulesMethods
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                def initialize
         
     | 
| 
       10 
     | 
    
         
            -
                  # Thanks for voting point
         
     | 
| 
      
 10 
     | 
    
         
            +
                  # Thanks for voting point. Tests that both rules are called when both
         
     | 
| 
      
 11 
     | 
    
         
            +
                  # apply.
         
     | 
| 
      
 12 
     | 
    
         
            +
                  score 1, on: 'comments#vote'
         
     | 
| 
       11 
13 
     | 
    
         
             
                  score 1, on: 'comments#vote'
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                  # All user's comments earn points
         
     | 
| 
         @@ -195,8 +195,10 @@ class NavigationTest < ActiveSupport::IntegrationCase 
     | 
|
| 
       195 
195 
     | 
    
         | 
| 
       196 
196 
     | 
    
         
             
                visit "/comments/#{Comment.last.id}/vote/4"
         
     | 
| 
       197 
197 
     | 
    
         
             
                user = User.first
         
     | 
| 
       198 
     | 
    
         
            -
                assert_equal  
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
      
 198 
     | 
    
         
            +
                assert_equal 47, user.points, 'Voting comments should grant 5 points for
         
     | 
| 
      
 199 
     | 
    
         
            +
                  voted, and 1 point for voting twice (repeated rule)'
         
     | 
| 
      
 200 
     | 
    
         
            +
                assert_equal 5, user.points(category: 'vote'), 'Voting comments should
         
     | 
| 
      
 201 
     | 
    
         
            +
                  grant 5 points for voted in vote category'
         
     | 
| 
       200 
202 
     | 
    
         | 
| 
       201 
203 
     | 
    
         
             
                visit '/comments/new'
         
     | 
| 
       202 
204 
     | 
    
         
             
                fill_in 'Name', with: 'Hi'
         
     | 
| 
         @@ -205,7 +207,8 @@ class NavigationTest < ActiveSupport::IntegrationCase 
     | 
|
| 
       205 
207 
     | 
    
         
             
                click_button('Create Comment')
         
     | 
| 
       206 
208 
     | 
    
         | 
| 
       207 
209 
     | 
    
         
             
                user = User.where(name: 'a').first
         
     | 
| 
       208 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 210 
     | 
    
         
            +
                assert_equal 51, user.points, 'Commenting should grant the integer in
         
     | 
| 
      
 211 
     | 
    
         
            +
                  comment points if comment is an integer'
         
     | 
| 
       209 
212 
     | 
    
         
             
              end
         
     | 
| 
       210 
213 
     | 
    
         | 
| 
       211 
214 
     | 
    
         
             
              test 'user workflow should grant levels at some times' do
         
     | 
| 
         @@ -246,14 +249,15 @@ class NavigationTest < ActiveSupport::IntegrationCase 
     | 
|
| 
       246 
249 
     | 
    
         
             
              end
         
     | 
| 
       247 
250 
     | 
    
         | 
| 
       248 
251 
     | 
    
         
             
              test 'assigning points to a group of records' do
         
     | 
| 
       249 
     | 
    
         
            -
                DummyObserver.any_instance.expects(:update).times  
     | 
| 
      
 252 
     | 
    
         
            +
                DummyObserver.any_instance.expects(:update).times 5
         
     | 
| 
       250 
253 
     | 
    
         
             
                commenter = User.create(name: 'commenter')
         
     | 
| 
       251 
254 
     | 
    
         
             
                comment_1 = commenter.comments.create(name: 'comment_1', comment: 'a')
         
     | 
| 
       252 
255 
     | 
    
         
             
                comment_2 = commenter.comments.create(name: 'comment_2', comment: 'b')
         
     | 
| 
       253 
256 
     | 
    
         | 
| 
       254 
257 
     | 
    
         
             
                visit comments_path
         
     | 
| 
       255 
258 
     | 
    
         
             
                # Thanks for voting point, to voted user and it's comments
         
     | 
| 
       256 
     | 
    
         
            -
                 
     | 
| 
      
 259 
     | 
    
         
            +
                # (repeated rule, called twice)
         
     | 
| 
      
 260 
     | 
    
         
            +
                assert_difference('Merit::ActivityLog.count', 5) do
         
     | 
| 
       257 
261 
     | 
    
         
             
                  within "tr#c_#{comment_2.id}" do
         
     | 
| 
       258 
262 
     | 
    
         
             
                    click_link '1'
         
     | 
| 
       259 
263 
     | 
    
         
             
                  end
         
     | 
    
        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.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Tute Costa
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-04-12 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: ambry
         
     | 
| 
         @@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       288 
288 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       289 
289 
     | 
    
         
             
            requirements: []
         
     | 
| 
       290 
290 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       291 
     | 
    
         
            -
            rubygems_version: 2.2. 
     | 
| 
      
 291 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       292 
292 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       293 
293 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       294 
294 
     | 
    
         
             
            summary: General reputation Rails engine.
         
     |