#NEWLINE# def test_detach_clears_all_records_when_no_ids( self ) : #NEWLINE# #INDENT# flexmock ( BelongsToMany , touch_if_touching = ( lambda : True ) ) #NEWLINE# relation = self . _get_relation ( ) #NEWLINE# query = flexmock ( ) #NEWLINE# query . should_receive ( 'from_' ) . once ( ) . with_args ( 'user_role' ) . and_return ( query ) #NEWLINE# query . should_receive ( 'where' ) . once ( ) . with_args ( 'user_id' , 1 ) . and_return ( query ) #NEWLINE# query . should_receive ( 'where_in' ) . never ( ) #NEWLINE# query . should_receive ( 'delete' ) . once ( ) . and_return ( True ) #NEWLINE# mock_query_builder = flexmock ( ) #NEWLINE# relation . get_query ( ) . should_receive ( 'get_query' ) . and_return ( mock_query_builder ) #NEWLINE# mock_query_builder . should_receive ( 'new_query' ) . once ( ) . and_return ( query ) #NEWLINE# relation . should_receive ( 'touch_if_touching' ) . once ( ) #NEWLINE# self . assertTrue ( relation . detach ( ) )