pose 3.0.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -19
  3. data/Rakefile +37 -5
  4. data/lib/pose/activerecord_base_additions.rb +7 -6
  5. data/{app/models → lib}/pose/assignment.rb +6 -1
  6. data/lib/pose/jobs/install.rb +27 -0
  7. data/lib/pose/jobs/reindex_all.rb +34 -0
  8. data/lib/pose/jobs/remove.rb +28 -0
  9. data/lib/pose/jobs/uninstall.rb +19 -0
  10. data/lib/pose/jobs/vacuum.rb +23 -0
  11. data/lib/pose/model_class_additions.rb +32 -14
  12. data/lib/pose/query.rb +49 -9
  13. data/lib/pose/search.rb +5 -5
  14. data/lib/pose/static_api.rb +21 -3
  15. data/lib/pose/version.rb +1 -1
  16. data/lib/pose/word.rb +33 -0
  17. data/lib/pose.rb +11 -5
  18. data/lib/tasks/pose_tasks.rake +16 -27
  19. data/spec/{dummy/db/development.sqlite3 → db/pose.sqlite3} +0 -0
  20. data/spec/factories/posable_one.rb +2 -0
  21. data/spec/factories/posable_three.rb +8 -0
  22. data/spec/factories/posable_two.rb +2 -0
  23. data/spec/factories/user.rb +2 -0
  24. data/spec/lib/pose/activerecord_base_additions_spec.rb +11 -0
  25. data/spec/{models → lib/pose}/assignment_spec.rb +5 -5
  26. data/spec/lib/pose/jobs/reindex_all_spec.rb +31 -0
  27. data/spec/lib/pose/jobs/remove_spec.rb +20 -0
  28. data/spec/lib/pose/model_class_additions_spec.rb +150 -0
  29. data/spec/lib/pose/query_spec.rb +106 -8
  30. data/spec/lib/pose/search_spec.rb +2 -22
  31. data/spec/lib/pose/word_spec.rb +68 -0
  32. data/spec/pose_api_spec.rb +33 -13
  33. data/spec/spec_helper.rb +4 -32
  34. data/spec/support/config/database.yml +51 -0
  35. data/spec/support/config/database.yml.example +16 -0
  36. data/spec/{dummy/db/migrate → support/migrations}/20130308054001_create_posable_one.rb +0 -0
  37. data/spec/{dummy/db/migrate → support/migrations}/20130308054142_create_posable_two.rb +0 -0
  38. data/spec/support/migrations/20130308054143_create_posable_three.rb +9 -0
  39. data/spec/{dummy/db/migrate → support/migrations}/20130708084009_create_users.rb +0 -0
  40. data/spec/support/migrations/20130808084009_setup_pose_specs.rb +5 -0
  41. data/spec/{dummy/app → support}/models/posable_one.rb +1 -1
  42. data/spec/support/models/posable_three.rb +10 -0
  43. data/spec/{dummy/app → support}/models/posable_two.rb +1 -1
  44. data/spec/{dummy/app → support}/models/user.rb +1 -1
  45. data/spec/support/spec_manager.rb +105 -0
  46. metadata +70 -101
  47. data/app/models/pose/word.rb +0 -22
  48. data/db/migrate/20130308144915_pose_install.rb +0 -18
  49. data/lib/generators/pose/install/install_generator.rb +0 -56
  50. data/lib/generators/pose/install/templates/install_migration.rb +0 -24
  51. data/lib/generators/pose/remove/remove_generator.rb +0 -56
  52. data/lib/generators/pose/remove/templates/remove_migration.rb +0 -23
  53. data/lib/generators/pose/upgrade/templates/upgrade_migration.rb +0 -7
  54. data/lib/generators/pose/upgrade/upgrade_generator.rb +0 -35
  55. data/lib/pose/engine.rb +0 -5
  56. data/lib/pose/helpers.rb +0 -89
  57. data/lib/pose/railtie.rb +0 -19
  58. data/spec/dummy/Rakefile +0 -7
  59. data/spec/dummy/config/application.rb +0 -23
  60. data/spec/dummy/config/boot.rb +0 -10
  61. data/spec/dummy/config/database.yml +0 -25
  62. data/spec/dummy/config/environment.rb +0 -5
  63. data/spec/dummy/config/environments/development.rb +0 -30
  64. data/spec/dummy/config/environments/production.rb +0 -81
  65. data/spec/dummy/config/environments/test.rb +0 -37
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  67. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  68. data/spec/dummy/config/initializers/inflections.rb +0 -15
  69. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  70. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  71. data/spec/dummy/config/initializers/session_store.rb +0 -8
  72. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  73. data/spec/dummy/config/locales/en.yml +0 -5
  74. data/spec/dummy/config/routes.rb +0 -2
  75. data/spec/dummy/config.ru +0 -4
  76. data/spec/dummy/db/schema.rb +0 -47
  77. data/spec/dummy/db/test.sqlite3 +0 -0
  78. data/spec/dummy/log/development.log +0 -309
  79. data/spec/dummy/log/test.log +0 -88518
  80. data/spec/dummy/script/rails +0 -6
  81. data/spec/lib/pose/helpers_spec.rb +0 -147
  82. data/spec/models/word_spec.rb +0 -42
@@ -1,38 +1,27 @@
1
- include Rake::DSL if defined?(Rake::DSL)
2
- require 'ruby-progressbar'
3
-
4
1
  namespace :pose do
5
2
 
6
- desc "Cleans out unused data from the search index."
7
- task :vacuum => :environment do |t, args|
8
- puts "Cleaning Pose search index ...\n\n"
9
- progress_bar = ProgressBar.create title: ' assignments', total: Pose::Assignment.count
10
- Pose::Assignment.cleanup_orphaned_pose_assignments progress_bar
11
- progress_bar.finish
3
+ desc "Creates the Pose tables in the database."
4
+ task :install => :environment do
5
+ Pose::Jobs::Install.new.perform
6
+ end
12
7
 
13
- progress_bar = ProgressBar.create title: ' words', total: Pose::Word.count
14
- Pose::Word.remove_unused_words progress_bar
15
- progress_bar.finish
8
+ desc "Removes the Pose tables from the database."
9
+ task :uninstall => :environment do
10
+ Pose::Jobs::Uninstall.new.perform
11
+ end
16
12
 
17
- puts "\nPose search index cleanup complete.\n\n"
13
+ desc "Cleans out unused data from the search index."
14
+ task :vacuum => :environment do
15
+ Pose::Jobs::Vacuum.new.perform
18
16
  end
19
17
 
20
18
  desc "Removes the search index for all instances of the given classes."
21
- task :remove, [:class_name] => :environment do |t, args|
22
- clazz = args.class_name.constantize
23
- Pose::Assignment.delete_class_index clazz
24
- puts "Search index for class #{clazz.name} deleted.\n\n"
19
+ task :remove, [:class_name] => :environment do |_, args|
20
+ Pose::Jobs::Remove.new(args.class_name).perform
25
21
  end
26
22
 
27
- desc "Deletes and recreates the search index for all instances of the given class."
28
- task :reindex_all, [:class_name] => [:environment] do |t, args|
29
- clazz = args.class_name.constantize
30
- progress_bar = ProgressBar.create title: " reindexing", total: clazz.count
31
- clazz.find_each do |instance|
32
- instance.update_pose_words
33
- progress_bar.increment
34
- end
35
- progress_bar.finish
23
+ desc "Recreates the search index for all instances of the given class from scratch."
24
+ task :reindex_all, [:class_name] => [:environment] do |_, args|
25
+ Pose::Jobs::ReindexAll.new(args.class_name).perform
36
26
  end
37
-
38
27
  end
@@ -1,5 +1,7 @@
1
1
  FactoryGirl.define do
2
+
2
3
  factory :posable_one do
3
4
  text { Faker::Lorem.words(2).join ' ' }
4
5
  end
6
+
5
7
  end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :posable_three do
4
+ text_1 { Faker::Lorem.words(2).join ' ' }
5
+ text_2 { Faker::Lorem.words(2).join ' ' }
6
+ end
7
+
8
+ end
@@ -1,5 +1,7 @@
1
1
  FactoryGirl.define do
2
+
2
3
  factory :posable_two do
3
4
  text { Faker::Lorem.words(2).join ' ' }
4
5
  end
6
+
5
7
  end
@@ -1,6 +1,8 @@
1
1
  FactoryGirl.define do
2
+
2
3
  factory :user do
3
4
  name 'foo'
4
5
  end
6
+
5
7
  end
6
8
 
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pose::ActiveRecordBaseAdditions do
4
+ describe "::posify" do
5
+ let(:posable) { create :posable_three, text_1: 't1', text_2: 't2' }
6
+
7
+ it 'includes all listed fields in index' do
8
+ posable.pose_fetch_content.should == 't1 t2 |custom text| |from pose block|'
9
+ end
10
+ end
11
+ end
@@ -6,8 +6,8 @@ module Pose
6
6
  describe :delete_class_index do
7
7
 
8
8
  before :each do
9
- FactoryGirl.create :assignment, posable_id: 1, posable_type: 'PosableOne'
10
- FactoryGirl.create :assignment, posable_id: 2, posable_type: 'PosableTwo'
9
+ create :assignment, posable_id: 1, posable_type: 'PosableOne'
10
+ create :assignment, posable_id: 2, posable_type: 'PosableTwo'
11
11
  Assignment.delete_class_index PosableOne
12
12
  end
13
13
 
@@ -24,20 +24,20 @@ module Pose
24
24
  describe :cleanup_orphaned_pose_assignments do
25
25
 
26
26
  it "deletes the assignment if the posable object doesn't exist" do
27
- FactoryGirl.create :assignment, posable_id: 2, posable_type: 'PosableOne'
27
+ create :assignment, posable_id: 2, posable_type: 'PosableOne'
28
28
  expect(Assignment.count).to be > 0
29
29
  Assignment.cleanup_orphaned_pose_assignments
30
30
  expect(Assignment.count).to eql 0
31
31
  end
32
32
 
33
33
  it "deletes the assignment if the word doesn't exist" do
34
- assignment = FactoryGirl.create :assignment, word: nil, word_id: 27
34
+ assignment = create :assignment, word: nil, word_id: 27
35
35
  Assignment.cleanup_orphaned_pose_assignments
36
36
  expect(Assignment.find_by_id(assignment.id)).to be_nil
37
37
  end
38
38
 
39
39
  it "doesn't delete the assignment if it is still used" do
40
- assignment = FactoryGirl.create :assignment
40
+ assignment = create :assignment
41
41
  Assignment.cleanup_orphaned_pose_assignments
42
42
  expect(Assignment.find_by_id(assignment.id)).to_not be_nil
43
43
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Pose::Jobs::ReindexAll do
5
+ let(:klass) { PosableOne }
6
+ subject { described_class.new(klass) }
7
+
8
+ describe "#initialize" do
9
+ its(:klass) { should == PosableOne }
10
+
11
+ context "string given" do
12
+ let(:klass) { 'PosableOne' }
13
+ its(:klass) { should == PosableOne }
14
+ end
15
+ end
16
+
17
+ describe "#perform" do
18
+ let(:posable_one_1) { create(:posable_one, text: '1') }
19
+ let(:posable_one_2) { create(:posable_one, text: '1 2') }
20
+
21
+ context "records were updated without running callbacks" do
22
+ before do
23
+ PosableOne.where(id: posable_one_1.id).update_all(text: '1 2')
24
+ PosableOne.where(id: posable_one_2.id).update_all(text: '1')
25
+ end
26
+
27
+ it { expect { subject.perform }.to change{ posable_one_1.pose_words.count }.from(1).to(2) }
28
+ it { expect { subject.perform }.to change{ posable_one_2.pose_words.count }.from(2).to(1) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Pose::Jobs::Remove do
5
+ let(:klass) { PosableOne }
6
+ subject { described_class.new(klass) }
7
+
8
+ describe "#initialize" do
9
+ its(:klass) { should == PosableOne }
10
+
11
+ context "string given" do
12
+ let(:klass) { 'PosableOne' }
13
+ its(:klass) { should == PosableOne }
14
+ end
15
+ end
16
+
17
+ describe "#perform" do
18
+ it { expect{ subject.perform }.not_to raise_error }
19
+ end
20
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Pose::ModelClassAdditions do
5
+ subject { create :posable_one, text: 'one two' }
6
+ let(:instance_2) { create :posable_one, text: 'two three four' }
7
+
8
+
9
+ it 'extends AR models' do
10
+ expect(subject).to be_a_kind_of described_class
11
+ end
12
+
13
+
14
+ describe 'creating an instance' do
15
+ it 'adds the instance data to the search index' do
16
+ expect(Pose::Assignment).to have(0).instances
17
+ expect(Pose::Word).to have(0).instances
18
+ subject
19
+ expect(Pose::Assignment).to have(2).instances
20
+ expect(Pose::Word).to have(2).instances
21
+ end
22
+ end
23
+
24
+ describe 'updating an instance' do
25
+ it 'updates the instance data in the search index' do
26
+ subject.text = 'two three four'
27
+ subject.save!
28
+ expect(subject).to have(3).pose_words
29
+ expect(Pose::Assignment).to have(3).instances
30
+ end
31
+ end
32
+
33
+ describe 'deleting an instance' do
34
+ it 'removes the instance data from the search index' do
35
+ subject ; instance_2
36
+ subject.destroy
37
+ expect(Pose::Assignment).to have(3).instances
38
+ end
39
+ end
40
+
41
+
42
+ describe '#pose_current_words' do
43
+ it 'returns all currently indexed words the instance' do
44
+ expect(subject.pose_current_words).to match_array %w[one two]
45
+ end
46
+ end
47
+
48
+
49
+ describe '#pose_fetch_content' do
50
+
51
+ context 'pristine object' do
52
+ it 'returns the searchable text snippet for this instance' do
53
+ expect(subject.pose_fetch_content).to eql 'one two'
54
+ end
55
+ end
56
+
57
+ context 'object with unsaved changes' do
58
+ it 'returns the new unsaved searchable text' do
59
+ subject.text = 'two three'
60
+ expect(subject.pose_fetch_content).to eql 'two three'
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+ describe '#pose_fresh_words' do
67
+
68
+ context 'pristine object' do
69
+ it 'returns the words that this instance should have based on its current content' do
70
+ expect(subject.pose_fresh_words).to match_array %w[one two]
71
+ end
72
+ end
73
+
74
+ context 'after a content change in the instance' do
75
+ it 'returns only the current words' do
76
+ subject.text = 'two three'
77
+ expect(subject.pose_fresh_words true).to match_array %w[two three]
78
+ end
79
+ end
80
+
81
+ describe 'reload parameter' do
82
+ before :each do
83
+ subject.pose_fresh_words
84
+ subject.text = 'new text'
85
+ end
86
+
87
+ context 'given nothing' do
88
+ it 'caches the data' do
89
+ expect(subject.pose_fresh_words).to match_array %w[one two]
90
+ end
91
+ end
92
+
93
+ context 'given false' do
94
+ it 'caches the data' do
95
+ expect(subject.pose_fresh_words false).to match_array %w[one two]
96
+ end
97
+ end
98
+
99
+ context 'given true' do
100
+ it 'always recalculates the data' do
101
+ expect(subject.pose_fresh_words true).to match_array %w[new text]
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ describe 'pose_stale_words' do
109
+
110
+ context 'pristine object' do
111
+ it 'has no stale words' do
112
+ expect(subject.pose_stale_words).to be_empty
113
+ end
114
+ end
115
+
116
+ context 'object with unsaved changes' do
117
+ it 'returns the words that have to be removed from the search index' do
118
+ subject.text = 'two three'
119
+ expect(subject.pose_stale_words true).to match_array %w[one]
120
+ end
121
+ end
122
+ end
123
+
124
+
125
+ describe 'pose_words_to_add' do
126
+
127
+ context 'pristine object' do
128
+ it 'has no words to add' do
129
+ expect(subject.pose_words_to_add).to be_empty
130
+ end
131
+ end
132
+
133
+ context 'object with unsaved changes' do
134
+ it 'returns the words that are missing in the search index for this instance' do
135
+ subject.text = 'two three'
136
+ expect(subject.pose_words_to_add true).to match_array %w[three]
137
+ end
138
+ end
139
+ end
140
+
141
+
142
+ describe 'delete_pose_index' do
143
+ it 'removes the search index for this instance' do
144
+ subject ; instance_2
145
+ expect(Pose::Assignment).to have(5).instances
146
+ subject.delete_pose_index
147
+ expect(Pose::Assignment).to have(3).instances
148
+ end
149
+ end
150
+ end
@@ -2,10 +2,9 @@
2
2
  require "spec_helper"
3
3
 
4
4
  module Pose
5
-
6
5
  describe Query do
6
+ let(:subject) { Query.new [PosableOne, [PosableTwo]], 'query string' }
7
7
 
8
- let(:subject) { Pose::Query.new [PosableOne, [PosableTwo]], 'query string' }
9
8
 
10
9
  describe :initialize do
11
10
 
@@ -14,15 +13,17 @@ module Pose
14
13
  end
15
14
  end
16
15
 
16
+
17
17
  describe :class_names do
18
18
 
19
19
  it 'returns the names of the given classes' do
20
- expect(subject.class_names).to eql ['PosableOne', 'PosableTwo']
20
+ expect(subject.class_names).to eql %w[PosableOne PosableTwo]
21
21
  end
22
22
  end
23
23
 
24
24
 
25
25
  describe :has_joins? do
26
+
26
27
  it 'returns TRUE if the query has joins' do
27
28
  query = Query.new [], '', joins: :user
28
29
  expect(query).to have_joins
@@ -34,6 +35,39 @@ module Pose
34
35
  end
35
36
  end
36
37
 
38
+
39
+ describe 'is_url?' do
40
+
41
+ it 'returns TRUE if the given string is a URL' do
42
+ expect(Query.is_url? 'http://web.com').to be_true
43
+ end
44
+
45
+ it 'returns TRUE if the given string is localhost' do
46
+ expect(Query.is_url? 'http://localhost').to be_true
47
+ end
48
+
49
+ it 'returns TRUE if localhost has a port' do
50
+ expect(Query.is_url? 'http://localhost:3000').to be_true
51
+ end
52
+
53
+ it 'returns TRUE if the given url has a port' do
54
+ expect(Query.is_url? 'http://web.com:8080').to be_true
55
+ end
56
+
57
+ it 'returns TRUE if the given string is a HTTPS URL' do
58
+ expect(Query.is_url? 'https://web.com').to be_true
59
+ end
60
+
61
+ it 'returns FALSE if the given string is not a URL' do
62
+ expect(Query.is_url? 'foo').to be_false
63
+ end
64
+
65
+ it 'returns FALSE if the given string is a malformed URL' do
66
+ expect(Query.is_url? 'http://web').to be_false
67
+ end
68
+ end
69
+
70
+
37
71
  describe :joins do
38
72
 
39
73
  it 'returns the given joins' do
@@ -41,7 +75,7 @@ module Pose
41
75
  expect(query.joins).to eql [:foo, :bar]
42
76
  end
43
77
 
44
- it 'returns the given join as an array' do
78
+ it 'returns a single given join as an array' do
45
79
  query = Query.new [], '', joins: :foo
46
80
  expect(query.joins).to eql [:foo]
47
81
  end
@@ -52,25 +86,89 @@ module Pose
52
86
  end
53
87
  end
54
88
 
89
+
55
90
  describe :query_words do
56
91
 
57
92
  it 'returns all individual words resulting from the given query' do
58
- expect(Pose::Query.new([], 'foo bar').query_words).to eq ['foo', 'bar']
93
+ expect(Query.new([], 'foo bar').query_words).to eq ['foo', 'bar']
59
94
  end
60
95
 
61
96
  it 'converts the individual words into their root form' do
62
- expect(Pose::Query.new([], 'bars').query_words).to eq ['bar']
97
+ expect(Query.new([], 'bars').query_words).to eq ['bar']
63
98
  end
64
99
 
65
100
  it 'splits complex words into separate terms' do
66
- expect(Pose::Query.new([], 'one-two').query_words).to eq ['one', 'two']
101
+ expect(Query.new([], 'one-two').query_words).to eq ['one', 'two']
67
102
  end
68
103
 
69
104
  it 'removes duplicates' do
70
- expect(Pose::Query.new([], 'foo-bar foo').query_words).to eq ['foo', 'bar']
105
+ expect(Query.new([], 'foo-bar foo').query_words).to eq ['foo', 'bar']
106
+ end
107
+ end
108
+
109
+
110
+ describe :root_word do
111
+
112
+ it 'converts words into singular' do
113
+ expect(Query.root_word('bars')).to eql(['bar'])
114
+ end
115
+
116
+ it 'removes special characters' do
117
+ expect(Query.root_word('(bar')).to eq ['bar']
118
+ expect(Query.root_word('bar)')).to eq ['bar']
119
+ expect(Query.root_word('(bar)')).to eq ['bar']
120
+ expect(Query.root_word('>foo')).to eq ['foo']
121
+ expect(Query.root_word('<foo')).to eq ['foo']
122
+ expect(Query.root_word('"foo"')).to eq ['foo']
123
+ expect(Query.root_word('"foo')).to eq ['foo']
124
+ expect(Query.root_word("'foo'")).to eq ['foo']
125
+ expect(Query.root_word("'foo's")).to eq ['foo']
126
+ expect(Query.root_word("foo?")).to eq ['foo']
127
+ expect(Query.root_word("foo!")).to eq ['foo']
128
+ expect(Query.root_word("foo/bar")).to eq ['foo', 'bar']
129
+ expect(Query.root_word("foo-bar")).to eq ['foo', 'bar']
130
+ expect(Query.root_word("foo--bar")).to eq ['foo', 'bar']
131
+ expect(Query.root_word("foo.bar")).to eq ['foo', 'bar']
132
+ end
133
+
134
+ it 'removes umlauts' do
135
+ expect(Query.root_word('fünf')).to eq ['funf']
136
+ end
137
+
138
+ it 'splits up numbers' do
139
+ expect(Query.root_word('11.2.2011')).to eq ['11', '2', '2011']
140
+ expect(Query.root_word('11-2-2011')).to eq ['11', '2', '2011']
141
+ expect(Query.root_word('30:4-5')).to eq ['30', '4', '5']
142
+ end
143
+
144
+ it 'converts into lowercase' do
145
+ expect(Query.root_word('London')).to eq ['london']
146
+ end
147
+
148
+ it "stores single-letter words" do
149
+ expect(Query.root_word('a b')).to eq ['a', 'b']
150
+ end
151
+
152
+ it "does't encode external URLs" do
153
+ expect(Query.root_word('http://web.com')).to eq ['http', 'web', 'com']
154
+ end
155
+
156
+ it "doesn't store empty words" do
157
+ expect(Query.root_word(' one two ')).to eq ['one', 'two']
158
+ end
159
+
160
+ it "removes duplicates" do
161
+ expect(Query.root_word('one_one')).to eq ['one']
162
+ expect(Query.root_word('one one')).to eq ['one']
163
+ end
164
+
165
+ it "splits up complex URLs" do
166
+ expect(Query.root_word('books?id=p7uyWPcVGZsC&dq=closure%20definitive%20guide&pg=PP1#v=onepage&q&f=false')).to eql([
167
+ "book", "id", "p7uywpcvgzsc", "dq", "closure", "definitive", "guide", "pg", "pp1", "v", "onepage", "q", "f", "false"])
71
168
  end
72
169
  end
73
170
 
171
+
74
172
  describe :where do
75
173
 
76
174
  it 'returns the given simple WHERE clause as an iterable array' do
@@ -4,13 +4,11 @@ module Pose
4
4
 
5
5
  describe Search do
6
6
  let(:subject) { Search.new [PosableOne, [PosableTwo]], 'query string' }
7
- let(:arel) { double() }
7
+ let(:arel) { double() }
8
8
  let(:arel_2) { double() }
9
9
  let(:arel_3) { double() }
10
10
 
11
-
12
11
  describe :add_join do
13
-
14
12
  it 'returns the new arel' do
15
13
  arel.should_receive(:joins).with('foo').and_return(arel_2)
16
14
  expect(subject.add_join arel, 'foo').to eql arel_2
@@ -39,9 +37,7 @@ module Pose
39
37
  end
40
38
  end
41
39
 
42
-
43
40
  describe :add_joins do
44
-
45
41
  it 'adds all joins to the given arel' do
46
42
  arel.should_receive(:joins).with('one').and_return(arel_2)
47
43
  arel_2.should_receive(:joins).with('two').and_return(arel_3)
@@ -57,9 +53,7 @@ module Pose
57
53
  end
58
54
  end
59
55
 
60
-
61
56
  describe :add_wheres do
62
-
63
57
  it 'adds all joins to the given arel' do
64
58
  arel.should_receive(:where).with(['one = ?', true]).and_return(arel_2)
65
59
  arel_2.should_receive(:where).with(['two = ?', false]).and_return(arel_3)
@@ -75,9 +69,7 @@ module Pose
75
69
  end
76
70
  end
77
71
 
78
-
79
72
  describe :empty_result do
80
-
81
73
  it 'returns a hash with classes and empty arrays for each class in the search query' do
82
74
  search = Search.new [PosableOne, PosableTwo], ''
83
75
  result = search.empty_result
@@ -87,7 +79,6 @@ module Pose
87
79
  end
88
80
  end
89
81
 
90
-
91
82
  describe :limit_ids do
92
83
  before :each do
93
84
  @search = Search.new nil, nil, limit: 2
@@ -129,7 +120,6 @@ module Pose
129
120
 
130
121
 
131
122
  describe :load_classes do
132
-
133
123
  context 'when the user wants ids' do
134
124
  it 'does nothing' do
135
125
  search = Search.new nil, nil, result_type: :ids
@@ -143,7 +133,7 @@ module Pose
143
133
  it 'loads the classes' do
144
134
  object_1 = create :posable_one
145
135
  object_2 = create :posable_one
146
- result = { PosableOne => [1, 2] }
136
+ result = { PosableOne => [object_1.id, object_2.id] }
147
137
  search = Search.new nil, nil
148
138
  search.load_classes result
149
139
  expect(result[PosableOne]).to eq [object_1, object_2]
@@ -154,7 +144,6 @@ module Pose
154
144
 
155
145
  describe :merge_search_result_word_matches do
156
146
  context 'given a new class name' do
157
-
158
147
  before :each do
159
148
  @result = {}
160
149
  end
@@ -166,7 +155,6 @@ module Pose
166
155
  end
167
156
 
168
157
  context 'given a class name with already existing ids from another word' do
169
-
170
158
  before :each do
171
159
  @result = { 'class1' => [1, 2] }
172
160
  end
@@ -178,7 +166,6 @@ module Pose
178
166
  end
179
167
 
180
168
  context 'with an existing empty result set from a previous query' do
181
-
182
169
  before :each do
183
170
  @result = { 'class1' => [] }
184
171
  end
@@ -190,7 +177,6 @@ module Pose
190
177
  end
191
178
 
192
179
  context 'with a new empty result set' do
193
-
194
180
  before :each do
195
181
  @result = { 'class1' => [1, 2] }
196
182
  end
@@ -202,7 +188,6 @@ module Pose
202
188
  end
203
189
 
204
190
  context 'with a completely different result set' do
205
-
206
191
  before :each do
207
192
  @result = { 'class1' => [1, 2] }
208
193
  end
@@ -216,7 +201,6 @@ module Pose
216
201
 
217
202
 
218
203
  describe :search do
219
-
220
204
  it 'finds all matching instances of all classes' do
221
205
  posable_one_1 = create :posable_one, text: 'foo bar'
222
206
  posable_one_2 = create :posable_one, text: 'foo bar'
@@ -255,7 +239,6 @@ module Pose
255
239
  end
256
240
 
257
241
  describe 'result types' do
258
-
259
242
  it 'loads classes by default' do
260
243
  posable_one = create :posable_one, text: 'foo'
261
244
  search = Search.new PosableOne, 'foo'
@@ -292,7 +275,6 @@ module Pose
292
275
 
293
276
 
294
277
  describe :search_word do
295
-
296
278
  context 'search results' do
297
279
  it 'returns the ids of the matching instances for this class' do
298
280
  posable_one_1 = create :posable_one, text: 'foo'
@@ -323,9 +305,7 @@ module Pose
323
305
  end
324
306
  end
325
307
 
326
-
327
308
  describe :search_words do
328
-
329
309
  context 'search results' do
330
310
  it 'returns the ids of all instances that match all query words' do
331
311
  posable_one = create :posable_one, text: 'foo bar'