Skip to content

Commit

Permalink
add export method
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Dec 29, 2019
1 parent e290c26 commit a42faa1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/inventory_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def import
true
end

def export(col_sep: "\t")
file = Tempfile.create do |f|
inventories.each do |inventory|
f.write inventory.to_hash.values.to_csv(col_sep)
end

f.rewind
f.read
end

file
end

def missing_items
Item.where(Inventory.where('items.id = inventories.item_id AND inventories.inventory_file_id = ?', id).exists.not)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/inventory_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
it "should be imported" do
expect(@file.import).to be_truthy
end

it "should export results" do
expect(@file.export).to be_truthy
end
end

# == Schema Information
Expand Down

0 comments on commit a42faa1

Please sign in to comment.