jsonapi-realizer 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/realizer/action/create_spec.rb +3 -3
- data/lib/jsonapi/realizer/action/index_spec.rb +3 -3
- data/lib/jsonapi/realizer/action/show_spec.rb +3 -3
- data/lib/jsonapi/realizer/action/update_spec.rb +3 -3
- data/lib/jsonapi/realizer/version.rb +1 -1
- data/lib/jsonapi/realizer.rb +4 -4
- data/lib/jsonapi/realizer_spec.rb +80 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e72cdbc01521b2454b71163a42709f62c44a0c68cb7278696d4b547a0d34dd9
|
4
|
+
data.tar.gz: ee5ba23558d88677206bef2564735d4d0f7050366bbf23fe702bd145b4b66b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd81b1e851ca61e8c1d8f29d4838b0a034b5475a18d16cd722f78a8020cb62f268d82c3d54ebcefabf3528021739698426580a5d870cd7b47fd92ceff12868b
|
7
|
+
data.tar.gz: e307d10a04c8384b76687dbe353540e983d93f480d6c31664e6f9dd87869f62d903312f5fd21a04cc22758b7908eaa8f739adfc14aa98ff6ef296733e37701db
|
@@ -6,9 +6,9 @@ RSpec.describe JSONAPI::Realizer::Action::Create do
|
|
6
6
|
describe "#call" do
|
7
7
|
subject { action.call }
|
8
8
|
|
9
|
-
context "with no top-level data"
|
10
|
-
|
11
|
-
|
9
|
+
context "with no top-level data and good headers"
|
10
|
+
context "with no top-level data and bad headers"
|
11
|
+
context "with a good payload and bad headers"
|
12
12
|
|
13
13
|
context "with a good payload and good headers" do
|
14
14
|
let(:payload) do
|
@@ -6,9 +6,9 @@ RSpec.describe JSONAPI::Realizer::Action::Index do
|
|
6
6
|
describe "#models" do
|
7
7
|
subject { action.models }
|
8
8
|
|
9
|
-
context "with no top-level data"
|
10
|
-
|
11
|
-
|
9
|
+
context "with no top-level data and good headers"
|
10
|
+
context "with no top-level data and bad headers"
|
11
|
+
context "with a good payload and bad headers"
|
12
12
|
|
13
13
|
context "with a good payload and good headers" do
|
14
14
|
let(:payload) do
|
@@ -6,9 +6,9 @@ RSpec.describe JSONAPI::Realizer::Action::Show do
|
|
6
6
|
describe "#model" do
|
7
7
|
subject { action.model }
|
8
8
|
|
9
|
-
context "with no top-level data"
|
10
|
-
|
11
|
-
|
9
|
+
context "with no top-level data and good headers"
|
10
|
+
context "with no top-level data and bad headers"
|
11
|
+
context "with a good payload and bad headers"
|
12
12
|
|
13
13
|
context "with a good payload and good headers" do
|
14
14
|
let(:payload) do
|
@@ -6,9 +6,9 @@ RSpec.describe JSONAPI::Realizer::Action::Update do
|
|
6
6
|
describe "#call" do
|
7
7
|
subject { action.call }
|
8
8
|
|
9
|
-
context "with no top-level data"
|
10
|
-
|
11
|
-
|
9
|
+
context "with no top-level data and good headers"
|
10
|
+
context "with no top-level data and bad headers"
|
11
|
+
context "with a good payload and bad headers"
|
12
12
|
|
13
13
|
context "with a good payload and good headers" do
|
14
14
|
let(:payload) do
|
data/lib/jsonapi/realizer.rb
CHANGED
@@ -34,18 +34,18 @@ module JSONAPI
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.update(payload, headers:)
|
37
|
-
enact(Update.new(payload: payload, headers: headers))
|
37
|
+
enact(Action::Update.new(payload: payload, headers: headers))
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.show(payload, headers:, type:)
|
41
|
-
enact(Show.new(payload: payload, headers: headers, type: type))
|
41
|
+
enact(Action::Show.new(payload: payload, headers: headers, type: type))
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.index(payload, headers:, type:)
|
45
|
-
enact(Index.new(payload: payload, headers: headers, type: type))
|
45
|
+
enact(Action::Index.new(payload: payload, headers: headers, type: type))
|
46
46
|
end
|
47
47
|
|
48
|
-
private_class_method def self.
|
48
|
+
private_class_method def self.enact(action)
|
49
49
|
action.tap(&:call)
|
50
50
|
end
|
51
51
|
end
|
@@ -1,6 +1,85 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe JSONAPI::Realizer do
|
4
|
-
|
4
|
+
describe ".index" do
|
5
|
+
subject { JSONAPI::Realizer.index(payload, headers: headers, type: type) }
|
6
|
+
|
7
|
+
context "with no top-level data and good headers"
|
8
|
+
context "with no top-level data and bad headers"
|
9
|
+
context "with a good payload and bad headers"
|
10
|
+
|
11
|
+
context "with a good payload and good headers" do
|
12
|
+
let(:payload) do
|
13
|
+
{}
|
14
|
+
end
|
15
|
+
let(:headers) do
|
16
|
+
{
|
17
|
+
"Content-Type" => "application/vnd.api+json",
|
18
|
+
"Accept" => "application/vnd.api+json"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
let(:type) do
|
22
|
+
:photos
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
Photo::STORE["550e8400-e29b-41d4-a716-446655440000"] = {
|
27
|
+
id: "550e8400-e29b-41d4-a716-446655440000",
|
28
|
+
title: "Ember Hamster",
|
29
|
+
src: "http://example.com/images/productivity.png"
|
30
|
+
}
|
31
|
+
Photo::STORE["d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"] = {
|
32
|
+
id: "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed",
|
33
|
+
title: "Ember Fox",
|
34
|
+
src: "http://example.com/images/productivity-2.png"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns an action that has N models" do
|
39
|
+
expect(subject).to have_attributes(models: array_including(a_kind_of(Photo)))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".show" do
|
45
|
+
subject { JSONAPI::Realizer.show(payload, headers: headers, type: type) }
|
46
|
+
|
47
|
+
context "with no top-level data and good headers"
|
48
|
+
context "with no top-level data and bad headers"
|
49
|
+
context "with a good payload and bad headers"
|
50
|
+
|
51
|
+
context "with a good payload and good headers" do
|
52
|
+
let(:payload) do
|
53
|
+
{
|
54
|
+
"id" => "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"
|
55
|
+
}
|
56
|
+
end
|
57
|
+
let(:headers) do
|
58
|
+
{
|
59
|
+
"Content-Type" => "application/vnd.api+json",
|
60
|
+
"Accept" => "application/vnd.api+json"
|
61
|
+
}
|
62
|
+
end
|
63
|
+
let(:type) do
|
64
|
+
:photos
|
65
|
+
end
|
66
|
+
|
67
|
+
before do
|
68
|
+
Photo::STORE["550e8400-e29b-41d4-a716-446655440000"] = {
|
69
|
+
id: "550e8400-e29b-41d4-a716-446655440000",
|
70
|
+
title: "Ember Hamster",
|
71
|
+
src: "http://example.com/images/productivity.png"
|
72
|
+
}
|
73
|
+
Photo::STORE["d09ae4c6-0fc3-4c42-8fe8-6029530c3bed"] = {
|
74
|
+
id: "d09ae4c6-0fc3-4c42-8fe8-6029530c3bed",
|
75
|
+
title: "Ember Fox",
|
76
|
+
src: "http://example.com/images/productivity-2.png"
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns an action that a model" do
|
81
|
+
expect(subject).to have_attributes(model: a_kind_of(Photo))
|
82
|
+
end
|
83
|
+
end
|
5
84
|
end
|
6
85
|
end
|