acts_as_ferret 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README +6 -0
  2. data/doc/demo/Gemfile +18 -0
  3. data/doc/demo/Rakefile +3 -6
  4. data/doc/demo/app/controllers/application_controller.rb +3 -0
  5. data/doc/demo/app/helpers/application_helper.rb +0 -1
  6. data/doc/demo/app/views/admin/backend/search.rhtml +1 -1
  7. data/doc/demo/app/views/contents/edit.rhtml +1 -1
  8. data/doc/demo/app/views/contents/new.rhtml +1 -1
  9. data/doc/demo/app/views/searches/search.html.erb +1 -1
  10. data/doc/demo/config.ru +4 -0
  11. data/doc/demo/config/application.rb +57 -0
  12. data/doc/demo/config/boot.rb +4 -107
  13. data/doc/demo/config/database.yml +16 -24
  14. data/doc/demo/config/environment.rb +4 -68
  15. data/doc/demo/config/environments/development.rb +22 -12
  16. data/doc/demo/config/environments/production.rb +43 -13
  17. data/doc/demo/config/environments/test.rb +32 -16
  18. data/doc/demo/config/initializers/backtrace_silencers.rb +7 -0
  19. data/doc/demo/config/initializers/inflections.rb +10 -0
  20. data/doc/demo/config/initializers/mime_types.rb +5 -0
  21. data/doc/demo/config/initializers/secret_token.rb +7 -0
  22. data/doc/demo/config/initializers/session_store.rb +13 -0
  23. data/doc/demo/config/locales/en.yml +5 -0
  24. data/doc/demo/config/routes.rb +4 -5
  25. data/doc/demo/public/404.html +23 -5
  26. data/doc/demo/public/422.html +26 -0
  27. data/doc/demo/public/500.html +23 -5
  28. data/doc/demo/public/images/rails.png +0 -0
  29. data/doc/demo/public/index.html +50 -88
  30. data/doc/demo/public/javascripts/application.js +2 -0
  31. data/doc/demo/public/javascripts/controls.js +965 -0
  32. data/doc/demo/public/javascripts/dragdrop.js +974 -0
  33. data/doc/demo/public/javascripts/effects.js +1123 -0
  34. data/doc/demo/public/javascripts/prototype.js +6001 -0
  35. data/doc/demo/public/javascripts/rails.js +191 -0
  36. data/doc/demo/public/robots.txt +5 -1
  37. data/doc/demo/script/rails +6 -0
  38. data/doc/demo/test/functional/admin/backend_controller_test.rb +1 -1
  39. data/doc/demo/test/functional/contents_controller_test.rb +1 -2
  40. data/doc/demo/test/functional/searches_controller_test.rb +1 -2
  41. data/doc/demo/test/performance/browsing_test.rb +9 -0
  42. data/doc/demo/test/test_helper.rb +13 -18
  43. data/doc/demo/test/unit/comment_test.rb +4 -4
  44. data/doc/demo/test/unit/content_test.rb +6 -4
  45. data/doc/demo/test/unit/ferret_result_test.rb +2 -3
  46. data/doc/demo/test/unit/multi_index_test.rb +2 -3
  47. data/doc/demo/test/unit/remote_index_test.rb +2 -2
  48. data/doc/demo/test/unit/shared_index1_test.rb +2 -3
  49. data/doc/demo/test/unit/shared_index2_test.rb +2 -3
  50. data/doc/demo/test/unit/sort_test.rb +2 -2
  51. data/doc/demo/test/unit/special_content_test.rb +3 -4
  52. data/lib/acts_as_ferret.rb +17 -3
  53. data/lib/acts_as_ferret/blank_slate.rb +11 -10
  54. data/lib/acts_as_ferret/class_methods.rb +9 -7
  55. data/lib/acts_as_ferret/ferret_find_methods.rb +5 -1
  56. data/lib/acts_as_ferret/ferret_result.rb +11 -4
  57. data/lib/acts_as_ferret/multi_index.rb +8 -1
  58. data/lib/acts_as_ferret/search_results.rb +0 -1
  59. data/lib/acts_as_ferret/version.rb +1 -1
  60. metadata +23 -44
  61. data/doc/demo/test/fixtures/remote_contents.yml +0 -9
  62. data/doc/demo/vendor/plugins/will_paginate/LICENSE +0 -18
  63. data/doc/demo/vendor/plugins/will_paginate/README +0 -108
  64. data/doc/demo/vendor/plugins/will_paginate/Rakefile +0 -23
  65. data/doc/demo/vendor/plugins/will_paginate/init.rb +0 -21
  66. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +0 -45
  67. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +0 -44
  68. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +0 -159
  69. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +0 -95
  70. data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +0 -23
  71. data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +0 -27
  72. data/doc/demo/vendor/plugins/will_paginate/test/console +0 -10
  73. data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +0 -219
  74. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +0 -3
  75. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +0 -24
  76. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +0 -23
  77. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +0 -11
  78. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +0 -13
  79. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +0 -4
  80. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +0 -7
  81. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +0 -20
  82. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +0 -5
  83. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +0 -44
  84. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +0 -19
  85. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +0 -30
  86. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +0 -2
  87. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +0 -35
  88. data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +0 -42
  89. data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +0 -64
  90. data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +0 -10
  91. data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +0 -136
@@ -1,219 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- require File.dirname(__FILE__) + '/../init'
3
-
4
- class FinderTest < ActiveRecordTestCase
5
- fixtures :topics, :replies, :users, :projects, :developers_projects, :companies
6
-
7
- def test_new_methods_presence
8
- assert_respond_to_all Topic, %w(per_page paginate paginate_by_sql)
9
- end
10
-
11
- def test_paginated_collection
12
- entries = %w(a b c)
13
- collection = WillPaginate::Collection.new 2, 3, 10
14
- collection.replace entries
15
-
16
- assert_equal entries, collection
17
- assert_respond_to_all collection, %w(page_count each offset size current_page per_page total_entries)
18
- assert_equal Array, collection.entries.class
19
- assert_equal 3, collection.offset
20
- end
21
-
22
- def test_simple_paginate
23
- entries = Topic.paginate :page => nil
24
- assert_equal 1, entries.current_page
25
- assert_nil entries.previous_page
26
- assert_nil entries.next_page
27
- assert_equal 1, entries.page_count
28
- assert_equal 4, entries.size
29
-
30
- entries = Topic.paginate :page => 2
31
- assert_equal 2, entries.current_page
32
- assert_equal 1, entries.previous_page
33
- assert_equal 1, entries.page_count
34
- assert entries.empty?
35
-
36
- # :page parameter in options is required!
37
- assert_raise(ArgumentError){ Topic.paginate }
38
- assert_raise(ArgumentError){ Topic.paginate({}) }
39
- end
40
-
41
- def test_paginate_with_per_page
42
- entries = Topic.paginate :page => 1, :per_page => 1
43
- assert_equal 1, entries.size
44
- assert_equal 4, entries.page_count
45
-
46
- # Developer class has explicit per_page at 10
47
- entries = Developer.paginate :page => 1
48
- assert_equal 10, entries.size
49
- assert_equal 2, entries.page_count
50
-
51
- entries = Developer.paginate :page => 1, :per_page => 5
52
- assert_equal 11, entries.total_entries
53
- assert_equal 5, entries.size
54
- assert_equal 3, entries.page_count
55
- end
56
-
57
- def test_paginate_with_order
58
- entries = Topic.paginate :page => 1, :order => 'created_at desc'
59
- expected = [topics(:futurama), topics(:harvey_birdman), topics(:rails), topics(:ar)].reverse
60
- assert_equal expected, entries.to_a
61
- assert_equal 1, entries.page_count
62
- end
63
-
64
- def test_paginate_with_conditions
65
- entries = Topic.paginate :page => 1, :conditions => ["created_at > ?", 30.minutes.ago]
66
- expected = [topics(:rails), topics(:ar)]
67
- assert_equal expected, entries.to_a
68
- assert_equal 1, entries.page_count
69
- end
70
-
71
- def test_paginate_associations
72
- dhh = users :david
73
- expected_name_ordered = [projects(:action_controller), projects(:active_record)]
74
- expected_id_ordered = [projects(:active_record), projects(:action_controller)]
75
-
76
- # with association-specified order
77
- entries = dhh.projects.paginate(:page => 1)
78
- assert_equal expected_name_ordered, entries
79
- assert_equal 2, entries.total_entries
80
-
81
- # with explicit order
82
- entries = dhh.projects.paginate(:page => 1, :order => 'projects.id')
83
- assert_equal expected_id_ordered, entries
84
- assert_equal 2, entries.total_entries
85
-
86
- assert_nothing_raised { dhh.projects.find(:all, :order => 'projects.id', :limit => 4) }
87
- entries = dhh.projects.paginate(:page => 1, :order => 'projects.id', :per_page => 4)
88
- assert_equal expected_id_ordered, entries
89
-
90
- # has_many with implicit order
91
- topic = Topic.find(1)
92
- expected = [replies(:spam), replies(:witty_retort)]
93
- assert_equal expected.map(&:id).sort, topic.replies.paginate(:page => 1).map(&:id).sort
94
- assert_equal expected.reverse, topic.replies.paginate(:page => 1, :order => 'replies.id ASC')
95
- end
96
-
97
- def test_paginate_with_joins
98
- entries = Developer.paginate :page => 1,
99
- :joins => 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id',
100
- :conditions => 'project_id = 1'
101
- assert_equal 2, entries.size
102
- developer_names = entries.map { |d| d.name }
103
- assert developer_names.include?('David')
104
- assert developer_names.include?('Jamis')
105
-
106
- expected = entries.to_a
107
- entries = Developer.paginate :page => 1,
108
- :joins => 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id',
109
- :conditions => 'project_id = 1', :count => { :select => "users.id" }
110
- assert_equal expected, entries.to_a
111
- end
112
-
113
- def test_paginate_with_include_and_order
114
- entries = Topic.paginate \
115
- :page => 1,
116
- :include => :replies,
117
- :order => 'replies.created_at asc, topics.created_at asc',
118
- :per_page => 10
119
-
120
- expected = Topic.find :all,
121
- :include => 'replies',
122
- :order => 'replies.created_at asc, topics.created_at asc',
123
- :limit => 10
124
-
125
- assert_equal expected, entries.to_a
126
- end
127
-
128
- def test_paginate_with_group
129
- entries = Developer.paginate :page => 1, :per_page => 10, :group => 'salary'
130
- expected = [ users(:david), users(:jamis), users(:dev_10), users(:poor_jamis) ].map(&:salary).sort
131
- assert_equal expected, entries.map(&:salary).sort
132
- end
133
-
134
- def test_paginate_with_dynamic_finder
135
- expected = [replies(:witty_retort), replies(:spam)]
136
- assert_equal expected, Reply.paginate_all_by_topic_id(1, :page => 1)
137
- assert_equal expected, Reply.paginate_by_topic_id(1, :page => 1)
138
-
139
- entries = Developer.paginate :conditions => { :salary => 100000 }, :page => 1, :per_page => 5
140
- assert_equal 8, entries.total_entries
141
- assert_equal entries, Developer.paginate_by_salary(100000, :page => 1, :per_page => 5)
142
-
143
- # dynamic finder + conditions
144
- entries = Developer.paginate_by_salary(100000, :page => 1,
145
- :conditions => ['id > ?', 6])
146
- assert_equal 4, entries.total_entries
147
- assert_equal (7..10).to_a, entries.map(&:id)
148
-
149
- assert_raises RuntimeError do
150
- Developer.paginate_by_inexistent_attribute 100000, :page => 1
151
- end
152
- end
153
-
154
- def test_paginate_by_sql
155
- assert_respond_to Developer, :paginate_by_sql
156
- entries = Developer.paginate_by_sql ['select * from users where salary > ?', 80000],
157
- :page => 2, :per_page => 3, :total_entries => 9
158
-
159
- assert_equal (5..7).to_a, entries.map(&:id)
160
- assert_equal 9, entries.total_entries
161
- end
162
-
163
- def test_count_by_sql
164
- entries = Developer.paginate_by_sql ['select * from users where salary > ?', 60000],
165
- :page => 2, :per_page => 3
166
-
167
- assert_equal 12, entries.total_entries
168
- end
169
-
170
- def test_scoped_paginate
171
- entries =
172
- Developer.with_poor_ones do
173
- Developer.paginate :page => 1
174
- end
175
-
176
- assert_equal 2, entries.size
177
- assert_equal 2, entries.total_entries
178
- end
179
-
180
- def test_edge_case_api_madness
181
- # explicit :all should not break anything
182
- assert_equal Topic.paginate(:page => nil), Topic.paginate(:all, :page => 1)
183
-
184
- # this is a little weird test for issue #37
185
- # the Topic model find and count methods accept an extra option, :foo
186
- # this checks if that extra option was intact by our paginating finder
187
- entries = Topic.paginate(:foo => 'bar', :page => 1)
188
- assert_equal 'bar', entries.first
189
- assert_equal 100, entries.total_entries
190
-
191
- # Are we on edge? Find out by testing find_all which was removed in [6998]
192
- unless Developer.respond_to? :find_all
193
- # AR finders also accept arrays of IDs
194
- # (this was broken in Rails before [6912])
195
- entries = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2)
196
- assert_equal (4..6).to_a, entries.map(&:id)
197
- assert_equal 8, entries.total_entries
198
- end
199
- end
200
-
201
- def test_count_doesnt_use_select_options
202
- assert_nothing_raised do
203
- Developer.paginate :select => 'users.*', :page => 1
204
- end
205
- end
206
-
207
- def test_should_use_scoped_finders_if_present
208
- companies = Company.paginate_best :all, :page => 1
209
- assert_equal 3, companies.total_entries
210
- end
211
-
212
- protected
213
-
214
- def assert_respond_to_all object, methods
215
- methods.each do |method|
216
- [method.to_s, method.to_sym].each {|m| assert_respond_to object, m }
217
- end
218
- end
219
- end
@@ -1,3 +0,0 @@
1
- class Admin < User
2
- has_many :companies, :finder_sql => 'SELECT * FROM companies'
3
- end
@@ -1,24 +0,0 @@
1
- thirty_seven_signals:
2
- id: 1
3
- name: 37Signals
4
- rating: 4
5
-
6
- TextDrive:
7
- id: 2
8
- name: TextDrive
9
- rating: 3
10
-
11
- PlanetArgon:
12
- id: 3
13
- name: Planet Argon
14
- rating: 3
15
-
16
- Google:
17
- id: 4
18
- name: Google
19
- rating: 5
20
-
21
- Ionist:
22
- id: 5
23
- name: Ioni.st
24
- rating: 4
@@ -1,23 +0,0 @@
1
- class Company < ActiveRecord::Base
2
- attr_protected :rating
3
- set_sequence_name :companies_nonstd_seq
4
-
5
- validates_presence_of :name
6
- def validate
7
- errors.add('rating', 'rating should not be 2') if rating == 2
8
- end
9
-
10
- def self.with_best
11
- with_scope :find => { :conditions => ['companies.rating > ?', 3] } do
12
- yield
13
- end
14
- end
15
-
16
- def self.find_best(*args)
17
- with_best { find(*args) }
18
- end
19
-
20
- def self.calculate_best(*args)
21
- with_best { calculate(*args) }
22
- end
23
- end
@@ -1,11 +0,0 @@
1
- class Developer < User
2
- has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name'
3
-
4
- def self.with_poor_ones(&block)
5
- with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
6
- yield
7
- end
8
- end
9
-
10
- def self.per_page() 10 end
11
- end
@@ -1,13 +0,0 @@
1
- david_action_controller:
2
- developer_id: 1
3
- project_id: 2
4
- joined_on: 2004-10-10
5
-
6
- david_active_record:
7
- developer_id: 1
8
- project_id: 1
9
- joined_on: 2004-10-10
10
-
11
- jamis_active_record:
12
- developer_id: 2
13
- project_id: 1
@@ -1,4 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers, :uniq => true
3
- has_many :topics
4
- end
@@ -1,7 +0,0 @@
1
- action_controller:
2
- id: 2
3
- name: Active Controller
4
-
5
- active_record:
6
- id: 1
7
- name: Active Record
@@ -1,20 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- class Reply < ActiveRecord::Base
2
- belongs_to :topic, :include => [:replies]
3
-
4
- validates_presence_of :content
5
- end
@@ -1,44 +0,0 @@
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
- );
@@ -1,19 +0,0 @@
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
@@ -1,30 +0,0 @@
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) %>
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,35 +0,0 @@
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