From 87742cb8e66ecf7b64f505f33c5c1484df3374d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Sun, 1 Sep 2024 18:46:33 +0200 Subject: [PATCH 01/12] Remove last usage of _reflections in favor of reflect_on_association. - better compatible with newer Rails, since it casts to needed type on its own --- .../avo/fields/belongs_to_field/autocomplete_component.rb | 2 +- app/components/avo/fields/has_one_field/show_component.rb | 2 +- app/controllers/avo/application_controller.rb | 2 +- app/controllers/avo/associations_controller.rb | 4 ++-- app/controllers/avo/base_controller.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/components/avo/fields/belongs_to_field/autocomplete_component.rb b/app/components/avo/fields/belongs_to_field/autocomplete_component.rb index ffcdacc301..87b2894af0 100644 --- a/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +++ b/app/components/avo/fields/belongs_to_field/autocomplete_component.rb @@ -41,7 +41,7 @@ def field_value end def reflection_class - has_polymorphic_association? ? polymorphic_class : @resource.model_class._reflections[@field.id.to_s].klass + has_polymorphic_association? ? polymorphic_class : @resource.model_class.reflect_on_association(@field.id).klass end private diff --git a/app/components/avo/fields/has_one_field/show_component.rb b/app/components/avo/fields/has_one_field/show_component.rb index a20953faa5..f6e80a31c5 100644 --- a/app/components/avo/fields/has_one_field/show_component.rb +++ b/app/components/avo/fields/has_one_field/show_component.rb @@ -36,7 +36,7 @@ def can_see_the_create_button? end def create_path - association_id = @field.resource.model_class._reflections[@field.id.to_s].inverse_of.name + association_id = @field.resource.model_class.reflect_on_association(@field.id).inverse_of.name args = { via_relation: association_id, diff --git a/app/controllers/avo/application_controller.rb b/app/controllers/avo/application_controller.rb index 7d7431134f..521159eaa6 100644 --- a/app/controllers/avo/application_controller.rb +++ b/app/controllers/avo/application_controller.rb @@ -226,7 +226,7 @@ def related_resource return field.use_resource if field&.use_resource.present? - reflection = @model._reflections[params[:related_name]] + reflection = @model.class.reflect_on_association(params[:related_name]) reflected_model = reflection.klass diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 698b9a2597..c44bf64bd4 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -101,7 +101,7 @@ def order private def set_reflection - @reflection = @model._reflections[params[:related_name].to_s] + @reflection = @model.class.reflect_on_association(params[:related_name]) end def set_attachment_class @@ -127,7 +127,7 @@ def attachment_id end def reflection_class - reflection = @model._reflections[params[:related_name]] + reflection = @model.class.reflect_on_association(params[:related_name]) klass = reflection.class.name.demodulize.to_s klass = reflection.through_reflection.class.name.demodulize.to_s if klass == "ThroughReflection" diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 4e26e87171..6cd972ba4b 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -134,7 +134,7 @@ def create # This means that the record has been created through another parent record and we need to attach it somehow. if params[:via_resource_id].present? && params[:via_belongs_to_resource_class].nil? - @reflection = @model._reflections[params[:via_relation]] + @reflection = @model.class.reflect_on_association(params[:via_relation]) # Figure out what kind of association does the record have with the parent record # Fills in the required infor for belongs_to and has_many From d30d552eeb64157d7affd15113deb97719ab8d2e Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 17:05:04 +0300 Subject: [PATCH 02/12] improve @reflection class check --- .../avo/associations_controller.rb | 24 +++++++++++-------- app/controllers/avo/base_controller.rb | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index c44bf64bd4..7b923d9924 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -62,7 +62,7 @@ def new def create association_name = BaseResource.valid_association_name(@model, params[:related_name]) - if reflection_class == "HasManyReflection" + if has_many_reflection? @model.send(association_name) << @attachment_model else @model.send("#{association_name}=", @attachment_model) @@ -80,7 +80,7 @@ def create def destroy association_name = BaseResource.valid_association_name(@model, params[:related_name]) - if reflection_class == "HasManyReflection" + if has_many_reflection? @model.send(association_name).delete @attachment_model else @model.send("#{association_name}=", nil) @@ -127,12 +127,11 @@ def attachment_id end def reflection_class - reflection = @model.class.reflect_on_association(params[:related_name]) - - klass = reflection.class.name.demodulize.to_s - klass = reflection.through_reflection.class.name.demodulize.to_s if klass == "ThroughReflection" - - klass + if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection) + @reflection.through_reflection.class + else + @reflection.class + end end def authorize_if_defined(method) @@ -155,8 +154,6 @@ def authorize_detach_action authorize_if_defined "detach_#{@field.id}?" end - private - def set_related_authorization @related_authorization = if related_resource related_resource.authorization(user: _current_user) @@ -164,5 +161,12 @@ def set_related_authorization Services::AuthorizationService.new _current_user end end + + def has_many_reflection? + reflection_class.in? [ + ActiveRecord::Reflection::HasManyReflection, + ActiveRecord::Reflection::HasAndBelongsToManyReflection + ] + end end end diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 6cd972ba4b..6ca338d5fc 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -148,7 +148,7 @@ def create end # For when working with has_one, has_one_through, has_many_through, has_and_belongs_to_many, polymorphic - if @reflection.is_a? ActiveRecord::Reflection::ThroughReflection + if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection) || @reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection) # find the record via_resource = ::Avo::App.get_resource_by_model_name(params[:via_relation_class]).dup @related_record = via_resource.find_record params[:via_resource_id], params: params From 1eae63c255646f786d0ac1c10855446efeee202a Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 17:21:47 +0300 Subject: [PATCH 03/12] update actions/upload-artifact to v4 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55204f917b..bda2464d39 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -110,7 +110,7 @@ jobs: id: run_tests run: bundle exec rspec spec/features - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: always() && steps.run_tests.outcome == 'failure' with: name: rspec_failed_screenshots @@ -197,7 +197,7 @@ jobs: id: run_tests run: bundle exec rspec spec/system - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: always() && steps.run_tests.outcome == 'failure' with: name: rspec_failed_screenshots From 15b0e80c5a534519f095de8efabed82ffd432b93 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 17:34:29 +0300 Subject: [PATCH 04/12] fix breadcrumbs spec --- spec/features/avo/breadcrumbs_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/features/avo/breadcrumbs_spec.rb b/spec/features/avo/breadcrumbs_spec.rb index f364f07033..7a7a42c1a1 100644 --- a/spec/features/avo/breadcrumbs_spec.rb +++ b/spec/features/avo/breadcrumbs_spec.rb @@ -11,8 +11,20 @@ subject { page.body } describe "with breadcrumbs" do - it { is_expected.to have_css ".breadcrumbs" } - it { is_expected.to have_text "Dashboard\n \n\nProjects\n \n\n#{project.name}\n \n\nEdit\n" } + it { + # Find the breadcrumbs container + breadcrumbs = find('.breadcrumbs') + + # Verify that the text includes all breadcrumbs + expect(breadcrumbs).to have_text('Dashboard') + expect(breadcrumbs).to have_text('Projects') + expect(breadcrumbs).to have_text(project.name) + expect(breadcrumbs).to have_text('Edit') + + # Ensure the breadcrumbs are in the correct order + breadcrumb_order = breadcrumbs.text + expect(breadcrumb_order).to match(/Dashboard.*Projects.*#{project.name}.*Edit/) + } end describe "on a custom tool" do From 59c2a8855675beab1f08f4274035e8facaa75167 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 17:34:52 +0300 Subject: [PATCH 05/12] dry --- spec/features/avo/breadcrumbs_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/features/avo/breadcrumbs_spec.rb b/spec/features/avo/breadcrumbs_spec.rb index 7a7a42c1a1..eae1c063c4 100644 --- a/spec/features/avo/breadcrumbs_spec.rb +++ b/spec/features/avo/breadcrumbs_spec.rb @@ -22,8 +22,7 @@ expect(breadcrumbs).to have_text('Edit') # Ensure the breadcrumbs are in the correct order - breadcrumb_order = breadcrumbs.text - expect(breadcrumb_order).to match(/Dashboard.*Projects.*#{project.name}.*Edit/) + expect(breadcrumbs.text).to match(/Dashboard.*Projects.*#{project.name}.*Edit/) } end From 6ae446211145c2689d9abe8a5e37f230b8180387 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 17:54:34 +0300 Subject: [PATCH 06/12] last touches --- .../avo/index/resource_controls_component.rb | 6 +++++- .../avo/views/resource_index_component.rb | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/components/avo/index/resource_controls_component.rb b/app/components/avo/index/resource_controls_component.rb index 044e4f6ae5..2fe5b9213e 100644 --- a/app/components/avo/index/resource_controls_component.rb +++ b/app/components/avo/index/resource_controls_component.rb @@ -77,7 +77,11 @@ def parent_resource end def is_has_many_association? - @reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection) + @reflection.class.in? [ + ActiveRecord::Reflection::HasManyReflection, + ActiveRecord::Reflection::HasAndBelongsToManyReflection, + ActiveRecord::Reflection::ThroughReflection + ] end def referrer_path diff --git a/app/components/avo/views/resource_index_component.rb b/app/components/avo/views/resource_index_component.rb index c4a9260fd4..13bc0d6cc7 100644 --- a/app/components/avo/views/resource_index_component.rb +++ b/app/components/avo/views/resource_index_component.rb @@ -62,10 +62,20 @@ def can_see_the_create_button? end def can_attach? - klass = @reflection - klass = @reflection.through_reflection if klass.is_a? ::ActiveRecord::Reflection::ThroughReflection + return false if has_reflection_and_is_read_only - @reflection.present? && klass.is_a?(::ActiveRecord::Reflection::HasManyReflection) && !has_reflection_and_is_read_only && authorize_association_for(:attach) + reflection_class = if @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection) + @reflection.through_reflection.class + else + @reflection.class + end + + return false unless reflection_class.in? [ + ActiveRecord::Reflection::HasManyReflection, + ActiveRecord::Reflection::HasAndBelongsToManyReflection + ] + + authorize_association_for(:attach) end def create_path From 2d9a5b855f08c00591d97565b12e2a6def8c8ff4 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 18:08:46 +0300 Subject: [PATCH 07/12] fix tabs spec --- spec/system/avo/tabs_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/avo/tabs_spec.rb b/spec/system/avo/tabs_spec.rb index 7cdf90f8b5..fe34ef8fed 100644 --- a/spec/system/avo/tabs_spec.rb +++ b/spec/system/avo/tabs_spec.rb @@ -41,7 +41,7 @@ expect(find("turbo-frame#has_and_belongs_to_many_field_show_teams")).to have_text "Teams" expect(find("turbo-frame#has_and_belongs_to_many_field_show_teams")).to have_link "Attach team" - expect(find("turbo-frame#has_and_belongs_to_many_field_show_teams")).to have_link "Create new team", href: "/admin/resources/teams/new?via_relation=users&via_relation_class=User&via_resource_id=#{user.slug}" + expect(find("turbo-frame#has_and_belongs_to_many_field_show_teams")).to have_link "Create new team", href: "/admin/resources/teams/new?via_relation=admin&via_relation_class=User&via_resource_id=#{user.slug}" end it "hides the birthday tab" do From a387761a86062e7ddf8f3091f1852caf92a5a50c Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 18:17:02 +0300 Subject: [PATCH 08/12] fix user <-> team association --- spec/dummy/app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/dummy/app/models/user.rb b/spec/dummy/app/models/user.rb index b03b6f88c4..60cdf6a3d9 100644 --- a/spec/dummy/app/models/user.rb +++ b/spec/dummy/app/models/user.rb @@ -37,7 +37,7 @@ class User < ApplicationRecord has_many :comments has_many :team_memberships has_and_belongs_to_many :projects, inverse_of: :users - has_and_belongs_to_many :teams, join_table: :team_memberships, inverse_of: :admin + has_many :teams, through: :team_memberships, inverse_of: :admin has_one_attached :cv From 8f26ad56d9712c22fed29ea58b56661083a61276 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 18:53:55 +0300 Subject: [PATCH 09/12] appraisal --- gemfiles/rails_6.0_ruby_3.0.3.gemfile.lock | 8 ++++---- gemfiles/rails_6.0_ruby_3.2.2.gemfile.lock | 8 ++++---- gemfiles/rails_6.1_ruby_3.0.3.gemfile.lock | 8 ++++---- gemfiles/rails_6.1_ruby_3.2.2.gemfile.lock | 8 ++++---- gemfiles/rails_7.0_ruby_3.0.3.gemfile.lock | 8 ++++---- gemfiles/rails_7.0_ruby_3.2.2.gemfile.lock | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gemfiles/rails_6.0_ruby_3.0.3.gemfile.lock b/gemfiles/rails_6.0_ruby_3.0.3.gemfile.lock index a5c8423d64..bf9d3f906c 100644 --- a/gemfiles/rails_6.0_ruby_3.0.3.gemfile.lock +++ b/gemfiles/rails_6.0_ruby_3.0.3.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -214,7 +214,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -266,7 +266,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -420,7 +420,7 @@ GEM thread_safe (~> 0.1) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/gemfiles/rails_6.0_ruby_3.2.2.gemfile.lock b/gemfiles/rails_6.0_ruby_3.2.2.gemfile.lock index a5c8423d64..bf9d3f906c 100644 --- a/gemfiles/rails_6.0_ruby_3.2.2.gemfile.lock +++ b/gemfiles/rails_6.0_ruby_3.2.2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -214,7 +214,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -266,7 +266,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -420,7 +420,7 @@ GEM thread_safe (~> 0.1) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/gemfiles/rails_6.1_ruby_3.0.3.gemfile.lock b/gemfiles/rails_6.1_ruby_3.0.3.gemfile.lock index b7a8eed6ca..443e86fc29 100644 --- a/gemfiles/rails_6.1_ruby_3.0.3.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.0.3.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -218,7 +218,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -270,7 +270,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -423,7 +423,7 @@ GEM concurrent-ruby (~> 1.0) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/gemfiles/rails_6.1_ruby_3.2.2.gemfile.lock b/gemfiles/rails_6.1_ruby_3.2.2.gemfile.lock index b7a8eed6ca..443e86fc29 100644 --- a/gemfiles/rails_6.1_ruby_3.2.2.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.2.2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -218,7 +218,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -270,7 +270,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -423,7 +423,7 @@ GEM concurrent-ruby (~> 1.0) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/gemfiles/rails_7.0_ruby_3.0.3.gemfile.lock b/gemfiles/rails_7.0_ruby_3.0.3.gemfile.lock index ca8e0941d2..902b22e325 100644 --- a/gemfiles/rails_7.0_ruby_3.0.3.gemfile.lock +++ b/gemfiles/rails_7.0_ruby_3.0.3.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -224,7 +224,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -276,7 +276,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -429,7 +429,7 @@ GEM concurrent-ruby (~> 1.0) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/gemfiles/rails_7.0_ruby_3.2.2.gemfile.lock b/gemfiles/rails_7.0_ruby_3.2.2.gemfile.lock index ca8e0941d2..902b22e325 100644 --- a/gemfiles/rails_7.0_ruby_3.2.2.gemfile.lock +++ b/gemfiles/rails_7.0_ruby_3.2.2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - avo (2.46.0) + avo (2.52.0) actionview (>= 6.0) active_link_to activerecord (>= 6.0) @@ -224,7 +224,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) iso (0.4.0) @@ -276,7 +276,7 @@ GEM nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (6.0.4) + pagy (6.5.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) @@ -429,7 +429,7 @@ GEM concurrent-ruby (~> 1.0) unaccent (0.4.0) unicode-display_width (2.4.2) - view_component (3.5.0) + view_component (3.14.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) From 5b523572ab5c62e9f8277de569b5fb5ba9ace92e Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 19:31:19 +0300 Subject: [PATCH 10/12] try dashboard_spec fix --- spec/system/avo/dashboards_spec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/system/avo/dashboards_spec.rb b/spec/system/avo/dashboards_spec.rb index 064b536119..6a4985abac 100644 --- a/spec/system/avo/dashboards_spec.rb +++ b/spec/system/avo/dashboards_spec.rb @@ -177,15 +177,12 @@ end describe "card options" do - let(:url) { "/admin/dashboards/dashy" } - - subject { - visit url - page - } + it do + visit "/admin/dashboards/dashy" - it { is_expected.to have_text "Users count" } - it { is_expected.to have_text "Active users metric" } + expect(page).to have_text "Users count" + expect(page).to have_text "Active users metric" + end end end From 57404e525d00845f968e1a7f3eb6aaa7206b2cd4 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 19:48:10 +0300 Subject: [PATCH 11/12] revert dashboards spec --- spec/system/avo/dashboards_spec.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/system/avo/dashboards_spec.rb b/spec/system/avo/dashboards_spec.rb index 6a4985abac..064b536119 100644 --- a/spec/system/avo/dashboards_spec.rb +++ b/spec/system/avo/dashboards_spec.rb @@ -177,12 +177,15 @@ end describe "card options" do - it do - visit "/admin/dashboards/dashy" + let(:url) { "/admin/dashboards/dashy" } - expect(page).to have_text "Users count" - expect(page).to have_text "Active users metric" - end + subject { + visit url + page + } + + it { is_expected.to have_text "Users count" } + it { is_expected.to have_text "Active users metric" } end end From e667e8a77278b87f9380bd2723c21023e9182d0c Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 6 Sep 2024 19:58:57 +0300 Subject: [PATCH 12/12] ensure the content is loaded before making assertions --- spec/system/avo/dashboards_spec.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/spec/system/avo/dashboards_spec.rb b/spec/system/avo/dashboards_spec.rb index 064b536119..b72ae4089f 100644 --- a/spec/system/avo/dashboards_spec.rb +++ b/spec/system/avo/dashboards_spec.rb @@ -8,7 +8,8 @@ it "shows the empty screen" do visit "/admin/dashboards/sales" - content = page.find(".content") + # Ensure the content is loaded before making assertions + content = page.find(".content", wait: 5) expect(content).to have_text "Sales" expect(content).to have_text "Tiny dashboard description" expect(content).to have_text "No cards present" @@ -19,21 +20,19 @@ end describe "dashboard with cards" do - let(:card) { page.find("turbo-frame[id='#{full_card_id}']") } + let(:card) { page.find("turbo-frame[id='#{full_card_id}']", wait: 5) } let(:wait_for_card) { wait_for_turbo_frame_id full_card_id } subject do visit "/admin/dashboards/dashy" - wait_for_card - card end it "shows the dashboard info" do visit "/admin/dashboards/dashy" - content = page.find(".content") + content = page.find(".content", wait: 5) expect(content).to have_text "Dashy" expect(content).to have_text "The first dashbaord" expect(content).not_to have_text "No cards present" @@ -49,7 +48,7 @@ let(:index) { 0 } let(:card_id) { "users_metric" } - let(:card) { page.find("turbo-frame[id='#{full_card_id}'][data-card-index='#{index}']") } + let(:card) { page.find("turbo-frame[id='#{full_card_id}'][data-card-index='#{index}']", wait: 5) } it do is_expected.to have_text "Users count" @@ -73,7 +72,7 @@ let(:index) { 3 } let(:card_id) { "users_metric" } - let(:card) { page.find("turbo-frame[id='#{full_card_id}'][data-card-index='#{index}']") } + let(:card) { page.find("turbo-frame[id='#{full_card_id}'][data-card-index='#{index}']", wait: 5) } it do is_expected.to have_text "Active users metric" @@ -179,10 +178,10 @@ describe "card options" do let(:url) { "/admin/dashboards/dashy" } - subject { + subject do visit url page - } + end it { is_expected.to have_text "Users count" } it { is_expected.to have_text "Active users metric" } @@ -191,10 +190,10 @@ RSpec.describe "Dashboards", type: :feature do describe "dashboards visibility" do - subject { + subject do visit url page - } + end describe "visible dashboard" do let(:url) { "/admin/dashboards/dashy" } @@ -219,5 +218,5 @@ def description_tooltip_has_text(text = "") card.find("[data-target='card-description']").hover - expect(page.find(".tippy-content[data-state='visible']")).to have_text text + expect(page.find(".tippy-content[data-state='visible']", wait: 5)).to have_text text end