File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 9090
9191 is_expected . to have_selector ( 'select#team_comment_ids' )
9292 end
93+
94+ context 'with records in different models share the same id' , js : true do
95+ let! ( :players ) { [ FactoryBot . create ( :player , id : team . id , name : 'Jackie Robinson' ) ] }
96+
97+ it 'clears the selected id on type change' , js : true do
98+ visit edit_path ( model_name : 'comment' , id : comment . id )
99+ select 'Player' , from : 'comment[commentable_type]'
100+ click_button 'Save'
101+ is_expected . to have_content 'Comment successfully updated'
102+ expect ( comment . reload . commentable ) . to eq nil
103+ end
104+
105+ it 'updates correctly' , js : true do
106+ visit edit_path ( model_name : 'comment' , id : comment . id )
107+ select 'Player' , from : 'comment[commentable_type]'
108+ find ( 'input.ra-filtering-select-input' ) . set ( 'Rob' )
109+ page . execute_script ( "document.querySelector('input.ra-filtering-select-input').dispatchEvent(new KeyboardEvent('keydown'))" )
110+ expect ( page ) . to have_selector ( 'ul.ui-autocomplete li.ui-menu-item a' )
111+ page . execute_script %{[...document.querySelectorAll('ul.ui-autocomplete li.ui-menu-item')].find(e => e.innerText.includes("Jackie Robinson")).click()}
112+ click_button 'Save'
113+ is_expected . to have_content 'Comment successfully updated'
114+ expect ( comment . reload . commentable ) . to eq players [ 0 ]
115+ end
116+ end
93117 end
94118
95119 context 'on show' do
Original file line number Diff line number Diff line change @@ -297,6 +297,7 @@ import I18n from "./i18n";
297297 destroy : function ( ) {
298298 this . input . remove ( ) ;
299299 this . button . remove ( ) ;
300+ this . element . html ( $ ( '<option value="" selected="selected"></option>' ) ) ;
300301 this . element . show ( ) ;
301302 this . filtering_select . remove ( ) ;
302303 $ . Widget . prototype . destroy . call ( this ) ;
Original file line number Diff line number Diff line change @@ -258,7 +258,6 @@ import I18n from "./i18n";
258258 "options"
259259 ) ;
260260 object_select . data ( "options" , selected_data ) ;
261- object_select . val ( "" ) ;
262261 object_select . filteringSelect ( "destroy" ) ;
263262 object_select . filteringSelect ( selected_data ) ;
264263 } ) ;
You can’t perform that action at this time.
0 commit comments