#NEWLINE# def test_sync_syncs_intermediate_table_with_given_list( self ) : #NEWLINE# #INDENT# for list_ in [ [ 2 , 3 , 4 ] , [ '2' , '3' , '4' ] ] : #NEWLINE# #INDENT# flexmock ( BelongsToMany ) #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# 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 ( mock_query_builder ) #NEWLINE# query . should_receive ( 'lists' ) . once ( ) . with_args ( 'role_id' ) . and_return ( [ 1 , list_ [ 0 ] , list_ [ 1 ] ] ) #NEWLINE# relation . should_receive ( 'attach' ) . once ( ) . with_args ( list_ [ 2 ] , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , False ) #NEWLINE# relation . should_receive ( 'detach' ) . once ( ) . with_args ( [ 1 ] ) #NEWLINE# relation . get_related ( ) . should_receive ( 'touches' ) . and_return ( False ) #NEWLINE# relation . get_parent ( ) . should_receive ( 'touches' ) . and_return ( False ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'attached' : [ list_ [ 2 ] ] , #NEWLINE# 'detached' : [ 1 ] , #NEWLINE# 'updated' : [ ] , #NEWLINE# #UNINDENT# } , relation . sync ( list_ ) )