Sha256: f3b197d84281b844a08beaf8f477e9d0f4fd7f9c837f6ff0122a7486925b8f49
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require 'spec_helper' describe 'Defining schema' do let(:setup) { ROM.setup(memory: 'memory://localhost') } let(:rom) { setup.finalize } let(:schema) { rom.schema } shared_context 'valid schema' do before do setup.schema do base_relation(:users) do repository :memory attribute :id attribute :name end end end it 'returns schema with relations' do users = schema.users expect(users.dataset.to_a).to eql(rom.memory.users.to_a) expect(users.header).to eql([:id, :name]) end end describe '.schema' do it 'returns an empty schema if it was not defined' do expect { schema.users }.to raise_error(NoMethodError) end context 'with an adapter that supports header injection' do it_behaves_like 'valid schema' end context 'can be called multiple times' do before do setup.schema do base_relation(:tasks) do repository :memory attribute :title end end setup.schema do base_relation(:tags) do repository :memory attribute :name end end end it_behaves_like 'valid schema' do it 'registers all base relations' do expect(schema.tasks.dataset).to be(rom.memory.tasks) expect(schema.tasks.header).to eql([:title]) expect(schema.tags.dataset).to be(rom.memory.tags) expect(schema.tags.header).to eql([:name]) end end end context 'with an adapter that does not support header injection' do before do ROM::Adapter::Memory::Dataset.send(:undef_method, :header) end after do ROM::Adapter::Memory::Dataset.send(:attr_reader, :header) end it_behaves_like 'valid schema' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-0.5.0 | spec/integration/schema_spec.rb |