will_paginate 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,7 +80,7 @@ module WillPaginate
80
80
 
81
81
  def count
82
82
  if limit_value
83
- excluded = [:order, :limit, :offset]
83
+ excluded = [:order, :limit, :offset, :reorder]
84
84
  excluded << :includes unless eager_loading?
85
85
  rel = self.except(*excluded)
86
86
  # TODO: hack. decide whether to keep
@@ -2,7 +2,7 @@ module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -30,7 +30,7 @@ module WillPaginate
30
30
  options = options.symbolize_keys
31
31
  options[:renderer] ||= LinkRenderer
32
32
 
33
- super(collection, options).try(:html_safe)
33
+ super(collection, options)
34
34
  end
35
35
 
36
36
  def page_entries_info(collection = nil, options = {}) #:nodoc:
@@ -106,6 +106,7 @@ module WillPaginate
106
106
  def url(page)
107
107
  @base_url_params ||= begin
108
108
  url_params = merge_get_params(default_url_params)
109
+ url_params[:only_path] = true
109
110
  merge_optional_params(url_params)
110
111
  end
111
112
 
@@ -91,7 +91,9 @@ module WillPaginate
91
91
  end
92
92
  # render HTML for pagination
93
93
  renderer.prepare collection, options, self
94
- renderer.to_html
94
+ output = renderer.to_html
95
+ output = output.html_safe if output.respond_to?(:html_safe)
96
+ output
95
97
  end
96
98
 
97
99
  # Renders a message containing number of displayed vs. total entries.
@@ -0,0 +1,18 @@
1
+ # Makes the test suite compatible with Bundler standalone mode (used in CI)
2
+ # because Active Record uses `gem` for loading adapters.
3
+ Kernel.module_eval do
4
+
5
+ remove_method :gem if 'method' == defined? gem
6
+
7
+ def gem(*args)
8
+ return if $VERBOSE.nil?
9
+ $stderr << "warning: gem(#{args.map {|o| o.inspect }.join(', ')}) ignored"
10
+ $stderr << "; called from:\n " << caller[0,5].join("\n ") if $DEBUG
11
+ $stderr << "\n"
12
+ end
13
+
14
+ private :gem
15
+
16
+ end
17
+
18
+ $" << "rubygems.rb"
@@ -200,6 +200,11 @@ describe WillPaginate::ActiveRecord do
200
200
  Developer.group(:salary).page(1).total_entries.should == 4
201
201
  end
202
202
 
203
+ it "removes :reorder for count with group" do
204
+ Project.group(:id).reorder(:id).page(1).total_entries
205
+ $query_sql.last.should_not =~ /\ORDER\b/
206
+ end
207
+
203
208
  it "should not have zero total_pages when the result set is empty" do
204
209
  Developer.where("1 = 2").page(1).total_pages.should == 1
205
210
  end
@@ -73,7 +73,10 @@ module ActiverecordTestConnector
73
73
  end
74
74
 
75
75
  def load_schema
76
- ActiveRecord::Base.silence do
76
+ silencer = ActiveRecord::Base.method(:silence)
77
+ silence_args = []
78
+ silence_args << :stdout if silencer.arity != 0
79
+ silencer.call(*silence_args) do
77
80
  ActiveRecord::Migration.verbose = false
78
81
  load File.join(FIXTURES_PATH, 'schema.rb')
79
82
  end
@@ -90,7 +90,7 @@ describe WillPaginate::DataMapper do
90
90
  animals = Animal.all(:limit => 2).page(1)
91
91
  array = animals.to_a
92
92
  array.size.should == 2
93
- array.is_a? WillPaginate::Collection
93
+ array.should be_kind_of(WillPaginate::Collection)
94
94
  array.current_page.should == 1
95
95
  array.per_page.should == 2
96
96
  end
@@ -7,7 +7,9 @@ class Developer < User
7
7
  end
8
8
  end
9
9
 
10
- scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
10
+ scope :poor, lambda {
11
+ where(['salary <= ?', 80000]).order('salary')
12
+ }
11
13
 
12
14
  def self.per_page() 10 end
13
15
  end
@@ -1,9 +1,10 @@
1
1
  class Reply < ActiveRecord::Base
2
2
  belongs_to :topic, :include => [:replies]
3
3
 
4
- scope :recent,
5
- :conditions => ['replies.created_at > ?', 15.minutes.ago],
6
- :order => 'replies.created_at DESC'
4
+ scope :recent, lambda {
5
+ where(['replies.created_at > ?', 15.minutes.ago]).
6
+ order('replies.created_at DESC')
7
+ }
7
8
 
8
9
  validates_presence_of :content
9
10
  end
@@ -2,6 +2,10 @@ class Topic < ActiveRecord::Base
2
2
  has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
3
3
  belongs_to :project
4
4
 
5
- scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%']
6
- scope :distinct, :select => "DISTINCT #{table_name}.*"
5
+ scope :mentions_activerecord, lambda {
6
+ where(['topics.title LIKE ?', '%ActiveRecord%'])
7
+ }
8
+ scope :distinct, lambda {
9
+ select("DISTINCT #{table_name}.*")
10
+ }
7
11
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rspec'
2
- require File.expand_path('../view_helpers/view_example_group', __FILE__)
2
+ require 'view_helpers/view_example_group'
3
3
  begin
4
4
  require 'ruby-debug'
5
5
  rescue LoadError
@@ -20,6 +20,7 @@ RSpec.configure do |config|
20
20
  }
21
21
 
22
22
  config.mock_with :mocha
23
+ config.backtrace_clean_patterns << /view_example_group/
23
24
  end
24
25
 
25
26
  class PhraseMatcher
@@ -56,6 +56,15 @@ describe WillPaginate::ActionView do
56
56
  end
57
57
  end
58
58
 
59
+ it "should override existing page param value" do
60
+ request.params :page => 1
61
+ paginate do |pagination|
62
+ assert_select 'a[href]', 3 do |elements|
63
+ validate_page_numbers [2,3,2], elements
64
+ end
65
+ end
66
+ end
67
+
59
68
  it "should render nothing when there is only 1 page" do
60
69
  paginate(:per_page => 30).should be_empty
61
70
  end
@@ -180,6 +189,15 @@ describe WillPaginate::ActionView do
180
189
  paginate
181
190
  assert_links_match /foo\[bar\]=baz/
182
191
  end
192
+
193
+ it "doesn't allow tampering with host, port, protocol" do
194
+ request.params :host => 'disney.com', :port => '99', :protocol => 'ftp'
195
+ paginate
196
+ assert_links_match %r{^/foo/bar}
197
+ assert_no_links_match /disney/
198
+ assert_no_links_match /99/
199
+ assert_no_links_match /ftp/
200
+ end
183
201
 
184
202
  it "should not preserve parameters on POST" do
185
203
  request.post
@@ -319,16 +337,16 @@ describe WillPaginate::ActionView do
319
337
  include Routes.url_helpers
320
338
  include WillPaginate::ActionView
321
339
  end
322
- helper.default_url_options[:host] = 'example.com'
323
- helper.default_url_options[:controller] = 'dummy'
324
- # helper.default_url_options[:only_path] = true
340
+ helper.default_url_options.update \
341
+ :only_path => true,
342
+ :controller => 'dummy'
325
343
 
326
344
  collection = WillPaginate::Collection.new(2, 1, 3)
327
345
  @render_output = helper.will_paginate(collection)
328
346
 
329
347
  assert_select 'a[href]', 4 do |links|
330
348
  urls = links.map {|l| l['href'] }.uniq
331
- urls.should == ['http://example.com/dummy/page/1', 'http://example.com/dummy/page/3']
349
+ urls.should == ['/dummy/page/1', '/dummy/page/3']
332
350
  end
333
351
  end
334
352
 
@@ -32,6 +32,18 @@ describe WillPaginate::ViewHelpers do
32
32
  collection = mock 'Collection', :total_pages => 1
33
33
  will_paginate(collection).should be_nil
34
34
  end
35
+
36
+ it "should call html_safe on result" do
37
+ collection = WillPaginate::Collection.new(1, 2, 4)
38
+
39
+ html = mock 'HTML'
40
+ html.expects(:html_safe).returns(html)
41
+ renderer = mock 'Renderer'
42
+ renderer.stubs(:prepare)
43
+ renderer.expects(:to_html).returns(html)
44
+
45
+ will_paginate(collection, :renderer => renderer).should eql(html)
46
+ end
35
47
  end
36
48
 
37
49
  describe "pagination_options" do
@@ -14,6 +14,7 @@ module ViewExampleGroup
14
14
  include MiniTest::Assertions if defined? MiniTest
15
15
 
16
16
  def assert(value, message)
17
+ message = message.call if message.respond_to?(:call)
17
18
  raise message unless value
18
19
  end
19
20
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
5
4
  prerelease:
5
+ version: 3.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mislav Marohnić
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: will_paginate provides a simple API for performing paginated queries
15
15
  with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
@@ -21,7 +21,6 @@ extra_rdoc_files:
21
21
  - README.md
22
22
  - LICENSE
23
23
  files:
24
- - Rakefile
25
24
  - lib/will_paginate/active_record.rb
26
25
  - lib/will_paginate/array.rb
27
26
  - lib/will_paginate/collection.rb
@@ -42,11 +41,11 @@ files:
42
41
  - lib/will_paginate/view_helpers/sinatra.rb
43
42
  - lib/will_paginate/view_helpers.rb
44
43
  - lib/will_paginate.rb
45
- - spec/ci.rb
46
44
  - spec/collection_spec.rb
47
45
  - spec/console
48
46
  - spec/console_fixtures.rb
49
47
  - spec/database.yml
48
+ - spec/fake_rubygems.rb
50
49
  - spec/finders/active_record_spec.rb
51
50
  - spec/finders/activerecord_test_connector.rb
52
51
  - spec/finders/data_mapper_spec.rb
@@ -75,7 +74,8 @@ files:
75
74
  - README.md
76
75
  - LICENSE
77
76
  homepage: https://github.com/mislav/will_paginate/wiki
78
- licenses: []
77
+ licenses:
78
+ - MIT
79
79
  post_install_message:
80
80
  rdoc_options:
81
81
  - --main
@@ -102,4 +102,3 @@ signing_key:
102
102
  specification_version: 3
103
103
  summary: Pagination plugin for web frameworks and other apps
104
104
  test_files: []
105
- has_rdoc:
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
- rescue LoadError
4
- # no spec tasks
5
- else
6
- task :default => :spec
7
-
8
- desc 'Run ALL OF the specs'
9
- RSpec::Core::RakeTask.new(:spec) do |t|
10
- # t.ruby_opts = '-w'
11
- t.pattern = 'spec/finders/active_record_spec.rb' if ENV['DB'] and ENV['DB'] != 'sqlite3'
12
- end
13
-
14
- namespace :spec do
15
- desc "Run Rails specs"
16
- RSpec::Core::RakeTask.new(:rails) do |t|
17
- t.pattern = %w'spec/finders/active_record_spec.rb spec/view_helpers/action_view_spec.rb'
18
- end
19
- end
20
- end
21
-
22
- desc 'Run specs against both Rails 3.1 and Rails 3.0'
23
- task :rails3 do |variable|
24
- system 'bundle exec rake spec && BUNDLE_GEMFILE=Gemfile.rails3.0 bundle exec rake spec:rails'
25
- end
data/spec/ci.rb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- databases = %w[ sqlite3 mysql mysql2 postgres ]
3
- databases.delete 'mysql2' if ENV['BUNDLE_GEMFILE'].to_s.include? 'rails3.0'
4
-
5
- def announce(name, msg)
6
- puts "\n\e[1;33m[#{name}] #{msg}\e[m\n"
7
- end
8
-
9
- def system(*args)
10
- puts "$ #{args.join(' ')}"
11
- super
12
- end
13
-
14
- if ENV['TRAVIS']
15
- system "mysql -e 'create database will_paginate;' >/dev/null"
16
- abort "failed to create mysql database" unless $?.success?
17
- system "psql -c 'create database will_paginate;' -U postgres >/dev/null"
18
- abort "failed to create postgres database" unless $?.success?
19
- end
20
-
21
- failed = false
22
-
23
- for db in databases
24
- announce "DB", db
25
- ENV['DB'] = db
26
- failed = true unless system %(rake)
27
- end
28
-
29
- exit 1 if failed