/
http_verbs_feature_test.rb
115 lines (95 loc) · 3.4 KB
/
http_verbs_feature_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'test_helper'
require 'roar/representer/feature/http_verbs'
require 'roar/representer/json'
class HttpVerbsTest < MiniTest::Spec
module BandRepresenter
include Roar::Representer::JSON
property :name
property :label
end
# keep this class clear of Roar modules.
class Band
attr_accessor :name, :label
end
describe "HttpVerbs" do
before do
@band = Band.new
@band.extend(BandRepresenter)
@band.extend(Roar::Representer::Feature::HttpVerbs)
end
describe "transport_engine" do
before do
@http_verbs = Roar::Representer::Feature::HttpVerbs
@net_http = Roar::Representer::Transport::NetHTTP
end
it "has a default set in the transport module level" do
assert_equal @net_http, @band.transport_engine
end
it "allows changing on instance level" do
@band.transport_engine = :soap
assert_equal @net_http, @http_verbs.transport_engine
assert_equal :soap, @band.transport_engine
end
end
describe "HttpVerbs.get" do
it "returns instance from incoming representation" do
band = @band.get("http://roar.example.com/bands/slayer", "application/json")
assert_equal "Slayer", band.name
assert_equal "Canadian Maple", band.label
end
# FIXME: move to faraday test.
describe 'a non-existent resource' do
it 'handles HTTP errors and raises a ResourceNotFound error with FaradayHttpTransport' do
@band.transport_engine = Roar::Representer::Transport::Faraday
assert_raises(::Faraday::Error::ResourceNotFound) do
@band.get('http://roar.example.com/bands/anthrax', "application/json")
end
end
it 'performs no HTTP error handling with NetHttpTransport' do
@band.transport_engine = Roar::Representer::Transport::NetHTTP
assert_raises(JSON::ParserError) do
@band.get('http://roar.example.com/bands/anthrax', "application/json")
end
end
end
end
describe "#get" do
it "updates instance with incoming representation" do
@band.get("http://roar.example.com/bands/slayer", "application/json")
assert_equal "Slayer", @band.name
assert_equal "Canadian Maple", @band.label
end
end
describe "#post" do
it "updates instance with incoming representation" do
@band.name = "Strung Out"
assert_equal nil, @band.label
@band.post("http://roar.example.com/bands", "application/xml")
assert_equal "Strung Out", @band.name
assert_equal "n/a", @band.label
end
end
describe "#put" do
it "updates instance with incoming representation" do
@band.name = "Strung Out"
@band.label = "Fat Wreck"
@band.put("http://roar.example.com/bands/strungout", "application/xml")
assert_equal "Strung Out", @band.name
assert_equal "Fat Wreck", @band.label
end
end
describe "#patch" do
it 'does something' do
@band.label = 'Fat Mike'
@band.patch("http://roar.example.com/bands/strungout", "application/xml")
assert_equal 'Fat Mike', @band.label
end
end
describe "#delete" do
it 'does something' do
@band.delete("http://roar.example.com/bands/metallica", "application/xml")
end
end
# HEAD, OPTIONs?
end
end