artemis 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/artemis/client.rb +14 -6
- data/lib/artemis/test_helper.rb +39 -13
- data/lib/artemis/version.rb +1 -1
- data/spec/callbacks_spec.rb +14 -0
- data/spec/fixtures/responses/{artist.yml → metaphysics/artist.yml} +7 -0
- data/spec/fixtures/responses/{artwork.json → metaphysics/artwork.json} +0 -0
- data/spec/fixtures/responses/spotify/artist.yml +5 -0
- data/spec/test_helper_spec.rb +25 -4
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d63a9c3c0a9082fd9b93c55499fae9865425d01178c4ec637fb96a16acc9a3f
|
4
|
+
data.tar.gz: c0892fe01fe9b5d9c6c4e8b19c13d313e8efc75c1b3235db141cacd472f0dff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efced6e7780065414b95d47248f6f2b71055ed1512a5a19b2f86c82dcb42e9ef205894935ec8a0f3a106dfd109cb8bf12f978ceeb3357e6caac61a6a7818cce7
|
7
|
+
data.tar.gz: a45b2cb975cb8399a3a9e26e6dc4abdbf8afeaeead80ace29a2f6fd9c31966d7ede04724a53d23cb7abfa1e1611ea9d30839be4eb2677e71e9fce846cd5d27d4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [v0.5.0](https://github.com/yuki24/artemis/tree/v0.5.0)
|
2
|
+
|
3
|
+
_<sup>released at 2019-06-02 22:01:57 UTC</sup>_
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
- Add support for Rails 6.0, 4.1, and 4.0
|
8
|
+
- [<tt>6701b54</tt>](https://github.com/yuki24/artemis/commit/6701b546a143c22109c7ab30018acf96d67067d1), [#62](https://github.com/yuki24/artemis/issues/62): Allow to dynamically call the operation ([@JanStevens](https://github.com/JanStevens))
|
9
|
+
|
10
|
+
#### Fixes
|
11
|
+
|
12
|
+
- [#67](https://github.com/yuki24/artemis/pull/67): Fix the wrong test version constraints in `Appraisals` ([@daemonsy](https://github.com/daemonsy))
|
13
|
+
- [#60](https://github.com/yuki24/artemis/pull/60): Fix an issue where not all adapters send required HTTP headers
|
14
|
+
|
1
15
|
## [v0.4.0](https://github.com/yuki24/artemis/tree/v0.4.0)
|
2
16
|
|
3
17
|
_<sup>released at 2019-01-30 03:42:14 UTC</sup>_
|
data/lib/artemis/client.rb
CHANGED
@@ -5,6 +5,7 @@ require 'delegate'
|
|
5
5
|
require 'active_support/configurable'
|
6
6
|
require 'active_support/core_ext/hash/deep_merge'
|
7
7
|
require 'active_support/core_ext/module/delegation'
|
8
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
8
9
|
require 'active_support/core_ext/string/inflections'
|
9
10
|
|
10
11
|
require 'artemis/graphql_endpoint'
|
@@ -16,10 +17,10 @@ module Artemis
|
|
16
17
|
|
17
18
|
# The paths in which the Artemis client looks for files that have the +.graphql+ extension.
|
18
19
|
# In a rails app, this value will be set to +["app/operations"]+ by Artemis' +Artemis::Railtie+.
|
19
|
-
|
20
|
+
cattr_accessor :query_paths
|
20
21
|
|
21
22
|
# Default context that is appended to every GraphQL request for the client.
|
22
|
-
config.default_context =
|
23
|
+
config.default_context = nil
|
23
24
|
|
24
25
|
# List of before callbacks that get invoked in every +execute+ call.
|
25
26
|
#
|
@@ -59,7 +60,7 @@ module Artemis
|
|
59
60
|
end
|
60
61
|
|
61
62
|
class << self
|
62
|
-
delegate :
|
63
|
+
delegate :default_context=, to: :config
|
63
64
|
|
64
65
|
# Creates a new instance of the GraphQL client for the service.
|
65
66
|
#
|
@@ -137,7 +138,7 @@ module Artemis
|
|
137
138
|
# end
|
138
139
|
#
|
139
140
|
def before_execute(&block)
|
140
|
-
config.before_callbacks
|
141
|
+
config.before_callbacks = [*config.before_callbacks, block]
|
141
142
|
end
|
142
143
|
|
143
144
|
# Defines a callback that will get called right after the
|
@@ -155,7 +156,14 @@ module Artemis
|
|
155
156
|
# end
|
156
157
|
#
|
157
158
|
def after_execute(&block)
|
158
|
-
config.after_callbacks
|
159
|
+
config.after_callbacks = [*config.after_callbacks, block]
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the default configured context or an empty hash by default
|
163
|
+
#
|
164
|
+
# @return [Hash]
|
165
|
+
def default_context
|
166
|
+
config.default_context || {}
|
159
167
|
end
|
160
168
|
|
161
169
|
def resolve_graphql_file_path(filename, fragment: false)
|
@@ -278,7 +286,7 @@ module Artemis
|
|
278
286
|
|
279
287
|
client.query(self.class.const_get(const_name), variables: arguments, context: context)
|
280
288
|
else
|
281
|
-
raise GraphQLFileNotFound.new("Query #{query}.graphql not found in: #{
|
289
|
+
raise GraphQLFileNotFound.new("Query #{query}.graphql not found in: #{query_paths.join(", ")}")
|
282
290
|
end
|
283
291
|
end
|
284
292
|
|
data/lib/artemis/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
6
|
require 'active_support/core_ext/module/attribute_accessors'
|
6
7
|
|
@@ -41,7 +42,7 @@ module Artemis
|
|
41
42
|
# da_vinci.data.artist.name # => "Leonardo da Vinci"
|
42
43
|
#
|
43
44
|
def stub_graphql(service, query_name, arguments = :__unspecified__)
|
44
|
-
StubbingDSL.new(service.to_s,
|
45
|
+
StubbingDSL.new(service.to_s, query_name, graphql_fixture_files, arguments)
|
45
46
|
end
|
46
47
|
|
47
48
|
# Returns out-going GraphQL requests.
|
@@ -60,15 +61,11 @@ module Artemis
|
|
60
61
|
__graphql_fixture_path__ || raise(Artemis::ConfigurationError, "GraphQL fixture path is unset")
|
61
62
|
end
|
62
63
|
|
63
|
-
def graphql_fixtures(query_name) #:nodoc:
|
64
|
-
graphql_fixture_files.detect {|fixture| fixture.name == query_name.to_s } || \
|
65
|
-
raise(Artemis::FixtureNotFound, "Fixture file `#{File.join(graphql_fixture_path, "#{query_name}.{yml,json}")}' not found")
|
66
|
-
end
|
67
|
-
|
68
64
|
def graphql_fixture_files #:nodoc:
|
69
65
|
@graphql_fixture_sets ||= Dir["#{graphql_fixture_path}/{**,*}/*.{yml,json}"]
|
70
|
-
|
71
|
-
|
66
|
+
.uniq
|
67
|
+
.select {|file| ::File.file?(file) }
|
68
|
+
.map {|file| GraphQLFixture.new(File.basename(file, File.extname(file)), file, read_erb_yaml(file)) }
|
72
69
|
end
|
73
70
|
|
74
71
|
def read_erb_yaml(path) #:nodoc:
|
@@ -76,15 +73,30 @@ module Artemis
|
|
76
73
|
end
|
77
74
|
|
78
75
|
class StubbingDSL #:nodoc:
|
79
|
-
attr_reader :service_name, :
|
76
|
+
attr_reader :service_name, :query_name, :fixture_sets, :arguments
|
77
|
+
|
78
|
+
def initialize(service_name, query_name, fixture_sets, arguments) #:nodoc:
|
79
|
+
@service_name, @query_name, @fixture_sets, @arguments = service_name, query_name, fixture_sets, arguments
|
80
|
+
end
|
81
|
+
|
82
|
+
def get(fixture_key)
|
83
|
+
fixture_set = find_fixture_set
|
84
|
+
fixture = fixture_set.data[fixture_key.to_s]
|
85
|
+
|
86
|
+
if fixture.nil?
|
87
|
+
raise Artemis::FixtureNotFound, "Fixture `#{fixture_key}' not found in #{fixture_set.path}"
|
88
|
+
end
|
80
89
|
|
81
|
-
|
82
|
-
@service_name, @fixture_set, @arguments = service_name, fixture_set, arguments
|
90
|
+
fixture
|
83
91
|
end
|
84
92
|
|
85
93
|
def to_return(fixture_key) #:nodoc:
|
86
|
-
|
87
|
-
|
94
|
+
fixture_set = find_fixture_set
|
95
|
+
fixture = fixture_set.data[fixture_key.to_s]
|
96
|
+
|
97
|
+
if fixture.nil?
|
98
|
+
raise Artemis::FixtureNotFound, "Fixture `#{fixture_key}' not found in #{fixture_set.path}"
|
99
|
+
end
|
88
100
|
|
89
101
|
Artemis::Adapters::TestAdapter.responses <<
|
90
102
|
TestResponse.new(
|
@@ -93,6 +105,20 @@ module Artemis
|
|
93
105
|
fixture
|
94
106
|
)
|
95
107
|
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def find_fixture_set
|
112
|
+
fixture_set = fixture_sets
|
113
|
+
.detect { |fixture| %r{#{service_name.downcase}/#{query_name}\.(yml|json)\z} =~ fixture.path }
|
114
|
+
fixture_set ||= fixture_sets.detect { |fixture| fixture.name == query_name.to_s }
|
115
|
+
|
116
|
+
if fixture_set.nil?
|
117
|
+
raise Artemis::FixtureNotFound, "Fixture file `#{query_name}.{yml,json}' not found"
|
118
|
+
end
|
119
|
+
|
120
|
+
fixture_set
|
121
|
+
end
|
96
122
|
end
|
97
123
|
|
98
124
|
TestResponse = Struct.new(:operation_name, :arguments, :data) #:nodoc:
|
data/lib/artemis/version.rb
CHANGED
data/spec/callbacks_spec.rb
CHANGED
@@ -19,6 +19,20 @@ describe "#{GraphQL::Client} Callbacks" do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
Spotify = Class.new(Artemis::Client) do
|
23
|
+
def self.name
|
24
|
+
'Spotify'
|
25
|
+
end
|
26
|
+
|
27
|
+
before_execute do
|
28
|
+
raise "this callback should not get invoked"
|
29
|
+
end
|
30
|
+
|
31
|
+
after_execute do
|
32
|
+
raise "this callback should not get invoked"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
22
36
|
describe ".before_execute" do
|
23
37
|
it "gets invoked before executing" do
|
24
38
|
Client.artist(id: 'yayoi-kusama', context: { user_id: 'yuki24' })
|
File without changes
|
data/spec/test_helper_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'artemis/test_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Artemis::TestHelper do
|
5
5
|
include Artemis::TestHelper
|
6
6
|
|
7
7
|
def graphql_fixture_path
|
@@ -53,12 +53,33 @@ describe GraphQL::Client do
|
|
53
53
|
it "can mock a GraphQL request for a query that has a query name"
|
54
54
|
|
55
55
|
it "raises an exception if the specified fixture file does not exist" do
|
56
|
-
expect { stub_graphql(Metaphysics, :does_not_exist) }
|
57
|
-
.to raise_error(Artemis::FixtureNotFound, %r|
|
56
|
+
expect { stub_graphql(Metaphysics, :does_not_exist).to_return(:data) }
|
57
|
+
.to raise_error(Artemis::FixtureNotFound, %r|does_not_exist.{yml,json}|)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "raises an exception if the specified fixture file exists but fixture key does not exist" do
|
61
61
|
expect { stub_graphql(Metaphysics, :artist).to_return(:does_not_exist) }
|
62
|
-
.to raise_error(Artemis::FixtureNotFound, %r|spec/fixtures/responses/artist.yml|)
|
62
|
+
.to raise_error(Artemis::FixtureNotFound, %r|spec/fixtures/responses/metaphysics/artist.yml|)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "picks up the fixture for the given different service if multiple services have the exact same fixture" do
|
66
|
+
stub_graphql(Metaphysics, :artist).to_return(:yoshiki)
|
67
|
+
|
68
|
+
yoshiki = Metaphysics.artist(id: "artist-yoshiki")
|
69
|
+
|
70
|
+
expect(yoshiki.data.artist.name).to eq("Artist Yoshiki")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "allows to get raw fixture data as a Hash" do
|
74
|
+
data = stub_graphql("Spotify", :artist).get(:yoshiki)
|
75
|
+
|
76
|
+
expect(data).to eq({
|
77
|
+
"data" => {
|
78
|
+
"artist" => {
|
79
|
+
"id" => "pianist-yoshiki",
|
80
|
+
"name" => "Pianist Yoshiki"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
})
|
63
84
|
end
|
64
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artemis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Allured
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -220,8 +220,9 @@ files:
|
|
220
220
|
- spec/fixtures/metaphysics/artists.graphql
|
221
221
|
- spec/fixtures/metaphysics/artwork.graphql
|
222
222
|
- spec/fixtures/metaphysics/schema.json
|
223
|
-
- spec/fixtures/responses/artist.yml
|
224
|
-
- spec/fixtures/responses/artwork.json
|
223
|
+
- spec/fixtures/responses/metaphysics/artist.yml
|
224
|
+
- spec/fixtures/responses/metaphysics/artwork.json
|
225
|
+
- spec/fixtures/responses/spotify/artist.yml
|
225
226
|
- spec/spec_helper.rb
|
226
227
|
- spec/test_helper_spec.rb
|
227
228
|
- tmp/.gitkeep
|