Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 31 additions & 2 deletions spec/features/admin/page_list_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down