pose 1.2.5 → 1.3
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.
- data/README.md +36 -14
- data/lib/pose/models/pose_word.rb +1 -1
- data/lib/pose/static_api.rb +6 -4
- data/lib/pose/version.rb +1 -1
- data/spec/pose_api_spec.rb +6 -6
- data/spec/spec_helper.rb +0 -1
- data/spec/support/matchers.rb +1 -8
- metadata +2 -2
data/README.md
CHANGED
@@ -55,7 +55,7 @@ end
|
|
55
55
|
```
|
56
56
|
|
57
57
|
Note that you can return whatever content you want in the `posify` block,
|
58
|
-
not only data from this object, but also data from related objects, class names, etc.
|
58
|
+
not only data from this object, but also data from related objects, class names, etc.
|
59
59
|
|
60
60
|
Now that this class is posified, any `create`, `update`, or `delete` operation on any instance of this class will update the search index automatically.
|
61
61
|
|
@@ -106,7 +106,7 @@ result = Pose.search 'foo', MyClass
|
|
106
106
|
|
107
107
|
### Configure the result data
|
108
108
|
|
109
|
-
By default, search results are the instances of the objects matching the search query.
|
109
|
+
By default, search results are the instances of the objects matching the search query.
|
110
110
|
If you want to just get the ids of the search results, and not the full instances, use the parameter `:result_type`.
|
111
111
|
|
112
112
|
```ruby
|
@@ -126,25 +126,25 @@ result = Pose.search 'foo', MyClass, limit: 20 # Returns only 20 search resul
|
|
126
126
|
|
127
127
|
### Combine fulltext search with structured data search
|
128
128
|
|
129
|
-
You can add your own ActiveRecord query clauses to a fulltext search operation.
|
129
|
+
You can add your own ActiveRecord query clauses to a fulltext search operation.
|
130
130
|
For example, given a class `Note` that belongs to a `User` class and has a boolean attribute `public`,
|
131
131
|
finding all public notes from other users containing "foo" is as easy as:
|
132
132
|
|
133
133
|
```ruby
|
134
|
-
result = Pose.search 'foo', MyClass, where: [ public: true, ['user_id <> ?', @current_user.id] ]
|
134
|
+
result = Pose.search 'foo', MyClass, where: [ public: true, ['user_id <> ?', @current_user.id] ]
|
135
135
|
```
|
136
136
|
|
137
137
|
|
138
138
|
## Maintenance
|
139
139
|
|
140
|
-
Besides an accasional search index cleanup, Pose is relatively maintenance free.
|
140
|
+
Besides an accasional search index cleanup, Pose is relatively maintenance free.
|
141
141
|
The search index is automatically updated when objects are created, updated, or deleted.
|
142
142
|
|
143
143
|
|
144
144
|
### Optimizing the search index
|
145
145
|
|
146
146
|
For performance reasons, the search index keeps all the words that were ever used around, in order to try to reuse them as much as possible.
|
147
|
-
After deleting or changing a large number of objects, you can shrink the memory consumption of Pose's search index by
|
147
|
+
After deleting or changing a large number of objects, you can shrink the memory consumption of Pose's search index by
|
148
148
|
removing no longer used search terms from it.
|
149
149
|
|
150
150
|
```bash
|
@@ -161,7 +161,7 @@ rake pose:index:recreate[MyClass]
|
|
161
161
|
```
|
162
162
|
|
163
163
|
|
164
|
-
|
164
|
+
## Uninstalling
|
165
165
|
|
166
166
|
To remove all traces of Pose from your database, run:
|
167
167
|
|
@@ -174,14 +174,36 @@ Also don't forget to remove the `posify` block from your models as well as the g
|
|
174
174
|
|
175
175
|
## Use Pose in your tests
|
176
176
|
|
177
|
-
|
178
|
-
|
177
|
+
Pose can slow down your tests, because it updates the search index on every `:create`, `:update`, and `:delete`
|
178
|
+
operation in the database.
|
179
|
+
If this becomes a problem, you can disable Pose in your `test` environments,
|
180
|
+
and only enable it for the tests that actually need search functionality.
|
181
|
+
|
182
|
+
To disable Pose for tests, add this line to `config/environments/test.rb`
|
179
183
|
|
180
184
|
```ruby
|
181
|
-
Pose::CONFIGURATION[:
|
185
|
+
Pose::CONFIGURATION[:perform_search] = false
|
186
|
+
```
|
187
|
+
|
188
|
+
Now, with search disabled in the test environment, enable Pose in some of your tests by setting the same value to `true` inside the tests:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
|
192
|
+
context 'with search enabled' do
|
193
|
+
|
194
|
+
before :all do
|
195
|
+
Pose::CONFIGURATION[:perform_search] = true
|
196
|
+
end
|
197
|
+
|
198
|
+
after :all do
|
199
|
+
Pose::CONFIGURATION[:perform_search] = false
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'has search enabled in this test here...'
|
203
|
+
|
204
|
+
it 'has search enabled in this test as well...'
|
205
|
+
end
|
182
206
|
```
|
183
|
-
|
184
|
-
Please don't forget to set this value to `false` when you are done, or your remaining tests will be slow. A good place to enable/disable this flag is in before/after blocks of your test cases.
|
185
207
|
|
186
208
|
|
187
209
|
## Development
|
@@ -192,8 +214,8 @@ Or, clone the repository, make your changes, and submit a pull request.
|
|
192
214
|
|
193
215
|
### Run the unit tests for the Pose Gem
|
194
216
|
|
195
|
-
Pose uses Postgresql for tests, since it is the most strict
|
196
|
-
To run tests, first
|
217
|
+
For now, Pose uses Postgresql for tests, since it is free, and one of the most strict databases.
|
218
|
+
To run tests, first create a test database.
|
197
219
|
|
198
220
|
```bash
|
199
221
|
createdb pose_test
|
@@ -9,7 +9,7 @@ class PoseWord < ActiveRecord::Base
|
|
9
9
|
# Will generate something like:
|
10
10
|
#
|
11
11
|
# DELETE FROM "pose_words" WHERE "pose_words"."id" IN
|
12
|
-
# (SELECT "pose_words"."id" FROM "pose_words" INNER JOIN "pose_assignments" ON "pose_assignments"."
|
12
|
+
# (SELECT "pose_words"."id" FROM "pose_words" INNER JOIN "pose_assignments" ON "pose_assignments"."pose_word_id" = "pose_words"."id"
|
13
13
|
# HAVING.... GROUP BY "pose_words"."id")
|
14
14
|
PoseWord.delete_all(id: PoseWord.select("pose_words.id").
|
15
15
|
joins("LEFT OUTER JOIN pose_assignments ON pose_assignments.pose_word_id = pose_words.id").
|
data/lib/pose/static_api.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
module Pose
|
4
4
|
|
5
|
-
# By default,
|
6
|
-
#
|
7
|
-
|
5
|
+
# By default, performs search functionality everywhere.
|
6
|
+
# Since this can severely slow down your tests,
|
7
|
+
# disable this setting in your "test" environments,
|
8
|
+
# and enable it for tests that verify search functionality.
|
9
|
+
CONFIGURATION = { perform_search: true }
|
8
10
|
|
9
11
|
class <<self
|
10
12
|
|
@@ -24,7 +26,7 @@ module Pose
|
|
24
26
|
#
|
25
27
|
# @return [false, true]
|
26
28
|
def perform_search?
|
27
|
-
|
29
|
+
CONFIGURATION.has_key?(:perform_search) ? CONFIGURATION[:perform_search] : true
|
28
30
|
end
|
29
31
|
|
30
32
|
|
data/lib/pose/version.rb
CHANGED
data/spec/pose_api_spec.rb
CHANGED
@@ -18,16 +18,16 @@ describe Pose do
|
|
18
18
|
context "in the 'test' environment" do
|
19
19
|
# Set global env configuration.
|
20
20
|
before :each do
|
21
|
-
Pose::CONFIGURATION[:
|
21
|
+
Pose::CONFIGURATION[:perform_search] = perform_search
|
22
22
|
end
|
23
23
|
|
24
24
|
# Restores global configuration to default.
|
25
25
|
after :each do
|
26
|
-
Pose::CONFIGURATION
|
26
|
+
Pose::CONFIGURATION.delete :perform_search
|
27
27
|
end
|
28
28
|
|
29
29
|
context "search_in_tests flag is not enabled" do
|
30
|
-
let(:
|
30
|
+
let(:perform_search) { false }
|
31
31
|
|
32
32
|
it "doesn't call update_pose_words" do
|
33
33
|
subject.should_not_receive :update_pose_words
|
@@ -36,7 +36,7 @@ describe Pose do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
context "search_in_tests flag is enabled" do
|
39
|
-
let(:
|
39
|
+
let(:perform_search) { true }
|
40
40
|
|
41
41
|
it "calls update_pose_words" do
|
42
42
|
subject.should_receive :update_pose_words
|
@@ -249,10 +249,10 @@ describe Pose do
|
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'allows to combine several conditions' do
|
252
|
-
|
252
|
+
three = FactoryGirl.create :posable_one, text: 'foo two', private: true
|
253
253
|
result = Pose.search 'foo', PosableOne, where: [ {private: true}, ['text = ?', 'foo two'] ]
|
254
254
|
result[PosableOne].should have(1).item
|
255
|
-
result[PosableOne].should include
|
255
|
+
result[PosableOne].should include three
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/matchers.rb
CHANGED
@@ -2,19 +2,12 @@
|
|
2
2
|
RSpec::Matchers.define :have_pose_words do |expected|
|
3
3
|
|
4
4
|
match do |actual|
|
5
|
-
actual.
|
6
|
-
texts = actual.pose_words.map &:text
|
7
|
-
expected.each do |expected_word|
|
8
|
-
# Note (KG): Can't use text.should include(expected_word) here
|
9
|
-
# because Ruby thinks I want to include a Module for some reason.
|
10
|
-
texts.include?(expected_word).should be_true
|
11
|
-
end
|
5
|
+
actual.pose_words.map(&:text).sort == expected.sort
|
12
6
|
end
|
13
7
|
|
14
8
|
failure_message_for_should do |actual|
|
15
9
|
texts = actual.pose_words.map &:text
|
16
10
|
"expected that subject would have pose words [#{expected.join ', '}], but it has [#{texts.join ', '}]"
|
17
11
|
end
|
18
|
-
|
19
12
|
end
|
20
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|