mislav-will_paginate 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 2.3.4, released 2008-09-16
2
+
3
+ * Removed gem dependency to Active Support (causes trouble with vendored rails).
4
+ * Rails 2.1: fix a failing test and a deprecation warning.
5
+ * Cope with scoped :select when counting.
6
+
1
7
  == 2.3.3, released 2008-08-29
2
8
 
3
9
  * Ensure that paginate_by_sql doesn't change the original SQL query.
data/README.rdoc CHANGED
@@ -87,7 +87,8 @@ contributions or just simply awesome ideas:
87
87
  Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
88
88
  Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
89
89
  van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
90
- Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris Eppstein.
90
+ Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris Eppstein,
91
+ Denis Barushev, Ben Pickles.
91
92
 
92
93
 
93
94
  == Usable pagination in the UI
@@ -181,7 +181,19 @@ module WillPaginate
181
181
  # in the database. It relies on the ActiveRecord +count+ method.
182
182
  def wp_count(options, args, finder)
183
183
  excludees = [:count, :order, :limit, :offset, :readonly]
184
- unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
184
+
185
+ # we may be in a model or an association proxy
186
+ klass = (@owner and @reflection) ? @reflection.klass : self
187
+
188
+ # Use :select from scope if it isn't already present.
189
+ options[:select] = scope(:find, :select) unless options[:select]
190
+
191
+ if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
192
+ # Remove quoting and check for table_name.*-like statement.
193
+ if options[:select].gsub('`', '') =~ /\w+\.\*/
194
+ options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}"
195
+ end
196
+ else
185
197
  excludees << :select # only exclude the select param if it doesn't begin with DISTINCT
186
198
  end
187
199
 
@@ -191,10 +203,7 @@ module WillPaginate
191
203
  # merge the hash found in :count
192
204
  # this allows you to specify :select, :order, or anything else just for the count query
193
205
  count_options.update options[:count] if options[:count]
194
-
195
- # we may be in a model or an association proxy
196
- klass = (@owner and @reflection) ? @reflection.klass : self
197
-
206
+
198
207
  # forget about includes if they are irrelevant (Rails 2.1)
199
208
  if count_options[:include] and
200
209
  klass.private_methods.include?('references_eager_loaded_tables?') and
data/test/finder_test.rb CHANGED
@@ -340,6 +340,12 @@ class FinderTest < ActiveRecordTestCase
340
340
  Developer.paginate :select => 'DISTINCT salary', :page => 2
341
341
  end
342
342
 
343
+ def test_count_with_scoped_select_when_distinct
344
+ Developer.stubs(:find).returns([])
345
+ Developer.expects(:count).with(:select => 'DISTINCT users.id').returns(0)
346
+ Developer.distinct.paginate :page => 2
347
+ end
348
+
343
349
  def test_should_use_scoped_finders_if_present
344
350
  # scope-out compatibility
345
351
  Topic.expects(:find_best).returns(Array.new(5))
@@ -390,12 +396,11 @@ class FinderTest < ActiveRecordTestCase
390
396
 
391
397
  def test_paginating_finder_doesnt_mangle_options
392
398
  Developer.expects(:find).returns([])
393
- options = { :page => 1 }
394
- options.expects(:delete).never
399
+ options = { :page => 1, :per_page => 2, :foo => 'bar' }
395
400
  options_before = options.dup
396
401
 
397
402
  Developer.paginate(options)
398
- assert_equal options, options_before
403
+ assert_equal options_before, options
399
404
  end
400
405
 
401
406
  def test_paginate_by_sql_doesnt_change_original_query
@@ -7,6 +7,7 @@ class Developer < User
7
7
  end
8
8
  end
9
9
 
10
+ named_scope :distinct, :select => 'DISTINCT `users`.*'
10
11
  named_scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
11
12
 
12
13
  def self.per_page() 10 end
@@ -16,16 +16,20 @@ class ActiveRecordTestConnector
16
16
  unless self.connected || !self.able_to_connect
17
17
  setup_connection
18
18
  load_schema
19
- Dependencies.load_paths.unshift FIXTURES_PATH
19
+ add_load_path FIXTURES_PATH
20
20
  self.connected = true
21
21
  end
22
22
  rescue Exception => e # errors from ActiveRecord setup
23
- $stderr.puts "\nSkipping ActiveRecord tests: #{e}"
24
- $stderr.puts "Install SQLite3 to run the full test suite for will_paginate.\n\n"
23
+ $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
25
24
  self.able_to_connect = false
26
25
  end
27
26
 
28
27
  private
28
+
29
+ def self.add_load_path(path)
30
+ dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
31
+ dep.load_paths.unshift path
32
+ end
29
33
 
30
34
  def self.setup_connection
31
35
  db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mislav-will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Mislav Marohni\xC4\x87"
@@ -10,18 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-29 00:00:00 -07:00
13
+ date: 2008-09-16 00:00:00 -07:00
14
14
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: activesupport
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.4.4
24
- version:
15
+ dependencies: []
16
+
25
17
  description: The will_paginate library provides a simple, yet powerful and extensible API for ActiveRecord pagination and rendering of pagination links in ActionView templates.
26
18
  email: mislav.marohnic@gmail.com
27
19
  executables: []