Skip to content

Commit

Permalink
Merge branch 'fix-unit-test'
Browse files Browse the repository at this point in the history
Closes #522, closes #531, closes #538, fixes #523
  • Loading branch information
mislav committed Jun 7, 2017
2 parents 18626f5 + 7a2da51 commit 8f8a71c
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 62 deletions.
22 changes: 20 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ rvm:
- 1.9.3
- 2.1.8
- 2.2.4
- 2.3.0
- 2.3.4
- 2.4.1
gemfile:
- Gemfile
- Gemfile.rails3.0
- Gemfile.rails3.1
- Gemfile.rails3.2
- Gemfile.rails4.0
- Gemfile.rails4.1
- Gemfile.rails4.2
- Gemfile.rails5.0
Expand All @@ -29,8 +31,18 @@ matrix:
gemfile: Gemfile.rails-edge
- rvm: 2.1.8
gemfile: Gemfile.rails-edge
- rvm: 2.4.1
gemfile: Gemfile.rails3.0
- rvm: 2.4.1
gemfile: Gemfile.rails3.1
- rvm: 2.4.1
gemfile: Gemfile.rails3.2
- rvm: 2.4.1
gemfile: Gemfile.rails4.0
- rvm: 2.4.1
gemfile: Gemfile.rails4.1
- rvm: 1.8.7
gemfile: Gemfile
gemfile: Gemfile.rails4.0
- rvm: 1.8.7
gemfile: Gemfile.rails4.1
- rvm: 1.8.7
Expand All @@ -41,3 +53,9 @@ matrix:
gemfile: Gemfile.rails5.0
- rvm: 2.1.8
gemfile: Gemfile.rails5.0
- rvm: 1.8.7
gemfile: Gemfile
- rvm: 1.9.3
gemfile: Gemfile
- rvm: 2.1.8
gemfile: Gemfile
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
brew 'mongodb', restart_service: true
brew 'mysql56', restart_service: true
brew '[email protected]', restart_service: true
brew 'postgresql', restart_service: true
7 changes: 2 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

rails_version = '~> 4.0.0'
rails_version = '~> 5.1.1'

gem 'activerecord', rails_version
gem 'actionpack', rails_version
Expand All @@ -16,10 +16,7 @@ gem 'dm-migrations'
gem 'dm-sqlite-adapter'
gem 'mongoid'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.3.10'
end
gem 'mysql2', '~> 0.4.6', :group => :mysql
gem 'pg', '~> 0.18.4', :group => :pg

group :development do
Expand Down
5 changes: 1 addition & 4 deletions Gemfile.rails-edge
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ gem 'mocha', '~> 0.9.8'

gem 'sqlite3', '~> 1.3.6'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.3.13'
end
gem 'mysql2', '~> 0.4.6', :group => :mysql
gem 'pg', '~> 0.11', :group => :pg

group :development do
Expand Down
22 changes: 22 additions & 0 deletions Gemfile.rails4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
source 'https://rubygems.org'

rails_version = '~> 4.0.13'

gem 'activerecord', rails_version
gem 'actionpack', rails_version

gem 'rspec', '~> 2.6.0'
gem 'mocha', '~> 0.9.8'

gem 'sqlite3', '~> 1.3.6'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.4.6'
end
gem 'pg', '~> 0.18.4', :group => :pg

group :development do
gem 'ruby-debug', :platforms => :mri_18
gem 'debugger', :platforms => :mri_19
end
4 changes: 2 additions & 2 deletions Gemfile.rails4.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

rails_version = '~> 4.1.2'
rails_version = '~> 4.1.16'

gem 'activerecord', rails_version
gem 'actionpack', rails_version
Expand All @@ -12,7 +12,7 @@ gem 'sqlite3', '~> 1.3.6'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.3.10'
gem 'mysql2', '~> 0.4.6'
end
gem 'pg', '~> 0.18.4', :group => :pg

Expand Down
8 changes: 3 additions & 5 deletions Gemfile.rails4.2
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
source 'https://rubygems.org'

rails_version = '~> 4.2.5'
rails_version = '~> 4.2.8'

gem 'activerecord', rails_version
gem 'actionpack', rails_version
gem 'rails-dom-testing'
gem 'nokogiri', '~> 1.6.8'

gem 'rspec', '~> 2.6.0'
gem 'mocha', '~> 0.9.8'

gem 'sqlite3', '~> 1.3.6'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.3.10'
end
gem 'mysql2', '~> 0.4.6', :group => :mysql
gem 'pg', '~> 0.18.4', :group => :pg

group :development do
Expand Down
7 changes: 2 additions & 5 deletions Gemfile.rails5.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

rails_version = '~> 5.0.0.beta1'
rails_version = '~> 5.0.3'

gem 'activerecord', rails_version
gem 'actionpack', rails_version
Expand All @@ -11,10 +11,7 @@ gem 'mocha', '~> 0.9.8'

gem 'sqlite3', '~> 1.3.6'

group :mysql do
gem 'mysql', '~> 2.9'
gem 'mysql2', '~> 0.3.10'
end
gem 'mysql2', '~> 0.4.6', :group => :mysql
gem 'pg', '~> 0.11', :group => :pg

group :development do
Expand Down
2 changes: 1 addition & 1 deletion lib/will_paginate/page_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def kind_of?(klass)
alias is_a? kind_of?
end

# Ultrahax: makes `Fixnum === current_page` checks pass
# Ultrahax: makes `Integer === current_page` checks pass
Numeric.extend Module.new {
def ===(obj)
obj.instance_of? PageNumber or super
Expand Down
4 changes: 2 additions & 2 deletions lib/will_paginate/view_helpers/link_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def prepare(collection, options, template)
# method as you see fit.
def to_html
html = pagination.map do |item|
item.is_a?(Fixnum) ?
item.is_a?(Integer) ?
page_number(item) :
send(item)
end.join(@options[:link_separator])
Expand Down Expand Up @@ -88,7 +88,7 @@ def param_name
end

def link(text, target, attributes = {})
if target.is_a? Fixnum
if target.is_a?(Integer)
attributes[:rel] = rel_value(target)
target = url(target)
end
Expand Down
13 changes: 8 additions & 5 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# vi:ft=sh:
set -e

brew bundle
if type -p brew >/dev/null; then
brew bundle --no-upgrade
export PATH="$(brew --prefix [email protected])/bin:$PATH"

while [ ! -e /tmp/mysql.sock ] && [ ! -e /var/run/mysql5/mysqld.sock ]; do
echo "Waiting for mysql to start up ..." >&2
sleep 1
done
while [ ! -e /tmp/mysql.sock ] && [ ! -e /var/run/mysql5/mysqld.sock ]; do
echo "Waiting for mysql to start up ..." >&2
sleep 1
done
fi

mysql -u root -e 'CREATE DATABASE IF NOT EXISTS will_paginate;'
psql --dbname will_paginate -c '' 2>/dev/null || createdb will_paginate
Expand Down
6 changes: 5 additions & 1 deletion script/test_all
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ export PATH="${PWD}/bin:$PATH"

rails_version="$(ruby -rubygems -e 'require "bundler"; puts Bundler.load.specs.find {|s| s.name == "activerecord" }.version')"

if [[ -n "$BUNDLE_GEMFILE" && "${BUNDLE_GEMFILE##*/}" != Gemfile ]]; then
export SKIP_NONRAILS_TESTS=1
fi

for db in sqlite3 mysql mysql2 postgres; do
[[ "$rails_version" = 3.0 && $db = "mysql2" ]] && continue
[[ "$rails_version" > 5.0 && $db = "mysql" ]] && continue
[[ "$rails_version" > 4.2 && $db = "mysql" ]] && continue

printf "\e[1;33m[DB] %s\e[m\n" "$db"
spec_files="spec"
Expand Down
2 changes: 1 addition & 1 deletion spec/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sqlite3:
mysql: &mysql
adapter: mysql
database: will_paginate
username:
username: root
encoding: utf8
<% if File.exist?("/var/run/mysql5/mysqld.sock") %>
host: localhost
Expand Down
1 change: 0 additions & 1 deletion spec/finders/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require File.expand_path('../activerecord_test_connector', __FILE__)

ActiverecordTestConnector.setup
abort unless ActiverecordTestConnector.able_to_connect

describe WillPaginate::ActiveRecord do

Expand Down
7 changes: 1 addition & 6 deletions spec/finders/activerecord_test_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def to_datetime
module ActiverecordTestConnector
extend self

attr_accessor :able_to_connect
attr_accessor :connected

FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
Expand All @@ -49,18 +48,14 @@ module ActiverecordTestConnector

# Set our defaults
self.connected = false
self.able_to_connect = true

def setup
unless self.connected || !self.able_to_connect
unless self.connected
setup_connection
load_schema
add_load_path FIXTURES_PATH
self.connected = true
end
rescue Exception => e # errors from ActiveRecord setup
$stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
self.able_to_connect = false
end

private
Expand Down
8 changes: 3 additions & 5 deletions spec/finders/data_mapper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require 'spec_helper'

begin
if !ENV['SKIP_NONRAILS_TESTS']
require 'will_paginate/data_mapper'
require File.expand_path('../data_mapper_test_connector', __FILE__)
rescue LoadError => error
warn "Error running DataMapper specs: #{error.message}"
datamapper_loaded = false
else
datamapper_loaded = true
else
datamapper_loaded = false
end

describe WillPaginate::DataMapper do
Expand Down
17 changes: 11 additions & 6 deletions spec/finders/mongoid_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
require 'spec_helper'

begin
if !ENV['SKIP_NONRAILS_TESTS']
if defined?(Rails)
old_rails = Rails
# Mongoid sees the `Rails` constant and then proceeds to `require "rails"`
# from its railtie. This tricks it into believing there is no Rails.
Object.send(:remove_const, :Rails)
end
require 'will_paginate/mongoid'
rescue LoadError => error
warn "Error running Mongoid specs: #{error.message}"
mongoid_loaded = false
else
Mongoid.connect_to 'will_paginate_test'
Object.send(:const_set, :Rails, old_rails) if old_rails

Mongoid.connect_to 'will_paginate_test'
class MongoidModel
include Mongoid::Document
end

mongoid_loaded = true
else
mongoid_loaded = false
end

describe WillPaginate::Mongoid do
Expand Down
8 changes: 3 additions & 5 deletions spec/finders/sequel_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require 'spec_helper'

begin
if !ENV['SKIP_NONRAILS_TESTS']
require 'will_paginate/sequel'
require File.expand_path('../sequel_test_connector', __FILE__)
rescue LoadError, ArgumentError => error
warn "Error running Sequel specs: #{error.message}"
sequel_loaded = false
else
sequel_loaded = true
else
sequel_loaded = false
end

describe Sequel::Dataset::Pagination, 'extension' do
Expand Down
10 changes: 5 additions & 5 deletions spec/page_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def num
(num.is_a? Numeric).should be
end

it "is a kind of Fixnum" do
(num.is_a? Fixnum).should be
it "is a kind of Integer" do
(num.is_a? Integer).should be
end

it "isn't directly a Fixnum" do
(num.instance_of? Fixnum).should_not be
it "isn't directly a Integer" do
(num.instance_of? Integer).should_not be

This comment has been minimized.

Copy link
@marksiemers

marksiemers Jun 8, 2017

@mislav
This could give a false passing test in ruby < 2.4:

# ruby 1.9.3-p551, ruby 2.3.4
1.instance_of? Integer #=> false
1.instance_of? Fixnum #=> true

# ruby 2.4.0
1.instance_of? Integer => true
1.instance_of? Fixnum => true
warning: constant ::Fixnum is deprecated

I feel like this test can be removed, since you are testing:

it "is a PageNumber" do
  (num.instance_of? WillPaginate::PageNumber).should be
end

This comment has been minimized.

Copy link
@mislav

mislav Jun 8, 2017

Author Owner

Good point! You are welcome to submit a PR that removes the test. 👍

end

it "passes the PageNumber=== type check" do |variable|
Expand All @@ -37,7 +37,7 @@ def num

it "passes the Numeric=== type check" do |variable|
(Numeric === num).should be
(Fixnum === num).should be
(Integer === num).should be
end
end

Expand Down

0 comments on commit 8f8a71c

Please sign in to comment.