wcc-data 0.3.2 → 0.4.0.pre.pre.2

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.
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WCC::Data::Response do
4
- let(:unit) { WCC::Data::Response }
5
- let(:raw) { double(:faraday_response) }
6
- subject { unit.new(raw) }
7
-
8
- describe "#initialize" do
9
- it "takes a Faraday response object and sets it to @raw" do
10
- expect(subject.raw).to eq(raw)
11
- end
12
- end
13
-
14
- describe "method delegation" do
15
- it "delegates `body` to @raw" do
16
- expect(raw).to receive(:body).and_return(:value)
17
- expect(subject.body).to eq(:value)
18
- expect(subject.respond_to?(:body)).to be_truthy
19
- end
20
-
21
- it "delegates `headers` to @raw" do
22
- expect(raw).to receive(:headers).and_return(:value)
23
- expect(subject.headers).to eq(:value)
24
- expect(subject.respond_to?(:headers)).to be_truthy
25
- end
26
-
27
- it "delegates `status` to @raw" do
28
- expect(raw).to receive(:status).and_return(:value)
29
- expect(subject.status).to eq(:value)
30
- expect(subject.respond_to?(:status)).to be_truthy
31
- end
32
-
33
- it "delegates `success?` to @raw" do
34
- expect(raw).to receive(:success?).and_return(:value)
35
- expect(subject.success?).to eq(:value)
36
- expect(subject.respond_to?(:success?)).to be_truthy
37
- end
38
- end
39
-
40
- describe "#json" do
41
- it "returns JSON deserialized body" do
42
- expect(raw).to receive(:body) {
43
- %[{"name":"Bob","interests":["Fishing","Rowing","Golfing"]}]
44
- }
45
- expect(subject.json).to eq({
46
- "name" => "Bob",
47
- "interests" => ["Fishing", "Rowing", "Golfing"],
48
- })
49
- end
50
-
51
- it "returns nil if body is not valid JSON" do
52
- expect(raw).to receive(:body) { "" }
53
- expect(subject.json).to be_nil
54
- end
55
- end
56
-
57
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WCC::Data::RESTEndpoint do
4
- let(:service) { WCC::Data::Service.new }
5
- subject { described_class.new(service: service) }
6
-
7
- describe "#initialize" do
8
- subject { described_class }
9
- it "sets @service from :service option" do
10
- obj = subject.new(service: service)
11
- expect(obj.service).to eq(service)
12
- end
13
- end
14
-
15
- shared_examples_for :rest_method_general_options do |method, verb, args|
16
- let(:test_args) {
17
- { foo: "bar", baz: "bing" }
18
- }
19
- it "takes a hash as last argument and passes to underlying service" do
20
- args = Array(args)
21
- expect(service).to receive(verb).with(hash_including(test_args))
22
- subject.public_send(method, *args, test_args)
23
- end
24
- end
25
-
26
- describe "#index" do
27
- it_behaves_like :rest_method_general_options, :index, :get
28
-
29
- it "calls #get directly on service" do
30
- expect(service).to receive(:get).and_return("hi there")
31
- expect(subject.index).to eq("hi there")
32
- end
33
- end
34
-
35
- describe "#show" do
36
- it_behaves_like :rest_method_general_options, :show, :get, 1
37
-
38
- it "calls #get on service adding the id param to the URI" do
39
- expect(service).to receive(:get).with(uri: "123").and_return("yo")
40
- expect(subject.show(123)).to eq("yo")
41
- end
42
- end
43
-
44
- describe "#create" do
45
- it_behaves_like :rest_method_general_options, :create, :post, { test: 1 }
46
-
47
- it "calls #post on service with attrs hash as body" do
48
- expect(service).to receive(:post).with(body: { foo: "bar" }).and_return("hey bra")
49
- expect(subject.create(foo: "bar")).to eq("hey bra")
50
- end
51
- end
52
-
53
- describe "#update" do
54
- it_behaves_like :rest_method_general_options, :update, :patch, [1, { test: 1 }]
55
-
56
- it "calls #patch on service with id as URI and attrs as body" do
57
- expect(service).to receive(:patch).with(uri: "123", body: {}).and_return("sup")
58
- expect(subject.update(123, {})).to eq("sup")
59
- end
60
- end
61
-
62
- describe "#destroy" do
63
- it_behaves_like :rest_method_general_options, :destroy, :delete, 1
64
-
65
- it "calls #delete on service with id as URI" do
66
- expect(service).to receive(:delete).with(uri: "123").and_return("oh noes!")
67
- expect(subject.destroy(123)).to eq("oh noes!")
68
- end
69
- end
70
-
71
- end
@@ -1,128 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WCC::Data::Service do
4
- let(:unit) { WCC::Data::Service }
5
- let(:connection) { double() }
6
- let(:default_args) {
7
- {
8
- uri: "http://test.com/foo/",
9
- connection: connection,
10
- }
11
- }
12
- subject { unit.new(default_args) }
13
-
14
- describe "#initialize" do
15
- it "sets :uri to @uri" do
16
- expect(subject.uri).to eq(URI(default_args[:uri]))
17
- end
18
-
19
- it "sets :connection to @connection" do
20
- expect(subject.connection).to eq(default_args[:connection])
21
- end
22
- end
23
-
24
- describe "#merge" do
25
- it "returns a new instance" do
26
- merged = subject.merge
27
- expect(merged).to be_a(unit)
28
- expect(merged.object_id).to_not eq(subject.object_id)
29
- end
30
-
31
- it "merges the URI params" do
32
- merged = subject.merge(uri: "bar/baz?query")
33
- expect(merged.uri.path).to eq("/foo/bar/baz")
34
- expect(merged.uri.query).to eq("query")
35
- end
36
-
37
- it "sets to the right instance's @connection" do
38
- connection = :bar
39
- merged = subject.merge(connection: connection)
40
- expect(merged.connection).to eq(connection)
41
- end
42
-
43
- it "accepts a hash of arguments as well as an instance" do
44
- right = unit.new(uri: "bar", connection: double())
45
- merged = subject.merge(right)
46
- expect(merged.uri).to eq(URI("http://test.com/foo/bar"))
47
- expect(merged.connection).to eq(right.connection)
48
- end
49
-
50
- end
51
-
52
- shared_examples_for :http_verb_methods do
53
- it "request verb matches the method name" do
54
- expect(connection).to receive(:run_request) do |verb, _, _, _|
55
- expect(verb).to eq(method)
56
- end
57
- subject.send(method, {})
58
- end
59
-
60
- it "returns a WCC::Data::Response instance" do
61
- expect(connection).to receive(:run_request) {}
62
- expect(subject.send(method, {})).to be_a(WCC::Data::Response)
63
- end
64
-
65
- it "merges :uri arg onto @uri" do
66
- expect(connection).to receive(:run_request) do |_, url, _, _|
67
- expect(url).to eq(URI("http://test.com/foo/bar"))
68
- end
69
- subject.send(method, uri: "bar")
70
- end
71
-
72
- it "sets the request body with :body arg" do
73
- expect(connection).to receive(:run_request) do |_, _, body, _|
74
- expect(body).to eq("a string")
75
- end
76
- subject.send(method, body: "a string")
77
- end
78
-
79
- it "provides request headers with :headers arg" do
80
- expect(connection).to receive(:run_request) do |_, _, _, headers|
81
- expect(headers).to eq(:foo)
82
- end
83
- subject.send(method, headers: :foo)
84
- end
85
-
86
- it "updates the params on the request if :params argument provided" do
87
- params = { foo: "bar" }
88
- request = double(params: double(:params))
89
- expect(connection).to receive(:run_request).and_yield(request)
90
-
91
- expect(request.params).to receive(:update).with(params)
92
- subject.send(method, params: params)
93
- end
94
-
95
- it "does not update the params on the request if :params is nil" do
96
- request = double(params: double(:params))
97
- expect(connection).to receive(:run_request).and_yield(request)
98
- expect(request.params).to_not receive(:update)
99
- subject.send(method, {})
100
- end
101
- end
102
-
103
- describe "#get" do
104
- let(:method) { :get }
105
- it_behaves_like :http_verb_methods
106
- end
107
-
108
- describe "#post" do
109
- let(:method) { :post }
110
- it_behaves_like :http_verb_methods
111
- end
112
-
113
- describe "#put" do
114
- let(:method) { :put }
115
- it_behaves_like :http_verb_methods
116
- end
117
-
118
- describe "#patch" do
119
- let(:method) { :patch }
120
- it_behaves_like :http_verb_methods
121
- end
122
-
123
- describe "#delete" do
124
- let(:method) { :delete }
125
- it_behaves_like :http_verb_methods
126
- end
127
-
128
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WCC::Data do
4
-
5
- describe "::config" do
6
- it "returns a cached instance of Config" do
7
- config = WCC::Data.config
8
- expect(config).to be_a(WCC::Data::Config)
9
- expect(WCC::Data.config).to eq(config)
10
- end
11
- end
12
-
13
- describe "::setup" do
14
- it "yields to the provided block with config" do
15
- config = WCC::Data.config
16
- called = false
17
- WCC::Data.setup do |passed_config|
18
- called = true
19
- expect(passed_config).to eq(config)
20
- end
21
- expect(called).to be_truthy
22
- end
23
- end
24
-
25
- end