rom-http 0.7.0 → 0.9.0

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 (51) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +81 -28
  3. data/README.md +15 -181
  4. data/lib/rom/http/associations/many_to_many.rb +12 -0
  5. data/lib/rom/http/associations/many_to_one.rb +20 -0
  6. data/lib/rom/http/associations/one_to_many.rb +20 -0
  7. data/lib/rom/http/associations/one_to_one.rb +12 -0
  8. data/lib/rom/http/associations.rb +14 -0
  9. data/lib/rom/http/attribute.rb +10 -0
  10. data/lib/rom/http/commands/create.rb +2 -0
  11. data/lib/rom/http/commands/delete.rb +2 -0
  12. data/lib/rom/http/commands/update.rb +2 -0
  13. data/lib/rom/http/commands.rb +6 -4
  14. data/lib/rom/http/dataset.rb +212 -115
  15. data/lib/rom/http/error.rb +2 -0
  16. data/lib/rom/http/gateway.rb +47 -6
  17. data/lib/rom/http/handlers/json.rb +64 -0
  18. data/lib/rom/http/handlers.rb +16 -0
  19. data/lib/rom/http/mapper_compiler.rb +11 -0
  20. data/lib/rom/http/relation.rb +22 -66
  21. data/lib/rom/http/schema/dsl.rb +12 -0
  22. data/lib/rom/http/schema.rb +40 -0
  23. data/lib/rom/http/transformer.rb +2 -0
  24. data/lib/rom/http/types.rb +13 -0
  25. data/lib/rom/http/version.rb +3 -1
  26. data/lib/rom/http.rb +9 -6
  27. data/lib/rom-http.rb +3 -1
  28. metadata +41 -120
  29. data/.gitignore +0 -16
  30. data/.rspec +0 -3
  31. data/.rubocop.yml +0 -22
  32. data/.rubocop_todo.yml +0 -12
  33. data/.travis.yml +0 -20
  34. data/Gemfile +0 -24
  35. data/LICENSE.txt +0 -22
  36. data/Rakefile +0 -24
  37. data/examples/repository_with_combine.rb +0 -154
  38. data/lib/rom/http/dataset/class_interface.rb +0 -33
  39. data/rakelib/rubocop.rake +0 -18
  40. data/rom-http.gemspec +0 -32
  41. data/spec/integration/abstract/commands/create_spec.rb +0 -119
  42. data/spec/integration/abstract/commands/delete_spec.rb +0 -52
  43. data/spec/integration/abstract/commands/update_spec.rb +0 -119
  44. data/spec/integration/abstract/relation_spec.rb +0 -78
  45. data/spec/shared/setup.rb +0 -18
  46. data/spec/shared/users_and_tasks.rb +0 -30
  47. data/spec/spec_helper.rb +0 -19
  48. data/spec/support/mutant.rb +0 -10
  49. data/spec/unit/rom/http/dataset_spec.rb +0 -824
  50. data/spec/unit/rom/http/gateway_spec.rb +0 -69
  51. data/spec/unit/rom/http/relation_spec.rb +0 -268
@@ -1,154 +0,0 @@
1
- require 'inflecto'
2
- require 'json'
3
- require 'uri'
4
- require 'net/http'
5
- require 'rom-repository'
6
-
7
- class RequestHandler
8
- def call(dataset)
9
- uri = URI(dataset.uri)
10
- uri.path = dataset.absolute_path
11
- uri.query = URI.encode_www_form(dataset.params)
12
-
13
- http = Net::HTTP.new(uri.host, uri.port)
14
- request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
15
-
16
- request = request_klass.new(uri.request_uri)
17
- dataset.headers.each_with_object(request) do |(header, value), request|
18
- request[header.to_s] = value
19
- end
20
-
21
- response = http.request(request)
22
- end
23
- end
24
-
25
- class ResponseHandler
26
- def call(response, dataset)
27
- if %i(post put patch).include?(dataset.request_method)
28
- JSON.parse(response.body, symbolize_names: true)
29
- else
30
- Array([JSON.parse(response.body, symbolize_names: true)]).flatten
31
- end
32
- end
33
- end
34
-
35
- class Users < ROM::Relation[:http]
36
- schema(:users) do
37
- attribute :id, ROM::Types::Int.meta(primary_key: true)
38
- attribute :name, ROM::Types::String
39
- attribute :username, ROM::Types::String
40
- attribute :email, ROM::Types::String
41
- attribute :phone, ROM::Types::String
42
- attribute :website, ROM::Types::String
43
- end
44
-
45
- def by_id(id)
46
- with_path(id.to_s)
47
- end
48
- end
49
-
50
- class Posts < ROM::Relation[:http]
51
- schema(:posts) do
52
- attribute :id, ROM::Types::Int.meta(primary_key: true)
53
- attribute :userId, ROM::Types::Int.meta(alias: :user_id)
54
- attribute :title, ROM::Types::String
55
- attribute :body, ROM::Types::String
56
- end
57
-
58
- def by_id(id)
59
- with_path(id.to_s)
60
- end
61
-
62
- def for_user(user)
63
- with_options(
64
- base_path: 'users',
65
- path: "#{user.first[:id]}/posts"
66
- )
67
- end
68
- end
69
-
70
- class UserRepository < ROM::Repository[:users]
71
- relations :posts
72
-
73
- def find(id)
74
- users.by_id(id).first
75
- end
76
-
77
- def find_with_posts(user_id)
78
- users.by_id(user_id).combine_children(many: posts.for_user).first
79
- end
80
- end
81
-
82
- configuration = ROM::Configuration.new(:http, {
83
- uri: 'http://jsonplaceholder.typicode.com',
84
- headers: {
85
- Accept: 'application/json'
86
- },
87
- request_handler: RequestHandler.new,
88
- response_handler: ResponseHandler.new
89
- })
90
- configuration.register_relation(Users)
91
- configuration.register_relation(Posts)
92
- container = ROM.container(configuration)
93
-
94
- UserRepository.new(container).find_with_posts(1)
95
- # =>
96
- # #<ROM::Struct[User]
97
- # id=1
98
- # name="Leanne Graham"
99
- # username="Bret"
100
- # email="Sincere@april.biz"
101
- # phone="1-770-736-8031 x56442"
102
- # website="hildegard.org"
103
- # posts=[
104
- # #<ROM::Struct[Post]
105
- # id=1
106
- # user_id=1
107
- # title="sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
108
- # body="quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto">,
109
- # #<ROM::Struct[Post]
110
- # id=2
111
- # user_id=1
112
- # title="qui est esse"
113
- # body="est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla">,
114
- # #<ROM::Struct[Post]
115
- # id=3
116
- # user_id=1
117
- # title="ea molestias quasi exercitationem repellat qui ipsa sit aut"
118
- # body="et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut">,
119
- # #<ROM::Struct[Post]
120
- # id=4
121
- # user_id=1
122
- # title="eum et est occaecati"
123
- # body="ullam et saepe reiciendis voluptatem adipisci\nsit amet autem assumenda provident rerum culpa\nquis hic commodi nesciunt rem tenetur doloremque ipsam iure\nquis sunt voluptatem rerum illo velit">,
124
- # #<ROM::Struct[Post]
125
- # id=5
126
- # user_id=1
127
- # title="nesciunt quas odio"
128
- # body="repudiandae veniam quaerat sunt sed\nalias aut fugiat sit autem sed est\nvoluptatem omnis possimus esse voluptatibus quis\nest aut tenetur dolor neque">,
129
- # #<ROM::Struct[Post]
130
- # id=6
131
- # user_id=1
132
- # title="dolorem eum magni eos aperiam quia"
133
- # body="ut aspernatur corporis harum nihil quis provident sequi\nmollitia nobis aliquid molestiae\nperspiciatis et ea nemo ab reprehenderit accusantium quas\nvoluptate dolores velit et doloremque molestiae">,
134
- # #<ROM::Struct[Post]
135
- # id=7
136
- # user_id=1
137
- # title="magnam facilis autem"
138
- # body="dolore placeat quibusdam ea quo vitae\nmagni quis enim qui quis quo nemo aut saepe\nquidem repellat excepturi ut quia\nsunt ut sequi eos ea sed quas">,
139
- # #<ROM::Struct[Post]
140
- # id=8
141
- # user_id=1
142
- # title="dolorem dolore est ipsam"
143
- # body="dignissimos aperiam dolorem qui eum\nfacilis quibusdam animi sint suscipit qui sint possimus cum\nquaerat magni maiores excepturi\nipsam ut commodi dolor voluptatum modi aut vitae">,
144
- # #<ROM::Struct[Post]
145
- # id=9
146
- # user_id=1
147
- # title="nesciunt iure omnis dolorem tempora et accusantium"
148
- # body="consectetur animi nesciunt iure dolore\nenim quia ad\nveniam autem ut quam aut nobis\net est aut quod aut provident voluptas autem voluptas">,
149
- # #<ROM::Struct[Post]
150
- # id=10
151
- # user_id=1
152
- # title="optio molestias id quia eum"
153
- # body="quo et expedita modi cum officia vel magni\ndoloribus qui repudiandae\nvero nisi sit\nquos veniam quod sed accusamus veritatis error">
154
- # ]>
@@ -1,33 +0,0 @@
1
- module ROM
2
- module HTTP
3
- # HTTP Dataset
4
- #
5
- # Represents a specific HTTP collection resource
6
- #
7
- # @api public
8
- class Dataset
9
- # @api private
10
- module ClassInterface
11
- # TODO: Remove in favour of configuration
12
- def default_request_handler(handler = Undefined)
13
- ::Dry::Core::Deprecations.announce(
14
- __method__,
15
- 'use configuration instead'
16
- )
17
- return config.default_request_handler if Undefined === handler
18
- config.default_request_handler = handler
19
- end
20
-
21
- # TODO: Remove in favour of configuration
22
- def default_response_handler(handler = Undefined)
23
- ::Dry::Core::Deprecations.announce(
24
- __method__,
25
- 'use configuration instead'
26
- )
27
- return config.default_response_handler if Undefined === handler
28
- config.default_response_handler = handler
29
- end
30
- end
31
- end
32
- end
33
- end
data/rakelib/rubocop.rake DELETED
@@ -1,18 +0,0 @@
1
- begin
2
- require 'rubocop/rake_task'
3
-
4
- Rake::Task[:default].enhance [:rubocop]
5
-
6
- RuboCop::RakeTask.new do |task|
7
- task.options << '--display-cop-names'
8
- end
9
-
10
- namespace :rubocop do
11
- desc 'Generate a configuration file acting as a TODO list.'
12
- task :auto_gen_config do
13
- exec 'bundle exec rubocop --auto-gen-config'
14
- end
15
- end
16
-
17
- rescue LoadError
18
- end
data/rom-http.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rom/http/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'rom-http'
8
- spec.version = ROM::HTTP::VERSION.dup
9
- spec.authors = ['Piotr Solnica', 'Andy Holland', 'Chris Flipse']
10
- spec.email = ['piotr.solnica@gmail.com', 'andyholland1991@aol.com', 'cflipse@gmail.com']
11
- spec.summary = 'HTTP support for ROM'
12
- spec.description = spec.summary
13
- spec.homepage = 'http://rom-rb.org'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_runtime_dependency 'concurrent-ruby'
22
- spec.add_runtime_dependency 'addressable'
23
- spec.add_runtime_dependency 'rom', '~> 4.0'
24
- spec.add_runtime_dependency 'dry-core', '~> 0.2', '>= 0.2.3'
25
- spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
26
- spec.add_runtime_dependency 'dry-configurable', '~> 0.6'
27
-
28
- spec.add_development_dependency 'bundler'
29
- spec.add_development_dependency 'rspec', '~> 3.1'
30
- spec.add_development_dependency 'rspec-its'
31
- spec.add_development_dependency 'rake', '~> 10.0'
32
- end
@@ -1,119 +0,0 @@
1
- RSpec.describe ROM::HTTP::Commands::Create do
2
- include_context 'setup'
3
- let(:relation) do
4
- Class.new(ROM::HTTP::Relation) do
5
- schema(:users) do
6
- attribute :id, ROM::Types::Int
7
- attribute :first_name, ROM::Types::String
8
- attribute :last_name, ROM::Types::String
9
- end
10
-
11
- def by_id(id)
12
- with_params(id: id)
13
- end
14
- end
15
- end
16
-
17
- context 'with single tuple' do
18
- let(:response) { double }
19
- let(:attributes) { { first_name: 'John', last_name: 'Jackson' } }
20
- let(:tuple) { attributes.merge(id: 1) }
21
- let(:command) do
22
- Class.new(ROM::HTTP::Commands::Create) do
23
- register_as :create
24
- relation :users
25
- result :one
26
- end
27
- end
28
- let(:dataset) do
29
- ROM::HTTP::Dataset.new(
30
- {
31
- uri: uri,
32
- headers: headers,
33
- request_handler: request_handler,
34
- response_handler: response_handler,
35
- name: :users
36
- },
37
- request_method: :post,
38
- params: attributes
39
- )
40
- end
41
-
42
- before do
43
- configuration.register_relation(relation)
44
- configuration.register_command(command)
45
-
46
- allow(request_handler).to receive(:call).and_return(response)
47
- allow(response_handler).to receive(:call).and_return(tuple)
48
- end
49
-
50
- subject! { container.commands[:users].create.call(attributes) }
51
-
52
- it do
53
- expect(request_handler).to have_received(:call).with(dataset)
54
- expect(response_handler).to have_received(:call).with(response, dataset)
55
- is_expected.to eq(tuple)
56
- end
57
- end
58
-
59
- context 'with a collection' do
60
- let(:response_1) { double }
61
- let(:response_2) { double }
62
- let(:attributes_1) { { first_name: 'John', last_name: 'Jackson' } }
63
- let(:attributes_2) { { first_name: 'Jill', last_name: 'Smith' } }
64
- let(:tuple_1) { attributes_1.merge(id: 1) }
65
- let(:tuple_2) { attributes_2.merge(id: 2) }
66
- let(:attributes) { [attributes_1, attributes_2] }
67
- let(:command) do
68
- Class.new(ROM::HTTP::Commands::Create) do
69
- register_as :create
70
- relation :users
71
- result :many
72
- end
73
- end
74
- let(:dataset_1) do
75
- ROM::HTTP::Dataset.new(
76
- {
77
- uri: uri,
78
- headers: headers,
79
- request_handler: request_handler,
80
- response_handler: response_handler,
81
- name: :users
82
- },
83
- request_method: :post,
84
- params: attributes_1
85
- )
86
- end
87
- let(:dataset_2) do
88
- ROM::HTTP::Dataset.new(
89
- {
90
- uri: uri,
91
- headers: headers,
92
- request_handler: request_handler,
93
- response_handler: response_handler,
94
- name: :users
95
- },
96
- request_method: :post,
97
- params: attributes_2
98
- )
99
- end
100
-
101
- before do
102
- configuration.register_relation(relation)
103
- configuration.register_command(command)
104
-
105
- allow(request_handler).to receive(:call).and_return(response_1, response_2)
106
- allow(response_handler).to receive(:call).and_return(tuple_1, tuple_2)
107
- end
108
-
109
- subject! { container.commands[:users].create.call(attributes) }
110
-
111
- it do
112
- expect(request_handler).to have_received(:call).with(dataset_1)
113
- expect(response_handler).to have_received(:call).with(response_1, dataset_1)
114
- expect(request_handler).to have_received(:call).with(dataset_2)
115
- expect(response_handler).to have_received(:call).with(response_2, dataset_2)
116
- is_expected.to eq([tuple_1, tuple_2])
117
- end
118
- end
119
- end
@@ -1,52 +0,0 @@
1
- RSpec.describe ROM::HTTP::Commands::Delete do
2
- include_context 'setup'
3
- let(:relation) do
4
- Class.new(ROM::HTTP::Relation) do
5
- schema(:users) do
6
- attribute :id, ROM::Types::Int
7
- end
8
-
9
- def by_id(id)
10
- with_params(id: id)
11
- end
12
- end
13
- end
14
- let(:response) { double }
15
- let(:tuple) { double }
16
- let(:tuples) { double(first: tuple) }
17
- let(:command) do
18
- Class.new(ROM::HTTP::Commands::Delete) do
19
- register_as :delete
20
- relation :users
21
- result :one
22
- end
23
- end
24
- let(:dataset) do
25
- ROM::HTTP::Dataset.new(
26
- {
27
- uri: uri,
28
- headers: headers,
29
- request_handler: request_handler,
30
- response_handler: response_handler,
31
- name: :users
32
- },
33
- request_method: :delete
34
- )
35
- end
36
-
37
- before do
38
- configuration.register_relation(relation)
39
- configuration.register_command(command)
40
-
41
- allow(request_handler).to receive(:call).and_return(response)
42
- allow(response_handler).to receive(:call).and_return(tuples)
43
- end
44
-
45
- subject! { container.commands[:users].delete.call }
46
-
47
- it do
48
- expect(request_handler).to have_received(:call).with(dataset)
49
- expect(response_handler).to have_received(:call).with(response, dataset)
50
- is_expected.to eq(tuple)
51
- end
52
- end
@@ -1,119 +0,0 @@
1
- RSpec.describe ROM::HTTP::Commands::Update do
2
- include_context 'setup'
3
- let(:relation) do
4
- Class.new(ROM::HTTP::Relation) do
5
- schema(:users) do
6
- attribute :id, ROM::Types::Int
7
- attribute :first_name, ROM::Types::String
8
- attribute :last_name, ROM::Types::String
9
- end
10
-
11
- def by_id(id)
12
- with_params(id: id)
13
- end
14
- end
15
- end
16
-
17
- context 'with single tuple' do
18
- let(:response) { double }
19
- let(:attributes) { { first_name: 'John', last_name: 'Jackson' } }
20
- let(:tuple) { attributes.merge(id: 1) }
21
- let(:command) do
22
- Class.new(ROM::HTTP::Commands::Update) do
23
- register_as :update
24
- relation :users
25
- result :one
26
- end
27
- end
28
- let(:dataset) do
29
- ROM::HTTP::Dataset.new(
30
- {
31
- uri: uri,
32
- headers: headers,
33
- request_handler: request_handler,
34
- response_handler: response_handler,
35
- name: :users
36
- },
37
- request_method: :put,
38
- params: attributes
39
- )
40
- end
41
-
42
- before do
43
- configuration.register_relation(relation)
44
- configuration.register_command(command)
45
-
46
- allow(request_handler).to receive(:call).and_return(response)
47
- allow(response_handler).to receive(:call).and_return(tuple)
48
- end
49
-
50
- subject! { container.commands[:users].update.call(attributes) }
51
-
52
- it do
53
- expect(request_handler).to have_received(:call).with(dataset)
54
- expect(response_handler).to have_received(:call).with(response, dataset)
55
- is_expected.to eq(tuple)
56
- end
57
- end
58
-
59
- context 'with a collection' do
60
- let(:response_1) { double }
61
- let(:response_2) { double }
62
- let(:attributes_1) { { first_name: 'John', last_name: 'Jackson' } }
63
- let(:attributes_2) { { first_name: 'Jill', last_name: 'Smith' } }
64
- let(:tuple_1) { attributes_1.merge(id: 1) }
65
- let(:tuple_2) { attributes_2.merge(id: 2) }
66
- let(:attributes) { [attributes_1, attributes_2] }
67
- let(:command) do
68
- Class.new(ROM::HTTP::Commands::Update) do
69
- register_as :update
70
- relation :users
71
- result :many
72
- end
73
- end
74
- let(:dataset_1) do
75
- ROM::HTTP::Dataset.new(
76
- {
77
- uri: uri,
78
- headers: headers,
79
- request_handler: request_handler,
80
- response_handler: response_handler,
81
- name: :users
82
- },
83
- request_method: :put,
84
- params: attributes_1
85
- )
86
- end
87
- let(:dataset_2) do
88
- ROM::HTTP::Dataset.new(
89
- {
90
- uri: uri,
91
- headers: headers,
92
- request_handler: request_handler,
93
- response_handler: response_handler,
94
- name: :users
95
- },
96
- request_method: :put,
97
- params: attributes_2
98
- )
99
- end
100
-
101
- before do
102
- configuration.register_relation(relation)
103
- configuration.register_command(command)
104
-
105
- allow(request_handler).to receive(:call).and_return(response_1, response_2)
106
- allow(response_handler).to receive(:call).and_return(tuple_1, tuple_2)
107
- end
108
-
109
- subject! { container.commands[:users].update.call(attributes) }
110
-
111
- it do
112
- expect(request_handler).to have_received(:call).with(dataset_1)
113
- expect(response_handler).to have_received(:call).with(response_1, dataset_1)
114
- expect(request_handler).to have_received(:call).with(dataset_2)
115
- expect(response_handler).to have_received(:call).with(response_2, dataset_2)
116
- is_expected.to eq([tuple_1, tuple_2])
117
- end
118
- end
119
- end
@@ -1,78 +0,0 @@
1
- require 'json'
2
- require 'rom-repository'
3
-
4
- RSpec.describe ROM::HTTP::Relation do
5
- subject(:users) { container.relations[:users].by_id(id).filter(params) }
6
-
7
- include_context 'setup'
8
-
9
- let(:relation) do
10
- Class.new(ROM::HTTP::Relation) do
11
- schema(:users) do
12
- attribute :id, ROM::Types::Int
13
- attribute :name, ROM::Types::String
14
- end
15
-
16
- def by_id(id)
17
- append_path(id.to_s)
18
- end
19
-
20
- def filter(params)
21
- with_params(params)
22
- end
23
- end
24
- end
25
-
26
- let(:response) { tuples.to_json }
27
- let(:tuples) { [{ id: 1337, name: 'John' }] }
28
- let(:id) { 1337 }
29
- let(:params) { { filters: { first_name: 'John' } } }
30
-
31
- let(:dataset) do
32
- ROM::HTTP::Dataset.new(
33
- {
34
- uri: uri,
35
- headers: headers,
36
- request_handler: request_handler,
37
- response_handler: response_handler,
38
- name: :users
39
- },
40
- path: "users/#{id}",
41
- params: params
42
- )
43
- end
44
-
45
- before do
46
- configuration.register_relation(relation)
47
-
48
- allow(request_handler).to receive(:call).and_return(response)
49
- allow(response_handler).to receive(:call).and_return(tuples)
50
- end
51
-
52
- it 'returns relation tuples' do
53
- expect(users.to_a).to eql(tuples)
54
-
55
- expect(request_handler).to have_received(:call).with(dataset).once
56
- expect(response_handler).to have_received(:call).with(response, dataset).once
57
- end
58
-
59
- context 'using a repo' do
60
- let(:repo) do
61
- Class.new(ROM::Repository) do
62
- def self.to_s
63
- 'UserRepo'
64
- end
65
- end.new(container)
66
- end
67
-
68
- it 'returns structs' do
69
- user = repo.users.by_id(1337).filter(params).first
70
-
71
- expect(user.id).to be(1337)
72
- expect(user.name).to eql('John')
73
-
74
- expect(request_handler).to have_received(:call).with(dataset).once
75
- expect(response_handler).to have_received(:call).with(response, dataset).once
76
- end
77
- end
78
- end
data/spec/shared/setup.rb DELETED
@@ -1,18 +0,0 @@
1
- RSpec.shared_context 'setup' do
2
- let(:configuration) do
3
- ROM::Configuration.new(
4
- :http,
5
- uri: uri,
6
- request_handler: request_handler,
7
- response_handler: response_handler,
8
- headers: headers
9
- )
10
- end
11
- let(:container) { ROM.container(configuration) }
12
- let(:rom) { container }
13
- let(:gateway) { container.gateways.fetch(:default) }
14
- let(:uri) { 'http://localhost:3000' }
15
- let(:request_handler) { double(Proc, freeze: self) }
16
- let(:response_handler) { double(Proc, freeze: self) }
17
- let(:headers) { { accept: 'application/json' } }
18
- end
@@ -1,30 +0,0 @@
1
- RSpec.shared_context 'users and tasks' do
2
- include_context 'setup'
3
- let(:users_relation) do
4
- Class.new(ROM::HTTP::Relation) do
5
- schema(:users) do
6
- attribute :id, ROM::Types::Int
7
- end
8
-
9
- def by_id(id)
10
- with_params(id: id)
11
- end
12
- end
13
- end
14
- let(:tasks_relation) do
15
- Class.new(ROM::HTTP::Relation) do
16
- schema(:tasks) do
17
- attribute :id, ROM::Types::Int
18
- end
19
-
20
- def by_id(id)
21
- with_params(id: id)
22
- end
23
- end
24
- end
25
-
26
- before do
27
- configuration.register_relation(users_relation)
28
- configuration.register_relation(tasks_relation)
29
- end
30
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'bundler'
4
- Bundler.setup
5
-
6
- require 'rom-http'
7
- require 'rspec/its'
8
- require 'dry/configurable/test_interface'
9
-
10
- ROM::HTTP::Dataset.enable_test_interface
11
-
12
- begin
13
- require 'byebug'
14
- rescue LoadError; end
15
-
16
- root = Pathname(__FILE__).dirname
17
-
18
- Dir[root.join('support/**/*.rb').to_s].each { |file| require file }
19
- Dir[root.join('shared/**/*.rb').to_s].each { |file| require file }
@@ -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