diff --git a/app/components/avo/base_component.rb b/app/components/avo/base_component.rb
index 197685f68..8b4613e3d 100644
--- a/app/components/avo/base_component.rb
+++ b/app/components/avo/base_component.rb
@@ -17,13 +17,16 @@ def field
end
# Fetch the resource and hydrate it with the model
- def relation_resource
- model_class_name = params[:via_resource_class] || params[:via_relation_class]
+ def association_resource
+ resource = ::Avo::App.get_resource(params[:via_resource_class])
+ model_class_name = params[:via_relation_class] || resource.model_class
+
model_klass = ::Avo::BaseResource.valid_model_class model_class_name
- resource = ::Avo::App.get_resource_by_model_name model_klass
model = model_klass.find params[:via_resource_id]
+ resource = ::Avo::App.get_resource_by_model_name model_klass if resource.blank?
+
resource.dup.hydrate model: model
end
diff --git a/app/components/avo/fields/belongs_to_field/edit_component.rb b/app/components/avo/fields/belongs_to_field/edit_component.rb
index f5916ce87..4f1df7431 100644
--- a/app/components/avo/fields/belongs_to_field/edit_component.rb
+++ b/app/components/avo/fields/belongs_to_field/edit_component.rb
@@ -12,7 +12,7 @@ def disabled
# When visiting the record through it's association we keep the field disabled by default
# We make an exception when the user deliberately instructs Avo to allow detaching in this scenario
- return !@field.allow_via_detaching if @field.target_resource.present? && @field.target_resource.model_class.name == params[:via_resource_class]
+ return !@field.allow_via_detaching if @field.target_resource.present? && visit_through_association?
return !@field.allow_via_detaching if @field.id.to_s == params[:via_relation].to_s
false
@@ -52,4 +52,10 @@ def polymorphic_record
def field_html_action
@field.get_html(:data, view: @resource.view, element: :input).fetch(:action, nil)
end
+
+ private
+
+ def visit_through_association?
+ @field.target_resource.class.to_s == params[:via_resource_class].to_s
+ end
end
diff --git a/app/components/avo/fields/belongs_to_field/show_component.rb b/app/components/avo/fields/belongs_to_field/show_component.rb
index 5d8110257..c1e22e161 100644
--- a/app/components/avo/fields/belongs_to_field/show_component.rb
+++ b/app/components/avo/fields/belongs_to_field/show_component.rb
@@ -5,7 +5,7 @@ def resource_view_path
helpers.resource_view_path(
model: @field.value,
resource: @field.target_resource,
- via_resource_class: @resource.model_class,
+ via_resource_class: @resource.class.to_s,
via_resource_id: @resource.model.id
)
end
diff --git a/app/components/avo/fields/index_component.rb b/app/components/avo/fields/index_component.rb
index 1450e920f..de364f318 100644
--- a/app/components/avo/fields/index_component.rb
+++ b/app/components/avo/fields/index_component.rb
@@ -3,13 +3,15 @@
class Avo::Fields::IndexComponent < ViewComponent::Base
include Avo::ResourcesHelper
+ attr_reader :parent_resource
attr_reader :view
- def initialize(field: nil, resource: nil, index: 0, parent_model: nil)
+ def initialize(field: nil, resource: nil, index: 0, parent_model: nil, parent_resource: nil)
@field = field
@resource = resource
@index = index
@parent_model = parent_model
+ @parent_resource = parent_resource
@view = :index
end
@@ -18,7 +20,7 @@ def resource_view_path
if @parent_model.present?
args = {
- via_resource_class: @parent_model.class,
+ via_resource_class: @parent_resource.class,
via_resource_id: @parent_model.id
}
end
diff --git a/app/components/avo/index/grid_item_component.rb b/app/components/avo/index/grid_item_component.rb
index 860ae30bb..e1e93a4bf 100644
--- a/app/components/avo/index/grid_item_component.rb
+++ b/app/components/avo/index/grid_item_component.rb
@@ -32,7 +32,7 @@ def resource_view_path
if @parent_model.present?
args = {
- via_resource_class: parent_resource.model_class,
+ via_resource_class: parent_resource.class.to_s,
via_resource_id: @parent_model.id
}
end
diff --git a/app/components/avo/index/resource_controls_component.rb b/app/components/avo/index/resource_controls_component.rb
index 94a439273..474e48312 100644
--- a/app/components/avo/index/resource_controls_component.rb
+++ b/app/components/avo/index/resource_controls_component.rb
@@ -36,7 +36,7 @@ def show_path
if @parent_model.present?
args = {
- via_resource_class: parent_resource.model_class,
+ via_resource_class: parent_resource.class.to_s,
via_resource_id: @parent_model.id
}
end
@@ -50,7 +50,7 @@ def edit_path
if @parent_model.present?
args = {
- via_resource_class: parent_resource.model_class,
+ via_resource_class: parent_resource.class.to_s,
via_resource_id: @parent_model.id
}
end
diff --git a/app/components/avo/index/table_row_component.html.erb b/app/components/avo/index/table_row_component.html.erb
index d07f40409..ae0ac58c6 100644
--- a/app/components/avo/index/table_row_component.html.erb
+++ b/app/components/avo/index/table_row_component.html.erb
@@ -17,7 +17,7 @@
<% end %>
<% @resource.get_fields(reflection: @reflection, only_root: true).each_with_index do |field, index| %>
- <%= render field.component_for_view(:index).new(field: field, resource: @resource, index: index, parent_model: @parent_model) %>
+ <%= render field.component_for_view(:index).new(field: field, resource: @resource, index: index, parent_model: @parent_model, parent_resource: @parent_resource) %>
<% end %>
<% if Avo.configuration.resource_controls_on_the_right? %>
diff --git a/app/components/avo/views/resource_edit_component.rb b/app/components/avo/views/resource_edit_component.rb
index 1077c5964..19637cf1e 100644
--- a/app/components/avo/views/resource_edit_component.rb
+++ b/app/components/avo/views/resource_edit_component.rb
@@ -31,7 +31,7 @@ def resources_path
end
def resource_view_path
- helpers.resource_view_path(model: relation_resource.model, resource: relation_resource)
+ helpers.resource_view_path(model: association_resource.model, resource: association_resource)
end
def can_see_the_destroy_button?
diff --git a/app/components/avo/views/resource_show_component.rb b/app/components/avo/views/resource_show_component.rb
index ddabac761..1f993e69e 100644
--- a/app/components/avo/views/resource_show_component.rb
+++ b/app/components/avo/views/resource_show_component.rb
@@ -26,8 +26,7 @@ def title
def back_path
if via_resource?
- model_class = ::Avo::BaseResource.valid_model_class params[:via_resource_class]
- helpers.resource_path(model: model_class, resource: relation_resource, resource_id: params[:via_resource_id])
+ helpers.resource_path(model: association_resource.model_class, resource: association_resource, resource_id: params[:via_resource_id])
else
helpers.resources_path(resource: @resource)
end
diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb
index fcb8a683e..b82f84d98 100644
--- a/app/controllers/avo/base_controller.rb
+++ b/app/controllers/avo/base_controller.rb
@@ -84,7 +84,7 @@ def show
# If we're accessing this resource via another resource add the parent to the breadcrumbs.
if params[:via_resource_class].present? && params[:via_resource_id].present?
- via_resource = Avo::App.get_resource_by_model_name(params[:via_resource_class]).dup
+ via_resource = Avo::App.get_resource(params[:via_resource_class]).dup
via_model = via_resource.class.find_scope.find params[:via_resource_id]
via_resource.hydrate model: via_model
@@ -371,7 +371,7 @@ def set_edit_title_and_breadcrumbs
last_crumb_args = {}
# If we're accessing this resource via another resource add the parent to the breadcrumbs.
if params[:via_resource_class].present? && params[:via_resource_id].present?
- via_resource = Avo::App.get_resource_by_model_name(params[:via_resource_class]).dup
+ via_resource = Avo::App.get_resource(params[:via_resource_class]).dup
via_model = via_resource.class.find_scope.find params[:via_resource_id]
via_resource.hydrate model: via_model
diff --git a/lib/avo/base_resource.rb b/lib/avo/base_resource.rb
index 1633c2557..9d26c2dd3 100644
--- a/lib/avo/base_resource.rb
+++ b/lib/avo/base_resource.rb
@@ -124,7 +124,7 @@ def get_available_models
def valid_model_class(model_class)
get_available_models.find do |m|
- m.to_s == model_class
+ m.to_s == model_class.to_s
end
end
end
diff --git a/lib/avo/concerns/fetches_things.rb b/lib/avo/concerns/fetches_things.rb
index 48b54ce42..06e83a311 100644
--- a/lib/avo/concerns/fetches_things.rb
+++ b/lib/avo/concerns/fetches_things.rb
@@ -36,7 +36,7 @@ def get_resource(resource)
possible_resource = "#{resource}Resource".gsub "ResourceResource", "Resource"
resources.find do |available_resource|
- possible_resource.safe_constantize == available_resource.class
+ possible_resource.to_s == available_resource.class.to_s
end
end
diff --git a/spec/dummy/app/avo/resources/z_post_resource.rb b/spec/dummy/app/avo/resources/z_post_resource.rb
new file mode 100644
index 000000000..3ad098a98
--- /dev/null
+++ b/spec/dummy/app/avo/resources/z_post_resource.rb
@@ -0,0 +1,68 @@
+class ZPostResource < Avo::BaseResource
+ self.title = :name
+ self.search_query = -> do
+ scope.ransack(id_eq: params[:q], name_cont: params[:q], body_cont: params[:q], m: "or").result(distinct: false)
+ end
+ self.search_query_help = "- search by id, name or body"
+ self.includes = [:user]
+ self.default_view_type = :grid
+ self.model_class = "Post"
+
+ # self.show_controls = -> do
+ # detach_button
+ # edit_button
+ # link_to "google", "goolee"
+ # end
+
+ field :id, as: :id
+ field :name, as: :text, required: true, sortable: true
+ field :body,
+ as: :trix,
+ placeholder: "Enter text",
+ always_show: false,
+ attachment_key: :attachments,
+ hide_attachment_url: true,
+ hide_attachment_filename: true,
+ hide_attachment_filesize: true
+ field :tags,
+ as: :tags,
+ # readonly: true,
+ acts_as_taggable_on: :tags,
+ close_on_select: false,
+ placeholder: "add some tags",
+ suggestions: -> { Post.tags_suggestions },
+ enforce_suggestions: true,
+ help: "The only allowed values here are `one`, `two`, and `three`"
+ field :cover_photo, as: :file, is_image: true, as_avatar: :rounded, full_width: true, hide_on: [], accept: "image/*"
+ field :cover_photo, as: :external_image, name: "Cover photo", required: true, hide_on: :all, link_to_resource: true, as_avatar: :rounded, format_using: ->(value) { value.present? ? value&.url : nil }
+ field :audio, as: :file, is_audio: true, accept: "audio/*"
+ field :excerpt, as: :text, hide_on: :all, as_description: true do |model|
+ ActionView::Base.full_sanitizer.sanitize(model.body).truncate 130
+ rescue
+ ""
+ end
+
+ field :is_featured, as: :boolean, visible: ->(resource:) { context[:user].is_admin? }
+ field :is_published, as: :boolean do |model|
+ model.published_at.present?
+ end
+ field :user, as: :belongs_to, placeholder: "—"
+ field :status, as: :select, enum: ::Post.statuses, display_value: false
+ field :comments, as: :has_many, use_resource: PhotoCommentResource
+
+ grid do
+ cover :cover_photo, as: :file, is_image: true, link_to_resource: true
+ title :name, as: :text, required: true, link_to_resource: true
+ body :excerpt, as: :text do |model|
+ ActionView::Base.full_sanitizer.sanitize(model.body).truncate 130
+ rescue
+ ""
+ end
+ end
+
+ filter FeaturedFilter
+ filter PublishedFilter
+ filter PostStatusFilter
+
+ action TogglePublished
+end
diff --git a/spec/dummy/app/controllers/avo/z_posts_controller.rb b/spec/dummy/app/controllers/avo/z_posts_controller.rb
new file mode 100644
index 000000000..dc03efd21
--- /dev/null
+++ b/spec/dummy/app/controllers/avo/z_posts_controller.rb
@@ -0,0 +1,2 @@
+class Avo::ZPostsController < Avo::ResourcesController
+end
diff --git a/spec/dummy/app/models/comment.rb b/spec/dummy/app/models/comment.rb
index eab5f60ad..93d599db7 100644
--- a/spec/dummy/app/models/comment.rb
+++ b/spec/dummy/app/models/comment.rb
@@ -16,7 +16,7 @@ class Comment < ApplicationRecord
validate :body_different
has_one_attached :photo
-
+
belongs_to :commentable, polymorphic: true, optional: true
belongs_to :user, optional: true
diff --git a/spec/dummy/config/initializers/avo.rb b/spec/dummy/config/initializers/avo.rb
index 84fcfd866..cb8fb12dd 100644
--- a/spec/dummy/config/initializers/avo.rb
+++ b/spec/dummy/config/initializers/avo.rb
@@ -26,7 +26,7 @@
## == Customization ==
config.id_links_to_resource = true
- config.full_width_container = true
+ config.full_width_container = false
config.buttons_on_form_footers = false
# config.resource_controls_placement = ENV["AVO_RESOURCE_CONTROLS_PLACEMENT"]&.to_sym || :right
config.resource_default_view = :show
@@ -95,6 +95,7 @@
end
group "Blog", collapsable: true do
+ # resource :z_posts
resource :posts
resource :comments
resource :photo_comments, visible: -> do
diff --git a/spec/features/avo/allow_via_detaching_spec.rb b/spec/features/avo/allow_via_detaching_spec.rb
index ecf156efa..4c6defd0c 100644
--- a/spec/features/avo/allow_via_detaching_spec.rb
+++ b/spec/features/avo/allow_via_detaching_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.feature "AllowViaDetachings", type: :feature do
describe "when allowed" do
@@ -6,13 +6,13 @@
let(:review) { create :review, reviewable: team }
it "is enabled" do
- visit "/admin/resources/reviews/#{review.id}/edit?via_resource_class=Team&via_resource_id=#{team.id}"
+ visit "/admin/resources/reviews/#{review.id}/edit?via_resource_class=TeamResource&via_resource_id=#{team.id}"
- expect(page).to have_field 'review_reviewable_type', type: :select, disabled: false
- # review_reviewable_id is disabled because it's a searchable field
- expect(page).to have_field 'review_reviewable_id', type: :text, disabled: true
- # review_user_id is disabled because it's a searchable field
- expect(page).to have_field 'review_user_id', type: :text, disabled: true
+ expect(page).to have_field "review_reviewable_type", type: :select, disabled: false
+ # review_reviewable_id is disabled because it"s a searchable field
+ expect(page).to have_field "review_reviewable_id", type: :text, disabled: true
+ # review_user_id is disabled because it"s a searchable field
+ expect(page).to have_field "review_user_id", type: :text, disabled: true
end
end
@@ -21,11 +21,11 @@
let(:comment) { create :comment, commentable: post }
it "is enabled" do
- visit "/admin/resources/comments/#{comment.id}/edit?via_resource_class=Post&via_resource_id=#{post.id}"
+ visit "/admin/resources/comments/#{comment.id}/edit?via_resource_class=PostResource&via_resource_id=#{post.id}"
- expect(page).to have_field 'comment_commentable_type', type: :select, disabled: true
- expect(page).to have_field 'comment_commentable_id', type: :select, disabled: true
- expect(page).to have_field 'comment_user_id', type: :select, disabled: false
+ expect(page).to have_field "comment_commentable_type", type: :select, disabled: true
+ expect(page).to have_field "comment_commentable_id", type: :select, disabled: true
+ expect(page).to have_field "comment_user_id", type: :select, disabled: false
end
end
end
diff --git a/spec/features/avo/belongs_to_spec.rb b/spec/features/avo/belongs_to_spec.rb
index b72f18561..d4443b851 100644
--- a/spec/features/avo/belongs_to_spec.rb
+++ b/spec/features/avo/belongs_to_spec.rb
@@ -39,7 +39,7 @@
describe "with user attached" do
let!(:post) { create :post, user: admin }
- it { is_expected.to have_link admin.name, href: "/admin/resources/users/#{admin.slug}?via_resource_class=Post&via_resource_id=#{post.id}" }
+ it { is_expected.to have_link admin.name, href: "/admin/resources/users/#{admin.slug}?via_resource_class=PostResource&via_resource_id=#{post.id}" }
end
describe "without user attached" do
@@ -66,7 +66,7 @@
click_on "Save"
expect(current_path).to eql "/admin/resources/posts/#{post.id}"
- expect(page).to have_link admin.name, href: "/admin/resources/users/#{admin.slug}?via_resource_class=Post&via_resource_id=#{post.id}"
+ expect(page).to have_link admin.name, href: "/admin/resources/users/#{admin.slug}?via_resource_class=PostResource&via_resource_id=#{post.id}"
end
end
@@ -85,7 +85,7 @@
click_on "Save"
expect(current_path).to eql "/admin/resources/posts/#{post.id}"
- expect(page).to have_link second_user.name, href: "/admin/resources/users/#{second_user.slug}?via_resource_class=Post&via_resource_id=#{post.id}"
+ expect(page).to have_link second_user.name, href: "/admin/resources/users/#{second_user.slug}?via_resource_class=PostResource&via_resource_id=#{post.id}"
end
it "nullifies the user" do
diff --git a/spec/features/avo/has_many_field_spec.rb b/spec/features/avo/has_many_field_spec.rb
index f30b36d9f..4d2a00021 100644
--- a/spec/features/avo/has_many_field_spec.rb
+++ b/spec/features/avo/has_many_field_spec.rb
@@ -59,14 +59,14 @@
## Table Rows
# show link
- show_path = "/admin/resources/posts/#{post.id}?via_resource_class=User&via_resource_id=#{user.id}"
+ show_path = "/admin/resources/posts/#{post.id}?via_resource_class=UserResource&via_resource_id=#{user.id}"
expect(page).to have_css("a[data-control='show'][href='#{show_path}']")
# id field show link
- expect(field_element_by_resource_id("id", post.id)).to have_css("a[href='/admin/resources/posts/#{post.id}?via_resource_class=User&via_resource_id=#{user.id}']")
+ expect(field_element_by_resource_id("id", post.id)).to have_css("a[href='/admin/resources/posts/#{post.id}?via_resource_class=UserResource&via_resource_id=#{user.id}']")
# edit link
- edit_path = "/admin/resources/posts/#{post.id}/edit?via_resource_class=User&via_resource_id=#{user.id}"
+ edit_path = "/admin/resources/posts/#{post.id}/edit?via_resource_class=UserResource&via_resource_id=#{user.id}"
expect(page).to have_selector("[data-component='resources-index'] a[data-control='edit'][data-resource-id='#{post.id}'][href='#{edit_path}']")
# detach form
@@ -136,7 +136,7 @@
expect(link.link).to eq "https://google.com"
expect(link.course.id).to eq course.id
- visit "/admin/resources/course_links/#{link.id}/edit?via_resource_class=Course&via_resource_id=#{course.id}"
+ visit "/admin/resources/course_links/#{link.id}/edit?via_resource_class=CourseResource&via_resource_id=#{course.id}"
fill_in "course_link_link", with: "https://apple.com"
click_on "Save"
link.reload
diff --git a/spec/features/avo/skip_show_view_spec.rb b/spec/features/avo/skip_show_view_spec.rb
index 8deed14ab..01735ab7b 100644
--- a/spec/features/avo/skip_show_view_spec.rb
+++ b/spec/features/avo/skip_show_view_spec.rb
@@ -85,7 +85,7 @@
expect(current_path).to eql "/admin/resources/courses/#{course.id}/edit"
# Delete
- visit "/admin/resources/course_links/#{course.links.first.id}/edit?via_resource_class=Course&via_resource_id=#{course.id}"
+ visit "/admin/resources/course_links/#{course.links.first.id}/edit?via_resource_class=CourseResource&via_resource_id=#{course.id}"
click_on "Delete"
@@ -172,10 +172,10 @@
expect(current_path).to eql "/admin/resources/courses/#{course.id}"
# Delete
- visit "/admin/resources/course_links/#{course.links.first.id}/edit?via_resource_class=Course&via_resource_id=#{course.id}"
+ visit "/admin/resources/course_links/#{course.links.first.id}/edit?via_resource_class=CourseResource&via_resource_id=#{course.id}"
expect(page).to_not have_selector("[data-control='destroy']")
- visit "/admin/resources/course_links/#{course.links.first.id}?via_resource_class=Course&via_resource_id=#{course.id}"
+ visit "/admin/resources/course_links/#{course.links.first.id}?via_resource_class=CourseResource&via_resource_id=#{course.id}"
click_on "Delete"
expect(page).to have_text("Record destroyed")
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
new file mode 100644
index 000000000..5978530fc
--- /dev/null
+++ b/spec/features/avo/via_resource_class_is_a_resource_class_spec.rb
@@ -0,0 +1,32 @@
+require "rails_helper"
+
+# The ethos of this spec and fix is that initially, we were sending model classes instead of resource classes in the GET params.
+# The receivers then had to guess the resource from the model class, but that failed in some edge cases when multiple resources weere mapped to the same model.
+RSpec.feature "ViaResourceClassIsAResourceClasses", type: :feature do
+ let!(:post) { create :post }
+ 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"
+
+ 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_resource_class=ZPostResource&via_resource_id=#{post.id}"
+ end
+ end
+
+ it "displays the right breadcrumb link" do
+ visit "/admin/resources/photo_comments/#{comment.id}?via_resource_class=ZPostResource&via_resource_id=#{post.id}"
+
+ within ".breadcrumbs" do
+ expect(page).to have_link post.name, href: "/admin/resources/z_posts/#{post.id}"
+ end
+ end
+
+ it "displays the right breadcrumb link" do
+ visit "/admin/resources/photo_comments/#{comment.id}?via_resource_class=PostResource&via_resource_id=#{post.id}"
+
+ within ".breadcrumbs" do
+ expect(page).to have_link post.name, href: "/admin/resources/posts/#{post.id}"
+ end
+ end
+end
diff --git a/spec/system/avo/app_spec.rb b/spec/system/avo/app_spec.rb
index 4bae07420..fea439cb1 100644
--- a/spec/system/avo/app_spec.rb
+++ b/spec/system/avo/app_spec.rb
@@ -11,7 +11,7 @@
visit "/admin/resources/projects/#{project.id}"
expect(find('turbo-frame[id="has_many_field_show_comments"]')).not_to have_text "Commentable"
- expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=Project&via_resource_id=#{project.id}"
+ expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=ProjectResource&via_resource_id=#{project.id}"
within 'turbo-frame[id="has_many_field_show_comments"]' do
click_on comment.id.to_s
@@ -37,7 +37,7 @@
visit "/admin/resources/projects/#{project.id}"
expect(find('turbo-frame[id="has_many_field_show_comments"]')).not_to have_text "Commentable"
- expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=Project&via_resource_id=#{project.id}"
+ expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=ProjectResource&via_resource_id=#{project.id}"
destroy_button = find("turbo-frame[id='has_many_field_show_comments'] tr[data-resource-id='#{comment.id}'] button[data-control=\"destroy\"]")
diff --git a/spec/system/avo/belongs_to_polymorphic_spec.rb b/spec/system/avo/belongs_to_polymorphic_spec.rb
index 46c4cfc05..d9cfa79ff 100644
--- a/spec/system/avo/belongs_to_polymorphic_spec.rb
+++ b/spec/system/avo/belongs_to_polymorphic_spec.rb
@@ -41,7 +41,7 @@
return_to_comment_page
expect(find_field_value_element("body")).to have_text "Sample comment"
- expect(find_field_value_element("user")).to have_link user.name, href: "/admin/resources/users/#{user.slug}?via_resource_class=Comment&via_resource_id=#{Comment.last.id}"
+ expect(find_field_value_element("user")).to have_link user.name, href: "/admin/resources/users/#{user.slug}?via_resource_class=CommentResource&via_resource_id=#{Comment.last.id}"
expect(find_field_value_element("commentable")).to have_text empty_dash
end
end
@@ -70,7 +70,7 @@
expect(current_path).to eq "/admin/resources/comments/#{comment.id}"
expect(find_field_value_element("body")).to have_text "Sample comment"
- expect(page).to have_link post.name, href: "/admin/resources/posts/#{post.id}?via_resource_class=Comment&via_resource_id=#{Comment.last.id}"
+ expect(page).to have_link post.name, href: "/admin/resources/posts/#{post.id}?via_resource_class=CommentResource&via_resource_id=#{Comment.last.id}"
click_on "Edit"
@@ -211,13 +211,13 @@
visit "/admin/resources/projects/#{project.id}"
expect(find('turbo-frame[id="has_many_field_show_comments"]')).not_to have_text "Commentable"
- expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=Project&via_resource_id=#{project.id}"
+ expect(find('turbo-frame[id="has_many_field_show_comments"]')).to have_link comment.id.to_s, href: "/admin/resources/comments/#{comment.id}?via_resource_class=ProjectResource&via_resource_id=#{project.id}"
click_on comment.id.to_s
expect(find_field_value_element("body")).to have_text "hey there"
- expect(find_field_value_element("user")).to have_link user.name, href: "/admin/resources/users/#{user.slug}?via_resource_class=Comment&via_resource_id=#{comment.id}"
- expect(find_field_value_element("commentable")).to have_link project.name, href: "/admin/resources/projects/#{project.id}?via_resource_class=Comment&via_resource_id=#{comment.id}"
+ expect(find_field_value_element("user")).to have_link user.name, href: "/admin/resources/users/#{user.slug}?via_resource_class=CommentResource&via_resource_id=#{comment.id}"
+ expect(find_field_value_element("commentable")).to have_link project.name, href: "/admin/resources/projects/#{project.id}?via_resource_class=CommentResource&via_resource_id=#{comment.id}"
click_on "Edit"
diff --git a/spec/system/recursive_resources_spec.rb b/spec/system/recursive_resources_spec.rb
index 687930a62..7e58fccb1 100644
--- a/spec/system/recursive_resources_spec.rb
+++ b/spec/system/recursive_resources_spec.rb
@@ -18,6 +18,6 @@
wait_for_loaded
- expect(page).to have_current_path(avo.resources_spouse_path(spouse, via_resource_class: "Person", via_resource_id: person.id))
+ expect(page).to have_current_path(avo.resources_spouse_path(spouse, via_resource_class: "PersonResource", via_resource_id: person.id))
end
end
|