diff --git a/config/routes.rb b/config/routes.rb index e5480b211..d4a9912d6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,11 +35,11 @@ draw(:dynamic_routes) # Associations - get "/:resource_name/:id/:related_name/new", to: "associations#new", as: "associations_new" - get "/:resource_name/:id/:related_name/", to: "associations#index", as: "associations_index" - get "/:resource_name/:id/:related_name/:related_id", to: "associations#show", as: "associations_show" - post "/:resource_name/:id/:related_name", to: "associations#create", as: "associations_create" - delete "/:resource_name/:id/:related_name/:related_id", to: "associations#destroy", as: "associations_destroy" + get "/:resource_name/:id/associations/:related_name/new", to: "associations#new", as: "associations_new" + get "/:resource_name/:id/associations/:related_name/", to: "associations#index", as: "associations_index" + get "/:resource_name/:id/associations/:related_name/:related_id", to: "associations#show", as: "associations_show" + post "/:resource_name/:id/associations/:related_name", to: "associations#create", as: "associations_create" + delete "/:resource_name/:id/associations/:related_name/:related_id", to: "associations#destroy", as: "associations_destroy" end scope "/avo_private", as: "avo_private" do diff --git a/lib/avo/fields/has_base_field.rb b/lib/avo/fields/has_base_field.rb index 2e32c0ba1..2c8c9460c 100644 --- a/lib/avo/fields/has_base_field.rb +++ b/lib/avo/fields/has_base_field.rb @@ -42,7 +42,7 @@ def turbo_frame def frame_url(add_turbo_frame: true) Avo::Services::URIService.parse(field_resource.record_path) - .append_path(id.to_s) + .append_paths("associations", id.to_s) .append_query(query_params(add_turbo_frame:)) .to_s end diff --git a/lib/avo/fields/has_one_field.rb b/lib/avo/fields/has_one_field.rb index 5b80072b1..be881e914 100644 --- a/lib/avo/fields/has_one_field.rb +++ b/lib/avo/fields/has_one_field.rb @@ -19,7 +19,7 @@ def label def frame_url Avo::Services::URIService.parse(field_resource.record_path) - .append_paths(id, value.to_param) + .append_paths("associations", id, value.to_param) .append_query(query_params) .to_s end diff --git a/spec/features/avo/belongs_to_spec.rb b/spec/features/avo/belongs_to_spec.rb index f22d2e65a..f9fbe35a8 100644 --- a/spec/features/avo/belongs_to_spec.rb +++ b/spec/features/avo/belongs_to_spec.rb @@ -146,7 +146,7 @@ let!(:comment) { create :comment, body: "a comment", user: user } it "hides the User column" do - visit "/admin/resources/users/#{user.id}/comments?turbo_frame=has_many_field_show_comments" + visit "/admin/resources/users/#{user.id}/associations/comments?turbo_frame=has_many_field_show_comments" expect(find("thead")).to have_text "Id" expect(find("thead")).to have_text "Tiny name" @@ -165,7 +165,7 @@ let!(:comment) { create :comment, body: "a comment", user: user, commentable: project } it "hides the Commentable column" do - visit "/admin/resources/projects/#{project.id}/comments?turbo_frame=has_many_field_show_comments" + visit "/admin/resources/projects/#{project.id}/associations/comments?turbo_frame=has_many_field_show_comments" expect(find("thead")).to have_text "Id" expect(find("thead")).to have_text "Tiny name" @@ -185,7 +185,7 @@ let!(:review) { create :review, body: "a review", user: user, reviewable: team } it "hides the Reviewable column" do - visit "/admin/resources/teams/#{team.id}/reviews?turbo_frame=has_many_field_show_reviews" + visit "/admin/resources/teams/#{team.id}/associations/reviews?turbo_frame=has_many_field_show_reviews" expect(find("thead")).to have_text "Id" expect(find("thead")).to have_text "Excerpt" diff --git a/spec/features/avo/breadcrumbs_spec.rb b/spec/features/avo/breadcrumbs_spec.rb index dec769a94..6d5e69a7f 100644 --- a/spec/features/avo/breadcrumbs_spec.rb +++ b/spec/features/avo/breadcrumbs_spec.rb @@ -50,7 +50,7 @@ context "when HTML request" do it "displays breadcrumbs" do - url = "/admin/resources/users/#{user.slug}/teams?view=show" + url = "/admin/resources/users/#{user.slug}/associations/teams?view=show" visit url expect(page).to have_selector ".breadcrumbs" @@ -64,7 +64,7 @@ end it "displays breadcrumbs" do - url = "/admin/resources/teams/#{team.id}/team_members?view=show" + url = "/admin/resources/teams/#{team.id}/associations/team_members?view=show" visit url expect(page).to have_selector ".breadcrumbs" @@ -78,7 +78,7 @@ end it "displays a back button" do - url = "/admin/resources/teams/#{team.id}/team_members?view=show" + url = "/admin/resources/teams/#{team.id}/associations/team_members?view=show" visit url expect(page).to have_selector "div[data-target='panel-tools'] a[href='/admin/resources/teams/#{team.id}']", text: "Go back" @@ -87,7 +87,7 @@ context "when Turbo request" do before(:example) do - url = "/admin/resources/teams/#{team.id}/team_members?view=show" + url = "/admin/resources/teams/#{team.id}/associations/team_members?view=show" page.driver.browser.header("Turbo-Frame", true) visit url end diff --git a/spec/features/avo/create_has_one_spec.rb b/spec/features/avo/create_has_one_spec.rb index 4fcfe0c47..21b9b7ef1 100644 --- a/spec/features/avo/create_has_one_spec.rb +++ b/spec/features/avo/create_has_one_spec.rb @@ -24,7 +24,7 @@ expect(page).to have_text "Post was successfully created." expect(page).to have_current_path("/admin/resources/users/#{user.slug}") - visit "/admin/resources/users/#{user.id}/post/#{user.post.slug}?turbo_frame=has_one_field_show_post" + visit "/admin/resources/users/#{user.id}/associations/post/#{user.post.slug}?turbo_frame=has_one_field_show_post" expect(page).to have_text "Detach main post" expect(page).to have_text "Main post name" diff --git a/spec/features/avo/discreet_pagination_spec.rb b/spec/features/avo/discreet_pagination_spec.rb index 514b64a26..9d98e1451 100644 --- a/spec/features/avo/discreet_pagination_spec.rb +++ b/spec/features/avo/discreet_pagination_spec.rb @@ -12,20 +12,20 @@ describe "with one page" do it "should not have pagination" do - visit "/admin/resources/courses/#{course_with_one_page_of_links.id}/links?turbo_frame=has_many_field_show_links&view=show" + visit "/admin/resources/courses/#{course_with_one_page_of_links.id}/associations/links?turbo_frame=has_many_field_show_links&view=show" wait_for_loaded - expect(current_path).to eql "/admin/resources/courses/#{course_with_one_page_of_links.id}/links" + expect(current_path).to eql "/admin/resources/courses/#{course_with_one_page_of_links.id}/associations/links" expect(page).not_to have_text "Displaying #{per_page} items" end end describe "with two pages" do it "should have pagination" do - visit "/admin/resources/courses/#{course_with_two_pages_of_links.id}/links?turbo_frame=has_many_field_show_links&view=show" + visit "/admin/resources/courses/#{course_with_two_pages_of_links.id}/associations/links?turbo_frame=has_many_field_show_links&view=show" wait_for_loaded - expect(current_path).to eql "/admin/resources/courses/#{course_with_two_pages_of_links.id}/links" + expect(current_path).to eql "/admin/resources/courses/#{course_with_two_pages_of_links.id}/associations/links" expect(page).to have_text "Displaying items 1-#{per_page} of #{per_page * 2} in total" end end @@ -39,20 +39,20 @@ describe "with one page" do it "should have pagination" do - visit "/admin/resources/people/#{person_with_one_page_of_spouses.id}/spouses?turbo_frame=has_many_field_show_spouses" + visit "/admin/resources/people/#{person_with_one_page_of_spouses.id}/associations/spouses?turbo_frame=has_many_field_show_spouses" wait_for_loaded - expect(current_path).to eql "/admin/resources/people/#{person_with_one_page_of_spouses.id}/spouses" + expect(current_path).to eql "/admin/resources/people/#{person_with_one_page_of_spouses.id}/associations/spouses" expect(page).to have_text "Displaying #{per_page} items" end end describe "with two pages" do it "should have pagination" do - visit "/admin/resources/people/#{person_with_two_pages_of_spouses.id}/spouses?turbo_frame=has_many_field_show_spouses" + visit "/admin/resources/people/#{person_with_two_pages_of_spouses.id}/associations/spouses?turbo_frame=has_many_field_show_spouses" wait_for_loaded - expect(current_path).to eql "/admin/resources/people/#{person_with_two_pages_of_spouses.id}/spouses" + expect(current_path).to eql "/admin/resources/people/#{person_with_two_pages_of_spouses.id}/associations/spouses" expect(page).to have_text "Displaying items 1-#{per_page} of #{per_page * 2} in total" end end diff --git a/spec/features/avo/has_many_attach_scope_spec.rb b/spec/features/avo/has_many_attach_scope_spec.rb index 9780cc4fd..4dfa34629 100644 --- a/spec/features/avo/has_many_attach_scope_spec.rb +++ b/spec/features/avo/has_many_attach_scope_spec.rb @@ -6,7 +6,7 @@ let!(:post_2) { create :post} it "filters out the current selection" do - visit "/admin/resources/users/#{user.id}/posts/new" + visit "/admin/resources/users/#{user.id}/associations/posts/new" expect(page).to have_select "fields[related_id]", options: ["Choose an option", post_2.name] end diff --git a/spec/features/avo/has_many_field_spec.rb b/spec/features/avo/has_many_field_spec.rb index 1a04ff3f0..ebd8e90a4 100644 --- a/spec/features/avo/has_many_field_spec.rb +++ b/spec/features/avo/has_many_field_spec.rb @@ -10,7 +10,7 @@ context "show" do # Test the frame directly - let(:url) { "/admin/resources/users/#{user.slug}/posts?turbo_frame=has_many_field_posts&view_type=table" } + let(:url) { "/admin/resources/users/#{user.slug}/associations/posts?turbo_frame=has_many_field_posts&view_type=table" } describe "without a related post" do it { is_expected.to have_text "No related record found" } @@ -48,13 +48,13 @@ visit url # grid view button - expect(page).to have_selector "[data-control='view-type-toggle-grid'][href='/admin/resources/users/#{user.slug}/posts?turbo_frame=has_many_field_posts&view_type=grid']" + expect(page).to have_selector "[data-control='view-type-toggle-grid'][href='/admin/resources/users/#{user.slug}/associations/posts?turbo_frame=has_many_field_posts&view_type=grid']" # create new button expect(page).to have_link("Create new post", href: "/admin/resources/posts/new?via_record_id=#{user.slug}&via_relation=user&via_relation_class=User&via_resource_class=Avo%3A%3AResources%3A%3AUser") # attach button - expect(page).to have_link("Attach post", href: /\/admin\/resources\/users\/#{user.slug}\/posts\/new/) + expect(page).to have_link("Attach post", href: /\/admin\/resources\/users\/#{user.slug}\/associations\/posts\/new/) ## Table Rows # show link @@ -69,7 +69,7 @@ expect(page).to have_selector("[data-component='resources-index'] a[data-control='edit'][data-resource-id='#{post.to_param}'][href='#{edit_path}']") # detach form - form = "form[action='/admin/resources/users/#{user.slug}/posts/#{post.to_param}']" + form = "form[action='/admin/resources/users/#{user.slug}/associations/posts/#{post.to_param}']" expect(page).to have_selector("[data-component='resources-index'] #{form}") expect(page).to have_selector(:css, "#{form} input[type='hidden'][name='_method'][value='delete']", visible: false) # expect(page).to have_selector(:css, "#{form} input#referrer_detach_#{post.slug}[value='/admin/resources/users/#{user.slug}/posts?turbo_frame=has_many_field_posts']", visible: false) @@ -91,7 +91,7 @@ subject do expect(TestBuddy).to receive(:hi).with("parent_resource:true,resource:true").at_least :once - visit "/admin/resources/users/#{user.id}/comments?turbo_frame=has_many_field_show_comments" + visit "/admin/resources/users/#{user.id}/associations/comments?turbo_frame=has_many_field_show_comments" page end @@ -142,7 +142,7 @@ team.team_members << user expect(team.team_members.count).to eq 1 - visit "/admin/resources/teams/#{team.id}/team_members?view=show&turbo_frame=has_many_field_show_team_members" + visit "/admin/resources/teams/#{team.id}/associations/team_members?view=show&turbo_frame=has_many_field_show_team_members" expect { find("tr[data-resource-id='#{user.to_param}'] [data-control='detach']").click }.to raise_error("Callback Called") end @@ -151,7 +151,7 @@ user.teams << team expect(user.teams.count).to eq 1 - visit "/admin/resources/users/#{user.to_param}/teams?view=show&turbo_frame=has_and_belongs_to_many_field_show_teams" + visit "/admin/resources/users/#{user.to_param}/associations/teams?view=show&turbo_frame=has_and_belongs_to_many_field_show_teams" expect { find("tr[data-resource-id='#{team.id}'] [data-control='detach']").click }.to raise_error("Callback Called") end diff --git a/spec/features/avo/i18n_spec.rb b/spec/features/avo/i18n_spec.rb index 0743598ab..ef379aa0e 100644 --- a/spec/features/avo/i18n_spec.rb +++ b/spec/features/avo/i18n_spec.rb @@ -7,7 +7,7 @@ describe "field translation_key" do describe "resource index (has_many)" do it "translation on the panel title" do - visit "/admin/resources/users/#{user.id}/people?turbo_frame=has_many_field_show_people" + visit "/admin/resources/users/#{user.id}/associations/people?turbo_frame=has_many_field_show_people" expect(find("[data-target='title']").text).to eq "People" end diff --git a/spec/features/avo/link_to_child_resource_spec.rb b/spec/features/avo/link_to_child_resource_spec.rb index 9b3bb92d3..760c2f85e 100644 --- a/spec/features/avo/link_to_child_resource_spec.rb +++ b/spec/features/avo/link_to_child_resource_spec.rb @@ -63,19 +63,19 @@ let(:john) { create :person, name: "john", relatives: [lisa, paul] } it "display records linked to the child resource sibling " do - visit "/admin/resources/people/#{john.id}/relatives?turbo_frame=has_many_field_show_relatives" + visit "/admin/resources/people/#{john.id}/associations/relatives?turbo_frame=has_many_field_show_relatives" wait_for_loaded - expect(current_path).to eql "/admin/resources/people/#{john.id}/relatives" + expect(current_path).to eql "/admin/resources/people/#{john.id}/associations/relatives" expect(page).to have_text "demonstrate" expect(page).to have_link(href: "/admin/resources/siblings/#{paul.id}/edit?via_record_id=#{john.to_param}&via_resource_class=Avo%3A%3AResources%3A%3APerson") expect(page).to have_link(href: "/admin/resources/spouses/#{lisa.id}/edit?via_record_id=#{john.to_param}&via_resource_class=Avo%3A%3AResources%3A%3APerson") end it "display records linked to the parent resource people " do - visit "/admin/resources/people/#{john.id}/peoples?turbo_frame=has_many_field_show_peoples" + visit "/admin/resources/people/#{john.id}/associations/peoples?turbo_frame=has_many_field_show_peoples" wait_for_loaded - expect(current_path).to eql "/admin/resources/people/#{john.id}/peoples" + expect(current_path).to eql "/admin/resources/people/#{john.id}/associations/peoples" expect(page).to have_link(href: "/admin/resources/people/#{paul.id}/edit?via_record_id=#{john.to_param}&via_resource_class=Avo%3A%3AResources%3A%3APerson") expect(page).to have_link(href: "/admin/resources/people/#{lisa.id}/edit?via_record_id=#{john.to_param}&via_resource_class=Avo%3A%3AResources%3A%3APerson") @@ -84,26 +84,26 @@ context "id field" do it "links to the parent class resource if link_to_child_resource false at the resource level" do Avo::Resources::Person.link_to_child_resource = false - visit "/admin/resources/people/#{john.id}/peoples?turbo_frame=has_many_field_show_relatives" + visit "/admin/resources/people/#{john.id}/associations/peoples?turbo_frame=has_many_field_show_relatives" wait_for_loaded expect(page).to have_link(paul.name, href: "/admin/resources/people/#{paul.id}?via_record_id=#{john.id}&via_resource_class=Avo%3A%3AResources%3A%3APerson") end it "links to the child class resource if link_to_child_resource true at the resource level" do Avo::Resources::Person.link_to_child_resource = true - visit "/admin/resources/people/#{john.id}/peoples?turbo_frame=has_many_field_show_relatives" + visit "/admin/resources/people/#{john.id}/associations/peoples?turbo_frame=has_many_field_show_relatives" wait_for_loaded expect(page).to have_link(paul.name, href: "/admin/resources/siblings/#{paul.id}?via_record_id=#{john.id}&via_resource_class=Avo%3A%3AResources%3A%3APerson") end it "links to the parent class resource if link_to_child_resource false at the field level" do - visit "/admin/resources/people/#{john.id}/peoples?turbo_frame=has_many_field_show_relatives" + visit "/admin/resources/people/#{john.id}/associations/peoples?turbo_frame=has_many_field_show_relatives" wait_for_loaded expect(page).to have_link(paul.name, href: "/admin/resources/people/#{paul.id}?via_record_id=#{john.id}&via_resource_class=Avo%3A%3AResources%3A%3APerson") end it "links to the child class resource if link_to_child_resource true at the field level" do - visit "/admin/resources/people/#{john.id}/relatives?turbo_frame=has_many_field_show_relatives" + visit "/admin/resources/people/#{john.id}/associations/relatives?turbo_frame=has_many_field_show_relatives" wait_for_loaded expect(page).to have_link(paul.name, href: "/admin/resources/siblings/#{paul.id}?via_record_id=#{john.id}&via_resource_class=Avo%3A%3AResources%3A%3APerson") end diff --git a/spec/features/avo/model_missing_resource_spec.rb b/spec/features/avo/model_missing_resource_spec.rb index aea85dfcb..e3fc7e803 100644 --- a/spec/features/avo/model_missing_resource_spec.rb +++ b/spec/features/avo/model_missing_resource_spec.rb @@ -4,7 +4,7 @@ subject { visit url } context "when has_one field" do - let(:url) { "/admin/resources/stores/#{store.id}/location/#{location.id}?turbo_frame=has_one_field_show_location" } + let(:url) { "/admin/resources/stores/#{store.id}/associations/location/#{location.id}?turbo_frame=has_one_field_show_location" } let!(:store) { create :store } let!(:location) { create :location, store: store } @@ -28,7 +28,7 @@ context "when has_many field" do let!(:team) { create :team } - let(:url) { "/admin/resources/teams/#{team.id}/locations?turbo_frame=has_many_field_show_locations" } + let(:url) { "/admin/resources/teams/#{team.id}/associations/locations?turbo_frame=has_many_field_show_locations" } it "shows informative error with suggested solution for missing resource" do expect { @@ -39,7 +39,7 @@ context "when has_and_belongs_to_many field" do let!(:course) { create :course } - let(:url) { "/admin/resources/courses/#{course.id}/locations?turbo_frame=has_and_belongs_to_many_field_show_locations" } + let(:url) { "/admin/resources/courses/#{course.id}/associations/locations?turbo_frame=has_and_belongs_to_many_field_show_locations" } it "shows informative error with suggested solution for missing resource" do expect { diff --git a/spec/features/avo/multiple_resources_spec.rb b/spec/features/avo/multiple_resources_spec.rb index 178ccc277..52c06f654 100644 --- a/spec/features/avo/multiple_resources_spec.rb +++ b/spec/features/avo/multiple_resources_spec.rb @@ -5,8 +5,8 @@ describe 'each resource' do it "returns to parent resource when cancel creation" do - visit "admin/resources/compact_users/#{user.to_param}/posts?turbo_frame=has_many_field_show_posts" - expect(current_path).to eql "/admin/resources/compact_users/#{user.to_param}/posts" + visit "admin/resources/compact_users/#{user.to_param}/associations/posts?turbo_frame=has_many_field_show_posts" + expect(current_path).to eql "/admin/resources/compact_users/#{user.to_param}/associations/posts" click_on "Create new post" @@ -17,8 +17,8 @@ end it "returns to parent resource when creating new associated record" do - visit "admin/resources/compact_users/#{user.to_param}/posts?turbo_frame=has_many_field_show_posts" - expect(current_path).to eql "/admin/resources/compact_users/#{user.to_param}/posts" + visit "admin/resources/compact_users/#{user.to_param}/associations/posts?turbo_frame=has_many_field_show_posts" + expect(current_path).to eql "/admin/resources/compact_users/#{user.to_param}/associations/posts" click_on "Create new post" diff --git a/spec/features/avo/resource_description_spec.rb b/spec/features/avo/resource_description_spec.rb index 30e686191..b3452d9cd 100644 --- a/spec/features/avo/resource_description_spec.rb +++ b/spec/features/avo/resource_description_spec.rb @@ -70,7 +70,7 @@ let!(:team) { create :team } it "does not display the description" do - visit "/admin/resources/teams/#{team.id}/team_members?turbo_frame=has_many_field_show_team_members" + visit "/admin/resources/teams/#{team.id}/associations/team_members?turbo_frame=has_many_field_show_team_members" expect(page).to have_text "No related record found" expect(page).not_to have_text "Users of the app. view: index" diff --git a/spec/features/avo/use_resource_spec.rb b/spec/features/avo/use_resource_spec.rb index 8495acc1e..3a9b65070 100644 --- a/spec/features/avo/use_resource_spec.rb +++ b/spec/features/avo/use_resource_spec.rb @@ -65,7 +65,7 @@ end def visit_page - visit "admin/resources/posts/#{post.id}/comments?turbo_frame=has_many_field_show_photo_comments" + visit "admin/resources/posts/#{post.id}/associations/comments?turbo_frame=has_many_field_show_photo_comments" - expect(current_path).to eql "/admin/resources/posts/#{post.id}/comments" + expect(current_path).to eql "/admin/resources/posts/#{post.id}/associations/comments" end diff --git a/spec/features/avo/via_resource_class_is_a_resource_class_spec.rb b/spec/features/avo/via_resource_class_is_a_resource_class_spec.rb index 324403d10..eda9c96d2 100644 --- a/spec/features/avo/via_resource_class_is_a_resource_class_spec.rb +++ b/spec/features/avo/via_resource_class_is_a_resource_class_spec.rb @@ -7,7 +7,7 @@ let!(:comment) { create :comment, commentable: post } it "displays the right resource class in association link" do - visit "/admin/resources/z_posts/#{post.id}/comments?turbo_frame=has_many_field_show_photo_comments" + visit "/admin/resources/z_posts/#{post.id}/associations/comments?turbo_frame=has_many_field_show_photo_comments" within "tr[data-resource-id=\"#{comment.id}\"] [data-field-id=\"id\"]" do expect(page).to have_link comment.id, href: "/admin/resources/photo_comments/#{comment.id}?via_record_id=#{post.slug}&via_resource_class=Avo%3A%3AResources%3A%3AZPost" diff --git a/spec/system/avo/has_many_spec.rb b/spec/system/avo/has_many_spec.rb index 1a8bba6b1..5f04501f7 100644 --- a/spec/system/avo/has_many_spec.rb +++ b/spec/system/avo/has_many_spec.rb @@ -11,7 +11,7 @@ let!(:comment) { create :comment, commentable: post, user: user } it "displays the other fields" do - visit "/admin/resources/posts/#{post.id}/comments?turbo_frame=has_many_field_show_comments" + visit "/admin/resources/posts/#{post.id}/associations/comments?turbo_frame=has_many_field_show_comments" row = find("[data-resource-name='comments'][data-resource-id='#{comment.id}']") @@ -27,7 +27,7 @@ let!(:review) { create :review, reviewable: team, user: user } it "displays the other fields" do - visit "/admin/resources/teams/#{team.id}/reviews?turbo_frame=has_many_field_show_reviews" + visit "/admin/resources/teams/#{team.id}/associations/reviews?turbo_frame=has_many_field_show_reviews" row = find("[data-resource-name='reviews'][data-resource-id='#{review.id}']")