Skip to content

Commit ef8c010

Browse files
authored
Merge pull request #3513 from AlchemyCMS/fix-page-filters
fix(page): Add `"page_layout"` to `ransackable_attributes`
2 parents f8b0ba6 + 20c0314 commit ef8c010

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

app/models/alchemy/page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def link_target_options
251251

252252
# Allow all string and text attributes to be searchable by Ransack.
253253
def ransackable_attributes(_auth_object = nil)
254-
searchable_alchemy_resource_attributes + ["updated_at"]
254+
searchable_alchemy_resource_attributes + %w[updated_at page_layout]
255255
end
256256
end
257257

spec/features/admin/page_list_feature_spec.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
end
1313

1414
context "as author" do
15-
let!(:alchemy_page) { create(:alchemy_page, name: "Page 1").tap { |p| p.update!(updated_at: Time.parse("2020-08-20")) } }
16-
let!(:alchemy_page_2) { create(:alchemy_page, name: "Contact", page_layout: "contact").tap { |p| p.update(updated_at: Time.parse("2020-08-24")) } }
15+
let!(:root_page) { create(:alchemy_page, :language_root, :public, name: "Intro") }
16+
let!(:alchemy_page) { create(:alchemy_page, parent: root_page, name: "Page 1").tap { |p| p.update!(updated_at: Time.parse("2020-08-20")) } }
17+
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")) } }
1718
let!(:alchemy_page_3) { create(:alchemy_page, :layoutpage, name: "Footer") }
1819

1920
before do
@@ -87,5 +88,33 @@
8788
expect(page).to_not have_css("tr:nth-child(3)")
8889
end
8990
end
91+
92+
specify "can filter table of pages by date", :js do
93+
root_page.update!(updated_at: Time.parse("2020-08-10"))
94+
Timecop.travel("2020-08-25") do
95+
visit admin_pages_path(view: "list")
96+
page.execute_script <<~JS.strip_heredoc
97+
const fp = document.getElementById("q_updated_at_gteq")._flatpickr;
98+
fp.setDate("2020-08-23 00:00", true);
99+
JS
100+
expect(page).to have_content("1 Page")
101+
within("table.list") do
102+
expect(page.find("tr:nth-child(1) td.name", text: "Contact")).to be
103+
expect(page).to_not have_css("tr:nth-child(2)")
104+
expect(page).to_not have_css("tr:nth-child(3)")
105+
end
106+
end
107+
end
108+
109+
specify "can filter table of pages by page type", :js do
110+
visit admin_pages_path(view: "list")
111+
select2("contact", from: "Page Type")
112+
expect(page).to have_content("1 Page")
113+
within("table.list") do
114+
expect(page.find("tr:nth-child(1) td.name", text: "Contact")).to be
115+
expect(page).to_not have_css("tr:nth-child(2)")
116+
expect(page).to_not have_css("tr:nth-child(3)")
117+
end
118+
end
90119
end
91120
end

spec/models/alchemy/page_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,22 @@ module Alchemy
682682
end
683683
end
684684

685+
describe ".ransackable_attributes" do
686+
let(:auth_object) { double }
687+
688+
subject { described_class.ransackable_attributes(auth_object) }
689+
690+
it do
691+
is_expected.to contain_exactly(
692+
"page_layout",
693+
"updated_at",
694+
"urlname",
695+
"title",
696+
"name"
697+
)
698+
end
699+
end
700+
685701
describe ".ransackable_scopes" do
686702
let(:auth_object) { double }
687703

0 commit comments

Comments
 (0)