@@ -11,16 +11,15 @@ def teardown
1111 end
1212
1313 def test_has_many_through
14- admin_role = Role . create :name => "Administrator" ,
15- :description => "System defined super user - access to right and role management."
16- admin_role . save!
14+ admin_role = Role . create! :name => "Administrator" ,
15+ :description => "super user - access to right and role management"
1716
1817 assert_equal ( 0 , admin_role . rights . sum ( :hours ) )
1918
20- role_rights = Right . create :name => "Administrator - Full Access To Roles" ,
21- :actions => "*" , :controller_name => "Admin::RolesController" , :hours => 0
22- right_rights = Right . create :name => "Administrator - Full Access To Rights" ,
23- :actions => "*" , :controller_name => "Admin::RightsController" , :hours => 1.5
19+ role_rights = Right . create :name => "Administrator - Full Access To Roles" ,
20+ :actions => "*" , :controller_name => "Admin::RolesController" , :hours => 0
21+ right_rights = Right . create :name => "Administrator - Full Access To Rights" ,
22+ :actions => "*" , :controller_name => "Admin::RightsController" , :hours => 1.5
2423
2524 admin_role . rights << role_rights
2625 admin_role . rights << right_rights
@@ -40,4 +39,20 @@ def test_has_many_through
4039 assert ! rights_only_role . has_right? ( role_rights )
4140 end
4241
42+ def test_has_many_select_rows_with_relation
43+ role = Role . create! :name => "main" , :description => "main role"
44+ Role . create! :name => "user" , :description => "user role"
45+
46+ Right . create! :name => "r0" , :hours => 0
47+ r1 = Right . create! :name => "r1" , :hours => 1
48+ r2 = Right . create! :name => "r2" , :hours => 2
49+ Right . create! :name => "r3" , :hours => 3
50+
51+ role . permission_groups . create! :right => r1 . reload
52+ role . permission_groups . create! :right => r2 . reload
53+
54+ groups = role . reload . permission_groups . select ( 'right_id' )
55+ assert_equal [ [ r1 . id ] , [ r2 . id ] ] , role . connection . select_rows ( groups )
56+ end if Test ::Unit ::TestCase . ar_version ( '3.0' )
57+
4358end
0 commit comments