pose 1.1.3 → 1.2.0

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.
@@ -5,6 +5,9 @@ class PoseAssignment < ActiveRecord::Base
5
5
  attr_accessible :pose_word, :posable
6
6
 
7
7
 
8
+ attr_accessible :pose_word, :posable
9
+
10
+
8
11
  # Removes all PoseAssignments for the given class.
9
12
  def self.delete_class_index clazz
10
13
  PoseAssignment.delete_all(['posable_type=?', clazz.name])
@@ -3,6 +3,8 @@ class PoseWord < ActiveRecord::Base
3
3
  has_many :pose_assignments
4
4
  attr_accessible :text
5
5
 
6
+ attr_accessible :text
7
+
6
8
  def self.remove_unused_words progress_bar = nil
7
9
  PoseWord.find_each(include: [:pose_assignments], batch_size: 5000) do |pose_word|
8
10
  pose_word.delete if pose_word.pose_assignments.size == 0
@@ -133,11 +133,38 @@ module Pose
133
133
  result_classes_and_ids.each do |class_name, ids|
134
134
  result_class = Kernel.const_get class_name
135
135
 
136
- if ids.any? && classes.include?(result_class)
137
- ids = ids.slice(0, options[:limit]) if options[:limit]
138
- result[result_class] = options[:result_type] == :ids ? ids : result_class.where(id: ids)
139
- else
136
+ if ids.size == 0
137
+ # Handle no results.
140
138
  result[result_class] = []
139
+
140
+ else
141
+ # Here we have results.
142
+
143
+ # Limit.
144
+ ids = ids.slice(0, options[:limit]) if options[:limit]
145
+
146
+ if options[:result_type] == :ids
147
+ # Ids requested for result.
148
+
149
+ if options.has_key? :scope
150
+ # We have a scope.
151
+ options[:scope].each do |scope|
152
+ result[result_class] = result_class.select('id').where(scope).map(&:id)
153
+ end
154
+ else
155
+ result[result_class] = ids
156
+ end
157
+
158
+ else
159
+ # Classes requested for result.
160
+
161
+ result[result_class] = result_class.where(id: ids)
162
+ if options.has_key? :scope
163
+ options[:scope].each do |scope|
164
+ result[result_class] = result[result_class].where(scope)
165
+ end
166
+ end
167
+ end
141
168
  end
142
169
  end
143
170
  end
data/lib/pose/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pose
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
data/spec/pose_spec.rb CHANGED
@@ -316,6 +316,51 @@ describe Pose do
316
316
  end
317
317
  end
318
318
  end
319
+
320
+ describe "'scopes' parameter" do
321
+
322
+ before :each do
323
+ @one = FactoryGirl.create :posable_one, text: 'foo one', private: true
324
+ @two = FactoryGirl.create :posable_one, text: 'foo two', private: false
325
+ end
326
+
327
+ context 'with result type :classes' do
328
+
329
+ it 'limits the result set by the given scope' do
330
+ result = Pose.search 'foo', PosableOne, scope: [ private: true ]
331
+ result[PosableOne].should have(1).item
332
+ result[PosableOne].should include @one
333
+ end
334
+
335
+ it 'allows to use the hash syntax for queries' do
336
+ result = Pose.search 'foo', PosableOne, scope: [ private: true ]
337
+ result[PosableOne].should have(1).item
338
+ result[PosableOne].should include @one
339
+ end
340
+
341
+ it 'allows to use the string syntax for queries' do
342
+ result = Pose.search 'foo', PosableOne, scope: [ ['private = ?', true] ]
343
+ result[PosableOne].should have(1).item
344
+ result[PosableOne].should include @one
345
+ end
346
+
347
+ it 'allows to combine several scopes' do
348
+ @three = FactoryGirl.create :posable_one, text: 'foo two', private: true
349
+ result = Pose.search 'foo', PosableOne, scope: [ {private: true}, ['text = ?', 'foo two'] ]
350
+ result[PosableOne].should have(1).item
351
+ result[PosableOne].should include @three
352
+ end
353
+ end
354
+
355
+ context 'with result type :ids' do
356
+
357
+ it 'limits the result set by the given scope' do
358
+ result = Pose.search 'foo', PosableOne, result_type: :ids, scope: [ private: true ]
359
+ result[PosableOne].should have(1).item
360
+ result[PosableOne].should include @one.id
361
+ end
362
+ end
363
+ end
319
364
  end
320
365
 
321
366
  describe 'autocomplete_words' do
data/spec/spec_helper.rb CHANGED
@@ -92,10 +92,12 @@ def setup_db
92
92
 
93
93
  create_table 'posable_ones' do |t|
94
94
  t.string 'text'
95
+ t.boolean 'private'
95
96
  end
96
97
 
97
98
  create_table 'posable_twos' do |t|
98
99
  t.string 'text'
100
+ t.boolean 'private'
99
101
  end
100
102
 
101
103
  create_table "pose_assignments" do |t|
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.1.3
4
+ version: 1.2.0
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-09-23 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: autotest-standalone
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: factory_girl
64
80
  requirement: !ruby/object:Gem::Requirement