diff --git a/Gemfile b/Gemfile index 2fd9843..09c5c7d 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec group :test do gem 'dry-struct' gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'master' + gem 'rom-repository', git: 'https://github.com/rom-rb/rom-repository', branch: 'master' gem 'rspec', '~> 3.1' gem 'codeclimate-test-reporter', require: false gem 'inflecto' diff --git a/lib/rom/csv/relation.rb b/lib/rom/csv/relation.rb index d02cd6d..5a15517 100644 --- a/lib/rom/csv/relation.rb +++ b/lib/rom/csv/relation.rb @@ -1,4 +1,5 @@ require 'rom/memory' +require 'rom/plugins/relation/key_inference' module ROM module CSV @@ -11,6 +12,7 @@ module CSV # @api public class Relation < ROM::Memory::Relation adapter :csv + use :key_inference def count dataset.count diff --git a/spec/integration/gateway_spec.rb b/spec/integration/gateway_spec.rb index 8b2e87f..dcfa1bc 100644 --- a/spec/integration/gateway_spec.rb +++ b/spec/integration/gateway_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'dry-struct' +require 'rom/repository' describe 'CSV gateway' do context 'without extra options' do @@ -135,5 +136,18 @@ class UserWithAddress < Dry::Struct expect(user[:email]).to eql('zolw@example.com') end end + + describe 'with a repository' do + let(:repo) do + Class.new(ROM::Repository[:users]).new(container) + end + + it 'auto-maps to structs' do + user = repo.users.first + + expect(user.name).to eql('Julie') + expect(user.email).to eql('julie.andrews@example.com') + end + end end end