From f3af3f4be297b3db776b023a3b8e3108d8d55086 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 14:59:19 +0200 Subject: [PATCH 1/9] Added the "Compatibility" chapter to the READMEs In order to make the support for different Elasticsearch versions more clear, a special "Compatibility" chapter has been added to the main README and individual gem READMEs. The versioning scheme follows the scheme for the Elasticsearch Ruby client, ie. the version number matches the supported major version of Elasticsearch. See: * https://github.com/elastic/elasticsearch-ruby/commit/3bdb385 --- README.md | 20 ++++++++++++++++---- elasticsearch-model/README.md | 16 ++++++++++++++-- elasticsearch-persistence/README.md | 14 +++++++++++++- elasticsearch-rails/README.md | 16 ++++++++++++++-- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 67c57d11f..03138c07e 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,27 @@ This repository contains various Ruby and Rails integrations for [Elasticsearch] Elasticsearch client and Ruby API is provided by the **[elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby)** project. -## Installation +## Compatibility The libraries are compatible with Ruby 1.9.3 and higher. -Install the `elasticsearch-model` and/or `elasticsearch-rails` package from -[Rubygems](https://rubygems.org/gems/elasticsearch): +The version numbers follow the Elasticsearch major versions, and the `master` branch +is compatible with the Elasticsearch `master` branch, therefore, with the next major version. + +| Rubygem | | Elasticsearch | +|:-------------:|:-:| :-----------: | +| 0.1 | → | 1.x | +| 2.x | → | 2.x | +| 5.x | → | 5.x | +| master | → | master | + +## Installation + +Install each library from [Rubygems](https://rubygems.org/gems/elasticsearch): ```ruby -gem install elasticsearch-model elasticsearch-rails +gem install elasticsearch-model +gem install elasticsearch-rails ``` To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com): diff --git a/elasticsearch-model/README.md b/elasticsearch-model/README.md index 8f963018d..4e0be9037 100644 --- a/elasticsearch-model/README.md +++ b/elasticsearch-model/README.md @@ -1,13 +1,25 @@ # Elasticsearch::Model The `elasticsearch-model` library builds on top of the -the [`elasticsearch`](https://github.com/elasticsearch/elasticsearch-ruby) library. +the [`elasticsearch`](https://github.com/elastic/elasticsearch-ruby) library. It aims to simplify integration of Ruby classes ("models"), commonly found e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the [Elasticsearch](http://www.elasticsearch.org) search and analytics engine. -The library is compatible with Ruby 1.9.3 and higher. +## Compatibility + +This library is compatible with Ruby 1.9.3 and higher. + +The library version numbers follow the Elasticsearch major versions, and the `master` branch +is compatible with the Elasticsearch `master` branch, therefore, with the next major version. + +| Rubygem | | Elasticsearch | +|:-------------:|:-:| :-----------: | +| 0.1 | → | 1.x | +| 2.x | → | 2.x | +| 5.x | → | 5.x | +| master | → | master | ## Installation diff --git a/elasticsearch-persistence/README.md b/elasticsearch-persistence/README.md index 053366813..9b7389b43 100644 --- a/elasticsearch-persistence/README.md +++ b/elasticsearch-persistence/README.md @@ -2,7 +2,19 @@ Persistence layer for Ruby domain objects in Elasticsearch, using the Repository and ActiveRecord patterns. -The library is compatible with Ruby 1.9.3 (or higher) and Elasticsearch 1.0 (or higher). +## Compatibility + +This library is compatible with Ruby 1.9.3 and higher. + +The library version numbers follow the Elasticsearch major versions, and the `master` branch +is compatible with the Elasticsearch `master` branch, therefore, with the next major version. + +| Rubygem | | Elasticsearch | +|:-------------:|:-:| :-----------: | +| 0.1 | → | 1.x | +| 2.x | → | 2.x | +| 5.x | → | 5.x | +| master | → | master | ## Installation diff --git a/elasticsearch-rails/README.md b/elasticsearch-rails/README.md index 476054938..ee513b5be 100644 --- a/elasticsearch-rails/README.md +++ b/elasticsearch-rails/README.md @@ -1,10 +1,22 @@ # Elasticsearch::Rails The `elasticsearch-rails` library is a companion for the -the [`elasticsearch-model`](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model) +the [`elasticsearch-model`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model) library, providing features suitable for Ruby on Rails applications. -The library is compatible with Ruby 1.9.3 and higher. +## Compatibility + +This library is compatible with Ruby 1.9.3 and higher. + +The library version numbers follow the Elasticsearch major versions, and the `master` branch +is compatible with the Elasticsearch `master` branch, therefore, with the next major version. + +| Rubygem | | Elasticsearch | +|:-------------:|:-:| :-----------: | +| 0.1 | → | 1.x | +| 2.x | → | 2.x | +| 5.x | → | 5.x | +| master | → | master | ## Installation From 5a324b3a543828e9f7c18feeb3aa74d64f0187b8 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 15:14:28 +0200 Subject: [PATCH 2/9] Updated the Bundler instructions and Github URLs in the READMEs --- README.md | 18 +++--------------- elasticsearch-model/README.md | 10 +++++----- elasticsearch-persistence/README.md | 12 ++++++------ elasticsearch-rails/README.md | 16 ++++++++-------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 03138c07e..7e92f687d 100644 --- a/README.md +++ b/README.md @@ -39,23 +39,11 @@ gem install elasticsearch-model gem install elasticsearch-rails ``` -To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com): +To use an unreleased version, add it to your `Gemfile` for [Bundler](http://bundler.io): ```ruby -gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' -gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' -``` - -or install it from a source code checkout: - -```bash -git clone https://github.com/elasticsearch/elasticsearch-rails.git -cd elasticsearch-model -bundle install -rake install -cd elasticsearch-rails -bundle install -rake install +gem 'elasticsearch-model', github: 'elastic/elasticsearch-rails', branch: '5.x' +gem 'elasticsearch-rails', github: 'elastic/elasticsearch-rails', branch: '5.x' ``` ## Usage diff --git a/elasticsearch-model/README.md b/elasticsearch-model/README.md index 4e0be9037..4eb74162e 100644 --- a/elasticsearch-model/README.md +++ b/elasticsearch-model/README.md @@ -29,11 +29,11 @@ Install the package from [Rubygems](https://rubygems.org): To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://bundler.io): - gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' + gem 'elasticsearch-model', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: '5.x' or install it from a source code checkout: - git clone https://github.com/elasticsearch/elasticsearch-rails.git + git clone https://github.com/elastic/elasticsearch-rails.git cd elasticsearch-rails/elasticsearch-model bundle install rake install @@ -121,7 +121,7 @@ See the `Elasticsearch::Model` module documentation for technical information. ### The Elasticsearch client -The module will set up a [client](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch), +The module will set up a [client](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch), connected to `localhost:9200`, by default. You can access and use it as any other `Elasticsearch::Client`: ```ruby @@ -144,7 +144,7 @@ Elasticsearch::Model.client = Elasticsearch::Client.new log: true You might want to do this during your application bootstrap process, e.g. in a Rails initializer. Please refer to the -[`elasticsearch-transport`](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport) +[`elasticsearch-transport`](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport) library documentation for all the configuration options, and to the [`elasticsearch-api`](http://rubydoc.info/gems/elasticsearch-api) library documentation for information about the Ruby client API. @@ -253,7 +253,7 @@ response.records.order(:title).to_a The `records` method returns the real instances of your model, which is useful when you want to access your model methods -- at the expense of slowing down your application, of course. In most cases, working with `results` coming from Elasticsearch is sufficient, and much faster. See the -[`elasticsearch-rails`](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails) +[`elasticsearch-rails`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails) library for more information about compatibility with the Ruby on Rails framework. When you want to access both the database `records` and search `results`, use the `each_with_hit` diff --git a/elasticsearch-persistence/README.md b/elasticsearch-persistence/README.md index 9b7389b43..cb0de66d2 100644 --- a/elasticsearch-persistence/README.md +++ b/elasticsearch-persistence/README.md @@ -24,11 +24,11 @@ Install the package from [Rubygems](https://rubygems.org): To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://bundler.io): - gem 'elasticsearch-persistence', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' + gem 'elasticsearch-persistence', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: '5.x' or install it from a source code checkout: - git clone https://github.com/elasticsearch/elasticsearch-rails.git + git clone https://github.com/elastic/elasticsearch-rails.git cd elasticsearch-rails/elasticsearch-persistence bundle install rake install @@ -112,7 +112,7 @@ repository.delete(note) The repository module provides a number of features and facilities to configure and customize the behavior: -* Configuring the Elasticsearch [client](https://github.com/elasticsearch/elasticsearch-ruby#usage) being used +* Configuring the Elasticsearch [client](https://github.com/elastic/elasticsearch-ruby#usage) being used * Setting the index name, document type, and object class for deserialization * Composing mappings and settings for the index * Creating, deleting or refreshing the index @@ -263,7 +263,7 @@ puts repository.find(1).attributes['image'] ##### Client -The repository uses the standard Elasticsearch [client](https://github.com/elasticsearch/elasticsearch-ruby#usage), +The repository uses the standard Elasticsearch [client](https://github.com/elastic/elasticsearch-ruby#usage), which is accessible with the `client` getter and setter methods: ```ruby @@ -622,7 +622,7 @@ puts results.response.aggregations.authors.buckets.each { |b| puts "#{b['key']} #### The Elasticsearch Client -The module will set up a [client](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch), +The module will set up a [client](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch), connected to `localhost:9200`, by default. To use a client with different configuration: @@ -688,7 +688,7 @@ rails generate scaffold Person name:String email:String birthday:Date --orm=elas A fully working Ruby on Rails application can be generated with the following command: ```bash -rails new music --force --skip --skip-bundle --skip-active-record --template https://raw.githubusercontent.com/elasticsearch/elasticsearch-rails/master/elasticsearch-persistence/examples/music/template.rb +rails new music --force --skip --skip-bundle --skip-active-record --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-persistence/examples/music/template.rb ``` The application demonstrates: diff --git a/elasticsearch-rails/README.md b/elasticsearch-rails/README.md index ee513b5be..eb0cb2782 100644 --- a/elasticsearch-rails/README.md +++ b/elasticsearch-rails/README.md @@ -26,11 +26,11 @@ Install the package from [Rubygems](https://rubygems.org): To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://bundler.io): - gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' + gem 'elasticsearch-rails', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: '5.x' or install it from a source code checkout: - git clone https://github.com/elasticsearch/elasticsearch-rails.git + git clone https://github.com/elastic/elasticsearch-rails.git cd elasticsearch-rails/elasticsearch-rails bundle install rake install @@ -99,22 +99,22 @@ You should see the duration of the request to Elasticsearch as part of each log You can generate a fully working example Ruby on Rails application, with an `Article` model and a search form, to play with (it even downloads _Elasticsearch_ itself, generates the application skeleton and leaves you with a _Git_ repository to explore the steps and the code) with the -[`01-basic.rb`](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/01-basic.rb) template: +[`01-basic.rb`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/01-basic.rb) template: ```bash -rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb +rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb ``` Run the same command again, in the same folder, with the -[`02-pretty`](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb) +[`02-pretty`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb) template to add features such as a custom `Article.search` method, result highlighting and [_Bootstrap_](http://getbootstrap.com) integration: ```bash -rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb +rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb ``` -Run the same command with the [`03-expert.rb`](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/03-expert.rb) +Run the same command with the [`03-expert.rb`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/03-expert.rb) template to refactor the application into a more complex use case, with couple of hundreds of The New York Times articles as the example content. The template will extract the Elasticsearch integration into a `Searchable` "concern" module, @@ -122,7 +122,7 @@ define complex mapping, custom serialization, implement faceted navigation and s a complex query, and add a _Sidekiq_-based worker for updating the index in the background. ```bash -rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb +rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb ``` ## License From a71c48e8d330a7719baa536f291f132be8c2c72e Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 15:53:27 +0200 Subject: [PATCH 3/9] Added a CHANGELOG to the repository --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ed56ccac5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## 0.1.9 + +The last version for the old versioning scheme -- please see the Git commit log +at https://github.com/elastic/elasticsearch-rails/commits/v0.1.9 From 5a7523a2581415187e8090ec72131a3875907bc9 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 16:41:30 +0200 Subject: [PATCH 4/9] Release 2.0.0 --- CHANGELOG.md | 38 +++++++++++++++++++ .../lib/elasticsearch/model/version.rb | 2 +- .../lib/elasticsearch/persistence/version.rb | 2 +- .../lib/elasticsearch/rails/version.rb | 2 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed56ccac5..7c770a989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,41 @@ +## 2.0.0 + +* Updated the Rake dependency to 11.1 +* Reduced verbosity of `rake test:unit` and `rake test:integration` +* Removed the "CI Reporter" integration from test Rake tasks +* Added the "Compatibility" chapter to the READMEs +* Updated the Bundler instructions and Github URLs in the READMEs + +### ActiveModel + +* Fixed a problem where `Hashie::Mash#min` and `#max` returned unexpected values +* Added information about `elasticsearch-dsl` to the README +* Added support for inherited index names and doc types +* Added a `Elasticsearch::Model.settings` method +* Changed the naming inheritance logic to use `Elasticsearch::Model.settings` +* Added information about the `settings` method and the `inheritance_enabled` setting into the README +* Disable "verbose" and "warnings" in integration tests +* Added code for establishing ActiveRecord connections to test classes +* Reorganized the class definitions in the integration tests +* Moved `require` within unit test to the top of the file +* Added ActiveRecord 5 support to integration test configuration +* Fixed records sorting with ActiveRecord 5.x +* Added, that `add_index` for ActiveRecord models is only called when it doesn't exist already +* Use `records.__send__ :load` instead of `records.load` in the ActiveRecord adapter +* Call `Kaminari::Hooks.init` only when available +* Fixed the deprecation messages for `raise_in_transactional_callbacks` +* Fixed the deprecation messages for `timestamps` in migrations in integration tests +* Fixed the naming for the indexing integration tests +* Fixed the failing integration tests for ActiveRecord associations +* Fixed integration tests for ActiveRecord pagination +* Added the `rake bundle:install` Rake task to install dependencies for all gemfiles +* Run unit tests against all Gemfiles +* Updated dependencies in gemspec + +### Persistence + +* Updated dependencies in gemspec + ## 0.1.9 The last version for the old versioning scheme -- please see the Git commit log diff --git a/elasticsearch-model/lib/elasticsearch/model/version.rb b/elasticsearch-model/lib/elasticsearch/model/version.rb index 44cfdabea..23b4d424e 100644 --- a/elasticsearch-model/lib/elasticsearch/model/version.rb +++ b/elasticsearch-model/lib/elasticsearch/model/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Model - VERSION = "0.1.9" + VERSION = "2.0.0" end end diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb index 93852c314..7bf8b2c53 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Persistence - VERSION = "0.1.9" + VERSION = "2.0.0" end end diff --git a/elasticsearch-rails/lib/elasticsearch/rails/version.rb b/elasticsearch-rails/lib/elasticsearch/rails/version.rb index 88b2dd758..0fc17d058 100644 --- a/elasticsearch-rails/lib/elasticsearch/rails/version.rb +++ b/elasticsearch-rails/lib/elasticsearch/rails/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Rails - VERSION = "0.1.9" + VERSION = "2.0.0" end end From 0abc4b875abe4fe82cf7f32379321e560892c614 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 16:55:51 +0200 Subject: [PATCH 5/9] [CI] Updated the version of Elasticsearch to run at Travis to "2.4.3" --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ba677f628..dbcb4f463 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ branches: only: - master - travis + - 2.x matrix: include: @@ -28,14 +29,14 @@ matrix: - rvm: 2.3.3 jdk: oraclejdk8 - env: TEST_SUITE=integration SERVER=start TEST_CLUSTER_LOGS=/tmp/log TEST_CLUSTER_COMMAND=/tmp/elasticsearch-1.7.5/bin/elasticsearch + env: TEST_SUITE=integration SERVER=start TEST_CLUSTER_LOGS=/tmp/log TEST_CLUSTER_COMMAND=/tmp/elasticsearch-2.4.3/bin/elasticsearch before_install: - gem update --system --no-rdoc --no-ri - gem --version - gem install bundler -v 1.14.3 --no-rdoc --no-ri - bundle version - - curl -sS https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.5.tar.gz | tar xz -C /tmp + - curl -sS https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.3/elasticsearch-2.4.3.tar.gz | tar xz -C /tmp install: - bundle install From 9cf180b7e4c1cbd18d89c85bc4cee606d67cc3a1 Mon Sep 17 00:00:00 2001 From: Yasunori Suzuki Date: Thu, 13 Apr 2017 15:34:05 +0900 Subject: [PATCH 6/9] [MODEL] Fixed incorrect dependency on "elasticsearch-ruby" The 2.x versions should depend on the corresponding version of the Ruby client. Closes #702 --- elasticsearch-model/elasticsearch-model.gemspec | 2 +- elasticsearch-persistence/elasticsearch-persistence.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch-model/elasticsearch-model.gemspec b/elasticsearch-model/elasticsearch-model.gemspec index 2f289b6bc..541d4bed0 100644 --- a/elasticsearch-model/elasticsearch-model.gemspec +++ b/elasticsearch-model/elasticsearch-model.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 1.9.3" - s.add_dependency "elasticsearch", '~> 1.1' + s.add_dependency "elasticsearch", '~> 2' s.add_dependency "activesupport", '> 3' s.add_dependency "hashie" diff --git a/elasticsearch-persistence/elasticsearch-persistence.gemspec b/elasticsearch-persistence/elasticsearch-persistence.gemspec index ab8ecc163..7a93dd5cf 100644 --- a/elasticsearch-persistence/elasticsearch-persistence.gemspec +++ b/elasticsearch-persistence/elasticsearch-persistence.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 1.9.3" - s.add_dependency "elasticsearch", '~> 1.1' + s.add_dependency "elasticsearch", '~> 2' s.add_dependency "elasticsearch-model", '>= 0.1' s.add_dependency "activesupport", '> 4' s.add_dependency "activemodel", '> 4' From c054f94ffcb3c794037c1e6ae23ea74f00f61164 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Fri, 7 Apr 2017 16:46:08 +0200 Subject: [PATCH 7/9] Added a Rake task for updating the version and compiling the CHANGELOG --- Rakefile | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/Rakefile b/Rakefile index 64fab6ac6..b4c90d710 100644 --- a/Rakefile +++ b/Rakefile @@ -126,3 +126,117 @@ task :release do puts '-'*80 end end + +desc <<-DESC + Update Rubygems versions in version.rb and *.gemspec files + + Example: + + $ rake update_version[5.0.0,5.0.1] +DESC +task :update_version, :old, :new do |task, args| + require 'ansi' + + puts "[!!!] Required argument [old] missing".ansi(:red) unless args[:old] + puts "[!!!] Required argument [new] missing".ansi(:red) unless args[:new] + + files = Dir['**/**/version.rb','**/**/*.gemspec'] + + longest_line = files.map { |f| f.size }.max + + puts "\n", "= FILES ".ansi(:faint) + ('='*92).ansi(:faint), "\n" + + files.each do |file| + begin + File.open(file, 'r+') do |f| + content = f.read + if content.match Regexp.new(args[:old]) + content.gsub! Regexp.new(args[:old]), args[:new] + puts "+ [#{file}]".ansi(:green).ljust(longest_line+20) + " [#{args[:old]}] -> [#{args[:new]}]".ansi(:green,:bold) + f.rewind + f.write content + else + puts "- [#{file}]".ansi(:yellow).ljust(longest_line+20) + " -".ansi(:faint,:strike) + end + end + rescue Exception => e + puts "[!!!] #{e.class} : #{e.message}".ansi(:red,:bold) + raise e + end + end + + puts "\n\n", "= CHANGELOG ".ansi(:faint) + ('='*88).ansi(:faint), "\n" + + log = `git --no-pager log --reverse --no-color --pretty='* %s' HEAD --not v#{args[:old]} elasticsearch-*`.split("\n") + + puts log.join("\n") + + log_entries = {} + log_entries[:common] = log.reject { |l| l =~ /^* \[/ } + log_entries[:model] = log.select { |l| l =~ /^* \[MODEL\]/ } + log_entries[:store] = log.select { |l| l =~ /^* \[STORE\]/ } + log_entries[:rails] = log.select { |l| l =~ /^* \[RAILS\]/ } + + changelog = File.read(File.open('CHANGELOG.md', 'r')) + + changelog_update = '' + + changelog_update << "## #{args[:new]}\n\n" + + unless log_entries[:common].empty? + changelog_update << log_entries[:common] + .map { |l| "#{l}" } + .join("\n") + changelog_update << "\n\n" + end + + unless log_entries[:model].empty? + changelog_update << "### ActiveModel\n\n" + changelog_update << log_entries[:model] + .map { |l| l.gsub /\[.+\] /, '' } + .map { |l| "#{l}" } + .join("\n") + changelog_update << "\n\n" + end + + unless log_entries[:store].empty? + changelog_update << "### Persistence\n\n" + changelog_update << log_entries[:store] + .map { |l| l.gsub /\[.+\] /, '' } + .map { |l| "#{l}" } + .join("\n") + changelog_update << "\n\n" + end + + unless log_entries[:rails].empty? + changelog_update << "### Ruby on Rails\n\n" + changelog_update << log_entries[:rails] + .map { |l| l.gsub /\[.+\] /, '' } + .map { |l| "#{l}" } + .join("\n") + changelog_update << "\n\n" + end + + unless changelog =~ /^## #{args[:new]}/ + File.open('CHANGELOG.md', 'w+') { |f| f.write changelog_update and f.write changelog } + end + + puts "\n\n", "= DIFF ".ansi(:faint) + ('='*93).ansi(:faint) + + diff = `git --no-pager diff --patch --word-diff=color --minimal elasticsearch-*`.split("\n") + + puts diff + .reject { |l| l =~ /^\e\[1mdiff \-\-git/ } + .reject { |l| l =~ /^\e\[1mindex [a-z0-9]{7}/ } + .reject { |l| l =~ /^\e\[1m\-\-\- i/ } + .reject { |l| l =~ /^\e\[36m@@/ } + .map { |l| l =~ /^\e\[1m\+\+\+ w/ ? "\n#{l} " + '-'*(104-l.size) : l } + .join("\n") + + puts "\n\n", "= COMMIT ".ansi(:faint) + ('='*91).ansi(:faint), "\n" + + puts "git add CHANGELOG.md elasticsearch-*", + "git commit --verbose --message='Release #{args[:new]}' --edit", + "rake release" + "\n" +end From aa659145f88615cf5944dd22314fc8ae2c2dd409 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Thu, 4 May 2017 15:55:42 +0200 Subject: [PATCH 8/9] Release 2.0.1 --- CHANGELOG.md | 6 ++++++ elasticsearch-model/lib/elasticsearch/model/version.rb | 2 +- .../lib/elasticsearch/persistence/version.rb | 2 +- elasticsearch-rails/lib/elasticsearch/rails/version.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c770a989..e307a1025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.1 + +### ActiveModel + +* Fixed incorrect dependency on the "elasticsearch" Rubygem + ## 2.0.0 * Updated the Rake dependency to 11.1 diff --git a/elasticsearch-model/lib/elasticsearch/model/version.rb b/elasticsearch-model/lib/elasticsearch/model/version.rb index 23b4d424e..7d845f398 100644 --- a/elasticsearch-model/lib/elasticsearch/model/version.rb +++ b/elasticsearch-model/lib/elasticsearch/model/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Model - VERSION = "2.0.0" + VERSION = "2.0.1" end end diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb index 7bf8b2c53..c1bc40bda 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Persistence - VERSION = "2.0.0" + VERSION = "2.0.1" end end diff --git a/elasticsearch-rails/lib/elasticsearch/rails/version.rb b/elasticsearch-rails/lib/elasticsearch/rails/version.rb index 0fc17d058..daa987806 100644 --- a/elasticsearch-rails/lib/elasticsearch/rails/version.rb +++ b/elasticsearch-rails/lib/elasticsearch/rails/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Rails - VERSION = "2.0.0" + VERSION = "2.0.1" end end From 154cd79b75ce76e6d1d68544b1510a7c0d7cf589 Mon Sep 17 00:00:00 2001 From: Tim Bleck Date: Fri, 7 Sep 2018 13:15:55 +0200 Subject: [PATCH 9/9] [MODEL] Fix import when preprocess returns empty collection (#720) Fixes #719 --- .../model/adapters/active_record.rb | 3 +- .../test/unit/adapter_active_record_test.rb | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb b/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb index 23c4267fa..aa74833d4 100644 --- a/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb +++ b/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb @@ -103,7 +103,8 @@ def __find_in_batches(options={}, &block) scope = scope.instance_exec(&query) if query scope.find_in_batches(options) do |batch| - yield (preprocess ? self.__send__(preprocess, batch) : batch) + batch = self.__send__(preprocess, batch) if preprocess + yield(batch) if batch.present? end end diff --git a/elasticsearch-model/test/unit/adapter_active_record_test.rb b/elasticsearch-model/test/unit/adapter_active_record_test.rb index 335e3bd10..152526e47 100644 --- a/elasticsearch-model/test/unit/adapter_active_record_test.rb +++ b/elasticsearch-model/test/unit/adapter_active_record_test.rb @@ -121,20 +121,37 @@ def ids DummyClassForActiveRecord.__find_in_batches(query: -> { where(color: "red") }) do; end end - should "preprocess the batch if option provided" do - class << DummyClassForActiveRecord - # Updates/transforms the batch while fetching it from the database - # (eg. with information from an external system) - # - def update_batch(batch) - batch.collect { |b| b.to_s + '!' } + context "when preprocessing batches" do + setup do + class << DummyClassForActiveRecord + def find_in_batches(options = {}, &block) + yield [:a, :b] + end + end + end + + should "preprocess the batch if option provided" do + class << DummyClassForActiveRecord + def update_batch(batch) + batch.collect { |b| b.to_s + '!' } + end + end + + DummyClassForActiveRecord.__find_in_batches(preprocess: :update_batch) do |batch| + assert_same_elements ["a!", "b!"], batch end end - DummyClassForActiveRecord.expects(:__find_in_batches).returns( [:a, :b] ) + should "skip batch if preprocess option provided and returns empty collection" do + class << DummyClassForActiveRecord + def update_batch(batch) + [] + end + end - DummyClassForActiveRecord.__find_in_batches(preprocess: :update_batch) do |batch| - assert_same_elements ["a!", "b!"], batch + DummyClassForActiveRecord.__find_in_batches(preprocess: :update_batch) do |batch| + flunk("block should not have been called on empty batch") + end end end