rom 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29e221f399a6c003c04d45c03b9518d19b5ffd48
4
- data.tar.gz: 223b1648de818651d5cc89f05e088fefdaf8ec19
3
+ metadata.gz: e6dd420bd1787efc67261de110b316f6b5c92ae8
4
+ data.tar.gz: e9f8fb3dbc40528ac46f6427d7b7238c162980bd
5
5
  SHA512:
6
- metadata.gz: 144b7539ca43248fd1c8304b624e5fd46f229016bb5057b20615f95026421b916b66888d223b49b4f5119a5698b44c7f96165fd454922b722387701e0d9eb7ee
7
- data.tar.gz: 7dee28d63ed1e6a7c7eee538172249d6d8c71cd83b8840c38d86550cc323f2944ef4d68cab49236f69c55ac632fa00f29e06d44439fb2c6a1f1cd9a67e054e97
6
+ metadata.gz: 6a48171fa2e771fec4e68e14b99e4f78cfd31f6d5162ff5f14546f41d6970b44c8522304cfa9546cff203967696853002e3524f714023d7ac0fd5ea086d7ea9f
7
+ data.tar.gz: 34e9a0f63fabaf30897d767db9b8d26e1ac92cd0661cff7bdb5b1f27979fe56feb9f6b0c12ae7305f514c623322e270009ecd3ce35e51867bfdac5a199393408
data/.travis.yml CHANGED
@@ -1,24 +1,24 @@
1
1
  language: ruby
2
- sudo: false
2
+ dist: trusty
3
+ sudo: required
3
4
  cache: bundler
4
- env:
5
- - CODECLIMATE_REPO_TOKEN=f7c652b65a700fcf1032174afc5ea243b991e48bf73077cc34c148e1c800a2f7
6
5
  bundler_args: --without sql benchmarks console tools
7
6
  script: "bundle exec rake ci"
7
+ after_success:
8
+ - '[ "$TRAVIS_RUBY_VERSION" = "2.3.1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
8
9
  rvm:
9
10
  - 2.1
10
11
  - 2.2
11
12
  - 2.3.1
12
- - rbx-2
13
+ - rbx-3
13
14
  - jruby-9.1.5.0
14
- - ruby-head
15
15
  env:
16
16
  global:
17
17
  - JRUBY_OPTS='--dev -J-Xmx1024M'
18
+ - COVERAGE='true'
18
19
  matrix:
19
20
  allow_failures:
20
- - rvm: ruby-head
21
- - rvm: rbx-2
21
+ - rvm: rbx-3
22
22
  notifications:
23
23
  webhooks:
24
24
  urls:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## v2.0.2 2016-11-11
2
+
3
+ ## Added
4
+
5
+ * API docs for `ROM::Container` (solnic)
6
+
7
+ ## Fixed
8
+
9
+ * Custom command input function is no longer overridden by schema hash (solnic)
10
+ * `Relation::Name#to_s` returns a string properly when there is no alias (solnic)
11
+
12
+ [Compare v2.0.1...v2.0.2](https://github.com/rom-rb/rom/compare/v2.0.0...v2.0.2)
13
+
1
14
  ## v2.0.1 2016-09-30
2
15
 
3
16
  ### Added
data/Gemfile CHANGED
@@ -8,14 +8,18 @@ group :console do
8
8
  end
9
9
 
10
10
  group :test do
11
- gem 'virtus'
12
- gem 'anima', '~> 0.2.0'
11
+ gem 'dry-equalizer'
12
+ gem 'dry-struct'
13
13
  gem 'minitest'
14
14
  gem 'inflecto', '~> 0.0', '>= 0.0.2'
15
15
 
16
- platforms :rbx do
17
- gem 'rubysl-bigdecimal', platforms: :rbx
16
+ platforms :mri do
18
17
  gem 'codeclimate-test-reporter', require: false
18
+ gem 'simplecov', require: false
19
+ end
20
+
21
+ platforms :rbx do
22
+ gem 'rubysl-bigdecimal'
19
23
  end
20
24
  end
21
25
 
@@ -27,7 +31,7 @@ group :sql do
27
31
  end
28
32
 
29
33
  group :benchmarks do
30
- gem 'activerecord', '5.0.0.beta4'
34
+ gem 'activerecord', '~> 5.0'
31
35
  gem 'benchmark-ips', '~> 2.2.0'
32
36
  gem 'rom-repository', github: 'rom-rb/rom-repository', branch: 'master'
33
37
  end
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ task default: [:ci]
7
7
  desc 'Run specs in isolation'
8
8
  task :"spec:isolation" do
9
9
  FileList["spec/**/*_spec.rb"].each do |spec|
10
- sh "rspec", spec
10
+ sh "COVERAGE=false bundle exec rspec #{spec}"
11
11
  end
12
12
  end
13
13
 
data/lib/rom/container.rb CHANGED
@@ -4,7 +4,97 @@ require 'rom/commands/graph/builder'
4
4
  require 'rom/support/publisher'
5
5
 
6
6
  module ROM
7
- # Exposes defined gateways, relations and mappers
7
+ # ROM container is an isolated environment with no global state where all
8
+ # components are registered. Container objects provide access to your
9
+ # relations, commands and mappers. ROM containers are usually configured and
10
+ # handled via framework integrations, although it is easy to use them
11
+ # standalone.
12
+ #
13
+ # There are 3 types of container setup:
14
+ #
15
+ # * in-line setup - a simple block-based configuration which allows configuring
16
+ # all components and gives you back a container instance. This type is suitable
17
+ # for small scripts, or in some cases rake tasks
18
+ # * multi-step setup - this type requires creating a configuration object,
19
+ # registering component classes (ie relation classes) and passing the config
20
+ # to container builder function. This type is suitable when your environment
21
+ # is not typical and you need full control over component registration
22
+ # * multi-step setup with auto-registration - same as multi-step but allows
23
+ # you to configure auto-registration mechanism which will register component
24
+ # classes for you, based on dir/file naming conventions. This is the most
25
+ # common type of setup that's used by framework integrations
26
+ #
27
+ # @example in-line setup
28
+ # rom = ROM.container(:sql, 'sqlite::memory') do |config|
29
+ # config.default.create_table :users do
30
+ # primary_key :id
31
+ # column :name, String, null: false
32
+ # end
33
+ #
34
+ # config.relation(:users) do
35
+ # schema(infer: true)
36
+ #
37
+ # def by_name(name)
38
+ # where(name: name)
39
+ # end
40
+ # end
41
+ # end
42
+ #
43
+ # rom.relations[:users].insert(name: "Jane")
44
+ #
45
+ # rom.relations[:users].by_name("Jane").to_a
46
+ # # [{:id=>1, :name=>"Jane"}]
47
+ #
48
+ # @example multi-step setup with explicit component classes
49
+ # config = ROM::Configuration.new(:sql, 'sqlite::memory')
50
+ #
51
+ # config.default.create_table :users do
52
+ # primary_key :id
53
+ # column :name, String, null: false
54
+ # end
55
+ #
56
+ # class Users < ROM::Relation[:sql]
57
+ # schema(:users, infer: true)
58
+ #
59
+ # def by_name(name)
60
+ # where(name: name)
61
+ # end
62
+ # end
63
+ #
64
+ # config.register_relation(Users)
65
+ #
66
+ # rom = ROM.container(config)
67
+ #
68
+ # rom.relations[:users].insert(name: "Jane")
69
+ #
70
+ # rom.relations[:users].by_name("Jane").to_a
71
+ # # [{:id=>1, :name=>"Jane"}]
72
+ #
73
+ #
74
+ # @example multi-step setup with auto-registration
75
+ # config = ROM::Configuration.new(:sql, 'sqlite::memory')
76
+ # config.auto_registration('./persistence', namespace: false)
77
+ #
78
+ # config.default.create_table :users do
79
+ # primary_key :id
80
+ # column :name, String, null: false
81
+ # end
82
+ #
83
+ # # ./persistence/relations/users.rb
84
+ # class Users < ROM::Relation[:sql]
85
+ # schema(infer: true)
86
+ #
87
+ # def by_name(name)
88
+ # where(name: name)
89
+ # end
90
+ # end
91
+ #
92
+ # rom = ROM.container(config)
93
+ #
94
+ # rom.relations[:users].insert(name: "Jane")
95
+ #
96
+ # rom.relations[:users].by_name("Jane").to_a
97
+ # # [{:id=>1, :name=>"Jane"}]
8
98
  #
9
99
  # @api public
10
100
  class Container
@@ -18,12 +108,12 @@ module ROM
18
108
 
19
109
  # @return [RelationRegistry] relation registry
20
110
  #
21
- # @api private
111
+ # @api public
22
112
  attr_reader :relations
23
113
 
24
114
  # @return [Registry] command registry
25
115
  #
26
- # @api private
116
+ # @api public
27
117
  attr_reader :commands
28
118
 
29
119
  # @return [Registry] mapper registry
@@ -39,7 +129,11 @@ module ROM
39
129
  @commands = commands
40
130
  end
41
131
 
42
- # Get lazy relation identified by its name
132
+ # Get relation instance identified by its name
133
+ #
134
+ # This method will use a custom mapper if it was configured. ie if you have
135
+ # a relation called `:users` and a mapper configured for `:users` relation,
136
+ # then by default this mapper will be used.
43
137
  #
44
138
  # @example
45
139
  # rom.relation(:users)
@@ -58,7 +152,7 @@ module ROM
58
152
  #
59
153
  # @yield [Relation]
60
154
  #
61
- # @return [Relation::Lazy]
155
+ # @return [Relation]
62
156
  #
63
157
  # @api public
64
158
  def relation(name, &block)
@@ -79,8 +173,7 @@ module ROM
79
173
  # Returns commands registry for the given relation
80
174
  #
81
175
  # @example
82
- #
83
- # # plain command returning tuples
176
+ # # plain command without mapping
84
177
  # rom.command(:users).create
85
178
  #
86
179
  # # allows auto-mapping using registered mappers
@@ -121,6 +214,16 @@ module ROM
121
214
  end
122
215
  end
123
216
 
217
+ # Disconnect all gateways
218
+ #
219
+ # @example
220
+ # rom = ROM.container(:sql, 'sqlite://my_db.sqlite')
221
+ # rom.relations[:users].insert(name: "Jane")
222
+ # rom.disconnect
223
+ #
224
+ # @return [Hash<Symbol=>Gateway>] a hash with disconnected gateways
225
+ #
226
+ # @api public
124
227
  def disconnect
125
228
  gateways.each_value(&:disconnect)
126
229
  end
@@ -16,7 +16,18 @@ module ROM
16
16
  if options.key?(:input) || !relation.schema?
17
17
  super
18
18
  else
19
- super(relation, options.merge(input: relation.schema_hash))
19
+ default_input = options.fetch(:input, input)
20
+
21
+ input_handler =
22
+ if default_input != Hash && relation.schema?
23
+ -> tuple { relation.schema_hash[input[tuple]] }
24
+ elsif relation.schema?
25
+ relation.schema_hash
26
+ else
27
+ default_input
28
+ end
29
+
30
+ super(relation, options.merge(input: input_handler))
20
31
  end
21
32
  end
22
33
  end
@@ -65,7 +65,7 @@ module ROM
65
65
  # @api private
66
66
  def to_s
67
67
  if relation == dataset
68
- relation
68
+ relation.to_s
69
69
  else
70
70
  "#{relation} on #{dataset}"
71
71
  end
@@ -51,7 +51,7 @@ module ROM
51
51
 
52
52
  # @api private
53
53
  def call
54
- Schema.new(name, attributes, inferrer: inferrer && inferrer.new(self))
54
+ Schema.new(name, attributes, inferrer: inferrer)
55
55
  end
56
56
  end
57
57
  end
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'dry-struct'
2
3
 
3
4
  describe 'Commands / Create' do
4
5
  include_context 'container'
@@ -40,12 +41,14 @@ describe 'Commands / Create' do
40
41
  end
41
42
  end
42
43
 
43
- Test::User = Class.new do
44
- include Anima.new(:name, :email)
44
+ Test::User = Class.new(Dry::Struct) do
45
+ attribute :name, Types::String
46
+ attribute :email, Types::String
45
47
  end
46
48
 
47
- Test::Task = Class.new do
48
- include Anima.new(:name, :title)
49
+ Test::Task = Class.new(Dry::Struct) do
50
+ attribute :name, Types::String
51
+ attribute :title, Types::String
49
52
  end
50
53
 
51
54
  class Test::UserMapper < ROM::Mapper
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
-
3
- require 'ostruct'
2
+ require 'dry-struct'
4
3
 
5
4
  describe 'Commands / Update' do
6
5
  include_context 'container'
@@ -87,7 +86,10 @@ describe 'Commands / Update' do
87
86
 
88
87
  describe 'piping results through mappers' do
89
88
  it 'allows scoping to a virtual relation' do
90
- user_model = Class.new { include Anima.new(:name, :email) }
89
+ user_model = Class.new(Dry::Struct) {
90
+ attribute :name, Types::String
91
+ attribute :email, Types::String
92
+ }
91
93
 
92
94
  configuration.mappers do
93
95
  define(:users) do
@@ -101,9 +101,9 @@ describe 'Mapper definition DSL' do
101
101
  it 'works' do
102
102
  container
103
103
 
104
- Test::User.send(:include, Equalizer.new(:name, :email, :tasks, :address, :book))
105
- Test::Task.send(:include, Equalizer.new(:title, :meta))
106
- Test::Address.send(:include, Equalizer.new(:city))
104
+ Test::User.send(:include, Dry::Equalizer(:name, :email, :tasks, :address, :book))
105
+ Test::Task.send(:include, Dry::Equalizer(:title, :meta))
106
+ Test::Address.send(:include, Dry::Equalizer(:city))
107
107
 
108
108
  result = users.combine(
109
109
  tasks.for_users.combine(tasks.tags),
@@ -130,7 +130,7 @@ describe 'Mapper definition DSL' do
130
130
 
131
131
  container
132
132
 
133
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
133
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
134
134
 
135
135
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
136
136
 
@@ -159,7 +159,7 @@ describe 'Mapper definition DSL' do
159
159
 
160
160
  container
161
161
 
162
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
162
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
163
163
 
164
164
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
165
165
 
@@ -189,8 +189,8 @@ describe 'Mapper definition DSL' do
189
189
 
190
190
  container
191
191
 
192
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
193
- Test::User.send(:include, Equalizer.new(:email))
192
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
193
+ Test::User.send(:include, Dry::Equalizer(:email))
194
194
 
195
195
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
196
196
 
@@ -54,7 +54,7 @@ describe 'Mappers / embedded' do
54
54
 
55
55
  jane = container.relation(:users).as(:users).first
56
56
 
57
- Test::Address.send(:include, Equalizer.new(:street, :city))
57
+ Test::Address.send(:include, Dry::Equalizer(:street, :city))
58
58
 
59
59
  expect(jane.name).to eql('Jane')
60
60
  expect(jane.address).to eql(Test::Address.new(street: 'Somewhere 1', city: 'NYC'))
@@ -44,7 +44,7 @@ describe 'Mapper definition DSL' do
44
44
 
45
45
  container
46
46
 
47
- Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
47
+ Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
48
48
 
49
49
  jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
50
50
 
@@ -74,7 +74,7 @@ describe 'Mapper definition DSL' do
74
74
 
75
75
  container
76
76
 
77
- Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
77
+ Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
78
78
 
79
79
  jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
80
80
 
@@ -106,8 +106,8 @@ describe 'Mapper definition DSL' do
106
106
 
107
107
  container
108
108
 
109
- Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
110
- Test::Task.send(:include, Equalizer.new(:title, :priority))
109
+ Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
110
+ Test::Task.send(:include, Dry::Equalizer(:title, :priority))
111
111
 
112
112
  jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
113
113
 
@@ -145,9 +145,9 @@ describe 'Mapper definition DSL' do
145
145
 
146
146
  container
147
147
 
148
- Test::TaskWithUsers.send(:include, Equalizer.new(:title, :priority, :users))
149
- Test::TaskUser.send(:include, Equalizer.new(:name, :contacts))
150
- Test::Contact.send(:include, Equalizer.new(:email))
148
+ Test::TaskWithUsers.send(:include, Dry::Equalizer(:title, :priority, :users))
149
+ Test::TaskUser.send(:include, Dry::Equalizer(:name, :contacts))
150
+ Test::Contact.send(:include, Dry::Equalizer(:email))
151
151
 
152
152
  task = container.relation(:tasks).with_users.map_with(:with_users).first
153
153
 
@@ -28,7 +28,7 @@ describe 'Mappers / Prefixing attributes' do
28
28
  user_email: 'jane@doe.org'
29
29
  }
30
30
 
31
- Test::User.send(:include, Equalizer.new(:id, :name, :email))
31
+ Test::User.send(:include, Dry::Equalizer(:id, :name, :email))
32
32
 
33
33
  jane = container.relation(:users).as(:users).first
34
34
 
@@ -30,7 +30,7 @@ describe 'Mappers / Renaming attributes' do
30
30
 
31
31
  container
32
32
 
33
- Test::User.send(:include, Equalizer.new(:id, :name))
33
+ Test::User.send(:include, Dry::Equalizer(:id, :name))
34
34
 
35
35
  container.relations.users << { _id: 123, user_name: 'Jane' }
36
36
 
@@ -63,7 +63,7 @@ describe 'Mappers / Renaming attributes' do
63
63
 
64
64
  container
65
65
 
66
- Test::UserWithAddress.send(:include, Equalizer.new(:id, :name, :address))
66
+ Test::UserWithAddress.send(:include, Dry::Equalizer(:id, :name, :address))
67
67
 
68
68
  container.relations.users << { _id: 123, user_name: 'Jane' }
69
69
 
@@ -102,7 +102,7 @@ describe 'Mappers / Renaming attributes' do
102
102
 
103
103
  container
104
104
 
105
- Test::UserWithAddresses.send(:include, Equalizer.new(:id, :name, :addresses))
105
+ Test::UserWithAddresses.send(:include, Dry::Equalizer(:id, :name, :addresses))
106
106
 
107
107
  container.relations.users << { _id: 123, user_name: 'Jane' }
108
108
 
@@ -40,7 +40,7 @@ describe 'Mapper definition DSL' do
40
40
 
41
41
  container
42
42
 
43
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
43
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
44
44
 
45
45
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
46
46
 
@@ -69,7 +69,7 @@ describe 'Mapper definition DSL' do
69
69
 
70
70
  container
71
71
 
72
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
72
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
73
73
 
74
74
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
75
75
 
@@ -104,9 +104,9 @@ describe 'Mapper definition DSL' do
104
104
 
105
105
  container
106
106
 
107
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
108
- Test::TaskUser.send(:include, Equalizer.new(:name, :contact))
109
- Test::Contact.send(:include, Equalizer.new(:email))
107
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
108
+ Test::TaskUser.send(:include, Dry::Equalizer(:name, :contact))
109
+ Test::Contact.send(:include, Dry::Equalizer(:email))
110
110
 
111
111
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
112
112
 
@@ -138,8 +138,8 @@ describe 'Mapper definition DSL' do
138
138
 
139
139
  container
140
140
 
141
- Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
142
- Test::User.send(:include, Equalizer.new(:email))
141
+ Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
142
+ Test::User.send(:include, Dry::Equalizer(:email))
143
143
 
144
144
  jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
145
145
 
@@ -63,8 +63,8 @@ describe 'Reading relations' do
63
63
 
64
64
  container
65
65
 
66
- Test::User.send(:include, Equalizer.new(:name, :email))
67
- Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
66
+ Test::User.send(:include, Dry::Equalizer(:name, :email))
67
+ Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
68
68
 
69
69
  user = container.relation(:users).sorted.as(:users).first
70
70
 
@@ -100,8 +100,8 @@ describe 'Reading relations' do
100
100
 
101
101
  container
102
102
 
103
- Test::User.send(:include, Equalizer.new(:name, :email))
104
- Test::UserWithTask.send(:include, Equalizer.new(:name, :email, :task))
103
+ Test::User.send(:include, Dry::Equalizer(:name, :email))
104
+ Test::UserWithTask.send(:include, Dry::Equalizer(:name, :email, :task))
105
105
 
106
106
  user = container.relation(:users).sorted.with_task.as(:with_task).first
107
107
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'virtus'
2
+ require 'dry-struct'
3
3
 
4
4
  describe 'Configuring ROM' do
5
5
  context 'with existing schema' do
@@ -79,9 +79,8 @@ describe 'Configuring ROM' do
79
79
  # NOTE: move to DSL tests
80
80
  it 'exposes boot DSL inside the setup block via `macros` plugin' do
81
81
  module Test
82
- User = Class.new do
83
- include Virtus.value_object
84
- values { attribute :name, String }
82
+ User = Class.new(Dry::Struct) do
83
+ attribute :name, Types::String
85
84
  end
86
85
  end
87
86
 
@@ -113,9 +112,8 @@ describe 'Configuring ROM' do
113
112
  describe 'multi-step setup' do
114
113
  it 'exposes boot DSL that can be invoked multiple times' do
115
114
  module Test
116
- User = Class.new do
117
- include Virtus.value_object
118
- values { attribute :name, String }
115
+ User = Class.new(Dry::Struct) do
116
+ attribute :name, Types::String
119
117
  end
120
118
  end
121
119
 
data/spec/spec_helper.rb CHANGED
@@ -4,9 +4,11 @@
4
4
  require "bundler"
5
5
  Bundler.setup
6
6
 
7
- if RUBY_ENGINE == "rbx"
8
- require "codeclimate-test-reporter"
9
- CodeClimate::TestReporter.start
7
+ if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION='2.3.1'
8
+ require "simplecov"
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
10
12
  end
11
13
 
12
14
  SPEC_ROOT = root = Pathname(__FILE__).dirname
@@ -15,7 +17,6 @@ require 'rom/support/deprecations'
15
17
  ROM::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
16
18
 
17
19
  require 'rom'
18
- require 'anima'
19
20
 
20
21
  begin
21
22
  require 'byebug'
@@ -0,0 +1,5 @@
1
+ require 'dry-types'
2
+
3
+ module Types
4
+ include Dry::Types.module
5
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'dry-struct'
2
3
 
3
4
  describe ROM::Commands::Graph do
4
5
  shared_examples_for 'a persisted graph' do
@@ -134,9 +135,19 @@ describe ROM::Commands::Graph do
134
135
  end
135
136
 
136
137
  before do
137
- Test::Tag = Class.new { include Anima.new(:name) }
138
- Test::Task = Class.new { include Anima.new(:title, :tags) }
139
- Test::User = Class.new { include Anima.new(:name, :task) }
138
+ Test::Tag = Class.new(Dry::Struct) {
139
+ attribute :name, Types::String
140
+ }
141
+
142
+ Test::Task = Class.new(Dry::Struct) {
143
+ attribute :title, Types::String
144
+ attribute :tags, Types::Array.member(Test::Tag)
145
+ }
146
+
147
+ Test::User = Class.new(Dry::Struct) {
148
+ attribute :name, Types::String
149
+ attribute :task, Test::Task
150
+ }
140
151
 
141
152
  class Test::UserMapper < ROM::Mapper
142
153
  relation :users
@@ -0,0 +1,66 @@
1
+ require 'rom/relation'
2
+ require 'rom/command'
3
+ require 'rom/plugins/command/schema'
4
+
5
+ RSpec.describe ROM::Plugins::Command::Schema do
6
+ describe '.build' do
7
+ let(:command_class) do
8
+ Class.new(ROM::Command) { use :schema }
9
+ end
10
+
11
+ context 'when relation has no schema defined' do
12
+ let(:relation) do
13
+ instance_double(ROM::Relation, schema?: false)
14
+ end
15
+
16
+ it 'sets default input handler when command does not have a custom one' do
17
+ command = Class.new(command_class).build(relation)
18
+
19
+ expect(command.input).to be(ROM::Command.input)
20
+ end
21
+
22
+ it 'sets custom input handler when command defines it' do
23
+ my_handler = double(:my_handler)
24
+
25
+ command = Class.new(command_class) { input my_handler }.build(relation)
26
+
27
+ expect(command.input).to be(my_handler)
28
+ end
29
+
30
+ it 'sets custom input handler when it is passed as an option' do
31
+ my_handler = double(:my_handler)
32
+
33
+ command = Class.new(command_class).build(relation, input: my_handler)
34
+
35
+ expect(command.input).to be(my_handler)
36
+ end
37
+ end
38
+
39
+ context 'when relation has a schema' do
40
+ let(:relation) do
41
+ instance_double(ROM::Relation, schema?: true, schema_hash: schema_hash)
42
+ end
43
+
44
+ let(:schema_hash) do
45
+ double(:schema_hash)
46
+ end
47
+
48
+ it 'sets schema hash as input handler' do
49
+ command = Class.new(command_class).build(relation)
50
+
51
+ expect(command.input).to be(schema_hash)
52
+ end
53
+
54
+ it 'sets a composed input handler with schema hash and a custom one' do
55
+ my_handler = double(:my_handler)
56
+
57
+ command = Class.new(command_class) { input my_handler }.build(relation)
58
+
59
+ expect(my_handler).to receive(:[]).with('some value').and_return('my handler')
60
+ expect(schema_hash).to receive(:[]).with('my handler').and_return('a tuple')
61
+
62
+ expect(command.input['some value']).to eql('a tuple')
63
+ end
64
+ end
65
+ end
66
+ end
@@ -48,4 +48,11 @@ RSpec.describe ROM::Relation::Name do
48
48
  expect(ROM::Relation::Name.new(:authors, :users).to_sym).to be(:authors)
49
49
  end
50
50
  end
51
+
52
+ describe '#to_s' do
53
+ it 'returns stringified relation name' do
54
+ expect(ROM::Relation::Name.new(:users).to_s).to eql('users')
55
+ expect(ROM::Relation::Name.new(:authors, :users).to_s).to eql('authors on users')
56
+ end
57
+ end
51
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -281,6 +281,7 @@ files:
281
281
  - spec/spec_helper.rb
282
282
  - spec/support/constant_leak_finder.rb
283
283
  - spec/support/mutant.rb
284
+ - spec/support/types.rb
284
285
  - spec/test/memory_repository_lint_test.rb
285
286
  - spec/unit/rom/association_set_spec.rb
286
287
  - spec/unit/rom/commands/graph_spec.rb
@@ -300,6 +301,7 @@ files:
300
301
  - spec/unit/rom/memory/repository_spec.rb
301
302
  - spec/unit/rom/memory/storage_spec.rb
302
303
  - spec/unit/rom/plugin_spec.rb
304
+ - spec/unit/rom/plugins/command/schema_spec.rb
303
305
  - spec/unit/rom/plugins/relation/key_inference_spec.rb
304
306
  - spec/unit/rom/plugins/relation/view_spec.rb
305
307
  - spec/unit/rom/relation/composite_spec.rb