pose 1.2.5 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
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
- # Uninstalling
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
- By default, Pose doesn't run in Rails' `test` environment. This is to not slow down tests due to constant updating of the search index when objects are created.
178
- If you want to test your models search functionality, you need to enable searching in tests:
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[:search_in_tests] = true
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 database.
196
- To run tests, first, create a test database.
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"."id" = "pose_words"."user_id"
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").
@@ -2,9 +2,11 @@
2
2
 
3
3
  module Pose
4
4
 
5
- # By default, doesn't run in tests.
6
- # Set this to true to test the search functionality.
7
- CONFIGURATION = { search_in_tests: false }
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
- !(Rails.env == 'test' and !CONFIGURATION[:search_in_tests])
29
+ CONFIGURATION.has_key?(:perform_search) ? CONFIGURATION[:perform_search] : true
28
30
  end
29
31
 
30
32
 
@@ -1,3 +1,3 @@
1
1
  module Pose
2
- VERSION = "1.2.5"
2
+ VERSION = "1.3"
3
3
  end
@@ -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[:search_in_tests] = search_in_tests
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[:search_in_tests] = true
26
+ Pose::CONFIGURATION.delete :perform_search
27
27
  end
28
28
 
29
29
  context "search_in_tests flag is not enabled" do
30
- let(:search_in_tests) { false }
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(:search_in_tests) { true }
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
- @three = FactoryGirl.create :posable_one, text: 'foo two', private: true
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 @three
255
+ result[PosableOne].should include three
256
256
  end
257
257
  end
258
258
 
@@ -41,7 +41,6 @@ RSpec.configure do |config|
41
41
 
42
42
  config.before :suite do
43
43
  setup_db
44
- Pose::CONFIGURATION[:search_in_tests] = true
45
44
  DatabaseCleaner.strategy = :deletion
46
45
  end
47
46
 
@@ -2,19 +2,12 @@
2
2
  RSpec::Matchers.define :have_pose_words do |expected|
3
3
 
4
4
  match do |actual|
5
- actual.should have(expected.size).pose_words
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.2.5
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-09 00:00:00.000000000 Z
12
+ date: 2012-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails