summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2018-02-06 18:35:52 -0600
committerMichael Herold <michael.j.herold@gmail.com>2018-02-06 19:02:54 -0600
commit7b1e375b53514c50bd5432dc4aab1e1f56701d6b (patch)
tree44713b8f051e94137f814a56323c59f4e2e890b2 /spec
parent3c6149cdd72ab8cc87cf008cc222514e30ef7470 (diff)
downloadhashie-7b1e375b53514c50bd5432dc4aab1e1f56701d6b.tar.gz
Add an integration spec for Elasticsearch
The Elasticsearch gems heavily integrate with Hashie. This leads people to want to use a Mash as the backer for an Elasticsearch model, but the behavior is different than they expect. By having this integration spec, we're covering two things: 1. It might help ensure that we don't break the Elasticsearch ecosystem with changes in Hashie as has happened in the past. 2. It communicates some gotchas that happen with using a Mash as the backer for an Elasticsearch model.
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/elasticsearch/Gemfile6
-rw-r--r--spec/integration/elasticsearch/integration_spec.rb40
2 files changed, 46 insertions, 0 deletions
diff --git a/spec/integration/elasticsearch/Gemfile b/spec/integration/elasticsearch/Gemfile
new file mode 100644
index 0000000..318242a
--- /dev/null
+++ b/spec/integration/elasticsearch/Gemfile
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+
+gem 'elasticsearch-model'
+gem 'hashie', path: '../../..'
+gem 'rake'
+gem 'rspec', '~> 3.5.0'
diff --git a/spec/integration/elasticsearch/integration_spec.rb b/spec/integration/elasticsearch/integration_spec.rb
new file mode 100644
index 0000000..2c4e220
--- /dev/null
+++ b/spec/integration/elasticsearch/integration_spec.rb
@@ -0,0 +1,40 @@
+require 'elasticsearch/model'
+require 'hashie'
+
+RSpec.configure do |config|
+ config.expect_with :rspec do |expect|
+ expect.syntax = :expect
+ end
+end
+
+class MyModel < Hashie::Mash
+ include Elasticsearch::Model
+
+ disable_warnings
+
+ index_name 'model'
+ document_type 'model'
+end
+
+RSpec.describe 'elaasticsearch-model' do
+ # See https://github.com/intridea/hashie/issues/354#issuecomment-363306114
+ # for the reason why this doesn't work as you would expect
+ it 'raises an error when the model does has an id' do
+ object = MyModel.new
+ stub_elasticsearch_client
+
+ expect { object.__elasticsearch__.index_document }.to raise_error(NoMethodError)
+ end
+
+ it 'does not raise an error when the model has an id' do
+ object = MyModel.new(id: 123)
+ stub_elasticsearch_client
+
+ expect { object.__elasticsearch__.index_document }.not_to raise_error
+ end
+
+ def stub_elasticsearch_client
+ response = double('Response', body: '{}')
+ allow_any_instance_of(Elasticsearch::Transport::Client).to receive(:perform_request) { response }
+ end
+end