watson-acts_as_ferret 0.4.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/LICENSE +20 -0
  2. data/README +104 -0
  3. data/acts_as_ferret.gemspec +58 -0
  4. data/bin/aaf_install +29 -0
  5. data/config/ferret_server.yml +24 -0
  6. data/doc/README.win32 +23 -0
  7. data/doc/demo/README +154 -0
  8. data/doc/demo/README_DEMO +23 -0
  9. data/doc/demo/Rakefile +10 -0
  10. data/doc/demo/app/controllers/admin/backend_controller.rb +14 -0
  11. data/doc/demo/app/controllers/admin_area_controller.rb +4 -0
  12. data/doc/demo/app/controllers/application.rb +5 -0
  13. data/doc/demo/app/controllers/contents_controller.rb +49 -0
  14. data/doc/demo/app/controllers/searches_controller.rb +8 -0
  15. data/doc/demo/app/helpers/admin/backend_helper.rb +2 -0
  16. data/doc/demo/app/helpers/application_helper.rb +3 -0
  17. data/doc/demo/app/helpers/content_helper.rb +2 -0
  18. data/doc/demo/app/helpers/search_helper.rb +2 -0
  19. data/doc/demo/app/models/comment.rb +48 -0
  20. data/doc/demo/app/models/content.rb +12 -0
  21. data/doc/demo/app/models/content_base.rb +28 -0
  22. data/doc/demo/app/models/search.rb +19 -0
  23. data/doc/demo/app/models/shared_index1.rb +3 -0
  24. data/doc/demo/app/models/shared_index2.rb +3 -0
  25. data/doc/demo/app/models/special_content.rb +3 -0
  26. data/doc/demo/app/models/stats.rb +20 -0
  27. data/doc/demo/app/views/admin/backend/search.rhtml +18 -0
  28. data/doc/demo/app/views/contents/_form.rhtml +10 -0
  29. data/doc/demo/app/views/contents/edit.rhtml +9 -0
  30. data/doc/demo/app/views/contents/index.rhtml +24 -0
  31. data/doc/demo/app/views/contents/new.rhtml +8 -0
  32. data/doc/demo/app/views/contents/show.rhtml +8 -0
  33. data/doc/demo/app/views/layouts/application.html.erb +17 -0
  34. data/doc/demo/app/views/searches/_content.html.erb +2 -0
  35. data/doc/demo/app/views/searches/search.html.erb +20 -0
  36. data/doc/demo/config/boot.rb +109 -0
  37. data/doc/demo/config/database.yml +38 -0
  38. data/doc/demo/config/environment.rb +69 -0
  39. data/doc/demo/config/environments/development.rb +16 -0
  40. data/doc/demo/config/environments/production.rb +19 -0
  41. data/doc/demo/config/environments/test.rb +21 -0
  42. data/doc/demo/config/ferret_server.yml +18 -0
  43. data/doc/demo/config/lighttpd.conf +40 -0
  44. data/doc/demo/config/routes.rb +9 -0
  45. data/doc/demo/db/development_structure.sql +15 -0
  46. data/doc/demo/db/migrate/001_initial_migration.rb +18 -0
  47. data/doc/demo/db/migrate/002_add_type_to_contents.rb +9 -0
  48. data/doc/demo/db/migrate/003_create_shared_index1s.rb +11 -0
  49. data/doc/demo/db/migrate/004_create_shared_index2s.rb +11 -0
  50. data/doc/demo/db/migrate/005_special_field.rb +9 -0
  51. data/doc/demo/db/migrate/006_create_stats.rb +15 -0
  52. data/doc/demo/db/schema.sql +18 -0
  53. data/doc/demo/db/schema.sqlite +14 -0
  54. data/doc/demo/doc/README_FOR_APP +2 -0
  55. data/doc/demo/doc/howto.txt +70 -0
  56. data/doc/demo/public/404.html +8 -0
  57. data/doc/demo/public/500.html +8 -0
  58. data/doc/demo/public/dispatch.cgi +10 -0
  59. data/doc/demo/public/dispatch.fcgi +24 -0
  60. data/doc/demo/public/dispatch.rb +10 -0
  61. data/doc/demo/public/favicon.ico +0 -0
  62. data/doc/demo/public/images/rails.png +0 -0
  63. data/doc/demo/public/index.html +277 -0
  64. data/doc/demo/public/robots.txt +1 -0
  65. data/doc/demo/public/stylesheets/scaffold.css +74 -0
  66. data/doc/demo/script/about +3 -0
  67. data/doc/demo/script/breakpointer +3 -0
  68. data/doc/demo/script/console +3 -0
  69. data/doc/demo/script/destroy +3 -0
  70. data/doc/demo/script/ferret_server +10 -0
  71. data/doc/demo/script/generate +3 -0
  72. data/doc/demo/script/performance/benchmarker +3 -0
  73. data/doc/demo/script/performance/profiler +3 -0
  74. data/doc/demo/script/plugin +3 -0
  75. data/doc/demo/script/process/inspector +3 -0
  76. data/doc/demo/script/process/reaper +3 -0
  77. data/doc/demo/script/process/spawner +3 -0
  78. data/doc/demo/script/process/spinner +3 -0
  79. data/doc/demo/script/runner +3 -0
  80. data/doc/demo/script/server +3 -0
  81. data/doc/demo/test/fixtures/comments.yml +12 -0
  82. data/doc/demo/test/fixtures/contents.yml +13 -0
  83. data/doc/demo/test/fixtures/remote_contents.yml +9 -0
  84. data/doc/demo/test/fixtures/shared_index1s.yml +7 -0
  85. data/doc/demo/test/fixtures/shared_index2s.yml +7 -0
  86. data/doc/demo/test/functional/admin/backend_controller_test.rb +35 -0
  87. data/doc/demo/test/functional/contents_controller_test.rb +81 -0
  88. data/doc/demo/test/functional/searches_controller_test.rb +71 -0
  89. data/doc/demo/test/smoke/drb_smoke_test.rb +321 -0
  90. data/doc/demo/test/smoke/process_stats.rb +21 -0
  91. data/doc/demo/test/test_helper.rb +30 -0
  92. data/doc/demo/test/unit/comment_test.rb +217 -0
  93. data/doc/demo/test/unit/content_test.rb +705 -0
  94. data/doc/demo/test/unit/ferret_result_test.rb +24 -0
  95. data/doc/demo/test/unit/multi_index_test.rb +329 -0
  96. data/doc/demo/test/unit/remote_index_test.rb +23 -0
  97. data/doc/demo/test/unit/shared_index1_test.rb +108 -0
  98. data/doc/demo/test/unit/shared_index2_test.rb +13 -0
  99. data/doc/demo/test/unit/sort_test.rb +21 -0
  100. data/doc/demo/test/unit/special_content_test.rb +25 -0
  101. data/doc/demo/vendor/plugins/will_paginate/LICENSE +18 -0
  102. data/doc/demo/vendor/plugins/will_paginate/README +108 -0
  103. data/doc/demo/vendor/plugins/will_paginate/Rakefile +23 -0
  104. data/doc/demo/vendor/plugins/will_paginate/init.rb +21 -0
  105. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +45 -0
  106. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +44 -0
  107. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +159 -0
  108. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +95 -0
  109. data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +23 -0
  110. data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +27 -0
  111. data/doc/demo/vendor/plugins/will_paginate/test/console +10 -0
  112. data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +219 -0
  113. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
  114. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +24 -0
  115. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +23 -0
  116. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
  117. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +13 -0
  118. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +4 -0
  119. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +7 -0
  120. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +20 -0
  121. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
  122. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +44 -0
  123. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +19 -0
  124. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +30 -0
  125. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
  126. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +35 -0
  127. data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +42 -0
  128. data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +64 -0
  129. data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +10 -0
  130. data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +136 -0
  131. data/doc/monit-example +22 -0
  132. data/init.rb +24 -0
  133. data/install.rb +18 -0
  134. data/lib/act_methods.rb +147 -0
  135. data/lib/acts_as_ferret.rb +593 -0
  136. data/lib/ar_mysql_auto_reconnect_patch.rb +41 -0
  137. data/lib/blank_slate.rb +54 -0
  138. data/lib/bulk_indexer.rb +56 -0
  139. data/lib/class_methods.rb +279 -0
  140. data/lib/ferret_extensions.rb +192 -0
  141. data/lib/ferret_find_methods.rb +142 -0
  142. data/lib/ferret_result.rb +58 -0
  143. data/lib/ferret_server.rb +238 -0
  144. data/lib/index.rb +99 -0
  145. data/lib/instance_methods.rb +172 -0
  146. data/lib/local_index.rb +202 -0
  147. data/lib/more_like_this.rb +217 -0
  148. data/lib/multi_index.rb +133 -0
  149. data/lib/rdig_adapter.rb +149 -0
  150. data/lib/remote_functions.rb +43 -0
  151. data/lib/remote_index.rb +54 -0
  152. data/lib/remote_multi_index.rb +20 -0
  153. data/lib/search_results.rb +50 -0
  154. data/lib/server_manager.rb +71 -0
  155. data/lib/unix_daemon.rb +86 -0
  156. data/lib/without_ar.rb +52 -0
  157. data/recipes/aaf_recipes.rb +116 -0
  158. data/script/ferret_daemon +94 -0
  159. data/script/ferret_server +12 -0
  160. data/script/ferret_service +178 -0
  161. data/tasks/ferret.rake +39 -0
  162. metadata +246 -0
@@ -0,0 +1,4 @@
1
+ class Project < ActiveRecord::Base
2
+ has_and_belongs_to_many :developers, :uniq => true
3
+ has_many :topics
4
+ end
@@ -0,0 +1,7 @@
1
+ action_controller:
2
+ id: 2
3
+ name: Active Controller
4
+
5
+ active_record:
6
+ id: 1
7
+ name: Active Record
@@ -0,0 +1,20 @@
1
+ witty_retort:
2
+ id: 1
3
+ topic_id: 1
4
+ content: Birdman is better!
5
+ created_at: <%= 6.hours.ago.to_s(:db) %>
6
+ updated_at: nil
7
+
8
+ another:
9
+ id: 2
10
+ topic_id: 2
11
+ content: Nuh uh!
12
+ created_at: <%= 1.hour.ago.to_s(:db) %>
13
+ updated_at: nil
14
+
15
+ spam:
16
+ id: 3
17
+ topic_id: 1
18
+ content: Nice site!
19
+ created_at: <%= 1.hour.ago.to_s(:db) %>
20
+ updated_at: nil
@@ -0,0 +1,5 @@
1
+ class Reply < ActiveRecord::Base
2
+ belongs_to :topic, :include => [:replies]
3
+
4
+ validates_presence_of :content
5
+ end
@@ -0,0 +1,44 @@
1
+ CREATE TABLE 'companies' (
2
+ 'id' INTEGER PRIMARY KEY NOT NULL,
3
+ 'name' TEXT DEFAULT NULL,
4
+ 'rating' INTEGER DEFAULT 1
5
+ );
6
+
7
+ CREATE TABLE 'replies' (
8
+ 'id' INTEGER PRIMARY KEY NOT NULL,
9
+ 'content' text,
10
+ 'created_at' datetime,
11
+ 'updated_at' datetime,
12
+ 'topic_id' integer
13
+ );
14
+
15
+ CREATE TABLE 'topics' (
16
+ 'id' INTEGER PRIMARY KEY NOT NULL,
17
+ 'project_id' INTEGER DEFAULT NULL,
18
+ 'title' varchar(255),
19
+ 'subtitle' varchar(255),
20
+ 'content' text,
21
+ 'created_at' datetime,
22
+ 'updated_at' datetime
23
+ );
24
+
25
+ CREATE TABLE 'users' (
26
+ 'id' INTEGER PRIMARY KEY NOT NULL,
27
+ 'name' TEXT DEFAULT NULL,
28
+ 'salary' INTEGER DEFAULT 70000,
29
+ 'created_at' DATETIME DEFAULT NULL,
30
+ 'updated_at' DATETIME DEFAULT NULL,
31
+ 'type' TEXT DEFAULT NULL
32
+ );
33
+
34
+ CREATE TABLE 'projects' (
35
+ 'id' INTEGER PRIMARY KEY NOT NULL,
36
+ 'name' TEXT DEFAULT NULL
37
+ );
38
+
39
+ CREATE TABLE 'developers_projects' (
40
+ 'developer_id' INTEGER NOT NULL,
41
+ 'project_id' INTEGER NOT NULL,
42
+ 'joined_on' DATE DEFAULT NULL,
43
+ 'access_level' INTEGER DEFAULT 1
44
+ );
@@ -0,0 +1,19 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
3
+ belongs_to :project
4
+
5
+ # pretend find and count were extended and accept an extra option
6
+ # if there is a :foo option, prepend its value to collection
7
+ def self.find(*args)
8
+ more = []
9
+ more << args.last.delete(:foo) if args.last.is_a?(Hash) and args.last[:foo]
10
+ res = super
11
+ more.empty?? res : more + res
12
+ end
13
+
14
+ # if there is a :foo option, always return 100
15
+ def self.count(*args)
16
+ return 100 if args.last.is_a?(Hash) and args.last[:foo]
17
+ super
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ futurama:
2
+ id: 1
3
+ title: Isnt futurama awesome?
4
+ subtitle: It really is, isnt it.
5
+ content: I like futurama
6
+ created_at: <%= 1.day.ago.to_s(:db) %>
7
+ updated_at:
8
+
9
+ harvey_birdman:
10
+ id: 2
11
+ title: Harvey Birdman is the king of all men
12
+ subtitle: yup
13
+ content: He really is
14
+ created_at: <%= 2.hours.ago.to_s(:db) %>
15
+ updated_at:
16
+
17
+ rails:
18
+ id: 3
19
+ project_id: 1
20
+ title: Rails is nice
21
+ subtitle: It makes me happy
22
+ content: except when I have to hack internals to fix pagination. even then really.
23
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
24
+
25
+ ar:
26
+ id: 4
27
+ project_id: 1
28
+ title: ActiveRecord sometimes freaks me out
29
+ content: "I mean, what's the deal with eager loading?"
30
+ created_at: <%= 15.minutes.ago.to_s(:db) %>
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,35 @@
1
+ david:
2
+ id: 1
3
+ name: David
4
+ salary: 80000
5
+ type: Developer
6
+
7
+ jamis:
8
+ id: 2
9
+ name: Jamis
10
+ salary: 150000
11
+ type: Developer
12
+
13
+ <% for digit in 3..10 %>
14
+ dev_<%= digit %>:
15
+ id: <%= digit %>
16
+ name: fixture_<%= digit %>
17
+ salary: 100000
18
+ type: Developer
19
+ <% end %>
20
+
21
+ poor_jamis:
22
+ id: 11
23
+ name: Jamis
24
+ salary: 9000
25
+ type: Developer
26
+
27
+ admin:
28
+ id: 12
29
+ name: admin
30
+ type: Admin
31
+
32
+ goofy:
33
+ id: 13
34
+ name: Goofy
35
+ type: Admin
@@ -0,0 +1,42 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ # gem install redgreen for colored test output
5
+ begin require 'redgreen'; rescue LoadError; end
6
+
7
+ dirname = File.dirname(__FILE__)
8
+ require File.join(dirname, 'boot') unless defined?(ActiveRecord)
9
+ require 'action_controller/test_process'
10
+ require File.join(dirname, 'lib', 'activerecord_test_connector')
11
+
12
+ # add plugin's main lib dir to load paths
13
+ $:.unshift(File.join(dirname, '..', 'lib')).uniq!
14
+
15
+ # Test case for inheritance
16
+ class ActiveRecordTestCase < Test::Unit::TestCase
17
+ # Set our fixture path
18
+ if ActiveRecordTestConnector.able_to_connect
19
+ self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
20
+ self.use_transactional_fixtures = false
21
+ end
22
+
23
+ def self.fixtures(*args)
24
+ super if ActiveRecordTestConnector.connected
25
+ end
26
+
27
+ def run(*args)
28
+ super if ActiveRecordTestConnector.connected
29
+ end
30
+
31
+ # Default so Test::Unit::TestCase doesn't complain
32
+ def test_truth
33
+ end
34
+ end
35
+
36
+ ActiveRecordTestConnector.setup
37
+ ActionController::Routing::Routes.reload rescue nil
38
+ ActionController::Routing::Routes.draw do |map|
39
+ map.connect ':controller/:action/:id'
40
+ end
41
+
42
+ ActionController::Base.perform_caching = false
@@ -0,0 +1,64 @@
1
+ class ActiveRecordTestConnector
2
+ cattr_accessor :able_to_connect
3
+ cattr_accessor :connected
4
+
5
+ # Set our defaults
6
+ self.connected = false
7
+ self.able_to_connect = true
8
+
9
+ def self.setup
10
+ unless self.connected || !self.able_to_connect
11
+ setup_connection
12
+ load_schema
13
+ require_fixture_models
14
+ self.connected = true
15
+ end
16
+ rescue Exception => e # errors from ActiveRecord setup
17
+ $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
18
+ #$stderr.puts " #{e.backtrace.join("\n ")}\n"
19
+ self.able_to_connect = false
20
+ end
21
+
22
+ private
23
+
24
+ def self.setup_connection
25
+ if Object.const_defined?(:ActiveRecord)
26
+ defaults = { :database => ':memory:' }
27
+ # ActiveRecord::Base.logger = Logger.new STDOUT
28
+
29
+ begin
30
+ options = defaults.merge :adapter => 'sqlite3', :timeout => 500
31
+ ActiveRecord::Base.establish_connection(options)
32
+ ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
33
+ ActiveRecord::Base.connection
34
+ rescue Exception # errors from establishing a connection
35
+ $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
36
+ options = defaults.merge :adapter => 'sqlite'
37
+ ActiveRecord::Base.establish_connection(options)
38
+ ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
39
+ ActiveRecord::Base.connection
40
+ end
41
+
42
+ unless Object.const_defined?(:QUOTED_TYPE)
43
+ Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
44
+ end
45
+ else
46
+ raise "Can't setup connection since ActiveRecord isn't loaded."
47
+ end
48
+ end
49
+
50
+ # Load actionpack sqlite tables
51
+ def self.load_schema
52
+ ActiveRecord::Base.silence do
53
+ File.read(File.dirname(__FILE__) + "/../fixtures/schema.sql").split(';').each do |sql|
54
+ ActiveRecord::Base.connection.execute(sql) unless sql.blank?
55
+ end
56
+ end
57
+ end
58
+
59
+ def self.require_fixture_models
60
+ models = Dir.glob(File.dirname(__FILE__) + "/../fixtures/*.rb")
61
+ models = (models.grep(/user.rb/) + models).uniq
62
+ models.each {|f| require f}
63
+ end
64
+ end
@@ -0,0 +1,10 @@
1
+ dirname = File.dirname(__FILE__)
2
+ require File.join(dirname, '..', 'boot')
3
+ require File.join(dirname, 'activerecord_test_connector')
4
+
5
+ # setup the connection
6
+ ActiveRecordTestConnector.setup
7
+
8
+ # load all fixtures
9
+ fixture_path = File.join(dirname, '..', 'fixtures')
10
+ Fixtures.create_fixtures(fixture_path, ActiveRecord::Base.connection.tables)
@@ -0,0 +1,136 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require File.dirname(__FILE__) + '/../init'
3
+
4
+ class PaginationTest < ActiveRecordTestCase
5
+ fixtures :users
6
+
7
+ class PaginationController < ActionController::Base
8
+ def list_developers
9
+ @developers = Developer.paginate :page => params[params[:param_name] || :page],
10
+ :per_page => (params[:per_page] || 4).to_i
11
+
12
+ @options = params.except(:count, :order)
13
+ WillPaginate::ViewHelpers.pagination_options.keys.each { |key| params.delete key }
14
+
15
+ render :inline => '<%= will_paginate @developers, @options %>'
16
+ end
17
+
18
+ def no_pagination
19
+ @developers = Developer.paginate :page => params[:page], :per_page => 15
20
+ render :inline => '<%= will_paginate @developers %>'
21
+ end
22
+
23
+ protected
24
+ def rescue_errors(e) raise e end
25
+ def rescue_action(e) raise e end
26
+ end
27
+
28
+ def setup
29
+ @controller = PaginationController.new
30
+ @request = ActionController::TestRequest.new
31
+ @response = ActionController::TestResponse.new
32
+ super
33
+ end
34
+
35
+ def test_will_paginate
36
+ get :list_developers
37
+
38
+ entries = assigns :developers
39
+ assert entries
40
+ assert_equal 4, entries.size
41
+
42
+ assert_select 'div.pagination', 1, 'no main DIV' do |el|
43
+ assert_select 'a[href]', 3 do |elements|
44
+ validate_page_numbers [2,3,2], elements
45
+ assert_select elements.last, ':last-child', "Next &raquo;"
46
+ end
47
+ assert_select 'span', 2
48
+ assert_select 'span.disabled:first-child', "&laquo; Previous"
49
+ assert_select 'span.current', entries.current_page.to_s
50
+ end
51
+ end
52
+
53
+ def test_will_paginate_with_options
54
+ get :list_developers, :page => 2, :class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next'
55
+ assert_response :success
56
+
57
+ entries = assigns :developers
58
+ assert entries
59
+ assert_equal 4, entries.size
60
+
61
+ assert_select 'div.will_paginate', 1, 'no main DIV' do
62
+ assert_select 'a[href]', 4 do |elements|
63
+ validate_page_numbers [nil,nil,3,3], elements
64
+ assert_select elements.first, 'a', "Prev"
65
+ assert_select elements.last, 'a', "Next"
66
+ end
67
+ assert_select 'span.current', entries.current_page.to_s
68
+ end
69
+ end
70
+
71
+ def test_will_paginate_preserves_parameters
72
+ get :list_developers, :foo => { :bar => 'baz' }
73
+ assert_response :success
74
+
75
+ assert_select 'div.pagination', 1, 'no main DIV' do
76
+ assert_select 'a[href]', 3 do |elements|
77
+ elements.each do |el|
78
+ assert_match /foo%5Bbar%5D=baz/, el['href']
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def test_will_paginate_with_custom_page_param
85
+ get :list_developers, :developers_page => 2, :param_name => :developers_page
86
+ assert_response :success
87
+
88
+ entries = assigns :developers
89
+ assert entries
90
+ assert_equal 4, entries.size
91
+
92
+ assert_select 'div.pagination', 1, 'no main DIV' do
93
+ assert_select 'a[href]', 4 do |elements|
94
+ validate_page_numbers [nil,nil,3,3], elements, :developers_page
95
+ end
96
+ assert_select 'span.current', entries.current_page.to_s
97
+ end
98
+ end
99
+
100
+ def test_will_paginate_windows
101
+ get :list_developers, :page => 6, :per_page => 1, :inner_window => 2
102
+ assert_response :success
103
+
104
+ entries = assigns :developers
105
+ assert entries
106
+ assert_equal 1, entries.size
107
+
108
+ assert_select 'div.pagination', 1, 'no main DIV' do
109
+ assert_select 'a[href]', 10 do |elements|
110
+ validate_page_numbers [5,nil,2,4,5,7,8,10,11,7], elements
111
+ assert_select elements.first, 'a', "&laquo; Previous"
112
+ assert_select elements.last, 'a', "Next &raquo;"
113
+ end
114
+ assert_select 'span.current', entries.current_page.to_s
115
+ end
116
+ end
117
+
118
+ def test_no_pagination
119
+ get :no_pagination
120
+ entries = assigns :developers
121
+ assert_equal 1, entries.page_count
122
+ assert_equal Developer.count, entries.size
123
+
124
+ assert_select 'div', false
125
+ assert_equal '', @response.body
126
+ end
127
+
128
+ protected
129
+
130
+ def validate_page_numbers expected, links, param_name = :page
131
+ assert_equal(expected, links.map { |e|
132
+ e['href'] =~ /\W#{param_name}=([^&]*)/
133
+ $1 ? $1.to_i : $1
134
+ })
135
+ end
136
+ end
@@ -0,0 +1,22 @@
1
+ # monit configuration snippet to watch the Ferret DRb server shipped with
2
+ # acts_as_ferret
3
+ check process ferret with pidfile /path/to/ferret.pid
4
+
5
+ # username is the user the drb server should be running as (It's good practice
6
+ # to run such services as a non-privileged user)
7
+ start program = "/bin/su -c 'cd /path/to/your/app/current/ && script/ferret_server -e production start' username"
8
+ stop program = "/bin/su -c 'cd /path/to/your/app/current/ && script/ferret_server -e production stop' username"
9
+
10
+ # cpu usage boundaries
11
+ if cpu > 60% for 2 cycles then alert
12
+ if cpu > 90% for 5 cycles then restart
13
+
14
+ # memory usage varies with index size and usage scenarios, so check how
15
+ # much memory your DRb server uses up usually and add some spare to that
16
+ # before enabling this rule:
17
+ # if totalmem > 50.0 MB for 5 cycles then restart
18
+
19
+ # adjust port numbers according to your setup:
20
+ if failed port 9010 then alert
21
+ if failed port 9010 for 2 cycles then restart
22
+ group ferret