This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ace-of-base/spec/ace_of_base/query_spec.rb
2019-07-10 21:46:42 +12:00

57 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
require 'fileutils'
RSpec.describe AceOfBase::Query do
let(:tmpdir) { Dir.mktmpdir }
let(:storage) { AceOfBase::Storage.new(tmpdir) }
subject { described_class.new(storage) }
around do |example|
# Import our fixture file.
path = File.expand_path('../fixtures/sample_file.txt', __dir__)
file = File.open(path, 'r')
importer = AceOfBase::FileImporter.import(file)
importer.records.each { |record| storage.store(record) }
# Run the example
example.run
# Clean up.
FileUtils.remove_entry(tmpdir, true)
end
describe 'query with select and order by' do
subject do
super()
.select(:project, :shot, :version, :status)
.order_by(:finish_date, :internal_bid)
.execute
end
it 'returns the correct data' do
expect(subject)
.to eq([
['lotr', '03', 16, 'finished'],
['king kong', '42', 128, 'not required'],
['the hobbit', '40', 32, 'finished'],
['the hobbit', '01', 64, 'scheduled']
])
end
end
describe 'query with select and filter' do
subject do
super()
.select(:project, :shot, :version, :status)
.filter(:finish_date, Date.civil(2006, 7, 22))
.execute
end
it 'returns the correct data' do
expect(subject)
.to eq([['king kong', '42', 128, 'not required']])
end
end
end