indulgence 0.0.4 → 0.0.5
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/README.rdoc +1 -5
 - data/lib/indulgence/ability.rb +6 -2
 - data/lib/indulgence/version.rb +3 -1
 - data/test/db/test.sqlite3.db +0 -0
 - data/test/lib/role.rb +4 -0
 - data/test/lib/role_permission.rb +16 -0
 - data/test/units/role_permission_test.rb +28 -0
 - metadata +5 -1
 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -188,10 +188,6 @@ This will create an Ability object with the following methods: 
     | 
|
| 
       188 
188 
     | 
    
         
             
            [compare_single] Used by :indulge?
         
     | 
| 
       189 
189 
     | 
    
         
             
            [filter_many]    Used by :indulgence 
         
     | 
| 
       190 
190 
     | 
    
         | 
| 
       191 
     | 
    
         
            -
            Alternatively, you can achieve the same result by defining lambdas for the
         
     | 
| 
       192 
     | 
    
         
            -
            ability methods :compare_single and :filter_many. If you use lambdas, you must
         
     | 
| 
       193 
     | 
    
         
            -
            also define a name.
         
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
191 
     | 
    
         
             
            Alternatively you can define the ability like this:
         
     | 
| 
       196 
192 
     | 
    
         | 
| 
       197 
193 
     | 
    
         
             
              def things_they_wrote
         
     | 
| 
         @@ -199,7 +195,7 @@ Alternatively you can define the ability like this: 
     | 
|
| 
       199 
195 
     | 
    
         
             
              end
         
     | 
| 
       200 
196 
     | 
    
         | 
| 
       201 
197 
     | 
    
         
             
            This will use :author to define attributes of an ability object. :author could
         
     | 
| 
       202 
     | 
    
         
            -
            be an association or an attribute that  
     | 
| 
      
 198 
     | 
    
         
            +
            be an association or an attribute that returns either the entity or the entity.id.
         
     | 
| 
       203 
199 
     | 
    
         | 
| 
       204 
200 
     | 
    
         
             
            So this also works:
         
     | 
| 
       205 
201 
     | 
    
         | 
    
        data/lib/indulgence/ability.rb
    CHANGED
    
    | 
         @@ -30,8 +30,12 @@ module Indulgence 
     | 
|
| 
       30 
30 
     | 
    
         
             
                def compare_single(thing, entity)
         
     | 
| 
       31 
31 
     | 
    
         
             
                  return @compare_single.call thing, entity if @compare_single
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                  identifier = thing.send(relationship) 
     | 
| 
       34 
     | 
    
         
            -
                  identifier 
     | 
| 
      
 33 
     | 
    
         
            +
                  identifier = thing.send(relationship)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  if identifier.kind_of?(Array)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    identifier.include? entity
         
     | 
| 
      
 36 
     | 
    
         
            +
                  else 
         
     | 
| 
      
 37 
     | 
    
         
            +
                    identifier == entity.id || identifier == entity   
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
       35 
39 
     | 
    
         
             
                end
         
     | 
| 
       36 
40 
     | 
    
         | 
| 
       37 
41 
     | 
    
         
             
                def filter_many(things, entity)
         
     | 
    
        data/lib/indulgence/version.rb
    CHANGED
    
    | 
         @@ -1,10 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Indulgence
         
     | 
| 
       2 
     | 
    
         
            -
              VERSION = "0.0. 
     | 
| 
      
 2 
     | 
    
         
            +
              VERSION = "0.0.5"
         
     | 
| 
       3 
3 
     | 
    
         
             
            end
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            # History
         
     | 
| 
       6 
6 
     | 
    
         
             
            # =======
         
     | 
| 
       7 
7 
     | 
    
         
             
            # 
         
     | 
| 
      
 8 
     | 
    
         
            +
            # 0.0.5   Allows simplified ability definition to be used with has_many
         
     | 
| 
      
 9 
     | 
    
         
            +
            # 
         
     | 
| 
       8 
10 
     | 
    
         
             
            # 0.0.4   Simplifies defining abilities
         
     | 
| 
       9 
11 
     | 
    
         
             
            # 
         
     | 
| 
       10 
12 
     | 
    
         
             
            #         Allows and ability to be defined by passing in the name of the 
         
     | 
    
        data/test/db/test.sqlite3.db
    CHANGED
    
    | 
         Binary file 
     | 
    
        data/test/lib/role.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'user'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'role'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'role_permission'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class RolePermissionTest < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 8 
     | 
    
         
            +
                @role = Role.create(:name => 'mortal')
         
     | 
| 
      
 9 
     | 
    
         
            +
                @user = User.create(:name => 'Trevor', :role_id => @role.id)
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
              
         
     | 
| 
      
 12 
     | 
    
         
            +
              def test_indulge_with_has_many
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert_equal(true, @role.indulge?(@user, :read))
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_equal(false, @role.indulge?(@user, :delete))
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              def test_indulgence_with_has_many
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal([@role], Role.indulgence(@user, :read))
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_raise ActiveRecord::RecordNotFound do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Role.indulgence(@user, :delete)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
              
         
     | 
| 
      
 24 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 25 
     | 
    
         
            +
                User.delete_all
         
     | 
| 
      
 26 
     | 
    
         
            +
                Role.delete_all
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: indulgence
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -82,12 +82,14 @@ files: 
     | 
|
| 
       82 
82 
     | 
    
         
             
            - test/units/indulgence/ability_tests/method_only.rb
         
     | 
| 
       83 
83 
     | 
    
         
             
            - test/units/indulgence/ability_tests/with_lambdas.rb
         
     | 
| 
       84 
84 
     | 
    
         
             
            - test/units/user_test.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - test/units/role_permission_test.rb
         
     | 
| 
       85 
86 
     | 
    
         
             
            - test/units/thing_permission_test.rb
         
     | 
| 
       86 
87 
     | 
    
         
             
            - test/units/thing_test.rb
         
     | 
| 
       87 
88 
     | 
    
         
             
            - test/lib/role.rb
         
     | 
| 
       88 
89 
     | 
    
         
             
            - test/lib/user.rb
         
     | 
| 
       89 
90 
     | 
    
         
             
            - test/lib/thing.rb
         
     | 
| 
       90 
91 
     | 
    
         
             
            - test/lib/thing_permission.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - test/lib/role_permission.rb
         
     | 
| 
       91 
93 
     | 
    
         
             
            - test/db/migrate/20130408103015_create_roles.rb
         
     | 
| 
       92 
94 
     | 
    
         
             
            - test/db/migrate/20130408085511_create_users.rb
         
     | 
| 
       93 
95 
     | 
    
         
             
            - test/db/migrate/20130408132217_create_things.rb
         
     | 
| 
         @@ -126,12 +128,14 @@ test_files: 
     | 
|
| 
       126 
128 
     | 
    
         
             
            - test/units/indulgence/ability_tests/method_only.rb
         
     | 
| 
       127 
129 
     | 
    
         
             
            - test/units/indulgence/ability_tests/with_lambdas.rb
         
     | 
| 
       128 
130 
     | 
    
         
             
            - test/units/user_test.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - test/units/role_permission_test.rb
         
     | 
| 
       129 
132 
     | 
    
         
             
            - test/units/thing_permission_test.rb
         
     | 
| 
       130 
133 
     | 
    
         
             
            - test/units/thing_test.rb
         
     | 
| 
       131 
134 
     | 
    
         
             
            - test/lib/role.rb
         
     | 
| 
       132 
135 
     | 
    
         
             
            - test/lib/user.rb
         
     | 
| 
       133 
136 
     | 
    
         
             
            - test/lib/thing.rb
         
     | 
| 
       134 
137 
     | 
    
         
             
            - test/lib/thing_permission.rb
         
     | 
| 
      
 138 
     | 
    
         
            +
            - test/lib/role_permission.rb
         
     | 
| 
       135 
139 
     | 
    
         
             
            - test/db/migrate/20130408103015_create_roles.rb
         
     | 
| 
       136 
140 
     | 
    
         
             
            - test/db/migrate/20130408085511_create_users.rb
         
     | 
| 
       137 
141 
     | 
    
         
             
            - test/db/migrate/20130408132217_create_things.rb
         
     |