/
base_spec.rb2
142 lines (119 loc) · 4.52 KB
/
base_spec.rb2
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'ruby-debug'
context Restfulie::Client::Base do
before(:all) do
module Restfulie::Client::Test
class Song
include ::Restfulie::Client::Base
uses_restfulie { |config| config.entry_point = 'http://localhost:4567/songs' }
end
end
@songs_from_class = Restfulie::Client::Test::Song.accepts("application/atom+xml").get!
end
it 'should load songs' do
@songs_from_class.response.code.should == 200
@songs_from_class.title.should == 'Songs feed'
@songs_from_class.id.should == 'http://localhost:4567/songs'
@songs_from_class.updated.year.should == 2010
@songs_from_class.entries.size.should == 4
a_song = @songs_from_class.entries.first
a_song.title.should == 'Song 1'
a_song.id.should == 'http://localhost:4567/songs_1'
end
it 'should load top ten songs' do
top_ten_songs = @songs_from_class.links.top_ten.get!
top_ten_songs.response.code.should == 200
top_ten_songs.title.should == 'Top Ten Songs feed'
top_ten_songs.id.should == 'http://localhost:4567/songs_top_ten'
top_ten_songs.updated.year.should == 2010
a_song = top_ten_songs.entries.first
a_song.title.should == 'Song 3'
a_song.id.should == 'http://localhost:4567/song_3'
end
it 'should load chained relationship' do
top_ten_songs = @songs_from_class.links.top_ten.get!
a_song = top_ten_songs.entries.first
related_songs = a_song.links.related_songs.get!
first_related_song = related_songs.entries.first
similar_song = first_related_song.links.similar_song
similar_song.get!.title.should == 'Song 4 feed'
end
#it '' do
#a_song.video.post
#a_song.video.put
#a_song.video.delete
#end
end
context Restfulie::Client::EntryPoint do
before(:all) do
r = Restfulie::Client::EntryPoint.at('http://localhost:4567/songs')
r = r.accepts('application/atom+xml')
@songs_from_ep = r.get!
end
it 'should load songs' do
@songs_from_ep.response.code.should == 200
@songs_from_ep.title.should == 'Songs feed'
@songs_from_ep.id.should == 'http://localhost:4567/songs'
@songs_from_ep.updated.year.should == 2010
@songs_from_ep.entries.size.should == 4
a_song = @songs_from_ep.entries.first
a_song.title.should == 'Song 1'
a_song.id.should == 'http://localhost:4567/songs_1'
end
it 'should load top ten songs' do
top_ten_songs = @songs_from_ep.links.top_ten.get!
top_ten_songs.response.code.should == 200
top_ten_songs.title.should == 'Top Ten Songs feed'
top_ten_songs.id.should == 'http://localhost:4567/songs_top_ten'
top_ten_songs.updated.year.should == 2010
a_song = top_ten_songs.entries.first
a_song.title.should == 'Song 3'
a_song.id.should == 'http://localhost:4567/song_3'
end
it 'should load chained relationship' do
top_ten_songs = @songs_from_ep.links.top_ten.get!
a_song = top_ten_songs.entries.first
related_songs = a_song.links.related_songs.get!
similar_song = related_songs.entries.first.links.similar_song
similar_song.get!.title.should == 'Song 4 feed'
end
#it '' do
#a_song.video.post
#a_song.video.put
#a_song.video.delete
#end
end
context Restfulie do
context 'Delegate to entrypoint' do
before(:all) do
@songs = Restfulie.at('http://localhost:4567/songs').accepts('application/atom+xml').get!
end
it 'should load songs' do
@songs.response.code.should == 200
@songs.title.should == 'Songs feed'
@songs.id.should == 'http://localhost:4567/songs'
@songs.updated.year.should == 2010
@songs.entries.size.should == 4
a_song = @songs.entries.first
a_song.title.should == 'Song 1'
a_song.id.should == 'http://localhost:4567/songs_1'
end
it 'should load top ten songs' do
top_ten_songs = @songs.links.top_ten.get!
top_ten_songs.response.code.should == 200
top_ten_songs.title.should == 'Top Ten Songs feed'
top_ten_songs.id.should == 'http://localhost:4567/songs_top_ten'
top_ten_songs.updated.year.should == 2010
a_song = top_ten_songs.entries.first
a_song.title.should == 'Song 3'
a_song.id.should == 'http://localhost:4567/song_3'
end
it 'should load chained relationship' do
top_ten_songs = @songs.links.top_ten.get!
a_song = top_ten_songs.entries.first
related_songs = a_song.links.related_songs.get!
similar_song = related_songs.entries.first.links.similar_song
similar_song.get!.title.should == 'Song 4 feed'
end
end
end