diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | spec/integration/elasticsearch/Gemfile | 6 | ||||
-rw-r--r-- | spec/integration/elasticsearch/integration_spec.rb | 40 |
3 files changed, 47 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a79834..5b9e140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ scheme are considered to be bugs. ### Miscellaneous * [#434](https://github.com/intridea/hashie/pull/434): Add documentation around Mash sub-Hashes - [@michaelherold](https://github.com/michaelherold). +* [#439](https://github.com/intridea/hashie/pull/439): Add an integration spec for Elasticsearch - [@michaelherold](https://github.com/michaelherold). * Your contribution here. ## [3.5.7] - 2017-12-19 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 |