@@ -1864,37 +1864,42 @@ def test_authorization_permit_association_proxy
18641864 TestModel . delete_all
18651865 end
18661866
1867- # def test_authorization_permit_nested_association_proxy
1868- # reader = Authorization::Reader::DSLReader.new
1869- # reader.parse %{
1870- # authorization do
1871- # role :test_role do
1872- # has_permission_on :branches, :to => :read do
1873- # if_attribute :test_model => { :test_attrs => {:attr => 1 } }
1874- # end
1875- # end
1876- # end
1877- # }
1878- # engine = Authorization::Engine.instance(reader)
1879-
1880- # test_model = TestModel.create!
1881- # test_model.test_attrs.create!(:attr => 0)
1882- # test_attr = test_model.test_attrs.create!(:attr => 1)
1883- # test_model.test_attrs.create!(:attr => 3)
1884- # test_branch = Branch.create!(:test_model => test_model)
1885-
1886- # test_model_2 = TestModel.create!
1887- # test_attr_2 = test_model_2.test_attrs.create!(:attr => 2)
1888- # test_branch_2 = Branch.create!(:test_model => test_model_2)
1889-
1890- # assert engine.permit?(:read, :object => test_branch,
1891- # :user => MockUser.new(:test_role))
1892- # assert !engine.permit?(:read, :object => test_branch_2,
1893- # :user => MockUser.new(:test_role))
1894- # TestModel.delete_all
1895- # Branch.delete_all
1896- # TestAttr.delete_all
1897- # end
1867+ def test_authorization_permit_nested_association_proxy
1868+ reader = Authorization ::Reader ::DSLReader . new
1869+ reader . parse %{
1870+ authorization do
1871+ role :test_role do
1872+ has_permission_on :branches, :to => :read do
1873+ if_attribute :test_model => { :test_attrs => {:attr => 1 } }
1874+ end
1875+ end
1876+ end
1877+ }
1878+ engine = Authorization ::Engine . instance ( reader )
1879+
1880+ test_model = TestModel . create!
1881+ test_model . test_attrs . create! ( :attr => 0 )
1882+ test_attr = test_model . test_attrs . create! ( :attr => 1 )
1883+ test_model . test_attrs . create! ( :attr => 3 )
1884+ test_branch = Branch . create! ( :test_model => test_model )
1885+
1886+ test_model_2 = TestModel . create!
1887+ test_attr_2 = test_model_2 . test_attrs . create! ( :attr => 2 )
1888+ test_branch_2 = Branch . create! ( :test_model => test_model_2 )
1889+
1890+ test_model_3 = TestModel . create!
1891+ test_branch_3 = Branch . create! ( :test_model => test_model_3 )
1892+
1893+ assert engine . permit? ( :read , :object => test_branch ,
1894+ :user => MockUser . new ( :test_role ) )
1895+ assert !engine . permit? ( :read , :object => test_branch_2 ,
1896+ :user => MockUser . new ( :test_role ) )
1897+ assert !engine . permit? ( :read , :object => test_branch_3 ,
1898+ :user => MockUser . new ( :test_role ) )
1899+ TestModel . delete_all
1900+ Branch . delete_all
1901+ TestAttr . delete_all
1902+ end
18981903
18991904 def test_multiple_roles_with_has_many_through
19001905 reader = Authorization ::Reader ::DSLReader . new
0 commit comments