Sha256: ad90f3f450a678372c1bb3f058d883006f8c9363bf1dfcd44d298cc53cdb3620
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
require 'models/rights_and_roles' module HasManyThroughMethods def setup CreateRightsAndRoles.up end def teardown CreateRightsAndRoles.down end def test_has_many_through admin_role = Role.create! :name => "Administrator", :description => "super user - access to right and role management" assert_equal(0, admin_role.rights.sum(:hours)) role_rights = Right.create :name => "Administrator - Full Access To Roles", :actions => "*", :controller_name => "Admin::RolesController", :hours => 0 right_rights = Right.create :name => "Administrator - Full Access To Rights", :actions => "*", :controller_name => "Admin::RightsController", :hours => 1.5 admin_role.rights << role_rights admin_role.rights << right_rights admin_role.save! assert_equal(1.5, admin_role.rights.sum(:hours)) rights_only_role = Role.create! :name => "Rights Manager", :description => "access to rights management" rights_only_role.rights << right_rights rights_only_role.save! rights_only_role.reload assert admin_role.has_right?(right_rights) assert rights_only_role.has_right?(right_rights) assert admin_role.reload.has_right?(role_rights) assert ! rights_only_role.has_right?(role_rights) end def test_has_many_select_rows_with_relation role = Role.create! :name => "main", :description => "main role" Role.create! :name => "user", :description => "user role" Right.create! :name => "r0", :hours => 0 r1 = Right.create! :name => "r1", :hours => 1 r2 = Right.create! :name => "r2", :hours => 2 Right.create! :name => "r3", :hours => 3 role.permission_groups.create! :right => r1.reload role.permission_groups.create! :right => r2.reload groups = role.reload.permission_groups.select('right_id') assert_equal [ [ r1.id ], [ r2.id ] ], role.connection.select_rows(groups) end if Test::Unit::TestCase.ar_version('3.0') end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-jdbc-adapter-1.3.0.beta1 | test/has_many_through.rb |