will_paginate 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b4a394317f67e89d1bea01f567721310ee8a13c
4
+ data.tar.gz: db08d65616e1e1f62e3cc8ec0da17703bd78dd3c
5
+ SHA512:
6
+ metadata.gz: 6cbe6fabc2c9b57da7d9df6fa8408b0c9ff471a8c956db8af8a1d82e0430fd8cae1f89cc9898a5e9796288f411ae76fca939c3ec77647c6179c8f2c61b699847
7
+ data.tar.gz: f58e6d478a08ea4c24494886d4d623b9f6ff2a2dca2c56d9261325179d8d4598426c20ebe947f8b8d6838cd90347a43e84396b1e367d10981b426eec2fb7b980
data/README.md CHANGED
@@ -5,8 +5,8 @@ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatr
5
5
  Installation:
6
6
 
7
7
  ``` ruby
8
- ## Gemfile for Rails 3, Sinatra, and Merb
9
- gem 'will_paginate', '~> 3.0'
8
+ ## Gemfile for Rails 3+, Sinatra, and Merb
9
+ gem 'will_paginate', '~> 3.0.6'
10
10
  ```
11
11
 
12
12
  See [installation instructions][install] on the wiki for more info.
@@ -2,6 +2,11 @@ require 'will_paginate/per_page'
2
2
  require 'will_paginate/page_number'
3
3
  require 'will_paginate/collection'
4
4
  require 'active_record'
5
+ begin
6
+ require 'active_record/deprecated_finders'
7
+ rescue LoadError
8
+ # only for Rails 4.1
9
+ end
5
10
 
6
11
  module WillPaginate
7
12
  # = Paginating finders for ActiveRecord models
@@ -78,16 +83,16 @@ module WillPaginate
78
83
  end
79
84
  end
80
85
 
81
- def count
86
+ def count(*args)
82
87
  if limit_value
83
88
  excluded = [:order, :limit, :offset, :reorder]
84
89
  excluded << :includes unless eager_loading?
85
90
  rel = self.except(*excluded)
86
91
  # TODO: hack. decide whether to keep
87
92
  rel = rel.apply_finder_options(@wp_count_options) if defined? @wp_count_options
88
- rel.count
93
+ rel.count(*args)
89
94
  else
90
- super
95
+ super(*args)
91
96
  end
92
97
  end
93
98
 
@@ -2,7 +2,7 @@ module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/database.yml CHANGED
@@ -8,15 +8,18 @@ mysql:
8
8
  database: will_paginate
9
9
  username:
10
10
  encoding: utf8
11
+ socket: <%= ENV["BOXEN_MYSQL_SOCKET"] %>
11
12
 
12
13
  mysql2:
13
14
  adapter: mysql2
14
15
  database: will_paginate
15
16
  username:
16
17
  encoding: utf8
18
+ socket: <%= ENV["BOXEN_MYSQL_SOCKET"] %>
17
19
 
18
20
  postgres:
19
21
  adapter: postgresql
20
22
  database: will_paginate
21
- username: postgres
23
+ username: <%= "postgres" if ENV["TRAVIS"] %>
22
24
  min_messages: warning
25
+ port: <%= ENV["BOXEN_POSTGRESQL_PORT"] %>
@@ -191,6 +191,7 @@ describe WillPaginate::ActiveRecord do
191
191
  it "keeps :include for count when they are referenced in :conditions" do
192
192
  developers = Developer.paginate(:page => 1, :per_page => 1).includes(:projects)
193
193
  with_condition = developers.where('projects.id > 1')
194
+ with_condition = with_condition.references(:projects) if with_condition.respond_to?(:references)
194
195
  with_condition.total_entries.should == 1
195
196
 
196
197
  $query_sql.last.should =~ /\bJOIN\b/
@@ -304,13 +305,16 @@ describe WillPaginate::ActiveRecord do
304
305
  end
305
306
 
306
307
  it "should paginate with :include and :conditions" do
307
- result = Topic.paginate \
308
+ klass = Topic
309
+ klass = klass.references(:replies) if klass.respond_to?(:references)
310
+
311
+ result = klass.paginate \
308
312
  :page => 1,
309
313
  :include => :replies,
310
314
  :conditions => "replies.content LIKE 'Bird%' ",
311
315
  :per_page => 10
312
316
 
313
- expected = Topic.find :all,
317
+ expected = klass.find :all,
314
318
  :include => 'replies',
315
319
  :conditions => "replies.content LIKE 'Bird%' ",
316
320
  :limit => 10
@@ -339,13 +343,19 @@ describe WillPaginate::ActiveRecord do
339
343
  it "should paginate with include" do
340
344
  project = projects(:active_record)
341
345
 
342
- result = project.topics.paginate \
346
+ topics = project.topics
347
+ topics = topics.references(:replies) if topics.respond_to?(:references)
348
+
349
+ result = topics.paginate \
343
350
  :page => 1,
344
351
  :include => :replies,
345
352
  :conditions => ["replies.content LIKE ?", 'Nice%'],
346
353
  :per_page => 10
347
354
 
348
- expected = Topic.find :all,
355
+ topics = Topic
356
+ topics = topics.references(:replies) if topics.respond_to?(:references)
357
+
358
+ expected = topics.find :all,
349
359
  :include => 'replies',
350
360
  :conditions => ["project_id = ? AND replies.content LIKE ?", project.id, 'Nice%'],
351
361
  :limit => 10
@@ -360,8 +370,10 @@ describe WillPaginate::ActiveRecord do
360
370
 
361
371
  lambda {
362
372
  # with association-specified order
363
- result = ignore_deprecation { dhh.projects.paginate(:page => 1) }
364
- result.should == expected_name_ordered
373
+ result = ignore_deprecation {
374
+ dhh.projects.includes(:topics).paginate(:page => 1, :order => 'projects.name')
375
+ }
376
+ result.to_a.should == expected_name_ordered
365
377
  result.total_entries.should == 2
366
378
  }.should run_queries(2)
367
379
 
@@ -1,6 +1,8 @@
1
1
  require 'active_record'
2
2
  require 'active_record/fixtures'
3
3
  require 'active_support/multibyte' # needed for Ruby 1.9.1
4
+ require 'stringio'
5
+ require 'erb'
4
6
 
5
7
  $query_count = 0
6
8
  $query_sql = []
@@ -9,7 +11,7 @@ ignore_sql = /
9
11
  ^(
10
12
  PRAGMA | SHOW\ max_identifier_length |
11
13
  SELECT\ (currval|CAST|@@IDENTITY|@@ROWCOUNT) |
12
- SHOW\ (FIELDS|TABLES)
14
+ SHOW\ ((FULL\ )?FIELDS|TABLES)
13
15
  )\b |
14
16
  \bFROM\ (sqlite_master|pg_tables|pg_attribute)\b
15
17
  /x
@@ -59,8 +61,9 @@ module ActiverecordTestConnector
59
61
 
60
62
  def setup_connection
61
63
  db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
62
-
63
- configurations = YAML.load_file(File.expand_path('../../database.yml', __FILE__))
64
+
65
+ erb = ERB.new(File.read(File.expand_path('../../database.yml', __FILE__)))
66
+ configurations = YAML.load(erb.result)
64
67
  raise "no configuration for '#{db}'" unless configurations.key? db
65
68
  configuration = configurations[db]
66
69
 
@@ -68,17 +71,17 @@ module ActiverecordTestConnector
68
71
  puts "using #{configuration['adapter']} adapter"
69
72
 
70
73
  ActiveRecord::Base.configurations = { db => configuration }
71
- ActiveRecord::Base.establish_connection(db)
74
+ ActiveRecord::Base.establish_connection(db.to_sym)
72
75
  ActiveRecord::Base.default_timezone = :utc
73
76
  end
74
77
 
75
78
  def load_schema
76
- silencer = ActiveRecord::Base.method(:silence)
77
- silence_args = []
78
- silence_args << :stdout if silencer.arity != 0
79
- silencer.call(*silence_args) do
79
+ begin
80
+ $stdout = StringIO.new
80
81
  ActiveRecord::Migration.verbose = false
81
82
  load File.join(FIXTURES_PATH, 'schema.rb')
83
+ ensure
84
+ $stdout = STDOUT
82
85
  end
83
86
  end
84
87
 
@@ -1,8 +1,9 @@
1
1
  class Developer < User
2
- has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name', :join_table => 'developers_projects'
2
+ has_and_belongs_to_many :projects, :order => 'projects.name', :join_table => 'developers_projects'
3
3
 
4
4
  def self.with_poor_ones(&block)
5
- with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
5
+ options = { :conditions => ['salary <= ?', 80000], :order => 'salary' }
6
+ with_scope({ :find => options }, :overwrite) do
6
7
  yield
7
8
  end
8
9
  end
@@ -7,9 +7,7 @@ class Project < ActiveRecord::Base
7
7
 
8
8
  has_many :replies, :through => :topics do
9
9
  def only_recent(params = {})
10
- scoped.where(['replies.created_at > ?', 15.minutes.ago])
10
+ where(['replies.created_at > ?', 15.minutes.ago])
11
11
  end
12
12
  end
13
-
14
- has_many :unique_replies, :through => :topics, :source => :replies, :uniq => true
15
13
  end
@@ -1,6 +1,4 @@
1
1
  class Reply < ActiveRecord::Base
2
- belongs_to :topic, :include => [:replies]
3
-
4
2
  scope :recent, lambda {
5
3
  where(['replies.created_at > ?', 15.minutes.ago]).
6
4
  order('replies.created_at DESC')
@@ -1,11 +1,8 @@
1
1
  class Topic < ActiveRecord::Base
2
- has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
2
+ has_many :replies, :dependent => :destroy
3
3
  belongs_to :project
4
4
 
5
5
  scope :mentions_activerecord, lambda {
6
6
  where(['topics.title LIKE ?', '%ActiveRecord%'])
7
7
  }
8
- scope :distinct, lambda {
9
- select("DISTINCT #{table_name}.*")
10
- }
11
8
  end
@@ -0,0 +1,27 @@
1
+ require 'stringio'
2
+
3
+ class DeprecationMatcher
4
+ def initialize(message)
5
+ @message = message
6
+ end
7
+
8
+ def matches?(block)
9
+ @actual = hijack_stderr(&block)
10
+ PhraseMatcher.new("DEPRECATION WARNING: #{@message}").matches?(@actual)
11
+ end
12
+
13
+ def failure_message
14
+ "expected deprecation warning #{@message.inspect}, got #{@actual.inspect}"
15
+ end
16
+
17
+ private
18
+
19
+ def hijack_stderr
20
+ err = $stderr
21
+ $stderr = StringIO.new
22
+ yield
23
+ $stderr.string.rstrip
24
+ ensure
25
+ $stderr = err
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ class PhraseMatcher
2
+ def initialize(string)
3
+ @string = string
4
+ @pattern = /\b#{Regexp.escape string}\b/
5
+ end
6
+
7
+ def matches?(actual)
8
+ @actual = actual.to_s
9
+ @actual =~ @pattern
10
+ end
11
+
12
+ def failure_message
13
+ "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
14
+ end
15
+
16
+ def negative_failure_message
17
+ "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ class QueryCountMatcher
2
+ def initialize(num)
3
+ @expected_count = num
4
+ end
5
+
6
+ def matches?(block)
7
+ run(block)
8
+
9
+ if @expected_count.respond_to? :include?
10
+ @expected_count.include? @count
11
+ else
12
+ @count == @expected_count
13
+ end
14
+ end
15
+
16
+ def run(block)
17
+ $query_count = 0
18
+ $query_sql = []
19
+ block.call
20
+ ensure
21
+ @queries = $query_sql.dup
22
+ @count = $query_count
23
+ end
24
+
25
+ def performed_queries
26
+ @queries
27
+ end
28
+
29
+ def failure_message
30
+ "expected #{@expected_count} queries, got #{@count}\n#{@queries.join("\n")}"
31
+ end
32
+
33
+ def negative_failure_message
34
+ "expected query count not to be #{@expected_count}"
35
+ end
36
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,8 @@ rescue LoadError
6
6
  # no debugger available
7
7
  end
8
8
 
9
+ Dir[File.expand_path('../matchers/*_matcher.rb', __FILE__)].each { |matcher| require matcher }
10
+
9
11
  RSpec.configure do |config|
10
12
  config.include Module.new {
11
13
  protected
@@ -22,51 +24,3 @@ RSpec.configure do |config|
22
24
  config.mock_with :mocha
23
25
  config.backtrace_clean_patterns << /view_example_group/
24
26
  end
25
-
26
- class PhraseMatcher
27
- def initialize(string)
28
- @string = string
29
- @pattern = /\b#{Regexp.escape string}\b/
30
- end
31
-
32
- def matches?(actual)
33
- @actual = actual.to_s
34
- @actual =~ @pattern
35
- end
36
-
37
- def failure_message
38
- "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
39
- end
40
-
41
- def negative_failure_message
42
- "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
43
- end
44
- end
45
-
46
- require 'stringio'
47
-
48
- class DeprecationMatcher
49
- def initialize(message)
50
- @message = message
51
- end
52
-
53
- def matches?(block)
54
- @actual = hijack_stderr(&block)
55
- PhraseMatcher.new("DEPRECATION WARNING: #{@message}").matches?(@actual)
56
- end
57
-
58
- def failure_message
59
- "expected deprecation warning #{@message.inspect}, got #{@actual.inspect}"
60
- end
61
-
62
- private
63
-
64
- def hijack_stderr
65
- err = $stderr
66
- $stderr = StringIO.new
67
- yield
68
- $stderr.string.rstrip
69
- ensure
70
- $stderr = err
71
- end
72
- end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'active_support/rescuable' # needed for Ruby 1.9.1
3
3
  require 'action_controller'
4
+ require 'action_view'
4
5
  require 'will_paginate/view_helpers/action_view'
5
6
  require 'will_paginate/collection'
6
7
 
@@ -312,13 +313,12 @@ describe WillPaginate::ActionView do
312
313
  end
313
314
 
314
315
  it "renders using ActionView helpers on a custom object" do
315
- helper = Object.new
316
- class << helper
316
+ helper = Class.new {
317
317
  attr_reader :controller
318
318
  include ActionView::Helpers::UrlHelper
319
319
  include Routes.url_helpers
320
320
  include WillPaginate::ActionView
321
- end
321
+ }.new
322
322
  helper.default_url_options[:controller] = 'dummy'
323
323
 
324
324
  collection = WillPaginate::Collection.new(2, 1, 3)
@@ -331,12 +331,11 @@ describe WillPaginate::ActionView do
331
331
  end
332
332
 
333
333
  it "renders using ActionDispatch helper on a custom object" do
334
- helper = Object.new
335
- class << helper
334
+ helper = Class.new {
336
335
  include ActionDispatch::Routing::UrlFor
337
336
  include Routes.url_helpers
338
337
  include WillPaginate::ActionView
339
- end
338
+ }.new
340
339
  helper.default_url_options.update \
341
340
  :only_path => true,
342
341
  :controller => 'dummy'
@@ -398,6 +397,7 @@ end
398
397
 
399
398
  class DummyRequest
400
399
  attr_accessor :symbolized_path_parameters
400
+ alias :path_parameters :symbolized_path_parameters
401
401
 
402
402
  def initialize
403
403
  @get = true
@@ -1,9 +1,13 @@
1
1
  require 'active_support'
2
+ require 'stringio'
2
3
  begin
4
+ $stderr = StringIO.new
3
5
  require 'minitest/unit'
4
6
  rescue LoadError
5
7
  # Fails on Ruby 1.8, but it's OK since we only need MiniTest::Assertions
6
8
  # on Rails 4 which doesn't support 1.8 anyway.
9
+ ensure
10
+ $stderr = STDERR
7
11
  end
8
12
  require 'action_dispatch/testing/assertions'
9
13
  require 'will_paginate/array'
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 3.0.5
4
+ version: 3.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mislav Marohnić
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: will_paginate provides a simple API for performing paginated queries
15
14
  with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
@@ -21,6 +20,9 @@ extra_rdoc_files:
21
20
  - README.md
22
21
  - LICENSE
23
22
  files:
23
+ - LICENSE
24
+ - README.md
25
+ - lib/will_paginate.rb
24
26
  - lib/will_paginate/active_record.rb
25
27
  - lib/will_paginate/array.rb
26
28
  - lib/will_paginate/collection.rb
@@ -34,13 +36,12 @@ files:
34
36
  - lib/will_paginate/railtie.rb
35
37
  - lib/will_paginate/sequel.rb
36
38
  - lib/will_paginate/version.rb
39
+ - lib/will_paginate/view_helpers.rb
37
40
  - lib/will_paginate/view_helpers/action_view.rb
38
41
  - lib/will_paginate/view_helpers/link_renderer.rb
39
42
  - lib/will_paginate/view_helpers/link_renderer_base.rb
40
43
  - lib/will_paginate/view_helpers/merb.rb
41
44
  - lib/will_paginate/view_helpers/sinatra.rb
42
- - lib/will_paginate/view_helpers.rb
43
- - lib/will_paginate.rb
44
45
  - spec/collection_spec.rb
45
46
  - spec/console
46
47
  - spec/console_fixtures.rb
@@ -64,6 +65,9 @@ files:
64
65
  - spec/fixtures/topics.yml
65
66
  - spec/fixtures/user.rb
66
67
  - spec/fixtures/users.yml
68
+ - spec/matchers/deprecation_matcher.rb
69
+ - spec/matchers/phrase_matcher.rb
70
+ - spec/matchers/query_count_matcher.rb
67
71
  - spec/page_number_spec.rb
68
72
  - spec/per_page_spec.rb
69
73
  - spec/spec_helper.rb
@@ -71,34 +75,31 @@ files:
71
75
  - spec/view_helpers/base_spec.rb
72
76
  - spec/view_helpers/link_renderer_base_spec.rb
73
77
  - spec/view_helpers/view_example_group.rb
74
- - README.md
75
- - LICENSE
76
78
  homepage: https://github.com/mislav/will_paginate/wiki
77
79
  licenses:
78
80
  - MIT
81
+ metadata: {}
79
82
  post_install_message:
80
83
  rdoc_options:
81
- - --main
84
+ - "--main"
82
85
  - README.md
83
- - --charset=UTF-8
86
+ - "--charset=UTF-8"
84
87
  require_paths:
85
88
  - lib
86
89
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
90
  requirements:
89
- - - ! '>='
91
+ - - ">="
90
92
  - !ruby/object:Gem::Version
91
93
  version: '0'
92
94
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
95
  requirements:
95
- - - ! '>='
96
+ - - ">="
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 1.8.23
101
+ rubygems_version: 2.2.2
101
102
  signing_key:
102
- specification_version: 3
103
+ specification_version: 4
103
104
  summary: Pagination plugin for web frameworks and other apps
104
105
  test_files: []