Skip to content

Commit

Permalink
fix: attach when using *_fields API (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Feb 7, 2024
1 parent 26eae09 commit 09ff10a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/avo/associations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<%
url = Avo::Services::URIService.parse(avo.root_url.to_s)
.append_paths('resources', params[:resource_name], params[:id], params[:related_name])
.append_query({view: @resource&.view&.to_s})
.to_s
%>
<%= form_with scope: 'fields',
Expand Down
18 changes: 18 additions & 0 deletions spec/features/avo/fields_methods_for_views_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.feature "Fields methods for each view", type: :feature do
let!(:links) { create_list :course_link, 3 }
let!(:attach_link) { create :course_link }
let!(:course) { create :course, links: links }

context "with `fields` declaration" do
Expand Down Expand Up @@ -168,5 +169,22 @@ def form_fields
find("tr[data-resource-id='#{course.links.first.to_param}'] [data-control='detach']").click
}.to change(course.links, :count).by(-1)
end

it "attach works using show and index fields api" do
visit "#{Avo::Engine.routes.url_helpers.resources_course_path(course)}/links?turbo_frame=has_many_field_links&view=show"

click_on "Attach link"

expect(page).to have_text "Choose course link"

select attach_link.link, from: "fields_related_id"

expect {
within '[aria-modal="true"]' do
click_on "Attach"
end
wait_for_loaded
}.to change(course.links, :count).by 1
end
end
end

0 comments on commit 09ff10a

Please sign in to comment.