Skip to content

Commit

Permalink
fix for different handling of module prepend in ruby <3
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 8, 2021
1 parent d6d71a5 commit 001f22f
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/pagy/extras/standalone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
"#{url_string}#{query_string}#{p_vars[:fragment]}"
end
end
Helpers.prepend UseStandaloneExtra

# single line in order to avoid complicating simplecov already tested with other GitHub Actions
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') \
&& Helpers.prepend(UseStandaloneExtra) \
|| ( Frontend.prepend(UseStandaloneExtra); Backend.prepend(UseStandaloneExtra) if defined?(Pagy::Backend::METADATA) ) # rubocop:disable Style/Semicolon

# defines a dummy #params method if not already defined in the including module
module Backend
Expand Down
103 changes: 103 additions & 0 deletions pagy-on-docker/docker-compose-backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Basic pagy-on-docker development environment
# it will keep the installed gems and HOME in the pagy_bundle and pagy_user_home pagy-on-docker volumes
# the pagy-jekill service will be updating a live preview for the docs

# USAGE
# cd pagy-on-docker
# docker-compose up pagy # only pagy service (running ruby development and test environment)
# docker-compose up pagy-jekyll # pagy and pagy-jekyll services (add the docs live site)
# docker-compose up pagy-cyress # pagy and pagy-cyress services (run the e2e tests and exit)

version: "3.8"

services:

# ruby dev and test pagy development
# It also runs a minimal sinatra app at http://0.0.0.0:8080
pagy:
image: pagy:4-backport
build:
context: .
dockerfile: pagy-backport.dockerfile
# set env variables with your user info
args:
user: $USER
group: $GROUP
uid: $UID
gid: $GID
password: "${PASSWORD:-rubydev}"
term: ${TERM:-xterm-256color}
container_name: pagy
volumes:
- ../.:/opt/project
- bundle:/usr/local/bundle
- user_home:/home/$USER
environment:
- COVERAGE_REPORT
stdin_open: true
tty: true

# Serve the docs site live at http://0.0.0.0:4000
# Use it to check/edit the rendered content in the docs dir
pagy-jekyll:
depends_on:
- pagy
image: pagy-jekyll:latest
build:
context: .
dockerfile: pagy-jekyll.dockerfile
container_name: pagy-jekyll
environment:
- JEKYLL_GITHUB_TOKEN
ports:
- "4000:4000"
- "35729:35729"
volumes:
- ../docs:/opt/docs
- docs_site:/opt/site
command: |
jekyll serve \
--incremental \
--livereload \
--watch \
--force-polling \
--host 0.0.0.0 \
--baseurl '' \
--source /opt/docs \
--destination /opt/site
stdin_open: true
tty: true

# you may want skip this service when you run the docker-compose.yml file
# and run it only on demand to run the tests and exit, or to interact with cypress
# using the additional open-cypress.yml (see the comments in the open-cypress.yml file)
# IMPORTANT: pick the build.dockerfile entry according to your UID
pagy-cypress:
depends_on:
- pagy
image: pagy-cypress:latest
build:
context: .
# switch between the following 2 lines if your user id is 1000 or not
dockerfile: pagy-cypress-uid1000.dockerfile
# dockerfile: pagy-cypress.dockerfile
args:
user: $USER
group: $GROUP
uid: $UID
gid: $GID
container_name: pagy-cypress
environment:
- CYPRESS_baseUrl=http://pagy:4567
working_dir: /test/e2e
volumes:
- ../test/e2e:/test/e2e

volumes:
bundle:
name: pagy_backport_bundle
user_home:
name: pagy_backport_user_home
docs_site:
name: pagy_docs_site

55 changes: 55 additions & 0 deletions pagy-on-docker/pagy-backport.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM ruby:2.7

ARG term
ENV TERM="${term:-xterm-256color}"

# install required packages
RUN apt-get update && apt-get install -y locales \
&& sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen \
&& locale-gen \
&& apt-get install -y \
nodejs \
git \
nano

ARG user
ARG group
ARG uid
ARG gid
ARG password=rubydev

# setup users and .bashrc
# - same pasword for user and root
# - color prompt for user and root
RUN groupadd --gid=$gid --force $group \
&& useradd --uid=$uid --gid=$gid --shell=/bin/bash --create-home $user \
&& echo $user:$password | chpasswd \
&& echo root:$password | chpasswd \
&& sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' /home/$user/.bashrc \
&& sed -i 's/\\u@\\h\\\[\\033\[00m\\\]:\\\[\\033\[01;34m\\\]\\w\\\[\\033\[00m\\\]/\\u \\\[\\033\[01;34m\\\]\\w\\\[\\033\[00m\\\] /' /home/$user/.bashrc \
&& cp /home/$user/.bashrc /root/.bashrc

ENV \
BUNDLE_PATH=/usr/local/bundle \
GEM_HOME=/usr/local/bundle \
BUNDLE_APP_CONFIG=/usr/local/bundle \
BUNDLE_BIN=/usr/local/bundle/bin \
BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_CACHE_ALL=1 \
LS_OPTIONS='--color=auto' \
EDITOR=nano \
TERM=${term:-xterm-256color} \
SHELL=/bin/bash \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
LC_ALL=en_US.UTF-8

RUN chown -R $uid:$gid $BUNDLE_PATH

WORKDIR /opt/project

VOLUME \
/home/$user \
$BUNDLE_PATH

USER $user
1 change: 1 addition & 0 deletions test/pagy/extras/bootstrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/bootstrap'

describe 'pagy/extras/bootstrap' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_bootstrap_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/bulma_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/bulma'

describe 'pagy/extras/bulma' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_bulma_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/foundation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/foundation'

describe 'pagy/extras/foundation' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_foundation_nav' do
Expand Down
17 changes: 6 additions & 11 deletions test/pagy/extras/headers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,23 @@
end
it 'returns the full headers hash' do
pagy, _records = @controller.send(:pagy, @collection)
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"3", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
end
it 'returns custom headers hash' do
pagy, _records = @controller.send(:pagy, @collection, headers:{items:'Per-Page', count: 'Total', pages:false})
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Per-Page"=>"20", "Total"=>"1000"})
end
it 'returns the countless headers hash' do
pagy, _records = @controller.send(:pagy_countless, @collection)
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\"", "Current-Page"=>"3", "Page-Items"=>"20"})
end
it 'omit prev on first page' do
pagy, _records = @controller.send(:pagy, @collection, page: 1)
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"1", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
end
it 'omit next on last page' do
pagy, _records = @controller.send(:pagy, @collection, page: 50)
_(@controller.send(:pagy_headers, pagy)).must_rematch
_(@controller.send(:pagy_headers_hash, pagy)).must_rematch
_(@controller.send(:pagy_headers, pagy)).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=49>; rel=\"prev\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"50", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
end
end

Expand All @@ -46,7 +41,7 @@
it 'returns the full headers hash' do
pagy, _records = @controller.send(:pagy, @collection)
@controller.send(:pagy_headers_merge, pagy)
_(@controller.send(:response).headers).must_rematch
_(@controller.send(:response).headers).must_equal({"Link"=>"<https://example.com:8080/foo?page=1>; rel=\"first\", <https://example.com:8080/foo?page=2>; rel=\"prev\", <https://example.com:8080/foo?page=4>; rel=\"next\", <https://example.com:8080/foo?page=50>; rel=\"last\"", "Current-Page"=>"3", "Page-Items"=>"20", "Total-Pages"=>"50", "Total-Count"=>"1000"})
end
end
end
1 change: 1 addition & 0 deletions test/pagy/extras/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'pagy/extras/i18n'

describe 'pagy/extras/i18n' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_t with I18n' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/items_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_items_vars_params(items, vars, params)
end

describe 'view_methods' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_url_for' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/items_trim_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'pagy/extras/trim'

describe 'pagy/extras/items_trim' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new('http://example.com:3000/foo?') }

describe '#pagy_marked_link' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/materialize_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/materialize'

describe 'pagy/extras/materialize' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_materialize_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/navs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/navs'

describe 'pagy/extras/navs' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_nav_js' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/semantic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/semantic'

describe 'pagy/extras/semantic' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_semantic_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/shared_json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/shared'

describe 'pagy/extras/shared_json' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new('http://example.com:3000/foo?') }

describe '#pagy_json_attr' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/shared_oj_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'pagy/extras/shared'

describe 'pagy/extras/shared_oj' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new('http://example.com:3000/foo?') }

describe '#pagy_json_attr' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/standalone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def params
end

describe 'pagy/extras/standalone' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe 'defines #params if missing' do
Expand Down
3 changes: 2 additions & 1 deletion test/pagy/extras/support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'pagy/countless'

describe 'pagy/extras/support' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_prev_url' do
Expand Down Expand Up @@ -70,7 +71,7 @@
_(view.pagy_prev_link(pagy, text: 'PREV', link_extra: 'link-extra')).must_rematch
_(view.pagy_prev_link(pagy_countless, text: 'PREV', link_extra: 'link-extra')).must_rematch
end

it 'renders the prev link for page 3' do
pagy = Pagy.new count: 1000, page: 3
pagy_countless = Pagy::Countless.new(page: 3).finalize(21)
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/trim_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative '../../test_helper'
require 'pagy/extras/trim'

require_relative '../../mock_helpers/view'
describe 'pagy/extras/trim' do

describe '#pagy_link_proc' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/uikit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/uikit'

describe 'pagy/extras/uikit' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_uikit_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/frontend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative '../test_helper'

require_relative '../mock_helpers/view'
describe 'pagy/frontend' do
let(:view) { MockView.new }

Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

require 'pagy/countless'
require 'rack'
require_relative 'mock_helpers/view'
require_relative 'mock_helpers/controller'
require 'minitest/autorun'

0 comments on commit 001f22f

Please sign in to comment.