rom 2.0.2 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +35 -430
  3. data/LICENSE +1 -1
  4. data/README.md +83 -11
  5. data/lib/rom/version.rb +1 -1
  6. data/lib/rom.rb +3 -46
  7. metadata +30 -236
  8. data/.gitignore +0 -24
  9. data/.rspec +0 -3
  10. data/.rubocop.yml +0 -87
  11. data/.rubocop_todo.yml +0 -46
  12. data/.travis.yml +0 -28
  13. data/CODE_OF_CONDUCT.md +0 -13
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile +0 -41
  16. data/Guardfile +0 -24
  17. data/Rakefile +0 -22
  18. data/lib/rom/association_set.rb +0 -26
  19. data/lib/rom/command.rb +0 -173
  20. data/lib/rom/command_registry.rb +0 -153
  21. data/lib/rom/commands/class_interface.rb +0 -148
  22. data/lib/rom/commands/composite.rb +0 -54
  23. data/lib/rom/commands/create.rb +0 -13
  24. data/lib/rom/commands/delete.rb +0 -14
  25. data/lib/rom/commands/graph/builder.rb +0 -176
  26. data/lib/rom/commands/graph/class_interface.rb +0 -62
  27. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  28. data/lib/rom/commands/graph.rb +0 -103
  29. data/lib/rom/commands/lazy/create.rb +0 -23
  30. data/lib/rom/commands/lazy/delete.rb +0 -27
  31. data/lib/rom/commands/lazy/update.rb +0 -34
  32. data/lib/rom/commands/lazy.rb +0 -99
  33. data/lib/rom/commands/result.rb +0 -96
  34. data/lib/rom/commands/update.rb +0 -14
  35. data/lib/rom/commands.rb +0 -3
  36. data/lib/rom/configuration.rb +0 -88
  37. data/lib/rom/configuration_dsl/command.rb +0 -43
  38. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  39. data/lib/rom/configuration_dsl/mapper.rb +0 -37
  40. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
  41. data/lib/rom/configuration_dsl/relation.rb +0 -26
  42. data/lib/rom/configuration_dsl.rb +0 -78
  43. data/lib/rom/configuration_plugin.rb +0 -17
  44. data/lib/rom/constants.rb +0 -30
  45. data/lib/rom/container.rb +0 -231
  46. data/lib/rom/create_container.rb +0 -61
  47. data/lib/rom/environment.rb +0 -70
  48. data/lib/rom/gateway.rb +0 -154
  49. data/lib/rom/global/plugin_dsl.rb +0 -49
  50. data/lib/rom/global.rb +0 -60
  51. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  52. data/lib/rom/lint/gateway.rb +0 -94
  53. data/lib/rom/lint/linter.rb +0 -78
  54. data/lib/rom/lint/spec.rb +0 -20
  55. data/lib/rom/lint/test.rb +0 -98
  56. data/lib/rom/mapper_registry.rb +0 -35
  57. data/lib/rom/memory/commands.rb +0 -58
  58. data/lib/rom/memory/dataset.rb +0 -98
  59. data/lib/rom/memory/gateway.rb +0 -64
  60. data/lib/rom/memory/relation.rb +0 -49
  61. data/lib/rom/memory/storage.rb +0 -59
  62. data/lib/rom/memory/types.rb +0 -9
  63. data/lib/rom/memory.rb +0 -4
  64. data/lib/rom/pipeline.rb +0 -106
  65. data/lib/rom/plugin.rb +0 -17
  66. data/lib/rom/plugin_base.rb +0 -31
  67. data/lib/rom/plugin_registry.rb +0 -173
  68. data/lib/rom/plugins/command/schema.rb +0 -37
  69. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
  70. data/lib/rom/plugins/relation/key_inference.rb +0 -46
  71. data/lib/rom/plugins/relation/registry_reader.rb +0 -32
  72. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  73. data/lib/rom/plugins/relation/view.rb +0 -95
  74. data/lib/rom/relation/class_interface.rb +0 -230
  75. data/lib/rom/relation/composite.rb +0 -46
  76. data/lib/rom/relation/curried.rb +0 -104
  77. data/lib/rom/relation/graph.rb +0 -115
  78. data/lib/rom/relation/loaded.rb +0 -118
  79. data/lib/rom/relation/materializable.rb +0 -66
  80. data/lib/rom/relation/name.rb +0 -102
  81. data/lib/rom/relation.rb +0 -172
  82. data/lib/rom/relation_registry.rb +0 -9
  83. data/lib/rom/schema/dsl.rb +0 -58
  84. data/lib/rom/schema.rb +0 -89
  85. data/lib/rom/setup/auto_registration.rb +0 -69
  86. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
  87. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
  88. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
  89. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  90. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  91. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  92. data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
  93. data/lib/rom/setup/finalize.rb +0 -146
  94. data/lib/rom/setup.rb +0 -55
  95. data/lib/rom/support/configurable.rb +0 -80
  96. data/lib/rom/types.rb +0 -18
  97. data/log/.gitkeep +0 -0
  98. data/rakelib/benchmark.rake +0 -15
  99. data/rakelib/mutant.rake +0 -19
  100. data/rakelib/rubocop.rake +0 -18
  101. data/rom.gemspec +0 -26
  102. data/spec/fixtures/app/commands/create_user.rb +0 -2
  103. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  104. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  105. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  106. data/spec/fixtures/app/my_relations/users.rb +0 -2
  107. data/spec/fixtures/app/relations/users.rb +0 -2
  108. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  109. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  110. data/spec/fixtures/custom/relations/users.rb +0 -6
  111. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  112. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  113. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  114. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  115. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  116. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  117. data/spec/integration/command_registry_spec.rb +0 -60
  118. data/spec/integration/commands/create_spec.rb +0 -177
  119. data/spec/integration/commands/delete_spec.rb +0 -67
  120. data/spec/integration/commands/error_handling_spec.rb +0 -25
  121. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  122. data/spec/integration/commands/graph_spec.rb +0 -288
  123. data/spec/integration/commands/update_spec.rb +0 -109
  124. data/spec/integration/commands_spec.rb +0 -67
  125. data/spec/integration/mappers/combine_spec.rb +0 -117
  126. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  127. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  128. data/spec/integration/mappers/embedded_spec.rb +0 -62
  129. data/spec/integration/mappers/exclude_spec.rb +0 -27
  130. data/spec/integration/mappers/fold_spec.rb +0 -71
  131. data/spec/integration/mappers/group_spec.rb +0 -163
  132. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  133. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  134. data/spec/integration/mappers/prefix_spec.rb +0 -48
  135. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  136. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  137. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  138. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  139. data/spec/integration/mappers/step_spec.rb +0 -119
  140. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  141. data/spec/integration/mappers/unfold_spec.rb +0 -92
  142. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  143. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  144. data/spec/integration/mappers/wrap_spec.rb +0 -155
  145. data/spec/integration/memory/commands/create_spec.rb +0 -23
  146. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  147. data/spec/integration/memory/commands/update_spec.rb +0 -23
  148. data/spec/integration/multi_env_spec.rb +0 -69
  149. data/spec/integration/multi_repo_spec.rb +0 -46
  150. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  151. data/spec/integration/relations/inheritance_spec.rb +0 -37
  152. data/spec/integration/relations/reading_spec.rb +0 -169
  153. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  154. data/spec/integration/repositories/extending_relations_spec.rb +0 -58
  155. data/spec/integration/repositories/setting_logger_spec.rb +0 -34
  156. data/spec/integration/setup_spec.rb +0 -160
  157. data/spec/shared/command_behavior.rb +0 -28
  158. data/spec/shared/command_graph.rb +0 -50
  159. data/spec/shared/container.rb +0 -9
  160. data/spec/shared/enumerable_dataset.rb +0 -52
  161. data/spec/shared/gateway_only.rb +0 -6
  162. data/spec/shared/materializable.rb +0 -36
  163. data/spec/shared/no_container.rb +0 -16
  164. data/spec/shared/one_behavior.rb +0 -26
  165. data/spec/shared/proxy.rb +0 -0
  166. data/spec/shared/users_and_tasks.rb +0 -10
  167. data/spec/spec_helper.rb +0 -52
  168. data/spec/support/constant_leak_finder.rb +0 -14
  169. data/spec/support/mutant.rb +0 -10
  170. data/spec/support/types.rb +0 -5
  171. data/spec/test/memory_repository_lint_test.rb +0 -27
  172. data/spec/unit/rom/association_set_spec.rb +0 -23
  173. data/spec/unit/rom/commands/graph_spec.rb +0 -191
  174. data/spec/unit/rom/commands/lazy_spec.rb +0 -307
  175. data/spec/unit/rom/commands/result_spec.rb +0 -70
  176. data/spec/unit/rom/commands_spec.rb +0 -165
  177. data/spec/unit/rom/configurable_spec.rb +0 -49
  178. data/spec/unit/rom/configuration_spec.rb +0 -61
  179. data/spec/unit/rom/container_spec.rb +0 -99
  180. data/spec/unit/rom/create_container_spec.rb +0 -151
  181. data/spec/unit/rom/environment_spec.rb +0 -123
  182. data/spec/unit/rom/gateway_spec.rb +0 -146
  183. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  184. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  185. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  186. data/spec/unit/rom/memory/relation_spec.rb +0 -109
  187. data/spec/unit/rom/memory/repository_spec.rb +0 -12
  188. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  189. data/spec/unit/rom/plugin_spec.rb +0 -150
  190. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  191. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  192. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
  193. data/spec/unit/rom/relation/composite_spec.rb +0 -89
  194. data/spec/unit/rom/relation/curried_spec.rb +0 -52
  195. data/spec/unit/rom/relation/graph_spec.rb +0 -92
  196. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  197. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  198. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  199. data/spec/unit/rom/relation/name_spec.rb +0 -58
  200. data/spec/unit/rom/relation/schema_spec.rb +0 -117
  201. data/spec/unit/rom/relation_spec.rb +0 -237
  202. data/spec/unit/rom/schema_spec.rb +0 -10
  203. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Relation registration DSL' do
4
- include_context 'container'
5
- include_context 'users and tasks'
6
-
7
- it 'allows to expose chainable relations' do
8
- configuration.relation(:tasks) do
9
- def high_priority
10
- restrict { |tuple| tuple[:priority] < 2 }
11
- end
12
-
13
- def by_title(title)
14
- restrict(title: title)
15
- end
16
- end
17
-
18
- configuration.relation(:users) do
19
- def with_tasks
20
- join(tasks)
21
- end
22
- end
23
-
24
- tasks = container.relations.tasks
25
-
26
- expect(tasks.class.name).to eql("ROM::Relation[Tasks]")
27
- expect(tasks.high_priority.inspect).to include("#<ROM::Relation[Tasks]")
28
-
29
- expect(tasks.high_priority.by_title("be nice")).to match_array(
30
- [name: "Joe", title: "be nice", priority: 1]
31
- )
32
-
33
- expect(tasks.by_title("be cool")).to match_array(
34
- [name: "Jane", title: "be cool", priority: 2]
35
- )
36
-
37
- users = container.relations.users
38
-
39
- expect(users.with_tasks).to match_array(
40
- [{ name: "Joe", email: "joe@doe.org", title: "be nice", priority: 1 },
41
- { name: "Joe", email: "joe@doe.org", title: "sleep well", priority: 2 },
42
- { name: "Jane", email: "jane@doe.org", title: "be cool", priority: 2 }]
43
- )
44
- end
45
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- describe 'Repository' do
5
- include_context 'container'
6
- include_context 'users and tasks'
7
-
8
- before do
9
- module ROM
10
- module Memory
11
- class Relation < ROM::Relation
12
- def self.freaking_awesome?
13
- true
14
- end
15
-
16
- def freaking_cool?
17
- true
18
- end
19
- end
20
- end
21
- end
22
- end
23
-
24
- after do
25
- ROM::Memory::Relation.class_eval do
26
- undef_method :freaking_cool?
27
- class << self
28
- undef_method :freaking_awesome?
29
- end
30
- end
31
- end
32
-
33
- shared_examples_for 'extended relation' do
34
- it 'can extend relation class' do
35
- expect(container.relations.users.class).to be_freaking_awesome
36
- end
37
-
38
- it 'can extend relation instance' do
39
- expect(container.relations.users).to be_freaking_cool
40
- end
41
- end
42
-
43
- context 'using DSL' do
44
- it_behaves_like 'extended relation' do
45
- before do
46
- configuration.relation(:users)
47
- end
48
- end
49
- end
50
-
51
- context 'using class definition' do
52
- it_behaves_like 'extended relation' do
53
- before do
54
- configuration.register_relation(Class.new(ROM::Relation[:memory]) { dataset :users })
55
- end
56
- end
57
- end
58
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- require 'logger'
5
-
6
- describe 'Repositories / Setting logger' do
7
- let(:logger_class) do
8
- Class.new do
9
- attr_reader :messages
10
-
11
- def initialize
12
- @messages = []
13
- end
14
-
15
- def info(msg)
16
- @messages << msg
17
- end
18
- end
19
- end
20
-
21
- let(:logger) do
22
- logger_class.new
23
- end
24
-
25
- it 'sets up a logger for a given gateway' do
26
- container = ROM.container(:memory) do |config|
27
- config.gateways[:default].use_logger(logger)
28
- end
29
-
30
- container.gateways[:default].logger.info("test")
31
-
32
- expect(logger.messages).to eql(["test"])
33
- end
34
- end
@@ -1,160 +0,0 @@
1
- require 'spec_helper'
2
- require 'dry-struct'
3
-
4
- describe 'Configuring ROM' do
5
- context 'with existing schema' do
6
- include_context 'container'
7
- include_context 'users and tasks'
8
-
9
- let(:jane) { { name: 'Jane', email: 'jane@doe.org' } }
10
- let(:joe) { { name: 'Joe', email: 'joe@doe.org' } }
11
-
12
- before do
13
- configuration.relation(:users)
14
- configuration.relation(:tasks)
15
- end
16
-
17
- it 'configures schema relations' do
18
- expect(container.gateways[:default][:users]).to match_array([joe, jane])
19
- end
20
-
21
- it 'configures rom relations' do
22
- users = container.relations.users
23
-
24
- expect(users).to be_kind_of(ROM::Relation)
25
- expect(users).to respond_to(:tasks)
26
-
27
- tasks = users.tasks
28
-
29
- expect(tasks).to be_kind_of(ROM::Relation)
30
- expect(tasks).to respond_to(:users)
31
- expect(tasks.users).to be(users)
32
- end
33
- end
34
-
35
- context 'without schema' do
36
- it 'builds empty registries if there is no schema' do
37
- container = ROM.container(:memory)
38
- expect(container.relations).to eql(ROM::RelationRegistry.new)
39
- expect(container.mappers).to eql(ROM::Registry.new)
40
- end
41
- end
42
-
43
- describe 'defining classes' do
44
- it 'sets up registries based on class definitions' do
45
- container = ROM.container(:memory) do |config|
46
-
47
- class Test::UserRelation < ROM::Relation[:memory]
48
- dataset :users
49
-
50
- def by_name(name)
51
- restrict(name: name)
52
- end
53
- end
54
-
55
- class Test::TaskRelation < ROM::Relation[:memory]
56
- dataset :tasks
57
- end
58
-
59
- class Test::CreateUser < ROM::Commands::Update[:memory]
60
- relation :users
61
- register_as :create
62
- end
63
-
64
- config.register_relation(Test::UserRelation, Test::TaskRelation)
65
- config.register_command(Test::CreateUser)
66
- end
67
-
68
- expect(container.relations.users).to be_kind_of(Test::UserRelation)
69
- expect(container.relations.users.tasks).to be(container.relations.tasks)
70
-
71
- expect(container.commands.users[:create]).to be_kind_of(Test::CreateUser)
72
-
73
- expect(container.relations.tasks).to be_kind_of(Test::TaskRelation)
74
- expect(container.relations.tasks.users).to be(container.relations.users)
75
- end
76
- end
77
-
78
- describe 'quick setup' do
79
- # NOTE: move to DSL tests
80
- it 'exposes boot DSL inside the setup block via `macros` plugin' do
81
- module Test
82
- User = Class.new(Dry::Struct) do
83
- attribute :name, Types::String
84
- end
85
- end
86
-
87
- container = ROM.container(:memory) do |rom|
88
- rom.relation(:users) do
89
- def by_name(name)
90
- restrict(name: name)
91
- end
92
- end
93
-
94
- rom.commands(:users) do
95
- define(:create)
96
- end
97
-
98
- rom.mappers do
99
- define(:users) do
100
- model Test::User
101
- end
102
- end
103
- end
104
-
105
- container.commands.users.create.call(name: 'Jane')
106
-
107
- expect(container.relation(:users).by_name('Jane').as(:users).to_a)
108
- .to eql([Test::User.new(name: 'Jane')])
109
- end
110
- end
111
-
112
- describe 'multi-step setup' do
113
- it 'exposes boot DSL that can be invoked multiple times' do
114
- module Test
115
- User = Class.new(Dry::Struct) do
116
- attribute :name, Types::String
117
- end
118
- end
119
-
120
- configuration = ROM::Configuration.new(:memory)
121
-
122
- configuration.relation(:users) do
123
- def by_name(name)
124
- restrict(name: name)
125
- end
126
- end
127
-
128
- configuration.commands(:users) do
129
- define(:create)
130
- end
131
-
132
- configuration.mappers do
133
- define(:users) do
134
- model Test::User
135
- end
136
- end
137
-
138
- container = ROM.container(configuration)
139
-
140
- container.command(:users).create.call(name: 'Jane')
141
-
142
- expect(container.relation(:users).by_name('Jane').as(:users).to_a)
143
- .to eql([Test::User.new(name: 'Jane')])
144
- end
145
- end
146
-
147
- it 'allows to use a relation with a schema in multiple containers' do
148
- class Test::UserRelation < ROM::Relation[:memory]
149
- dataset :users
150
-
151
- schema do
152
- attribute :id, Types::Int.meta(primary_key: true)
153
- end
154
- end
155
-
156
- 2.times do
157
- ROM.container(:memory) { |c| c.register_relation(Test::UserRelation) }
158
- end
159
- end
160
- end
@@ -1,28 +0,0 @@
1
- shared_examples_for 'a command' do
2
- describe '#name' do
3
- it 'returns relation name' do
4
- expect(command.name).to eql(command.relation.name)
5
- end
6
- end
7
-
8
- describe '#gateway' do
9
- it 'returns relation gateway' do
10
- expect(command.gateway).to eql(command.relation.gateway)
11
- end
12
- end
13
-
14
- describe '#method_missing' do
15
- it 'forwards to relation and wraps response if it returned another relation' do
16
- if command.class.restrictable
17
- new_command = command.by_id(1)
18
-
19
- expect(new_command).to be_instance_of(command.class)
20
- expect(new_command.relation).to eql(command.by_id(1).relation)
21
- end
22
- end
23
-
24
- it 'raises error when message is not known' do
25
- expect { command.not_here }.to raise_error(NoMethodError, /not_here/)
26
- end
27
- end
28
- end
@@ -1,50 +0,0 @@
1
- shared_context 'command graph' do
2
- include_context 'container'
3
-
4
- before do
5
- configuration.relation :users do
6
- def by_name(name)
7
- restrict(name: name)
8
- end
9
- end
10
-
11
- configuration.relation :tasks do
12
- def by_user_and_title(user, title)
13
- by_user(user).by_title(title)
14
- end
15
-
16
- def by_user(user)
17
- restrict(user: user)
18
- end
19
-
20
- def by_title(title)
21
- restrict(title: title)
22
- end
23
- end
24
-
25
- configuration.relation :books
26
- configuration.relation :tags
27
-
28
- configuration.commands(:users) do
29
- define(:create) do
30
- result :one
31
- end
32
- end
33
-
34
- configuration.commands(:books) do
35
- define(:create) do
36
- def execute(tuples, user)
37
- super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
38
- end
39
- end
40
- end
41
-
42
- configuration.commands(:tags) do
43
- define(:create) do
44
- def execute(tuples, task)
45
- super(tuples.map { |t| t.merge(task: task.fetch(:title)) })
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,9 +0,0 @@
1
- RSpec.shared_context 'container' do
2
- let(:container) { ROM.container(configuration) }
3
- let!(:configuration) { ROM::Configuration.new(:memory) }
4
- let(:gateway) { configuration.gateways[:default] }
5
- let(:users_relation) { container.relation(:users) }
6
- let(:tasks_relation) { container.relation(:tasks) }
7
- let(:users_dataset) { gateway.dataset(:users) }
8
- let(:tasks_dataset) { gateway.dataset(:tasks) }
9
- end
@@ -1,52 +0,0 @@
1
- shared_examples_for "an enumerable dataset" do
2
- subject(:dataset) { klass.new(data) }
3
-
4
- let(:data) do
5
- [{ 'name' => 'Jane' }, { 'name' => 'Joe' }]
6
- end
7
-
8
- describe '#each' do
9
- it 'yields tuples through row_proc' do
10
- result = []
11
-
12
- dataset.each do |tuple|
13
- result << tuple
14
- end
15
-
16
- expect(result).to match_array([{ name: 'Jane' }, { name: 'Joe' }])
17
- end
18
- end
19
-
20
- describe '#to_a' do
21
- it 'casts dataset to an array' do
22
- expect(dataset.to_a).to eql([{ name: 'Jane' }, { name: 'Joe' }])
23
- end
24
- end
25
-
26
- describe '#find_all' do
27
- it 'yields tuples through row_proc' do
28
- result = dataset.find_all { |tuple| tuple[:name] == 'Jane' }
29
-
30
- expect(result).to be_instance_of(klass)
31
- expect(result).to match_array([{ name: 'Jane' }])
32
- end
33
- end
34
-
35
- describe '#kind_of?' do
36
- it 'does not forward to data object' do
37
- expect(dataset).to be_kind_of(klass)
38
- end
39
- end
40
-
41
- describe '#instance_of?' do
42
- it 'does not forward to data object' do
43
- expect(dataset).to be_instance_of(klass)
44
- end
45
- end
46
-
47
- describe '#is_a?' do
48
- it 'does not forward to data object' do
49
- expect(dataset.is_a?(klass)).to be(true)
50
- end
51
- end
52
- end
@@ -1,6 +0,0 @@
1
- RSpec.shared_context 'gateway only' do
2
- let(:gateway) { ROM::Memory::Gateway.new }
3
-
4
- let(:users_dataset) { gateway.dataset(:users) }
5
- let(:tasks_dataset) { gateway.dataset(:tasks) }
6
- end
@@ -1,36 +0,0 @@
1
- shared_examples_for 'materializable relation' do
2
- describe '#each' do
3
- it 'yields objects' do
4
- count = relation.to_a.size
5
- result = []
6
-
7
- relation.each do |object|
8
- result << object
9
- end
10
-
11
- expect(result.count).to eql(count)
12
- end
13
-
14
- it 'returns enumerator when block is not provided' do
15
- expect(relation.each.to_a).to eql(relation.to_a)
16
- end
17
- end
18
-
19
- describe '#one' do
20
- it 'returns one tuple' do
21
- expect(relation.one).to be_instance_of(Hash)
22
- end
23
- end
24
-
25
- describe '#first' do
26
- it 'returns first tuple' do
27
- expect(relation.first).to be_instance_of(Hash)
28
- end
29
- end
30
-
31
- describe '#call' do
32
- it 'materializes relation' do
33
- expect(relation.call).to be_instance_of(ROM::Relation::Loaded)
34
- end
35
- end
36
- end
@@ -1,16 +0,0 @@
1
- require 'rom/memory'
2
-
3
- RSpec.shared_context 'no container' do
4
- let(:gateway) { ROM::Memory::Gateway.new }
5
-
6
- let(:users_dataset) { gateway.dataset(:users) }
7
- let(:tasks_dataset) { gateway.dataset(:tasks) }
8
-
9
- let(:users_relation) do
10
- Class.new(ROM::Memory::Relation).new(users_dataset)
11
- end
12
-
13
- let(:tasks_relation) do
14
- Class.new(ROM::Memory::Relation).new(tasks_dataset)
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- shared_examples_for 'a relation that returns one tuple' do
2
- describe '#one' do
3
- it 'returns first tuple' do
4
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
5
- expect(relation.one).to eql(name: 'Jane', email: 'jane@doe.org')
6
- end
7
-
8
- it 'raises error when there is more than one tuple' do
9
- expect { relation.one }.to raise_error(ROM::TupleCountMismatchError)
10
- end
11
- end
12
-
13
- describe '#one!' do
14
- it 'returns first tuple' do
15
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
16
- expect(relation.one!).to eql(name: 'Jane', email: 'jane@doe.org')
17
- end
18
-
19
- it 'raises error when there is no tuples' do
20
- users_relation.delete(name: 'Jane', email: 'jane@doe.org')
21
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
22
-
23
- expect { relation.one! }.to raise_error(ROM::TupleCountMismatchError)
24
- end
25
- end
26
- end
data/spec/shared/proxy.rb DELETED
File without changes
@@ -1,10 +0,0 @@
1
- RSpec.shared_context 'users and tasks' do
2
- before do
3
- users_dataset.insert(name: "Joe", email: "joe@doe.org")
4
- users_dataset.insert(name: "Jane", email: "jane@doe.org")
5
-
6
- tasks_dataset.insert(name: "Joe", title: "be nice", priority: 1)
7
- tasks_dataset.insert(name: "Joe", title: "sleep well", priority: 2)
8
- tasks_dataset.insert(name: "Jane", title: "be cool", priority: 2)
9
- end
10
- end
data/spec/spec_helper.rb DELETED
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # this is needed for guard to work, not sure why :(
4
- require "bundler"
5
- Bundler.setup
6
-
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
12
- end
13
-
14
- SPEC_ROOT = root = Pathname(__FILE__).dirname
15
-
16
- require 'rom/support/deprecations'
17
- ROM::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
18
-
19
- require 'rom'
20
-
21
- begin
22
- require 'byebug'
23
- rescue LoadError
24
- end
25
-
26
- Dir[root.join('support/*.rb').to_s].each do |f|
27
- require f
28
- end
29
- Dir[root.join('shared/*.rb').to_s].each do |f|
30
- require f
31
- end
32
-
33
- # Namespace holding all objects created during specs
34
- module Test
35
- def self.remove_constants
36
- constants.each(&method(:remove_const))
37
- end
38
- end
39
-
40
- def T(*args)
41
- ROM::Processor::Transproc::Functions[*args]
42
- end
43
-
44
- RSpec.configure do |config|
45
- config.after do
46
- Test.remove_constants
47
- end
48
-
49
- config.around do |example|
50
- ConstantLeakFinder.find(example)
51
- end
52
- end
@@ -1,14 +0,0 @@
1
- # Finds leaking constants created during ROM specs
2
- module ConstantLeakFinder
3
- def self.find(example)
4
- constants = Object.constants
5
-
6
- example.run
7
-
8
- added_constants = (Object.constants - constants)
9
- added = added_constants.map(&Object.method(:const_get))
10
- if added.any? { |mod| mod.ancestors.map(&:name).grep(/\AROM/).any? }
11
- raise "Leaking constants: #{added_constants.inspect}"
12
- end
13
- end
14
- end
@@ -1,10 +0,0 @@
1
- module Mutant
2
- class Selector
3
- # Expression based test selector
4
- class Expression < self
5
- def call(_subject)
6
- integration.all_tests
7
- end
8
- end # Expression
9
- end # Selector
10
- end # Mutant
@@ -1,5 +0,0 @@
1
- require 'dry-types'
2
-
3
- module Types
4
- include Dry::Types.module
5
- end
@@ -1,27 +0,0 @@
1
- require 'rom'
2
- require 'rom/memory'
3
- require 'rom/lint/test'
4
-
5
- require 'minitest/autorun'
6
-
7
- class MemoryRepositoryLintTest < Minitest::Test
8
- include ROM::Lint::TestGateway
9
-
10
- def setup
11
- @gateway = ROM::Memory::Gateway
12
- @identifier = :memory
13
- end
14
-
15
- def gateway_instance
16
- ROM::Memory::Gateway.new
17
- end
18
- end
19
-
20
- class MemoryDatasetLintTest < Minitest::Test
21
- include ROM::Lint::TestEnumerableDataset
22
-
23
- def setup
24
- @data = [{ name: 'Jane', age: 24 }, { name: 'Joe', age: 25 }]
25
- @dataset = ROM::Memory::Dataset.new(@data)
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- RSpec.describe ROM::AssociationSet do
2
- describe '#try' do
3
- it 'returns association when it exists' do
4
- assoc = spy(:assoc)
5
- assoc_set = ROM::AssociationSet.new(users: assoc)
6
-
7
- assoc_set.try(:users, &:done)
8
-
9
- expect(assoc).to have_received(:done)
10
- end
11
-
12
- it 'returns false when assoc is not found' do
13
- assoc = spy(:assoc)
14
- fallback = spy(:fallback)
15
- assoc_set = ROM::AssociationSet.new({})
16
-
17
- assoc_set.try(:users, &:done) or fallback.done
18
-
19
- expect(assoc).to_not have_received(:done)
20
- expect(fallback).to have_received(:done)
21
- end
22
- end
23
- end