Skip to content

Commit f1a3187

Browse files
authored
fix: array resource actions query (#3829)
* fix: array resource actions query * test * lint
1 parent 15e2637 commit f1a3187

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

lib/avo/resources/array_resource.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def find_record(id, query: nil, params: nil)
3737

3838
return super(id, query: fetched_records, params:) if is_active_record_relation?(fetched_records)
3939

40-
fetched_records.find { |i| i.id.to_s == id.to_s }
40+
# Id is Array when find record is called from actions controller
41+
if id.is_a?(Array)
42+
fetched_records.select { |record| id.map(&:to_s).include?(record.id.to_s) }
43+
else
44+
fetched_records.find { |record| record.id.to_s == id.to_s }
45+
end
4146
end
4247

4348
def fetch_records(array_of_records = nil)

spec/dummy/app/avo/resources/movie.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,8 @@ def fields
283283

284284
field :attendees, as: :array
285285
end
286+
287+
def actions
288+
action Avo::Actions::Test::Query
289+
end
286290
end

spec/system/avo/array_resource_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,26 @@
5050
all('a[data-control="show"]').last.click
5151
expect(page).to have_text("#{User.first(6).last.name} rendered as array resource")
5252
end
53+
54+
it "can access query on actions" do
55+
visit avo.resources_movies_path
56+
57+
check_select_all
58+
click_on "Select all matching"
59+
60+
movies_count = 50
61+
62+
open_panel_action(action_name: "Test query access ")
63+
64+
expect(page).to have_text("message #{movies_count} selected")
65+
expect(page).to have_field("fields_selected", with: "#{movies_count} selected def fields")
66+
expect(page).to have_text("cancel_button_label #{movies_count} selected")
67+
expect(page).to have_text("confirm_button_label #{movies_count} selected")
68+
expect(page).to have_text("Test query access #{movies_count}")
69+
70+
run_action
71+
72+
expect(page).to have_text("succeed #{movies_count} selected")
73+
end
5374
end
5475
end

0 commit comments

Comments
 (0)