Skip to content
This repository
Browse code

WIP: interview, working on the period issue

  • Loading branch information...
commit 6607a80ad53fb2105bdff906ed59834c8c0a2ded 1 parent be5a378
authored November 14, 2012 nertzy committed March 03, 2013
2  .rspec
... ...
@@ -1 +1,3 @@
1 1
 --colour
  2
+--fail-fast
  3
+--order random
2  Gemfile
@@ -5,6 +5,8 @@ gemspec
5 5
 gem "rake"
6 6
 gem "rdoc"
7 7
 gem "pry"
  8
+gem "pry-doc"
  9
+gem "pry-debugger"
8 10
 
9 11
 platforms :ruby do
10 12
   gem 'pg'
10  lib/pg_search/scope_options.rb
@@ -11,7 +11,15 @@ def initialize(config)
11 11
     end
12 12
 
13 13
     def apply(scope)
14  
-      scope.select("#{quoted_table_name}.*, (#{rank}) AS pg_search_rank").where(conditions).order("pg_search_rank DESC, #{order_within_rank}").joins(joins)
  14
+      relation = scope.select("#{quoted_table_name}.*, (#{rank}) AS pg_search_rank").where(conditions).order("pg_search_rank DESC, #{order_within_rank}").joins(joins)
  15
+
  16
+      class << relation
  17
+        def eager_loading?
  18
+          false
  19
+        end
  20
+      end
  21
+
  22
+      relation
15 23
     end
16 24
 
17 25
     private
27  spec/pg_search_spec.rb
@@ -152,6 +152,33 @@
152 152
         results.should_not include(excluded)
153 153
       end
154 154
 
  155
+      context "when joining to an association" do
  156
+        with_model :OtherModel do
  157
+          table do |t|
  158
+            t.belongs_to :model_with_pg_search
  159
+          end
  160
+
  161
+          model do
  162
+            belongs_to :model_with_pg_search
  163
+          end
  164
+        end
  165
+
  166
+        before do
  167
+          ModelWithPgSearch.has_many :other_models
  168
+        end
  169
+
  170
+        it "supports queries with periods" do
  171
+          included = ModelWithPgSearch.create!(:content => 'bar.foo')
  172
+          excluded = ModelWithPgSearch.create!(:content => 'foo.bar')
  173
+
  174
+          results = ModelWithPgSearch.search_content('bar.foo').eager_load(:other_models)
  175
+          results.to_a
  176
+
  177
+          results.should include(included)
  178
+          results.should_not include(excluded)
  179
+        end
  180
+      end
  181
+
155 182
       it "returns rows where the column contains all the terms in the query in any order" do
156 183
         included = [ModelWithPgSearch.create!(:content => 'foo bar'),
157 184
                     ModelWithPgSearch.create!(:content => 'bar foo')]
1  spec/spec_helper.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require "bundler/setup"
2 2
 require "pg_search"
  3
+require "pry"
3 4
 
4 5
 begin
5 6
   require "pg"

0 notes on commit 6607a80

Please sign in to comment.
Something went wrong with that request. Please try again.