diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index a874f010f4..4d76c9c576 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -251,7 +251,7 @@ def link_target_options # Allow all string and text attributes to be searchable by Ransack. def ransackable_attributes(_auth_object = nil) - searchable_alchemy_resource_attributes + ["updated_at"] + searchable_alchemy_resource_attributes + %w[updated_at page_layout] end end diff --git a/spec/features/admin/page_list_feature_spec.rb b/spec/features/admin/page_list_feature_spec.rb index c666d19595..0c9b87a51d 100644 --- a/spec/features/admin/page_list_feature_spec.rb +++ b/spec/features/admin/page_list_feature_spec.rb @@ -12,8 +12,9 @@ end context "as author" do - let!(:alchemy_page) { create(:alchemy_page, name: "Page 1").tap { |p| p.update!(updated_at: Time.parse("2020-08-20")) } } - let!(:alchemy_page_2) { create(:alchemy_page, name: "Contact", page_layout: "contact").tap { |p| p.update(updated_at: Time.parse("2020-08-24")) } } + let!(:root_page) { create(:alchemy_page, :language_root, :public, name: "Intro") } + let!(:alchemy_page) { create(:alchemy_page, parent: root_page, name: "Page 1").tap { |p| p.update!(updated_at: Time.parse("2020-08-20")) } } + let!(:alchemy_page_2) { create(:alchemy_page, parent: root_page, name: "Contact", page_layout: "contact").tap { |p| p.update(updated_at: Time.parse("2020-08-24")) } } let!(:alchemy_page_3) { create(:alchemy_page, :layoutpage, name: "Footer") } before do @@ -87,5 +88,33 @@ expect(page).to_not have_css("tr:nth-child(3)") end end + + specify "can filter table of pages by date", :js do + root_page.update!(updated_at: Time.parse("2020-08-10")) + Timecop.travel("2020-08-25") do + visit admin_pages_path(view: "list") + page.execute_script <<~JS.strip_heredoc + const fp = document.getElementById("q_updated_at_gteq")._flatpickr; + fp.setDate("2020-08-23 00:00", true); + JS + expect(page).to have_content("1 Page") + within("table.list") do + expect(page.find("tr:nth-child(1) td.name", text: "Contact")).to be + expect(page).to_not have_css("tr:nth-child(2)") + expect(page).to_not have_css("tr:nth-child(3)") + end + end + end + + specify "can filter table of pages by page type", :js do + visit admin_pages_path(view: "list") + select2("contact", from: "Page Type") + expect(page).to have_content("1 Page") + within("table.list") do + expect(page.find("tr:nth-child(1) td.name", text: "Contact")).to be + expect(page).to_not have_css("tr:nth-child(2)") + expect(page).to_not have_css("tr:nth-child(3)") + end + end end end diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index b9aa990d49..98a2ef62a8 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -682,6 +682,22 @@ module Alchemy end end + describe ".ransackable_attributes" do + let(:auth_object) { double } + + subject { described_class.ransackable_attributes(auth_object) } + + it do + is_expected.to contain_exactly( + "page_layout", + "updated_at", + "urlname", + "title", + "name" + ) + end + end + describe ".ransackable_scopes" do let(:auth_object) { double }