-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganization and renaming of test helpers
- Loading branch information
Showing
29 changed files
with
440 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class MockCollection < Array | ||
|
||
def initialize(arr=Array(1..1000)) | ||
super | ||
@collection = self.clone | ||
end | ||
|
||
def offset(value) | ||
@collection = self[value..-1] | ||
self | ||
end | ||
|
||
def limit(value) | ||
@collection[0, value] | ||
end | ||
|
||
def count(*) | ||
size | ||
end | ||
|
||
class Grouped < MockCollection | ||
|
||
def count(*) | ||
Hash[@collection.map { |value| [value, value + 1] }] | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
require_relative 'collection' | ||
|
||
class MockController | ||
include Pagy::Backend | ||
# we ned to explicitly include this because Pagy::Backend | ||
# does not include it when the test loads this module witout the headers | ||
include Pagy::Helpers | ||
|
||
attr_reader :params | ||
|
||
def initialize(params={a: 'a', page: 3}, url='https://example.com:8080/foo?page=3') | ||
@params = params | ||
@url = url | ||
end | ||
|
||
def request | ||
@request ||= Rack::Request.new(Rack::MockRequest.env_for(@url)) | ||
end | ||
|
||
def response | ||
@response ||= Rack::Response.new | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
class MockView | ||
include Pagy::Frontend | ||
|
||
def initialize(url='http://example.com:3000/foo?page=2') | ||
@url = url | ||
end | ||
|
||
def request | ||
Rack::Request.new(Rack::MockRequest.env_for(@url)) | ||
end | ||
|
||
class Overridden < MockView | ||
def pagy_get_params(params) | ||
params.except(:a).merge!(k: 'k') | ||
end | ||
end | ||
end | ||
|
||
|
||
class Hash | ||
def except!(*keys) | ||
keys.each { |key| delete(key) } | ||
self | ||
end | ||
|
||
def except(*keys) | ||
dup.except!(*keys) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.