public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Search Repo:
Set up tests for MySQL and PostgreSQL besides SQLite3. Change their 
configurations or set up additional ones in test/database.yml. Fixed some 
tests for MySQL and Postgres.


git-svn-id: svn://errtheblog.com/svn/plugins/will_paginate@442 
1eaa51fe-a21a-0410-9c2e-ae7a00a434c4
mislav (author)
Mon Jan 28 14:26:59 -0800 2008
commit  e321a367b8dd111c57b573e247e50321324f9414
tree    543ef3aa2da55de6fcbacb342e2479323e5d9ced
parent  805b0e6ede77c505e800fe49de20c9aab2d801dd
...
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
16
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
0
@@ -11,6 +11,17 @@ Rake::TestTask.new(:test) do |t|
0
   t.verbose = true
0
 end
0
 
0
+for configuration in %w( sqlite3 mysql postgres )
0
+ Rake::TestTask.new("test_#{configuration}") do |t|
0
+ t.pattern = 'test/finder_test.rb'
0
+ t.verbose = true
0
+ t.options = "-- -#{configuration}"
0
+ end
0
+end
0
+
0
+task :test_databases => %w(test_mysql test_sqlite3 test_postgres)
0
+task :test_all => %w(test test_mysql test_postgres)
0
+
0
 desc 'Generate RDoc documentation for the will_paginate plugin.'
0
 Rake::RDocTask.new(:rdoc) do |rdoc|
0
   files = ['README', 'LICENSE', 'lib/**/*.rb']
...
169
170
171
172
 
 
173
174
 
175
176
177
...
204
205
206
207
 
208
209
210
211
212
 
213
214
215
...
263
264
265
266
 
267
268
269
270
271
272
273
...
169
170
171
 
172
173
174
 
175
176
177
178
...
205
206
207
 
208
209
210
211
212
 
213
214
215
216
...
264
265
266
 
267
268
269
270
 
271
272
273
0
@@ -169,9 +169,10 @@ class FinderTest < ActiveRecordTestCase
0
   end
0
 
0
   def test_paginate_with_group
0
- entries = Developer.paginate :page => 1, :per_page => 10, :group => 'salary'
0
+ entries = Developer.paginate :page => 1, :per_page => 10,
0
+ :group => 'salary', :select => 'salary', :order => 'salary'
0
     expected = [ users(:david), users(:jamis), users(:dev_10), users(:poor_jamis) ].map(&:salary).sort
0
- assert_equal expected, entries.map(&:salary).sort
0
+ assert_equal expected, entries.map(&:salary)
0
   end
0
 
0
   def test_paginate_with_dynamic_finder
0
@@ -204,12 +205,12 @@ class FinderTest < ActiveRecordTestCase
0
     assert_nothing_raised { Developer.paginate :readonly => true, :page => 1 }
0
   end
0
 
0
- # Are we on edge? Find out by testing find_all which was removed in [6998]
0
+ # Is this Rails 2.0? Find out by testing find_all which was removed in [6998]
0
   unless Developer.respond_to? :find_all
0
     def test_paginate_array_of_ids
0
       # AR finders also accept arrays of IDs
0
       # (this was broken in Rails before [6912])
0
- entries = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2)
0
+ entries = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2, :order => 'id')
0
       assert_equal (4..6).to_a, entries.map(&:id)
0
       assert_equal 8, entries.total_entries
0
     end
0
@@ -263,11 +264,10 @@ class FinderTest < ActiveRecordTestCase
0
 
0
     def test_paginate_by_sql
0
       assert_respond_to Developer, :paginate_by_sql
0
- Developer.expects(:find_by_sql).with('sql LIMIT 3 OFFSET 3').returns([])
0
+ Developer.expects(:find_by_sql).with(regexp_matches(/sql LIMIT 3(,| OFFSET) 3/)).returns([])
0
       Developer.expects(:count_by_sql).with('SELECT COUNT(*) FROM (sql) AS count_table').returns(0)
0
       
0
       entries = Developer.paginate_by_sql 'sql', :page => 2, :per_page => 3
0
- assert_equal 0, entries.total_entries
0
     end
0
 
0
     def test_paginate_by_sql_respects_total_entries_setting
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
3
4
5
 
6
7
8
9
10
11
 
12
13
14
15
16
17
 
18
19
20
21
22
23
 
24
25
26
27
28
29
 
0
@@ -3,32 +3,27 @@ witty_retort:
0
   topic_id: 1
0
   content: Birdman is better!
0
   created_at: <%= 6.hours.ago.to_s(:db) %>
0
- updated_at: nil
0
   
0
 another:
0
   id: 2
0
   topic_id: 2
0
   content: Nuh uh!
0
   created_at: <%= 1.hour.ago.to_s(:db) %>
0
- updated_at: nil
0
   
0
 spam:
0
   id: 3
0
   topic_id: 1
0
   content: Nice site!
0
   created_at: <%= 1.hour.ago.to_s(:db) %>
0
- updated_at: nil
0
 
0
 decisive:
0
   id: 4
0
   topic_id: 4
0
   content: "I'm getting to the bottom of this"
0
   created_at: <%= 30.minutes.ago.to_s(:db) %>
0
- updated_at: nil
0
 
0
 brave:
0
   id: 5
0
   topic_id: 4
0
   content: "AR doesn't scare me a bit"
0
   created_at: <%= 10.minutes.ago.to_s(:db) %>
0
- updated_at: nil
...
1
2
3
4
5
6
7
 
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
18
 
 
 
 
 
19
20
21
...
27
28
29
30
31
32
 
 
33
34
35
 
36
37
38
...
1
2
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
 
 
 
 
 
15
16
17
18
19
20
21
22
...
28
29
30
 
 
 
31
32
33
34
 
35
36
37
38
0
@@ -1,21 +1,22 @@
0
 ActiveRecord::Schema.define do
0
 
0
- create_table "developers_projects", :id => false, :force => true do |t|
0
- t.column "developer_id", :integer, :null => false
0
- t.column "project_id", :integer, :null => false
0
- t.column "joined_on", :date
0
- t.column "access_level", :integer, :default => 1
0
+ create_table "users", :force => true do |t|
0
+ t.column "name", :text
0
+ t.column "salary", :integer, :default => 70000
0
+ t.column "created_at", :datetime
0
+ t.column "updated_at", :datetime
0
+ t.column "type", :text
0
   end
0
 
0
   create_table "projects", :force => true do |t|
0
     t.column "name", :text
0
   end
0
 
0
- create_table "replies", :force => true do |t|
0
- t.column "content", :text
0
- t.column "created_at", :datetime
0
- t.column "updated_at", :datetime
0
- t.column "topic_id", :integer
0
+ create_table "developers_projects", :id => false, :force => true do |t|
0
+ t.column "developer_id", :integer, :null => false
0
+ t.column "project_id", :integer, :null => false
0
+ t.column "joined_on", :date
0
+ t.column "access_level", :integer, :default => 1
0
   end
0
 
0
   create_table "topics", :force => true do |t|
0
@@ -27,12 +28,11 @@ ActiveRecord::Schema.define do
0
     t.column "updated_at", :datetime
0
   end
0
 
0
- create_table "users", :force => true do |t|
0
- t.column "name", :text
0
- t.column "salary", :integer, :default => 70000
0
+ create_table "replies", :force => true do |t|
0
+ t.column "content", :text
0
     t.column "created_at", :datetime
0
     t.column "updated_at", :datetime
0
- t.column "type", :text
0
+ t.column "topic_id", :integer
0
   end
0
 
0
 end
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ class ActiveRecordTestCase < Test::Unit::TestCase
0
   # Set our fixture path
0
   if ActiveRecordTestConnector.able_to_connect
0
     self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
0
- self.use_transactional_fixtures = false
0
+ self.use_transactional_fixtures = true
0
   end
0
 
0
   def self.fixtures(*args)
...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
 
 
50
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
53
54
...
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -27,28 +27,26 @@ class ActiveRecordTestConnector
0
   private
0
 
0
   def self.setup_connection
0
- if Object.const_defined?(:ActiveRecord)
0
- defaults = { :database => ':memory:' }
0
- ActiveRecord::Base.logger = Logger.new STDOUT if $0 == 'irb'
0
-
0
- begin
0
- options = defaults.merge :adapter => 'sqlite3', :timeout => 500
0
- ActiveRecord::Base.establish_connection(options)
0
- ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
0
- ActiveRecord::Base.connection
0
- rescue Exception # errors from establishing a connection
0
- $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
0
- options = defaults.merge :adapter => 'sqlite'
0
- ActiveRecord::Base.establish_connection(options)
0
- ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
0
- ActiveRecord::Base.connection
0
- end
0
-
0
- unless Object.const_defined?(:QUOTED_TYPE)
0
- Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
0
- end
0
+ arg = ARGV.last
0
+ if arg.index('-') == 0
0
+ db = arg.sub('-', '').downcase
0
     else
0
- raise "Can't setup connection since ActiveRecord isn't loaded."
0
+ db, arg = 'sqlite3', nil
0
+ end
0
+
0
+ configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
0
+ raise "no configuration for '#{db}'" unless configurations.key? db
0
+ configuration = configurations[db]
0
+
0
+ ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
0
+ puts "using #{configuration['adapter']} adapter" if arg
0
+
0
+ ActiveRecord::Base.establish_connection(configuration)
0
+ ActiveRecord::Base.configurations = { db => configuration }
0
+ ActiveRecord::Base.connection
0
+
0
+ unless Object.const_defined?(:QUOTED_TYPE)
0
+ Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
0
     end
0
   end
0
 

Comments

    No one has commented yet.