File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -638,7 +638,9 @@ def is_filter_relationship?(filter)
638638
639639 def verify_filter ( filter , raw , context = nil )
640640 filter_values = [ ]
641- filter_values += CSV . parse_line ( raw ) unless raw . nil? || raw . empty?
641+ if raw . present?
642+ filter_values += raw . is_a? ( String ) ? CSV . parse_line ( raw ) : [ raw ]
643+ end
642644
643645 strategy = _allowed_filters . fetch ( filter , Hash . new ) [ :verify ]
644646
Original file line number Diff line number Diff line change @@ -103,6 +103,13 @@ def test_index_filter_by_title
103103 assert_equal 1 , json_response [ 'data' ] . size
104104 end
105105
106+ def test_index_filter_with_hash_values
107+ get :index , { filter : { search : { title : 'New post' } } }
108+ assert_response :success
109+ assert json_response [ 'data' ] . is_a? ( Array )
110+ assert_equal 1 , json_response [ 'data' ] . size
111+ end
112+
106113 def test_index_filter_by_ids
107114 get :index , { filter : { ids : '1,2' } }
108115 assert_response :success
Original file line number Diff line number Diff line change @@ -945,6 +945,14 @@ def title=(title)
945945 records . where ( 'id IN (?)' , value )
946946 }
947947
948+ filter :search ,
949+ verify : -> ( values , context ) {
950+ values . all? { |v | v . is_a? ( Hash ) } && values
951+ } ,
952+ apply : -> ( records , values , _options ) {
953+ records . where ( title : values . first [ 'title' ] )
954+ }
955+
948956 def self . updatable_fields ( context )
949957 super ( context ) - [ :author , :subject ]
950958 end
You can’t perform that action at this time.
0 commit comments