Commit a7e26c22a1c53257c3ed840768476f10dc19ceb5
Exists in
master
and in
21 other branches
Merge branch 'eksoverzero-nobrainer'
Showing
7 changed files
with
80 additions
and
2 deletions
Show diff stats
.travis.yml
... | ... | @@ -6,6 +6,7 @@ services: |
6 | 6 | - mongodb |
7 | 7 | before_install: |
8 | 8 | - wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.deb && sudo dpkg -i elasticsearch-1.3.2.deb && sudo service elasticsearch restart |
9 | + - script ./test/nobrainer.sh | |
9 | 10 | script: bundle exec rake test |
10 | 11 | before_script: |
11 | 12 | - psql -c 'create database searchkick_test;' -U postgres |
... | ... | @@ -21,3 +22,7 @@ gemfile: |
21 | 22 | - gemfiles/mongoid2.gemfile |
22 | 23 | - gemfiles/mongoid3.gemfile |
23 | 24 | - gemfiles/mongoid4.gemfile |
25 | +matrix: | |
26 | + include: | |
27 | + - gemfile: gemfiles/nobrainer.gemfile | |
28 | + env: NOBRAINER=true | ... | ... |
lib/searchkick/results.rb
... | ... | @@ -24,7 +24,11 @@ module Searchkick |
24 | 24 | hits.group_by{|hit, i| hit["_type"] }.each do |type, grouped_hits| |
25 | 25 | records = type.camelize.constantize |
26 | 26 | if options[:includes] |
27 | - records = records.includes(options[:includes]) | |
27 | + if defined?(NoBrainer::Document) and records < NoBrainer::Document | |
28 | + records = records.preload(options[:includes]) | |
29 | + else | |
30 | + records = records.includes(options[:includes]) | |
31 | + end | |
28 | 32 | end |
29 | 33 | results[type] = results_query(records, grouped_hits) |
30 | 34 | end |
... | ... | @@ -143,6 +147,9 @@ module Searchkick |
143 | 147 | elsif records.respond_to?(:queryable) |
144 | 148 | # Mongoid 3+ |
145 | 149 | records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a |
150 | + elsif records.respond_to?(:unscoped) and records.all.respond_to?(:preload) | |
151 | + # Nobrainer | |
152 | + records.unscoped.where(:id.in => grouped_hits.map{|hit| hit["_id"] }).to_a | |
146 | 153 | else |
147 | 154 | raise "Not sure how to load records" |
148 | 155 | end | ... | ... |
test/facets_test.rb
... | ... | @@ -0,0 +1,10 @@ |
1 | +#!/usr/bin/env sh | |
2 | + | |
3 | +if [ ! -z "$NOBRAINER" ]; then | |
4 | + source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list | |
5 | + wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - | |
6 | + sudo apt-get update -q | |
7 | + sudo apt-get install rethinkdb | |
8 | + sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf | |
9 | + sudo service rethinkdb restart | |
10 | +fi | ... | ... |
test/sql_test.rb
... | ... | @@ -312,7 +312,7 @@ class TestSql < Minitest::Test |
312 | 312 | end |
313 | 313 | |
314 | 314 | # TODO see if Mongoid is loaded |
315 | - if !defined?(Mongoid) | |
315 | + unless defined?(Mongoid) or defined?(NoBrainer) | |
316 | 316 | def test_include |
317 | 317 | store_names ["Product A"] |
318 | 318 | assert Product.search("product", include: [:store]).first.association(:store).loaded? | ... | ... |
test/test_helper.rb
... | ... | @@ -73,6 +73,55 @@ if defined?(Mongoid) |
73 | 73 | |
74 | 74 | class Cat < Animal |
75 | 75 | end |
76 | +elsif defined?(NoBrainer) | |
77 | + # | |
78 | + # Aliasing create bang. | |
79 | + # | |
80 | + module NoBrainer::Document::Persistance | |
81 | + extend ActiveSupport::Concern | |
82 | + | |
83 | + module ClassMethods | |
84 | + alias :create! :create | |
85 | + end | |
86 | + end | |
87 | + | |
88 | + NoBrainer.configure do |config| | |
89 | + config.rethinkdb_url = 'rethinkdb://localhost/searchkick_test' | |
90 | + end | |
91 | + | |
92 | + class Product | |
93 | + include NoBrainer::Document | |
94 | + include NoBrainer::Document::Timestamps | |
95 | + | |
96 | + field :name, type: String | |
97 | + field :store_id, type: Integer | |
98 | + field :in_stock, type: Boolean | |
99 | + field :backordered, type: Boolean | |
100 | + field :orders_count, type: Integer | |
101 | + field :price, type: Integer | |
102 | + field :color, type: String | |
103 | + field :latitude | |
104 | + field :longitude | |
105 | + field :description, type: String | |
106 | + end | |
107 | + | |
108 | + class Store | |
109 | + include NoBrainer::Document | |
110 | + | |
111 | + field :name, type: String | |
112 | + end | |
113 | + | |
114 | + class Animal | |
115 | + include NoBrainer::Document | |
116 | + | |
117 | + field :name, type: String | |
118 | + end | |
119 | + | |
120 | + class Dog < Animal | |
121 | + end | |
122 | + | |
123 | + class Cat < Animal | |
124 | + end | |
76 | 125 | else |
77 | 126 | require "active_record" |
78 | 127 | ... | ... |