Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
[ACTIVEMODEL] Allow passing :index option to MyModel.import
Browse files Browse the repository at this point in the history
Allows to index the data into a different index:

    Article.import index: 'new_articles'
  • Loading branch information
karmi committed Jan 5, 2013
1 parent 63e3e8a commit cc5fc25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tire/model/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module ClassMethods

def import options={}, &block
options = { :method => 'paginate' }.update options
index = options[:index] ? Tire::Index.new(options.delete(:index)) : self.index
index.import klass, options, &block
end

Expand Down
4 changes: 4 additions & 0 deletions test/unit/model_import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class ImportTest < Test::Unit::TestCase
# Add 1 to every "document" and return them
documents.map { |d| d + 1 }
end
end

should "store the documents in a different index" do
Tire::Index.expects(:new).with('new_index').returns( mock('index') { expects(:import) } )
ImportModel.import :index => 'new_index'
end

end
Expand Down

0 comments on commit cc5fc25

Please sign in to comment.