teamsnap_rb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,160 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3003/teams
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: 'OK '
20
+ headers:
21
+ Content-Type:
22
+ - application/vnd.collection+json
23
+ Content-Length:
24
+ - '2809'
25
+ X-Content-Type-Options:
26
+ - nosniff
27
+ X-Ratelimit-Limit:
28
+ - '5000'
29
+ X-Ratelimit-Remaining:
30
+ - '4999'
31
+ X-Ratelimit-Reset:
32
+ - '1415740100'
33
+ Etag:
34
+ - '"5daf3cf1d2f681f9ce53cdea0e70b9fb"'
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ X-Request-Id:
38
+ - b700c77f-a114-4cfb-b682-df629213ff22
39
+ X-Runtime:
40
+ - '0.062563'
41
+ Server:
42
+ - WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
43
+ Date:
44
+ - Tue, 11 Nov 2014 20:08:20 GMT
45
+ Connection:
46
+ - Keep-Alive
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"collection":{"version":"3.1.1","href":"http://localhost:3003/teams","template":{"data":[{"name":"name","value":null},{"name":"location_country","value":null},{"name":"location_postal_code","value":null},{"name":"time_zone","value":null},{"name":"sport_id","value":null},{"name":"division_name","value":null},{"name":"season_name","value":null},{"name":"league_name","value":null},{"name":"league_url","value":null}]},"links":[{"rel":"active_season_team","href":"http://localhost:3003/teams"},{"rel":"assignments","href":"http://localhost:3003/assignments"},{"rel":"availabilities","href":"http://localhost:3003/availabilities"},{"rel":"contact_email_addresses","href":"http://localhost:3003/contact_email_addresses"},{"rel":"contact_phone_numbers","href":"http://localhost:3003/contact_phone_numbers"},{"rel":"contacts","href":"http://localhost:3003/contacts"},{"rel":"custom_data","href":"http://localhost:3003/custom_data"},{"rel":"custom_fields","href":"http://localhost:3003/custom_fields"},{"rel":"events","href":"http://localhost:3003/events"},{"rel":"locations","href":"http://localhost:3003/locations"},{"rel":"managers","href":"http://localhost:3003/members"},{"rel":"member_email_addresses","href":"http://localhost:3003/member_email_addresses"},{"rel":"member_files","href":"http://localhost:3003/member_files"},{"rel":"member_links","href":"http://localhost:3003/member_links"},{"rel":"member_phone_numbers","href":"http://localhost:3003/member_phone_numbers"},{"rel":"members","href":"http://localhost:3003/members"},{"rel":"members_preferences","href":"http://localhost:3003/members_preferences"},{"rel":"opponents","href":"http://localhost:3003/opponents"},{"rel":"owner","href":"http://localhost:3003/members"},{"rel":"plan","href":"http://localhost:3003/plans"},{"rel":"sport","href":"http://localhost:3003/sports"},{"rel":"team_preferences","href":"http://localhost:3003/teams_preferences"},{"rel":"team_public_site","href":"http://localhost:3003/team_public_sites"},{"rel":"team_results","href":"http://localhost:3003/teams_results"},{"rel":"tracked_item_statuses","href":"http://localhost:3003/tracked_item_statuses"},{"rel":"tracked_items","href":"http://localhost:3003/tracked_items"},{"rel":"root","href":"http://localhost:3003/"},{"rel":"self","href":"http://localhost:3003/teams"}],"queries":[{"rel":"search","href":"http://localhost:3003/teams/search","data":[{"name":"id","value":null},{"name":"team_id","value":null},{"name":"user_id","value":null}]}],"commands":[{"rel":"invite","href":"http://localhost:3003/teams/invite","prompt":"invite
50
+ team members or contacts to join TeamSnap.","data":[{"name":"team_id","value":null},{"name":"contact_id","value":null},{"name":"member_id","value":null},{"name":"introduction","value":null},{"name":"notify_as_member_id","value":null}]}]}}'
51
+ http_version:
52
+ recorded_at: Tue, 11 Nov 2014 20:08:20 GMT
53
+ - request:
54
+ method: post
55
+ uri: http://localhost:3003/teams
56
+ body:
57
+ encoding: UTF-8
58
+ string: '{"template":{"data":[{"name":"name","value":"Teamsters"},{"name":"location_country","value":"United
59
+ States"},{"name":"location_postal_code","value":"80951"},{"name":"time_zone","value":"America/Denver"},{"name":"sport_id","value":1}]}}'
60
+ headers:
61
+ User-Agent:
62
+ - Faraday v0.9.0
63
+ Content-Type:
64
+ - application/json
65
+ Accept-Encoding:
66
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
67
+ Accept:
68
+ - "*/*"
69
+ response:
70
+ status:
71
+ code: 201
72
+ message: 'Created '
73
+ headers:
74
+ Content-Type:
75
+ - application/vnd.collection+json
76
+ Location:
77
+ - http://localhost:3003/teams/search?id=5
78
+ Content-Length:
79
+ - '6284'
80
+ X-Content-Type-Options:
81
+ - nosniff
82
+ X-Ratelimit-Limit:
83
+ - '5000'
84
+ X-Ratelimit-Remaining:
85
+ - '4991'
86
+ X-Ratelimit-Reset:
87
+ - '1415740100'
88
+ Etag:
89
+ - '"7685a9d4f241478253b29a4775bd305c"'
90
+ Cache-Control:
91
+ - max-age=0, private, must-revalidate
92
+ X-Request-Id:
93
+ - a9ae86e1-7d53-4cc5-a776-9bdefda9f871
94
+ X-Runtime:
95
+ - '0.090504'
96
+ Server:
97
+ - WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
98
+ Date:
99
+ - Tue, 11 Nov 2014 20:53:04 GMT
100
+ Connection:
101
+ - Keep-Alive
102
+ body:
103
+ encoding: UTF-8
104
+ string: '{"collection":{"version":"3.1.1","href":"http://localhost:3003/teams","template":{"data":[{"name":"name","value":null},{"name":"location_country","value":null},{"name":"location_postal_code","value":null},{"name":"time_zone","value":null},{"name":"sport_id","value":null},{"name":"division_name","value":null},{"name":"season_name","value":null},{"name":"league_name","value":null},{"name":"league_url","value":null}]},"links":[{"rel":"active_season_team","href":"http://localhost:3003/teams"},{"rel":"assignments","href":"http://localhost:3003/assignments"},{"rel":"availabilities","href":"http://localhost:3003/availabilities"},{"rel":"contact_email_addresses","href":"http://localhost:3003/contact_email_addresses"},{"rel":"contact_phone_numbers","href":"http://localhost:3003/contact_phone_numbers"},{"rel":"contacts","href":"http://localhost:3003/contacts"},{"rel":"custom_data","href":"http://localhost:3003/custom_data"},{"rel":"custom_fields","href":"http://localhost:3003/custom_fields"},{"rel":"events","href":"http://localhost:3003/events"},{"rel":"locations","href":"http://localhost:3003/locations"},{"rel":"managers","href":"http://localhost:3003/members"},{"rel":"member_email_addresses","href":"http://localhost:3003/member_email_addresses"},{"rel":"member_files","href":"http://localhost:3003/member_files"},{"rel":"member_links","href":"http://localhost:3003/member_links"},{"rel":"member_phone_numbers","href":"http://localhost:3003/member_phone_numbers"},{"rel":"members","href":"http://localhost:3003/members"},{"rel":"members_preferences","href":"http://localhost:3003/members_preferences"},{"rel":"opponents","href":"http://localhost:3003/opponents"},{"rel":"owner","href":"http://localhost:3003/members"},{"rel":"plan","href":"http://localhost:3003/plans"},{"rel":"sport","href":"http://localhost:3003/sports"},{"rel":"team_preferences","href":"http://localhost:3003/teams_preferences"},{"rel":"team_public_site","href":"http://localhost:3003/team_public_sites"},{"rel":"team_results","href":"http://localhost:3003/teams_results"},{"rel":"tracked_item_statuses","href":"http://localhost:3003/tracked_item_statuses"},{"rel":"tracked_items","href":"http://localhost:3003/tracked_items"},{"rel":"root","href":"http://localhost:3003/"},{"rel":"self","href":"http://localhost:3003/teams"}],"queries":[{"rel":"search","href":"http://localhost:3003/teams/search","data":[{"name":"id","value":null},{"name":"team_id","value":null},{"name":"user_id","value":null}]}],"commands":[{"rel":"invite","href":"http://localhost:3003/teams/invite","prompt":"invite
105
+ team members or contacts to join TeamSnap.","data":[{"name":"team_id","value":null},{"name":"contact_id","value":null},{"name":"member_id","value":null},{"name":"introduction","value":null},{"name":"notify_as_member_id","value":null}]}],"items":[{"href":"http://localhost:3003/teams/5","data":[{"name":"id","value":5},{"name":"type","value":"team"},{"name":"name","value":"Teamsters"},{"name":"time_zone_offset","value":"-07:00"},{"name":"time_zone_iana_name","value":"America/Denver"},{"name":"time_zone_description","value":"Mountain
106
+ Time (US & Canada)"},{"name":"updated_at","value":"2014-11-11T20:53:04Z","type":"DateTime"},{"name":"created_at","value":"2014-11-11T20:53:04Z","type":"DateTime"},{"name":"league_name","value":null},{"name":"league_url","value":null},{"name":"division_name","value":null},{"name":"season_name","value":null},{"name":"location_country","value":"United
107
+ States"},{"name":"location_postal_code","value":"80951"},{"name":"is_archived_season","value":false},{"name":"sport_id","value":1},{"name":"plan_id","value":14}],"links":[{"rel":"assignments","href":"http://localhost:3003/assignments/search?team_id=5"},{"rel":"availabilities","href":"http://localhost:3003/availabilities/search?team_id=5"},{"rel":"calendar_http","href":"http://86ed2e8eefaaee16c4b7-16391cffaf9272bff70e93998d553c16.r2.cf1.rackcdn.com/team_schedule/.ics"},{"rel":"calendar_http_games_only","href":"http://86ed2e8eefaaee16c4b7-16391cffaf9272bff70e93998d553c16.r2.cf1.rackcdn.com/team_schedule/filter/games/.ics"},{"rel":"calendar_webcal","href":"webcal://86ed2e8eefaaee16c4b7-16391cffaf9272bff70e93998d553c16.r2.cf1.rackcdn.com/team_schedule/.ics"},{"rel":"calendar_webcal_games_only","href":"webcal://86ed2e8eefaaee16c4b7-16391cffaf9272bff70e93998d553c16.r2.cf1.rackcdn.com/team_schedule/filter/games/.ics"},{"rel":"contact_email_addresses","href":"http://localhost:3003/contact_email_addresses/search?team_id=5"},{"rel":"contact_phone_numbers","href":"http://localhost:3003/contact_phone_numbers/search?team_id=5"},{"rel":"contacts","href":"http://localhost:3003/contacts/search?team_id=5"},{"rel":"custom_data","href":"http://localhost:3003/custom_data/search?team_id=5"},{"rel":"custom_fields","href":"http://localhost:3003/custom_fields/search?team_id=5"},{"rel":"events","href":"http://localhost:3003/events/search?team_id=5"},{"rel":"locations","href":"http://localhost:3003/locations/search?team_id=5"},{"rel":"managers","href":"http://localhost:3003/members/managers?team_id=5"},{"rel":"member_email_addresses","href":"http://localhost:3003/member_email_addresses/search?team_id=5"},{"rel":"member_files","href":"http://localhost:3003/member_files/search?team_id=5"},{"rel":"member_links","href":"http://localhost:3003/member_links/search?team_id=5"},{"rel":"member_phone_numbers","href":"http://localhost:3003/member_phone_numbers/search?team_id=5"},{"rel":"members","href":"http://localhost:3003/members/search?team_id=5"},{"rel":"members_preferences","href":"http://localhost:3003/members_preferences/search?team_id=5"},{"rel":"opponents","href":"http://localhost:3003/opponents/search?team_id=5"},{"rel":"owner","href":"http://localhost:3003/owner_members?team_id=5"},{"rel":"plan","href":"http://localhost:3003/plans/14"},{"rel":"sport","href":"http://localhost:3003/sports/1"},{"rel":"team_preferences","href":"http://localhost:3003/teams_preferences/5"},{"rel":"team_public_site","href":"http://localhost:3003/team_public_sites/5"},{"rel":"team_results","href":"http://localhost:3003/teams_results/5"},{"rel":"tracked_item_statuses","href":"http://localhost:3003/tracked_item_statuses/search?team_id=5"},{"rel":"tracked_items","href":"http://localhost:3003/tracked_items/search?team_id=5"}]}]}}'
108
+ http_version:
109
+ recorded_at: Tue, 11 Nov 2014 20:53:04 GMT
110
+ - request:
111
+ method: post
112
+ uri: http://localhost:3003/teams
113
+ body:
114
+ encoding: UTF-8
115
+ string: '{"template":{"data":[{"name":"name","value":"Teamsters"}]}}'
116
+ headers:
117
+ User-Agent:
118
+ - Faraday v0.9.0
119
+ Content-Type:
120
+ - application/json
121
+ Accept-Encoding:
122
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
123
+ Accept:
124
+ - "*/*"
125
+ response:
126
+ status:
127
+ code: 400
128
+ message: 'Bad Request '
129
+ headers:
130
+ Content-Type:
131
+ - application/vnd.collection+json
132
+ Content-Length:
133
+ - '135'
134
+ X-Content-Type-Options:
135
+ - nosniff
136
+ X-Ratelimit-Limit:
137
+ - '5000'
138
+ X-Ratelimit-Remaining:
139
+ - '4990'
140
+ X-Ratelimit-Reset:
141
+ - '1415740100'
142
+ Cache-Control:
143
+ - no-cache
144
+ X-Request-Id:
145
+ - 206bb383-7b6b-40d7-9cb4-b0c5b4f825aa
146
+ X-Runtime:
147
+ - '0.024213'
148
+ Server:
149
+ - WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
150
+ Date:
151
+ - Tue, 11 Nov 2014 20:55:14 GMT
152
+ Connection:
153
+ - Keep-Alive
154
+ body:
155
+ encoding: UTF-8
156
+ string: '{"collection":{"error":{"message":"sport_id can''t be blank; location_country
157
+ can''t be blank; You must enter a valid IANA time zone."}}}'
158
+ http_version:
159
+ recorded_at: Tue, 11 Nov 2014 20:55:14 GMT
160
+ recorded_with: VCR 2.9.3
data/spec/item_spec.rb CHANGED
@@ -1,5 +1,115 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe TeamsnapRb::Item do
4
- pending
5
- end
4
+ use_vcr_cassette "team", :allow_playback_repeats => true
5
+ let(:team_collection) { TeamsnapRb::Collection.new("http://localhost:3003/teams/1", {}, TeamsnapRb::Config.new) }
6
+ let(:team_item) { team_collection[0] }
7
+
8
+ it "represents a single item and therefore does not include Enumerable" do
9
+ expect(TeamsnapRb::Item).to_not include(Enumerable)
10
+ end
11
+
12
+ context "PATCH teams/1", :vcr do
13
+ describe "#save" do
14
+ it "successfully saves the item and returns it's collection" do
15
+ expect(team_item.with(:name => "Danger Rangers").save).to be_a(TeamsnapRb::Collection)
16
+ end
17
+
18
+ it "includes the item in the returned collection" do
19
+ expect(team_item.with(:name => "Danger Rangers").save.first.href).to eq(team_item.href)
20
+ end
21
+
22
+ it "includes the updated item's attributes in the returned collection" do
23
+ expect(team_item.with(:name => "Danger Rangers").save.first.name).to eq("Danger Rangers")
24
+ end
25
+ end
26
+ end
27
+
28
+ context "DELETE teams/1", :vcr do
29
+ describe "#delete" do
30
+ it "successfully deletes the item and returns true" do
31
+ expect(team_item.delete).to eq(true)
32
+ end
33
+ end
34
+ end
35
+
36
+ context "GET teams/1", :vcr do
37
+ describe "#href" do
38
+ it "returns 'teams/1' where 1 is the id of the item" do
39
+ expect(team_item.href).to eq("http://localhost:3003/teams/1")
40
+ end
41
+ end
42
+
43
+ describe "accessing item properties" do
44
+ it "provides direct access to item properties" do
45
+ expect(team_item.name).to eq("Test Mania")
46
+ end
47
+ end
48
+
49
+ describe "#data" do
50
+ let(:data) { team_item.data }
51
+
52
+ it "returns a Conglomerate::Array of attributes from the collection response's data section" do
53
+ expect(data).to be_a(Conglomerate::Array)
54
+ end
55
+
56
+ it "returns a Conglomerate::Datum for each data item in the Conglomerate::Array" do
57
+ expect(data.first).to be_a(Conglomerate::Datum)
58
+ end
59
+
60
+ it "returns the correct value for a given datum" do
61
+ expect(data.first.name).to eq("id")
62
+ expect(data.first.value).to eq(1)
63
+ end
64
+ end
65
+
66
+ describe "#template" do
67
+ it "returns a TeamsnapRb::Template" do
68
+ expect(team_item.template).to be_a(TeamsnapRb::Template)
69
+ end
70
+
71
+ it "caches the template on the Item class" do
72
+ team_item.template
73
+ expect(TeamsnapRb::Item.templates.keys).to include("team")
74
+ end
75
+ end
76
+
77
+ describe "#this" do
78
+ it "returns the collection this item belongs to" do
79
+ expect(team_item.this).to be_a(TeamsnapRb::Collection)
80
+ end
81
+
82
+ it "returns a collection with an href that is the generalized form of the specific item href" do
83
+ expect(team_item.href).to include(team_item.this.href)
84
+ end
85
+ end
86
+
87
+ describe "#links" do
88
+ it "returns a LinksProxy" do
89
+ expect(team_item.links).to be_a(TeamsnapRb::LinksProxy)
90
+ end
91
+
92
+ it "consists of an array of Links" do
93
+ expect(team_item.links.first).to be_a(TeamsnapRb::Link)
94
+ end
95
+
96
+ it "can be accessed like an array" do
97
+ expect(team_item.links.first.href).to eq("http://localhost:3003/assignments/search?team_id=1")
98
+ end
99
+ end
100
+
101
+ describe "#with(attrs)" do
102
+ it "returns a new TeamsnapRb::Item" do
103
+ expect(team_item.with(name: "Goofballs")).to be_a(TeamsnapRb::Item)
104
+ end
105
+
106
+ it "has the updated attributes on the new TeamsnapRb::Item" do
107
+ expect(team_item.with(name: "Goofballs").name).to eq("Goofballs")
108
+ end
109
+
110
+ it "creates a new object rather than mutating the existing object" do
111
+ expect{team_item.with(name: "Goofballs")}.to_not change(team_item, :name)
112
+ end
113
+ end
114
+ end
115
+ end
data/spec/link_spec.rb CHANGED
@@ -1,5 +1,43 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe TeamsnapRb::Link do
4
- pending
5
- end
4
+ let(:config) { TeamsnapRb::Config.new }
5
+ let(:collection) { double(
6
+ TeamsnapRb::Collection, :href => "http://localhost:3003/")
7
+ }
8
+ let(:conglomerate_link) { double(
9
+ Conglomerate::Link, :rel => "team",
10
+ :href => "http://localhost:3003/", :follow => collection
11
+ ) }
12
+ let(:link) { TeamsnapRb::Link.new(conglomerate_link, config) }
13
+
14
+ describe "#new" do
15
+ it "accepts a Conglomerate item as a link" do
16
+ expect{link}.to_not raise_exception
17
+ end
18
+ end
19
+
20
+ describe "#follow" do
21
+ use_vcr_cassette "root"
22
+
23
+ it "returns the Collection represented by that href" do
24
+ expect(link.follow).to be_a(TeamsnapRb::Collection)
25
+ end
26
+
27
+ it "returns the Collection represented by that href" do
28
+ expect(link.follow.href).to eq("http://localhost:3003/")
29
+ end
30
+ end
31
+
32
+ describe "#rel" do
33
+ it "returns the rel of the link passed in" do
34
+ expect(link.rel).to eq("team")
35
+ end
36
+ end
37
+
38
+ describe "#href" do
39
+ it "returns the href of the link passed in" do
40
+ expect(link.href).to eq("http://localhost:3003/")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe TeamsnapRb::LinksProxy do
4
+ use_vcr_cassette "root"
5
+ let(:links_proxy) { TeamsnapRb::Collection.new(
6
+ "http://localhost:3003", {}, TeamsnapRb::Config.new
7
+ ).links }
8
+
9
+ describe "#new" do
10
+ it "accepts an array of links from a collection+json response and a config" do
11
+ expect(links_proxy).to be_a(TeamsnapRb::LinksProxy)
12
+ end
13
+ end
14
+
15
+ describe "#rels" do
16
+ it "returns an array of the link names represented as symbols" do
17
+ expect(links_proxy.rels).to include(:teams, :members)
18
+ end
19
+ end
20
+
21
+ describe "sending a link name to the LinksProxy" do
22
+ use_vcr_cassette "teams"
23
+
24
+ it "follows the link if a matching link rel is found" do
25
+ expect(links_proxy.teams).to be_a(TeamsnapRb::Collection)
26
+ end
27
+
28
+ it "returns a TeamsnapRb::Collection of the matching rel as the link" do
29
+ expect(links_proxy.teams.href).to include("/teams")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe TeamsnapRb::QueriesProxy do
4
+ use_vcr_cassette "root"
5
+
6
+ let(:queries_proxy) { TeamsnapRb::Collection.new(
7
+ "http://localhost:3003", {}, TeamsnapRb::Config.new
8
+ ).queries }
9
+
10
+ describe "#new" do
11
+ it "accepts an array of queries from a collection+json response and a config" do
12
+ expect(queries_proxy).to be_a(TeamsnapRb::QueriesProxy)
13
+ end
14
+ end
15
+
16
+ describe "#rels" do
17
+ it "returns an array of the link names represented as symbols" do
18
+ expect(queries_proxy.rels).to include(:bulk_load)
19
+ end
20
+ end
21
+
22
+ describe "sending a link name to the QueriesProxy" do
23
+ it "raises a MissingQueryParameter exception if params are missing from the query" do
24
+ expect{queries_proxy.bulk_load}.to raise_exception(TeamsnapRb::Query::MissingQueryParameter)
25
+ end
26
+
27
+ it "returns a TeamsnapRB::Collection when the query executes successfully" do
28
+ expect(queries_proxy.bulk_load(:team_id => 1)).to be_a(TeamsnapRb::Collection)
29
+ end
30
+ end
31
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,19 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require "teamsnap_rb"
2
5
  require "pry"
6
+ require "webmock/rspec"
7
+ require "vcr"
3
8
 
4
9
  RSpec.configure do |config|
10
+ config.extend VCR::RSpec::Macros
5
11
  config.color = true
6
12
  config.order = "random"
7
13
  end
14
+
15
+ VCR.configure do |c|
16
+ c.configure_rspec_metadata!
17
+ c.cassette_library_dir = "spec/fixtures/cassettes"
18
+ c.hook_into :webmock
19
+ end
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ describe TeamsnapRb::Template do
4
+ use_vcr_cassette "teams", :match_requests_on => [:host, :path, :body]
5
+
6
+ let(:template) { TeamsnapRb::Collection.new(
7
+ "http://localhost:3003/teams", {}, TeamsnapRb::Config.new
8
+ ).template }
9
+
10
+ describe "#new" do
11
+ it "returns a template object from Collection#template" do
12
+ expect(template).to be_a(TeamsnapRb::Template)
13
+ end
14
+ end
15
+
16
+ describe "#build" do
17
+ it "returns an empty hash when no attributes are passed in" do
18
+ expect(template.build).to eq("template" => {})
19
+ end
20
+
21
+ it "returns a properly serialized template hash when attrs are passed in" do
22
+ expect(template.build("name" => "Teamsters")).to eq(
23
+ {
24
+ "template"=> {
25
+ "data"=>[{
26
+ "name"=>"name", "value"=>"Teamsters"
27
+ }]
28
+ }
29
+ }
30
+ )
31
+ end
32
+ end
33
+
34
+ describe "#data" do
35
+ it "returns a Conglomerate::Array of data that can be passed into the template" do
36
+ expect(template.data).to be_a(Conglomerate::Array)
37
+ end
38
+ end
39
+
40
+ describe "POST /teams via Template#push" do
41
+ it "returns a bad response (400) when the template fails to post" do
42
+ expect(template.push("name" => "Teamsters").status).to eq(400)
43
+ end
44
+
45
+ it "returns a success (200) when the template posts with all required data" do
46
+ expect(
47
+ template.push(
48
+ "name" => "Teamsters",
49
+ "sport_id" => 1,
50
+ "location_country" => "United States",
51
+ "location_postal_code" => "80951",
52
+ "time_zone" => "America/Denver"
53
+ ).status
54
+ ).to eq(201)
55
+ end
56
+ end
57
+ end