activegroonga 1.0.4 → 1.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.
Files changed (113) hide show
  1. data/README.textile +55 -0
  2. data/Rakefile +45 -165
  3. data/{license/LGPL → doc/text/lgpl.txt} +0 -0
  4. data/doc/text/news.textile +60 -0
  5. data/doc/text/tutorial.textile +3 -0
  6. data/lib/active_groonga/base.rb +50 -2
  7. data/lib/active_groonga/railtie.rb +6 -5
  8. data/lib/active_groonga/railties/groonga.rake +8 -4
  9. data/lib/active_groonga/result_set.rb +133 -8
  10. data/lib/active_groonga/version.rb +1 -1
  11. data/test/active-groonga-test-utils.rb +6 -0
  12. data/test/run-test.rb +11 -24
  13. data/test/test-base.rb +10 -4
  14. data/test/test-result-set.rb +121 -9
  15. metadata +90 -138
  16. data/AUTHORS +0 -1
  17. data/NEWS.ja.rdoc +0 -46
  18. data/NEWS.rdoc +0 -46
  19. data/README.ja.rdoc +0 -52
  20. data/README.rdoc +0 -52
  21. data/test-unit-notify/Rakefile +0 -47
  22. data/test-unit-notify/lib/test/unit/notify.rb +0 -104
  23. data/test-unit/COPYING +0 -56
  24. data/test-unit/GPL +0 -340
  25. data/test-unit/PSFL +0 -271
  26. data/test-unit/Rakefile +0 -53
  27. data/test-unit/TODO +0 -5
  28. data/test-unit/bin/testrb +0 -5
  29. data/test-unit/html/bar.svg +0 -153
  30. data/test-unit/html/developer.svg +0 -469
  31. data/test-unit/html/favicon.ico +0 -0
  32. data/test-unit/html/favicon.svg +0 -82
  33. data/test-unit/html/heading-mark.svg +0 -393
  34. data/test-unit/html/index.html +0 -247
  35. data/test-unit/html/index.html.ja +0 -270
  36. data/test-unit/html/install.svg +0 -636
  37. data/test-unit/html/logo.svg +0 -483
  38. data/test-unit/html/test-unit.css +0 -339
  39. data/test-unit/html/tutorial.svg +0 -559
  40. data/test-unit/lib/test/unit.rb +0 -328
  41. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  42. data/test-unit/lib/test/unit/assertions.rb +0 -1334
  43. data/test-unit/lib/test/unit/attribute.rb +0 -125
  44. data/test-unit/lib/test/unit/autorunner.rb +0 -363
  45. data/test-unit/lib/test/unit/collector.rb +0 -36
  46. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  47. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  48. data/test-unit/lib/test/unit/collector/load.rb +0 -144
  49. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  50. data/test-unit/lib/test/unit/color-scheme.rb +0 -106
  51. data/test-unit/lib/test/unit/color.rb +0 -96
  52. data/test-unit/lib/test/unit/diff.rb +0 -740
  53. data/test-unit/lib/test/unit/error.rb +0 -130
  54. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  55. data/test-unit/lib/test/unit/failure.rb +0 -136
  56. data/test-unit/lib/test/unit/fixture.rb +0 -176
  57. data/test-unit/lib/test/unit/notification.rb +0 -129
  58. data/test-unit/lib/test/unit/omission.rb +0 -191
  59. data/test-unit/lib/test/unit/pending.rb +0 -150
  60. data/test-unit/lib/test/unit/priority.rb +0 -180
  61. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  62. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  63. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  64. data/test-unit/lib/test/unit/testcase.rb +0 -483
  65. data/test-unit/lib/test/unit/testresult.rb +0 -121
  66. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  67. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  68. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -430
  69. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  70. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -82
  71. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -53
  72. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  73. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  74. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -42
  75. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  76. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  77. data/test-unit/lib/test/unit/util/output.rb +0 -31
  78. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  79. data/test-unit/lib/test/unit/version.rb +0 -7
  80. data/test-unit/sample/adder.rb +0 -13
  81. data/test-unit/sample/subtracter.rb +0 -12
  82. data/test-unit/sample/test_adder.rb +0 -20
  83. data/test-unit/sample/test_subtracter.rb +0 -20
  84. data/test-unit/sample/test_user.rb +0 -23
  85. data/test-unit/test/collector/test-descendant.rb +0 -133
  86. data/test-unit/test/collector/test-load.rb +0 -442
  87. data/test-unit/test/collector/test_dir.rb +0 -406
  88. data/test-unit/test/collector/test_objectspace.rb +0 -100
  89. data/test-unit/test/run-test.rb +0 -15
  90. data/test-unit/test/test-attribute.rb +0 -86
  91. data/test-unit/test/test-color-scheme.rb +0 -69
  92. data/test-unit/test/test-color.rb +0 -47
  93. data/test-unit/test/test-diff.rb +0 -518
  94. data/test-unit/test/test-emacs-runner.rb +0 -60
  95. data/test-unit/test/test-fixture.rb +0 -287
  96. data/test-unit/test/test-notification.rb +0 -33
  97. data/test-unit/test/test-omission.rb +0 -81
  98. data/test-unit/test/test-pending.rb +0 -70
  99. data/test-unit/test/test-priority.rb +0 -119
  100. data/test-unit/test/test-testcase.rb +0 -544
  101. data/test-unit/test/test_assertions.rb +0 -1197
  102. data/test-unit/test/test_error.rb +0 -26
  103. data/test-unit/test/test_failure.rb +0 -33
  104. data/test-unit/test/test_testresult.rb +0 -113
  105. data/test-unit/test/test_testsuite.rb +0 -129
  106. data/test-unit/test/testunit-test-util.rb +0 -14
  107. data/test-unit/test/ui/test_tap.rb +0 -33
  108. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  109. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  110. data/test-unit/test/util/test-output.rb +0 -11
  111. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  112. data/test-unit/test/util/test_observable.rb +0 -102
  113. data/test-unit/test/util/test_procwrapper.rb +0 -36
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -23,14 +23,15 @@ module ActiveGroonga
23
23
  class Railtie < Rails::Railtie
24
24
  config.active_groonga = ActiveSupport::OrderedOptions.new
25
25
 
26
- config.generators.orm(:active_groonga,
27
- :migration => true,
28
- :timestamps => true)
26
+ config.app_generators.orm(:active_groonga,
27
+ :migration => true,
28
+ :timestamps => true)
29
29
 
30
30
  config.before_configuration do
31
31
  application_config = Rails.application.config
32
32
  application_config.extend(Railties::Configurable)
33
- application_config.paths.config.groonga("config/groonga.yml")
33
+ application_config.paths.add("config/groonga",
34
+ :with => "config/groonga.yml")
34
35
  end
35
36
 
36
37
  rake_tasks do
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -121,15 +121,16 @@ namespace :groonga do
121
121
  desc('Load the seed data from db/groonga/seeds/#{RAILS_ENV}.grn, ' +
122
122
  'db/groonga/seeds/#{RAILS_ENV}.rb, db/groonga/seeds.grn or ' +
123
123
  'db/groonga/seeds.rb')
124
- task :seed => :load_config do
124
+ task :seed => :environment do
125
125
  base_dir = Rails.root + "db" + "groonga"
126
126
  candidates = [base_dir + "seeds" + "#{Rails.env}.grn",
127
127
  base_dir + "seeds" + "#{Rails.env}.rb",
128
128
  base_dir + "seeds.grn",
129
129
  base_dir + "seeds.rb"]
130
130
  seed_file_path = candidates.find(&:exist?)
131
- break unless seed_file_path
132
- case seed_file_path.extname
131
+ extension = nil
132
+ extension = seed_file_path.extname if seed_file_path
133
+ case extension
133
134
  when /\A\.grn\z/i
134
135
  ActiveGroonga::Base.database.ensure_available
135
136
  context = ActiveGroonga::Base.context
@@ -143,6 +144,9 @@ namespace :groonga do
143
144
  end
144
145
  when /\A\.rb\z/i
145
146
  load(seed_file_path)
147
+ when nil
148
+ candidate_paths = candidates.collect(&:to_s)
149
+ raise "seed file doesn't exist. candidates: #{candidate_paths.inspect}"
146
150
  else
147
151
  raise "unsupported seed file type: <#{seed_file_path}>"
148
152
  end
@@ -27,21 +27,122 @@ module ActiveGroonga
27
27
  @expression = @records.expression
28
28
  end
29
29
  @n_records = options[:n_records] || @records.size
30
+ @default_sort_keys = options[:default_sort_keys]
31
+ @default_limit = options[:default_limit]
30
32
  compute_n_key_nested
31
33
  end
32
34
 
33
- def paginate(sort_keys, options={})
34
- options[:page] = normalize_page_value(options[:page])
35
+ # Paginates the result set.
36
+ #
37
+ # @overload paginate(sort_keys, options={})
38
+ # @param [Array<Array<String, Symbol>>] sort_keys
39
+ # The array of sort key for paginating. Each sort
40
+ # key is an array of sort key column name and order.
41
+ # @option options [Integer] :size The page size.
42
+ # {Base.limit} is used as the default value.
43
+ # @option options [Integer] :page The target page.
44
+ # The page is 1 origin not 0 origin. 1 is used as
45
+ # the default value.
46
+ # @return [ResultSet] paginated result set.
47
+ #
48
+ # @example
49
+ # result_set = User.all
50
+ # # Paginates by sorting by "name" column value in
51
+ # # ascending order. The paginated result set has
52
+ # # less than or equal 10 records. And the returned
53
+ # # page is user requested page. If user doesn't
54
+ # # specify page, the first page is returned.
55
+ # result_set.paginate([["name", :ascending]],
56
+ # :size => 10,
57
+ # :page => param[:page])
58
+ #
59
+ # @overload paginate(options={})
60
+ # @option options [Integer] :size The page size.
61
+ # {Base.limit} is used as the default value.
62
+ # @option options [Integer] :page The target page.
63
+ # 1 is used as the default value.
64
+ # @return [ResultSet] paginated result set.
65
+ #
66
+ # @example
67
+ # # The default sort keys.
68
+ # User.sort_keys = [["name", :ascending]]
69
+ # result_set = User.all
70
+ # # Paginates by sorting by "name" column value in
71
+ # # ascending order because it is the default sort
72
+ # # keys. The paginated result set has
73
+ # # less than or equal 10 records. And the returned
74
+ # # page is user requested page. If user doesn't
75
+ # # specify page, the first page is returned.
76
+ # result_set.paginate(:size => 10,
77
+ # :page => param[:page])
78
+ #
79
+ # {Base.sort_keys} is used as the sort keys.
80
+ def paginate(sort_keys=nil, options={})
81
+ if sort_keys.is_a?(Hash) and options.empty?
82
+ options = sort_keys
83
+ sort_keys = nil
84
+ end
85
+ options[:size] = normalize_limit(options[:size])
86
+ options[:page] = normalize_page(options[:page])
87
+ sort_keys = normalize_sort_keys(sort_keys)
35
88
  records = @records.paginate(sort_keys, options)
36
- set = self.class.new(records, @klass,
37
- :expression => @expression)
89
+ set = create_result_set(records)
38
90
  set.extend(PaginationProxy)
39
91
  set
40
92
  end
41
93
 
42
- def sort(keys, options={})
43
- self.class.new(@records.sort(keys, options), @klass,
44
- :expression => @expression)
94
+ # Sorts the result set.
95
+ #
96
+ # @overload sort(keys, options={})
97
+ # @param [Array<Array<String, Symbol>>] keys
98
+ # The array of sort key for sort. Each sort
99
+ # key is an array of sort key column name and order.
100
+ # @option options [Integer] :limit The max number of records.
101
+ # {Base.limit} is used as the default value.
102
+ # If {Base.limit} is nil, all records are returned.
103
+ # @option options [Integer] :offset The record start offset.
104
+ # Offset is 0-origin not 1-origin.
105
+ # The default value is 0.
106
+ # @return [ResultSet] sorted result set.
107
+ #
108
+ # @example
109
+ # result_set = User.all
110
+ # # Sorts by "name" column value in
111
+ # # ascending order. The sorted result set has
112
+ # # from the 5th records to the 14th records.
113
+ # result_set.paginate([["name", :ascending]],
114
+ # :limit => 10,
115
+ # :offset => 4)
116
+ #
117
+ # @overload sort(options={})
118
+ # @option options [Integer] :limit The max number of records.
119
+ # {Base.limit} is used as the default value.
120
+ # If {Base.limit} is nil, all records are returned.
121
+ # @option options [Integer] :offset The record start offset.
122
+ # Offset is 0-origin not 1-origin.
123
+ # The default value is 0.
124
+ # @return [ResultSet] sorted result set.
125
+ #
126
+ # @example
127
+ # # The default sort keys.
128
+ # User.sort_keys = [["name", :ascending]]
129
+ # result_set = User.all
130
+ # # Sorts by "name" column value in
131
+ # # ascending order because it is the default sort
132
+ # # keys. The sorted result set has
133
+ # # from the 5th records to the 14th records.
134
+ # result_set.paginate(:limit => 10,
135
+ # :offset => 4)
136
+ #
137
+ # {Base.sort_keys} is used as the sort keys.
138
+ def sort(keys=nil, options={})
139
+ if keys.is_a?(Hash) and options.empty?
140
+ options = keys
141
+ keys = nil
142
+ end
143
+ keys = normalize_sort_keys(keys)
144
+ options[:limit] = normalize_limit(options[:limit]) || @n_records
145
+ create_result_set(@records.sort(keys, options))
45
146
  end
46
147
 
47
148
  def group(key)
@@ -82,7 +183,18 @@ module ActiveGroonga
82
183
  end
83
184
  end
84
185
 
85
- def normalize_page_value(page)
186
+ def normalize_limit(limit)
187
+ unless limit.blank?
188
+ begin
189
+ Integer(limit)
190
+ rescue
191
+ limit = nil
192
+ end
193
+ end
194
+ limit || @default_limit
195
+ end
196
+
197
+ def normalize_page(page)
86
198
  if page.blank?
87
199
  1
88
200
  else
@@ -94,6 +206,19 @@ module ActiveGroonga
94
206
  end
95
207
  end
96
208
 
209
+ def normalize_sort_keys(keys)
210
+ keys = @default_sort_keys if keys.blank?
211
+ keys = [["_id", :ascending]] if keys.blank?
212
+ keys
213
+ end
214
+
215
+ def create_result_set(records)
216
+ self.class.new(records, @klass,
217
+ :default_sort_keys => @default_sort_keys,
218
+ :default_limit => @default_limit,
219
+ :expression => @expression)
220
+ end
221
+
97
222
  module PaginationProxy
98
223
  Groonga::Pagination.instance_methods.each do |method_name|
99
224
  define_method(method_name) do
@@ -17,7 +17,7 @@ module ActiveGroonga
17
17
  module VERSION
18
18
  MAJOR = 1
19
19
  MINOR = 0
20
- TINY = 4
20
+ TINY = 5
21
21
 
22
22
  STRING = [MAJOR, MINOR, TINY].join(".")
23
23
  end
@@ -208,6 +208,12 @@ module ActiveGroongaTestUtils
208
208
  "fulltext search engine",
209
209
  "<html><body>groonga</body></html>")
210
210
 
211
+ @bookmark_records[:rroonga] =
212
+ create_bookmark(@user_records[:daijiro],
213
+ "http://groonga.rubyforge.org/",
214
+ "The Ruby bindings for groonga",
215
+ "<html><body>rroonga</body></html>")
216
+
211
217
  @bookmark_records[:cutter] =
212
218
  create_bookmark(@user_records[:gunyarakun],
213
219
  "http://cutter.sourceforge.net/",
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -20,21 +20,12 @@
20
20
  require 'pathname'
21
21
  require 'shellwords'
22
22
 
23
+ require "rubygems"
24
+ gem "test-unit"
25
+ require "test/unit"
26
+ require "test/unit/notify"
27
+
23
28
  base_dir = Pathname(__FILE__).dirname.parent.expand_path
24
- test_unit_dir = base_dir + "test-unit"
25
- test_unit_notify_dir = base_dir + "test-unit-notify"
26
- test_unit_repository_base = "http://test-unit.rubyforge.org/svn"
27
- unless test_unit_dir.exist?
28
- system("svn", "co", "#{test_unit_repository_base}/trunk",
29
- test_unit_dir.to_s)
30
- end
31
- unless test_unit_notify_dir.exist?
32
- test_unit_notify_repository = "#{test_unit_repository_base}/extensions/test-unit-notify/trunk/"
33
- system("svn", "co",
34
- test_unit_notify_repository.to_s,
35
- test_unit_notify_dir.to_s) or exit(false)
36
- system("svn", "up", test_unit_dir.to_s) or exit(false)
37
- end
38
29
 
39
30
  rroonga_dir = base_dir.parent + "rroonga"
40
31
  lib_dir = base_dir + "lib"
@@ -55,16 +46,9 @@ if rroonga_dir.exist?
55
46
  $LOAD_PATH.unshift(rroonga_dir + "lib")
56
47
  end
57
48
 
58
- $LOAD_PATH.unshift(test_unit_notify_dir + "lib")
59
- $LOAD_PATH.unshift(test_unit_dir + "lib")
60
-
61
49
  ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] = "10000"
62
50
 
63
- require 'test/unit'
64
- require 'test/unit/notify'
65
-
66
- ARGV.unshift("--priority-mode")
67
- ARGV.unshift("--notify")
51
+ Test::Unit::Priority.enable
68
52
 
69
53
  $LOAD_PATH.unshift(lib_dir)
70
54
 
@@ -75,4 +59,7 @@ Dir.glob("test/**/test{_,-}*.rb") do |file|
75
59
  require file.sub(/\.rb$/, '')
76
60
  end
77
61
 
78
- exit Test::Unit::AutoRunner.run(false)
62
+ success = Test::Unit::AutoRunner.run do |runner|
63
+ runner.runner_options[:show_detail_immediately] = true
64
+ end
65
+ exit(success)
@@ -19,7 +19,9 @@ class TestBase < Test::Unit::TestCase
19
19
 
20
20
  def test_select
21
21
  bookmarks = Bookmark.select
22
- assert_equal(["http://groonga.org/", "http://cutter.sourceforge.net/"].sort,
22
+ assert_equal(["http://groonga.org/",
23
+ "http://groonga.rubyforge.org/",
24
+ "http://cutter.sourceforge.net/"].sort,
23
25
  bookmarks.collect(&:uri).sort)
24
26
  end
25
27
 
@@ -158,14 +160,17 @@ class TestBase < Test::Unit::TestCase
158
160
  bookmarks = Bookmark.select do |record|
159
161
  record.user == daijiro
160
162
  end
161
- assert_equal([Bookmark.find(@bookmark_records[:groonga].id), google],
163
+ assert_equal([Bookmark.find(@bookmark_records[:groonga].id),
164
+ Bookmark.find(@bookmark_records[:rroonga].id),
165
+ google],
162
166
  bookmarks.to_a)
163
167
  end
164
168
 
165
169
  def test_find_reference_by_id
166
170
  daijiro = @user_records[:daijiro]
167
171
  bookmarks = Bookmark.select {|record| record.user == daijiro}
168
- assert_equal([Bookmark.find(@bookmark_records[:groonga])],
172
+ assert_equal([Bookmark.find(@bookmark_records[:groonga]),
173
+ Bookmark.find(@bookmark_records[:rroonga])],
169
174
  bookmarks.to_a)
170
175
  end
171
176
 
@@ -225,7 +230,8 @@ class TestBase < Test::Unit::TestCase
225
230
  end
226
231
  target =~ "groonga"
227
232
  end
228
- assert_equal([["http://groonga.org/", 10]],
233
+ assert_equal([["http://groonga.org/", 10],
234
+ ["http://groonga.rubyforge.org/", 5]],
229
235
  bookmarks.collect {|bookmark| [bookmark.uri, bookmark.score]})
230
236
  end
231
237
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -17,15 +17,127 @@
17
17
  class TestResultSet < Test::Unit::TestCase
18
18
  include ActiveGroongaTestUtils
19
19
 
20
- def test_paginate
21
- bookmarks = Bookmark.select
22
- assert_equal(["http://cutter.sourceforge.net/"].sort,
23
- bookmarks.paginate(["uri"], :size => 1).collect(&:uri))
20
+ def teardown
21
+ Bookmark.sort_keys = nil
22
+ Bookmark.limit = nil
24
23
  end
25
24
 
26
- def test_sort
27
- bookmarks = Bookmark.select
28
- assert_equal(["http://cutter.sourceforge.net/"].sort,
29
- bookmarks.sort(["uri"], :limit => 1).collect(&:uri))
25
+ class TestPaginate < self
26
+ def test_explicit
27
+ bookmarks = Bookmark.select
28
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
29
+ bookmarks.paginate(["uri"], :size => 1).collect(&:uri))
30
+ end
31
+ end
32
+
33
+ class TestPaginateSortKeys < self
34
+ def test_implicit
35
+ Bookmark.sort_keys = ["uri"]
36
+ bookmarks = Bookmark.select
37
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
38
+ bookmarks.paginate(:size => 1).collect(&:uri))
39
+ end
40
+
41
+ def test_explicit
42
+ Bookmark.sort_keys = ["uri"]
43
+ bookmarks = Bookmark.select
44
+ assert_equal([User.find(@user_records[:daijiro].id)].sort,
45
+ bookmarks.paginate(["user"], :size => 1).collect(&:user))
46
+ end
47
+ end
48
+
49
+ class TestPaginateLimit < self
50
+ def test_implicit
51
+ Bookmark.limit = 2
52
+ bookmarks = Bookmark.select
53
+ assert_equal(["http://cutter.sourceforge.net/",
54
+ "http://groonga.org/"].sort,
55
+ bookmarks.paginate(["uri"]).collect(&:uri))
56
+ end
57
+
58
+ def test_explicit
59
+ Bookmark.limit = 2
60
+ bookmarks = Bookmark.select
61
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
62
+ bookmarks.paginate(["uri"], :size => 1).collect(&:uri))
63
+ end
64
+ end
65
+
66
+ class TestPaginateAll < self
67
+ def test_implicit
68
+ Bookmark.sort_keys = ["uri"]
69
+ Bookmark.limit = 2
70
+ bookmarks = Bookmark.select
71
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
72
+ bookmarks.paginate(:size => 1).collect(&:uri))
73
+ end
74
+
75
+ def test_explicit
76
+ Bookmark.sort_keys = ["uri"]
77
+ Bookmark.limit = 2
78
+ bookmarks = Bookmark.select
79
+ assert_equal([User.find(@user_records[:daijiro].id)].sort,
80
+ bookmarks.paginate(["user"], :size => 1).collect(&:user))
81
+ end
82
+ end
83
+
84
+ class TestSort < self
85
+ def test_explicit
86
+ bookmarks = Bookmark.select
87
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
88
+ bookmarks.sort(["uri"], :limit => 1).collect(&:uri))
89
+ end
90
+ end
91
+
92
+ class TestSortSortKeys < self
93
+ def test_implicit
94
+ Bookmark.sort_keys = ["uri"]
95
+ bookmarks = Bookmark.select
96
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
97
+ bookmarks.sort(:limit => 1).collect(&:uri))
98
+ end
99
+
100
+ def test_explicit
101
+ Bookmark.sort_keys = ["uri"]
102
+ bookmarks = Bookmark.select
103
+ assert_equal([User.find(@user_records[:daijiro].id)].sort,
104
+ bookmarks.sort(["user"], :limit => 1).collect(&:user))
105
+ end
106
+ end
107
+
108
+ class TestSortLimit < self
109
+ def test_implicit
110
+ Bookmark.limit = 2
111
+ bookmarks = Bookmark.select
112
+ assert_equal(["http://cutter.sourceforge.net/",
113
+ "http://groonga.org/",].sort,
114
+ bookmarks.sort(["uri"]).collect(&:uri))
115
+ end
116
+
117
+ def test_explicit
118
+ Bookmark.limit = 2
119
+ bookmarks = Bookmark.select
120
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
121
+ bookmarks.sort(["uri"], :limit => 1).collect(&:uri))
122
+ end
123
+ end
124
+
125
+ class TestSortAll < self
126
+ def test_implicit
127
+ Bookmark.sort_keys = ["uri"]
128
+ Bookmark.limit = 2
129
+ bookmarks = Bookmark.select
130
+ assert_equal(["http://cutter.sourceforge.net/",
131
+ "http://groonga.org/"].sort,
132
+ bookmarks.sort.collect(&:uri))
133
+ end
134
+
135
+ def test_explicit
136
+ Bookmark.sort_keys = ["uri"]
137
+ Bookmark.limit = 2
138
+ bookmarks = Bookmark.select
139
+ assert_equal([User.find(@user_records[:daijiro].id)].sort,
140
+ bookmarks.sort(["user"], :limit => 1).collect(&:user))
141
+ end
30
142
  end
31
143
  end