Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change associations controller path to avoid naming collisions #3529

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/has_base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/has_one_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/features/avo/belongs_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions spec/features/avo/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/avo/create_has_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions spec/features/avo/discreet_pagination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/avo/has_many_attach_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/features/avo/has_many_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/avo/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/features/avo/link_to_child_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/features/avo/model_missing_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions spec/features/avo/multiple_resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion spec/features/avo/resource_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/avo/use_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading
Loading