diff --git a/elasticsearch-model/.gitignore b/elasticsearch-model/.gitignore index d87d4be66..02799166c 100644 --- a/elasticsearch-model/.gitignore +++ b/elasticsearch-model/.gitignore @@ -15,3 +15,6 @@ spec/reports test/tmp test/version_tmp tmp + +gemfiles/3.gemfile.lock +gemfiles/4.gemfile.lock diff --git a/elasticsearch-model/elasticsearch-model.gemspec b/elasticsearch-model/elasticsearch-model.gemspec index 4174cbcd3..0f2230177 100644 --- a/elasticsearch-model/elasticsearch-model.gemspec +++ b/elasticsearch-model/elasticsearch-model.gemspec @@ -32,8 +32,8 @@ Gem::Specification.new do |s| s.add_development_dependency "sqlite3" s.add_development_dependency "activesupport", "> 3.0" s.add_development_dependency "activemodel", "> 3.0" - s.add_development_dependency "activerecord", "> 3.0" - s.add_development_dependency "mongoid", "> 2.0" + s.add_development_dependency "activerecord", "> 4.0" + s.add_development_dependency "oj" s.add_development_dependency "shoulda-context" diff --git a/elasticsearch-model/examples/mongoid_article.rb b/elasticsearch-model/examples/mongoid_article.rb index 380d35588..fac9fa849 100644 --- a/elasticsearch-model/examples/mongoid_article.rb +++ b/elasticsearch-model/examples/mongoid_article.rb @@ -21,14 +21,18 @@ Mongoid.connect_to 'articles' -Elasticsearch::Model.client = Elasticsearch::Client.new log: true +Elasticsearch::Model.client = Elasticsearch::Client.new host: 'localhost:9250', log: true class Article include Mongoid::Document field :id, type: String field :title, type: String field :published_at, type: DateTime - attr_accessible :id, :title, :published_at + attr_accessible :id, :title, :published_at if respond_to? :attr_accessible + + def as_indexed_json(options={}) + as_json(except: [:id, :_id]) + end end # Extend the model with Elasticsearch support @@ -45,7 +49,7 @@ class Article # Index data # -client = Elasticsearch::Client.new log:true +client = Elasticsearch::Client.new host:'localhost:9250', log:true client.indices.delete index: 'articles' rescue nil client.bulk index: 'articles', diff --git a/elasticsearch-model/gemfiles/3.gemfile b/elasticsearch-model/gemfiles/3.gemfile new file mode 100644 index 000000000..43082a833 --- /dev/null +++ b/elasticsearch-model/gemfiles/3.gemfile @@ -0,0 +1,11 @@ +# Usage: +# +# $ BUNDLE_GEMFILE=./gemfiles/3.gemfile bundle install +# $ BUNDLE_GEMFILE=./gemfiles/3.gemfile bundle exec rake test:integration + +source 'https://rubygems.org' + +gem 'activerecord', '~> 3.2' +gem 'mongoid', '>= 3.0' + +gemspec path: '../' diff --git a/elasticsearch-model/gemfiles/4.gemfile b/elasticsearch-model/gemfiles/4.gemfile new file mode 100644 index 000000000..fc32961c3 --- /dev/null +++ b/elasticsearch-model/gemfiles/4.gemfile @@ -0,0 +1,11 @@ +# Usage: +# +# $ BUNDLE_GEMFILE=./gemfiles/4.gemfile bundle install +# $ BUNDLE_GEMFILE=./gemfiles/4.gemfile bundle exec rake test:integration + +source 'https://rubygems.org' + +gem 'activerecord', '~> 4' +gem 'mongoid', '~> 4.0.0.alpha1' + +gemspec path: '../' diff --git a/elasticsearch-model/test/integration/active_record_basic_test.rb b/elasticsearch-model/test/integration/active_record_basic_test.rb index 6ee992b99..162166360 100644 --- a/elasticsearch-model/test/integration/active_record_basic_test.rb +++ b/elasticsearch-model/test/integration/active_record_basic_test.rb @@ -1,5 +1,7 @@ require 'test_helper' +puts "ActiveRecord #{ActiveRecord::VERSION::STRING}", '-'*80 + module Elasticsearch module Model class ActiveRecordBasicIntegrationTest < Elasticsearch::Test::IntegrationTestCase diff --git a/elasticsearch-model/test/integration/mongoid_basic_test.rb b/elasticsearch-model/test/integration/mongoid_basic_test.rb index 1e81fb1f9..3d8ccce72 100644 --- a/elasticsearch-model/test/integration/mongoid_basic_test.rb +++ b/elasticsearch-model/test/integration/mongoid_basic_test.rb @@ -9,6 +9,7 @@ end if ENV["MONGODB_AVAILABLE"] + puts "Mongoid #{Mongoid::VERSION}", '-'*80 logger = ::Logger.new(STDERR) logger.formatter = lambda { |s, d, p, m| " #{m.ansi(:faint, :cyan)}\n" } @@ -30,12 +31,16 @@ class ::MongoidArticle field :id, type: String field :title, type: String - attr_accessible :title + attr_accessible :title if respond_to? :attr_accessible mapping do indexes :title, type: 'string', analyzer: 'snowball' indexes :created_at, type: 'date' end + + def as_indexed_json(options={}) + as_json(except: [:id, :_id]) + end end context "Mongoid integration" do