Skip to content

Commit

Permalink
Fix bug with prototype page pagination not working for paginate (#804)
Browse files Browse the repository at this point in the history
- Also update various gems and get tests passing
  • Loading branch information
jaredcwhite authored Aug 29, 2023
1 parent ae6e963 commit 237e9e0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 82 deletions.
49 changes: 29 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.6)
activesupport (= 7.0.6)
activesupport (7.0.6)
activemodel (7.0.7.2)
activesupport (= 7.0.7.2)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.4)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
amazing_print (1.5.0)
ansi (1.5.0)
ast (2.4.2)
backport (1.2.0)
base64 (0.1.1)
benchmark (0.2.1)
benchmark-ips (2.12.0)
builder (3.2.4)
Expand Down Expand Up @@ -93,7 +94,7 @@ GEM
docile (1.4.0)
e2mmap (0.1.0)
erubi (1.12.0)
faraday (2.7.9)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
Expand All @@ -110,6 +111,7 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
liquid (5.4.0)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand All @@ -118,29 +120,33 @@ GEM
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
minitest (5.18.1)
mini_portile2 (2.8.4)
minitest (5.19.0)
minitest-profile (0.0.2)
minitest-reporters (1.6.0)
minitest-reporters (1.6.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_test (1.1.0)
nokogiri (1.15.2)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
nokolexbor (0.5.0)
nokolexbor (0.5.0-arm64-darwin)
nokolexbor (0.5.0-x86_64-darwin)
nokolexbor (0.5.0-x86_64-linux)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
public_suffix (5.0.1)
public_suffix (5.0.3)
racc (1.7.1)
rack (3.0.8)
rack-test (2.1.0)
Expand All @@ -154,8 +160,8 @@ GEM
regexp_parser (2.8.1)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.5)
roda (3.69.0)
rexml (3.2.6)
roda (3.71.0)
rack
rouge (3.30.0)
rspec (3.12.0)
Expand All @@ -167,26 +173,28 @@ GEM
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.48.1)
rubocop (1.56.2)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.26.0, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-bridgetown (0.3.2)
rubocop (~> 1.23)
rubocop-performance (~> 1.12)
rubocop-performance (1.18.0)
rubocop-performance (1.19.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.13.0)
Expand Down Expand Up @@ -233,9 +241,10 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
yard (0.9.34)
zeitwerk (2.6.8)
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-22
ruby
x86_64-darwin-21
x86_64-linux
Expand Down
3 changes: 2 additions & 1 deletion bridgetown-core/lib/bridgetown-core/drops/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def fetch(key, default = nil, &block)
return self[key] if key?(key)
raise KeyError, %(key not found: "#{key}") if default.nil? && block.nil?
return yield(key) unless block.nil?
return default unless default.nil?

default unless default.nil?
end

private
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def uri_escape(input)
def obfuscate_link(input, prefix = "mailto")
link = "<a href=\"#{prefix}:#{input}\">#{input}</a>"
script = "<script type=\"text/javascript\">document.currentScript.insertAdjacentHTML('"
script += "beforebegin', '#{rot47(link).gsub(%r!\\!, '\\\\\\')}'.replace(/[!-~]/g," # rubocop:disable Style/StringLiteralsInInterpolation
script += "beforebegin', '#{rot47(link).gsub("\\", '\\\\\\')}'.replace(/[!-~]/g," # rubocop:disable Style/StringLiteralsInInterpolation
script += "function(c){{var j=c.charCodeAt(0);if((j>=33)&&(j<=126)){"
script += "return String.fromCharCode(33+((j+ 14)%94));}"
script += "else{return String.fromCharCode(j);}}}));</script>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ def initialize(prototyped_page, collection, search_term, term) # rubocop:disable
end

def process_prototype_page_data(collection, search_term, term)
pagination_key = prototyped_page.data.key?("paginate") ? "paginate" : "pagination"
# Fill in pagination details to be handled later by Bridgetown::Paginate
data["pagination"] = Bridgetown::Utils.deep_merge_hashes(
prototyped_page.data["pagination"].to_h, {
prototyped_page.data[pagination_key].to_h, {
"enabled" => true,
"collection" => collection,
"where_query" => [search_term, term],
Expand Down
4 changes: 3 additions & 1 deletion bridgetown-core/script/test
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ then
set -x
ruby -S bundle exec ruby -I test \
"test/test_resource.rb"
time BYPASS_RESOURCE_TEST=true SEED=2345 ruby -S bundle exec \
ruby -S bundle exec ruby -I test \
"test/test_ssr.rb"
time BYPASS_RESOURCE_TEST=true ruby -S bundle exec \
rake TESTOPTS=$testopts test
else
set -x
Expand Down
6 changes: 3 additions & 3 deletions bridgetown-core/test/test_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class TestCollections < BridgetownUnitTest
end

should "not include the underscored files in the list of docs" do
refute_includes @collection.resources.map(&:relative_path).map(&:to_s), "_methods/_do_not_read_me.md"
refute_includes @collection.resources.map(&:relative_path).map(&:to_s),
refute_includes @collection.resources.map { _1.relative_path.to_s }, "_methods/_do_not_read_me.md"
refute_includes @collection.resources.map { _1.relative_path.to_s },
"_methods/site/_dont_include_me_either.md"
end
end
Expand Down Expand Up @@ -182,7 +182,7 @@ class TestCollections < BridgetownUnitTest
@site.process
@tutorials_collection = @site.collections["tutorials"]

@actual_array = @tutorials_collection.resources.map(&:relative_path).map(&:to_s)
@actual_array = @tutorials_collection.resources.map { _1.relative_path.to_s }
end

should "sort documents in a collection with 'sort_by' metadata set to a " \
Expand Down
107 changes: 55 additions & 52 deletions bridgetown-core/test/test_ssr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,74 @@
require "rack/test"

class TestSSR < BridgetownUnitTest
include Rack::Test::Methods
# The test suite is more stable when this is run first separately
unless ENV["BYPASS_RESOURCE_TEST"]
include Rack::Test::Methods

def app
@@ssr_app ||= Rack::Builder.parse_file(File.expand_path("ssr/config.ru", __dir__)) # rubocop:disable Style/ClassVars
end

def site
app.opts[:bridgetown_site]
end

context "Roda-powered Bridgetown server" do
setup do
Bridgetown::Current.site = nil
def app
@@ssr_app ||= Rack::Builder.parse_file(File.expand_path("ssr/config.ru", __dir__)) # rubocop:disable Style/ClassVars
end

teardown do
Bridgetown::Current.preloaded_configuration = nil
def site
app.opts[:bridgetown_site]
end

should "return the index page" do
get "/"
assert last_response.ok?
assert_equal "<h1>Index</h1>", last_response.body
end
context "Roda-powered Bridgetown server" do
setup do
Bridgetown::Current.site = nil
end

should "return JSON for the hello route" do
get "/hello/world"
assert last_response.ok?
assert_equal({ hello: "friend world VALUE" }.to_json, last_response.body)
end
teardown do
Bridgetown::Current.preloaded_configuration = nil
end

should "support _method override of POST" do
post "/hello/methods", _method: "put"
assert last_response.ok?
assert_equal({ saved: "methods" }.to_json, last_response.body)
end
should "return the index page" do
get "/"
assert last_response.ok?
assert_equal "<h1>Index</h1>", last_response.body
end

should "preserve site data between live reloads" do
assert_equal 1, site.data.iterations
site.reset(soft: true)
assert_equal 2, site.data.iterations
end
should "return JSON for the hello route" do
get "/hello/world"
assert last_response.ok?
assert_equal({ hello: "friend world VALUE" }.to_json, last_response.body)
end

should "support indifferent cookies" do
post "/cookies", value: "Gookie!"
get "/cookies"
assert last_response.ok?
assert_equal({ value: "Gookie!" }.to_json, last_response.body)
end
should "support _method override of POST" do
post "/hello/methods", _method: "put"
assert last_response.ok?
assert_equal({ saved: "methods" }.to_json, last_response.body)
end

should "support incoming JSON payloads" do
post "/ooh_json", { tell_me: "what you're chasin'" }
assert last_response.ok?
assert_equal({ because_the_night: "will never give you what you want" }.to_json, last_response.body)
end
should "preserve site data between live reloads" do
assert_equal 1, site.data.iterations
site.reset(soft: true)
assert_equal 2, site.data.iterations
end

should "support indifferent cookies" do
post "/cookies", value: "Gookie!"
get "/cookies"
assert last_response.ok?
assert_equal({ value: "Gookie!" }.to_json, last_response.body)
end

should "support incoming JSON payloads" do
post "/ooh_json", { tell_me: "what you're chasin'" }
assert last_response.ok?
assert_equal({ because_the_night: "will never give you what you want" }.to_json, last_response.body)
end

should "support redirecting with helpers" do
site.config.url = "http://test.site"
post "/redirect_me/now"
should "support redirecting with helpers" do
site.config.url = "http://test.site"
post "/redirect_me/now"

refute last_response.ok?
refute last_response.ok?

get last_response["Location"].sub("http://test.site", "")
assert last_response.ok?
assert_equal("Redirected!", last_response.body)
get last_response["Location"].sub("http://test.site", "")
assert last_response.ok?
assert_equal("Redirected!", last_response.body)
end
end
end
end
6 changes: 3 additions & 3 deletions bridgetown-website/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.7)
activesupport (= 7.0.7)
activesupport (7.0.7)
activemodel (7.0.7.2)
activesupport (= 7.0.7.2)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down

0 comments on commit 237e9e0

Please sign in to comment.