2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe CsvBuilders::Stream do
|
|
|
|
let(:event_1) { double(title: 'Added salt', description: 'A teaspoon') }
|
|
|
|
let(:event_2) { double(title: 'Added sugar', description: 'Just a pinch') }
|
|
|
|
let(:fake_relation) { FakeRelation.new([event_1, event_2]) }
|
|
|
|
|
|
|
|
subject(:builder) { described_class.new(fake_relation, 'Title' => 'title', 'Description' => 'description') }
|
|
|
|
|
|
|
|
describe '#render' do
|
|
|
|
before do
|
|
|
|
stub_const('FakeRelation', Array)
|
|
|
|
|
|
|
|
FakeRelation.class_eval do
|
|
|
|
def find_each(&block)
|
|
|
|
each(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a lazy enumerator' do
|
|
|
|
expect(builder.render).to be_an(Enumerator::Lazy)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all rows up to default max value' do
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(builder.render.to_a).to eq(
|
|
|
|
[
|
|
|
|
"Title,Description\n",
|
|
|
|
"Added salt,A teaspoon\n",
|
|
|
|
"Added sugar,Just a pinch\n"
|
|
|
|
])
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'truncates to max rows' do
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(builder.render(1).to_a).to eq(
|
|
|
|
[
|
|
|
|
"Title,Description\n",
|
|
|
|
"Added salt,A teaspoon\n"
|
|
|
|
])
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|