teamsnap_rb 1.3.3 → 2.0.0.beta
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +131 -29
- data/lib/config/inflecto.rb +13 -0
- data/lib/config/oj.rb +5 -0
- data/lib/teamsnap.rb +36 -376
- data/lib/teamsnap/api.rb +113 -0
- data/lib/teamsnap/auth_middleware.rb +62 -0
- data/lib/teamsnap/client.rb +51 -0
- data/lib/teamsnap/collection.rb +125 -0
- data/lib/teamsnap/item.rb +100 -0
- data/lib/teamsnap/response.rb +101 -0
- data/lib/teamsnap/structure.rb +80 -0
- data/lib/teamsnap/version.rb +1 -1
- data/spec/cassettes/apiv3-init.yml +756 -124
- data/spec/cassettes/client/when_calling_via_s_on_the_client/does_not_raise_an_error_when_the_HTTP_actions_are_called.yml +56 -0
- data/spec/cassettes/structure/_create_collection_class/registers_new_classes_via_introspection_of_the_root_collection.yml +110 -0
- data/spec/cassettes/structure/_create_collection_class/sets_the_href_attribute_on_the_new_class.yml +57 -0
- data/spec/cassettes/structure/_init/has_all_classes_in_schema_loaded_except_for_exceptions_list_endpoints.yml +56 -0
- data/spec/cassettes/structure/has_all_classes_in_schema_loaded_except_for_exceptions_list_endpoints.yml +56 -0
- data/spec/cassettes/teamsnap__client/when_calling_via_s_on_the_client/does_not_raise_an_error_when_the_HTTP_actions_are_called.yml +69 -0
- data/spec/cassettes/teamsnap__client/when_calling_via_s_on_the_client/passes_them_to_the_faraday_client_using_method_missing.yml +69 -0
- data/spec/cassettes/teamsnap__collection/adds_find_if_search_is_available.yml +61 -0
- data/spec/cassettes/teamsnap__collection/adds_href_to_items.yml +62 -0
- data/spec/cassettes/teamsnap__collection/can_follow_plural_links.yml +179 -0
- data/spec/cassettes/teamsnap__collection/can_follow_singular_links.yml +120 -0
- data/spec/cassettes/teamsnap__collection/can_handle_links_with_no_data.yml +107 -0
- data/spec/cassettes/{teamsnap_rb/can_handle_errors_generated_by_command.yml → teamsnap__collection/can_handle_no_argument_errors_generated_by_command.yml} +10 -16
- data/spec/cassettes/teamsnap__collection/handles_executing_an_action_via_commands.yml +64 -0
- data/spec/cassettes/teamsnap__collection/handles_executing_an_action_via_commands_with_multiple_params.yml +70 -0
- data/spec/cassettes/teamsnap__collection/handles_fetching_data_via_queries.yml +61 -0
- data/spec/cassettes/teamsnap__collection/handles_queries_with_no_data.yml +57 -0
- data/spec/cassettes/teamsnap__collection/raises_an_exception_if_find_returns_nothing.yml +57 -0
- data/spec/cassettes/teamsnap__collection/supports_relations_with_expected_behaviors/when_a_plural_relation_is_called/responds_with_an_array_of_objects_when_successful.yml +117 -0
- data/spec/cassettes/teamsnap__collection/supports_relations_with_expected_behaviors/when_a_plural_relation_is_called/responds_with_an_empty_array_when_no_objects_exist.yml +111 -0
- data/spec/cassettes/teamsnap__collection/supports_relations_with_expected_behaviors/when_a_singular_relation_is_called/responds_with_nil_if_it_does_NOT_exist.yml +111 -0
- data/spec/cassettes/teamsnap__collection/supports_relations_with_expected_behaviors/when_a_singular_relation_is_called/responds_with_the_object_if_it_exists.yml +124 -0
- data/spec/cassettes/teamsnap__structure/_create_collection_class/registers_new_classes_via_introspection_of_the_root_collection.yml +57 -0
- data/spec/cassettes/teamsnap__structure/_create_collection_class/sets_the_href_attribute_on_the_new_class.yml +57 -0
- data/spec/cassettes/teamsnap__structure/_init/has_all_classes_in_schema_loaded_except_for_exceptions_list_endpoints.yml +69 -0
- data/spec/cassettes/teamsnap_rb/_bulk_load/can_handle_an_empty_bulk_load.yml +55 -0
- data/spec/cassettes/teamsnap_rb/{can_handle_an_error_with_bulk_load.yml → _bulk_load/can_handle_an_error_with_bulk_load.yml} +11 -23
- data/spec/cassettes/teamsnap_rb/_bulk_load/can_use_bulk_load.yml +121 -0
- data/spec/cassettes/teamsnap_rb/_client_send/when_sent_a_known_via_/calls_DELETE_on_the_given_client.yml +2405 -0
- data/spec/cassettes/teamsnap_rb/_client_send/when_sent_a_known_via_/calls_GET_on_the_given_client.yml +69 -0
- data/spec/cassettes/teamsnap_rb/_client_send/when_sent_a_known_via_/calls_PATCH_on_the_given_client.yml +2404 -0
- data/spec/cassettes/teamsnap_rb/_client_send/when_sent_a_known_via_/calls_POST_on_the_given_client.yml +2404 -0
- data/spec/cassettes/teamsnap_rb/_run/processes_the_response.yml +267 -0
- data/spec/cassettes/teamsnap_rb/adds_find_if_search_is_available.yml +27 -30
- data/spec/cassettes/teamsnap_rb/adds_href_to_items.yml +31 -19
- data/spec/cassettes/teamsnap_rb/can_follow_plural_links.yml +118 -67
- data/spec/cassettes/teamsnap_rb/can_follow_singular_links.yml +59 -56
- data/spec/cassettes/teamsnap_rb/can_handle_links_with_no_data.yml +48 -38
- data/spec/cassettes/teamsnap_rb/can_handle_no_argument_errors_generated_by_command.yml +42 -0
- data/spec/cassettes/teamsnap_rb/handles_executing_an_action_via_commands.yml +32 -20
- data/spec/cassettes/teamsnap_rb/handles_executing_an_action_via_commands_with_multiple_params.yml +29 -404
- data/spec/cassettes/teamsnap_rb/handles_fetching_data_via_queries.yml +26 -23
- data/spec/cassettes/teamsnap_rb/handles_queries_with_no_data.yml +24 -28
- data/spec/cassettes/teamsnap_rb/raises_an_exception_if_find_returns_nothing.yml +24 -28
- data/spec/cassettes/teamsnap_rb/supports_relations_with_expected_behaviors/when_a_plural_relation_is_called/responds_with_an_array_of_objects_when_successful.yml +53 -45
- data/spec/cassettes/teamsnap_rb/supports_relations_with_expected_behaviors/when_a_plural_relation_is_called/responds_with_an_empty_array_when_no_objects_exist.yml +50 -54
- data/spec/cassettes/teamsnap_rb/supports_relations_with_expected_behaviors/when_a_singular_relation_is_called/responds_with_nil_if_it_does_NOT_exist.yml +50 -54
- data/spec/cassettes/teamsnap_rb/supports_relations_with_expected_behaviors/when_a_singular_relation_is_called/responds_with_the_object_if_it_exists.yml +59 -58
- data/spec/spec_helper.rb +2 -0
- data/spec/teamsnap/client_spec.rb +75 -0
- data/spec/teamsnap/collection_spec.rb +155 -0
- data/spec/teamsnap/item_spec.rb +155 -0
- data/spec/teamsnap/structure_spec.rb +63 -0
- data/spec/teamsnap_spec.rb +169 -157
- data/teamsnap_rb.gemspec +1 -1
- metadata +92 -15
- data/spec/cassettes/teamsnap_rb/can_handle_an_empty_bulk_load.yml +0 -60
- data/spec/cassettes/teamsnap_rb/can_use_bulk_load.yml +0 -74
@@ -0,0 +1,155 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "teamsnap"
|
3
|
+
|
4
|
+
RSpec.describe "teamsnap__item", :vcr => true do
|
5
|
+
before(:all) do
|
6
|
+
VCR.use_cassette("apiv3-init") do
|
7
|
+
TeamSnap.init(
|
8
|
+
:url => ROOT_TEST_URL,
|
9
|
+
:client_id => "classic",
|
10
|
+
:client_secret => "dont_tell_the_cops"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".load_items" do
|
16
|
+
it "returns TeamSnap::Object for the given json item" do
|
17
|
+
collection = {
|
18
|
+
:items => [
|
19
|
+
{
|
20
|
+
:href => "http://localhost:3000/teams/10",
|
21
|
+
:data => [
|
22
|
+
{
|
23
|
+
:name => "id",
|
24
|
+
:value => 10
|
25
|
+
},
|
26
|
+
{
|
27
|
+
:name => "type",
|
28
|
+
:value => "team"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
:name => "division_name",
|
32
|
+
:value => nil
|
33
|
+
},
|
34
|
+
{
|
35
|
+
:name => "division_id",
|
36
|
+
:value => nil
|
37
|
+
},
|
38
|
+
{
|
39
|
+
:name => "is_archived_season",
|
40
|
+
:value => false
|
41
|
+
},
|
42
|
+
{
|
43
|
+
:name => "is_retired",
|
44
|
+
:value => false
|
45
|
+
},
|
46
|
+
{
|
47
|
+
:name => "league_name",
|
48
|
+
:value => nil
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:name => "league_url",
|
52
|
+
:value => nil
|
53
|
+
},
|
54
|
+
{
|
55
|
+
:name => "is_in_league",
|
56
|
+
:value => false
|
57
|
+
},
|
58
|
+
{
|
59
|
+
:name => "location_country",
|
60
|
+
:value => "United States"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
:name => "location_postal_code",
|
64
|
+
:value => "80951"
|
65
|
+
},
|
66
|
+
{
|
67
|
+
:name => "location_latitude",
|
68
|
+
:value => nil
|
69
|
+
},
|
70
|
+
{
|
71
|
+
:name => "location_longitude",
|
72
|
+
:value => nil
|
73
|
+
},
|
74
|
+
{
|
75
|
+
:name => "name",
|
76
|
+
:value => "Cheerleading Team"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
:name => "plan_id",
|
80
|
+
:value => 33
|
81
|
+
},
|
82
|
+
{
|
83
|
+
:name => "billed_at",
|
84
|
+
:value => "2016-02-08T00:00:00.000+00:00"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
:name => "season_name",
|
88
|
+
:value => nil
|
89
|
+
},
|
90
|
+
{
|
91
|
+
:name => "sport_id",
|
92
|
+
:value => 31
|
93
|
+
},
|
94
|
+
{
|
95
|
+
:name => "time_zone_description",
|
96
|
+
:value => "Mountain Time (US & Canada)"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
:name => "time_zone_iana_name",
|
100
|
+
:value => "America/Denver"
|
101
|
+
},
|
102
|
+
{
|
103
|
+
:name => "time_zone_offset",
|
104
|
+
:value => "-07:00"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
:name => "updated_at",
|
108
|
+
:value => "2016-02-08T20:04:21Z",
|
109
|
+
:type => "DateTime"
|
110
|
+
},
|
111
|
+
{
|
112
|
+
:name => "created_at",
|
113
|
+
:value => "2016-02-08T20:04:06Z",
|
114
|
+
:type => "DateTime"
|
115
|
+
},
|
116
|
+
{
|
117
|
+
:name => "has_reached_roster_limit",
|
118
|
+
:value => false
|
119
|
+
},
|
120
|
+
{
|
121
|
+
:name => "roster_limit",
|
122
|
+
:value => 4000
|
123
|
+
},
|
124
|
+
{
|
125
|
+
:name => "has_exportable_media",
|
126
|
+
:value => false
|
127
|
+
},
|
128
|
+
{
|
129
|
+
:name => "can_export_media",
|
130
|
+
:value => false
|
131
|
+
},
|
132
|
+
{
|
133
|
+
:name => "last_accessed_at",
|
134
|
+
:value => nil,
|
135
|
+
:type => "DateTime"
|
136
|
+
},
|
137
|
+
{
|
138
|
+
:name => "media_storage_used",
|
139
|
+
:value => 0
|
140
|
+
},
|
141
|
+
{
|
142
|
+
:name => "humanized_media_storage_used",
|
143
|
+
:value => "0 B"
|
144
|
+
}
|
145
|
+
]
|
146
|
+
}
|
147
|
+
]
|
148
|
+
}
|
149
|
+
|
150
|
+
expect(
|
151
|
+
TeamSnap::Item.load_items(TeamSnap.root_client, collection)[0].class
|
152
|
+
).to eq(TeamSnap::Team)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "teamsnap"
|
3
|
+
|
4
|
+
RSpec.describe "teamsnap__structure", :vcr => true do
|
5
|
+
|
6
|
+
describe ".create_collection_class" do
|
7
|
+
let(:client) {
|
8
|
+
client = TeamSnap::Client.new({
|
9
|
+
:url => ROOT_TEST_URL,
|
10
|
+
:client_id => "classic",
|
11
|
+
:client_secret => "dont_tell_the_cops"
|
12
|
+
})
|
13
|
+
}
|
14
|
+
let(:resp) { TeamSnap.run(client, :get, "/teams", {}) }
|
15
|
+
|
16
|
+
it "registers new classes via introspection of the root collection" do
|
17
|
+
TeamSnap::Structure.send(
|
18
|
+
:create_collection_class,
|
19
|
+
"teams",
|
20
|
+
"http://localhost:3000/teams",
|
21
|
+
resp,
|
22
|
+
nil
|
23
|
+
)
|
24
|
+
expect { TeamSnap::Team }.to_not raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets the href attribute on the new class" do
|
28
|
+
TeamSnap::Structure.send(
|
29
|
+
:create_collection_class,
|
30
|
+
"teams",
|
31
|
+
"http://localhost:3000/teams",
|
32
|
+
resp,
|
33
|
+
nil
|
34
|
+
)
|
35
|
+
|
36
|
+
expect(TeamSnap::Team.href).to eq("#{ROOT_TEST_URL}/teams")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".init" do
|
41
|
+
before(:all) do
|
42
|
+
VCR.use_cassette("apiv3-init") do
|
43
|
+
TeamSnap.init(
|
44
|
+
:url => ROOT_TEST_URL,
|
45
|
+
:client_id => "classic",
|
46
|
+
:client_secret => "dont_tell_the_cops"
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has all classes in schema loaded except for exceptions list endpoints" do
|
52
|
+
collection = TeamSnap.run(TeamSnap.root_client, :get, "/", {})
|
53
|
+
links = collection.fetch(:links) { [] }
|
54
|
+
.select{|l| !TeamSnap::EXCLUDED_RELS.include?(l[:rel]) }
|
55
|
+
|
56
|
+
links.each do |obj|
|
57
|
+
expect {
|
58
|
+
Object.const_get("TeamSnap::" + Inflecto.classify(obj[:rel]))
|
59
|
+
}.to_not raise_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/teamsnap_spec.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "teamsnap"
|
3
3
|
|
4
|
-
RSpec.describe "teamsnap_rb" do
|
4
|
+
RSpec.describe "teamsnap_rb", :vcr => true do
|
5
5
|
let(:default_url) { TeamSnap::DEFAULT_URL }
|
6
6
|
let(:specified_url) { "https://url-fun-zone.com" }
|
7
7
|
let(:response) { Typhoeus::Response.new(
|
8
|
-
code: 200,
|
8
|
+
code: 200,
|
9
|
+
headers: { "content-type" => "application/json" },
|
10
|
+
body: { :collection => { :links => [] } }.to_json
|
9
11
|
) }
|
12
|
+
let(:client_id) { "classic" }
|
13
|
+
let(:client_secret) { "dont_tell_the_cops" }
|
10
14
|
|
11
15
|
describe ".init" do
|
12
16
|
it "requires token or client id and client secret" do
|
@@ -18,7 +22,7 @@ RSpec.describe "teamsnap_rb" do
|
|
18
22
|
it "initializes with default url and token auth" do
|
19
23
|
Typhoeus.stub(%r(#{default_url})).and_return(response)
|
20
24
|
|
21
|
-
TeamSnap.init(:token => "mytoken"
|
25
|
+
TeamSnap.init(:token => "mytoken")
|
22
26
|
end
|
23
27
|
|
24
28
|
it "requires client secret when given client id" do
|
@@ -31,7 +35,7 @@ RSpec.describe "teamsnap_rb" do
|
|
31
35
|
Typhoeus.stub(/#{default_url}/).and_return(response)
|
32
36
|
|
33
37
|
TeamSnap.init(
|
34
|
-
:client_id => "myclient", :client_secret => "mysecret"
|
38
|
+
:client_id => "myclient", :client_secret => "mysecret"
|
35
39
|
)
|
36
40
|
end
|
37
41
|
|
@@ -39,190 +43,198 @@ RSpec.describe "teamsnap_rb" do
|
|
39
43
|
Typhoeus.stub(/#{specified_url}/).and_return(response)
|
40
44
|
|
41
45
|
TeamSnap.init(
|
42
|
-
:client_id => "myclient", :client_secret => "mysecret",
|
46
|
+
:client_id => "myclient", :client_secret => "mysecret",
|
43
47
|
:url => specified_url
|
44
48
|
)
|
45
49
|
end
|
46
50
|
end
|
47
|
-
end
|
48
|
-
|
49
|
-
RSpec.describe "teamsnap_rb", :vcr => true do
|
50
|
-
before(:all) do
|
51
|
-
VCR.use_cassette("apiv3-init") do
|
52
|
-
TeamSnap.init(
|
53
|
-
:url => ROOT_TEST_URL,
|
54
|
-
:backup_cache => false,
|
55
|
-
:client_id => "classic",
|
56
|
-
:client_secret => "dont_tell_the_cops"
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "registers new classes via introspection of the root collection" do
|
62
|
-
expect { TeamSnap::Team }.to_not raise_error
|
63
|
-
end
|
64
|
-
|
65
|
-
it "handles fetching data via queries" do
|
66
|
-
ts = TeamSnap::Team.search(:id => 1)
|
67
|
-
|
68
|
-
expect(ts).to_not be_empty
|
69
|
-
expect(ts[0].id).to eq(1)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "handles queries with no data" do
|
73
|
-
ts = TeamSnap::Team.search(:id => 0)
|
74
|
-
|
75
|
-
expect(ts).to be_empty
|
76
|
-
end
|
77
51
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
52
|
+
describe ".run" do
|
53
|
+
context "works when" do
|
54
|
+
after(:each) do
|
55
|
+
VCR.use_cassette("apiv3-init") do
|
56
|
+
TeamSnap.init(
|
57
|
+
:url => ROOT_TEST_URL,
|
58
|
+
:client_id => client_id,
|
59
|
+
:client_secret => client_secret
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
89
63
|
|
90
|
-
|
91
|
-
|
92
|
-
|
64
|
+
it "calls client_send with the given attributes" do
|
65
|
+
expect(TeamSnap).to receive("client_send").with(any_args).and_call_original
|
66
|
+
end
|
93
67
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
:token => "6-classic-dont_tell_the_cops"
|
99
|
-
)
|
100
|
-
|
101
|
-
ms = TeamSnap::Team.invite(
|
102
|
-
:team_id => 1, :member_id => [9, 11], :notify_as_member_id => 3,
|
103
|
-
:introduction => "Welcome! This is our team\n ...the superstars!"
|
104
|
-
)
|
105
|
-
|
106
|
-
expect(ms.size).to eq(2)
|
107
|
-
expect(ms.map(&:id)).to eq([9, 11])
|
108
|
-
expect(ms.map(&:is_invited)).to eq([true, true])
|
109
|
-
end
|
68
|
+
it "the API responds and loads the collection" do
|
69
|
+
expect(TeamSnap::Response).to receive("load_collection").with(any_args).and_call_original
|
70
|
+
end
|
71
|
+
end
|
110
72
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
73
|
+
it "processes the response" do
|
74
|
+
VCR.use_cassette("apiv3-init") do
|
75
|
+
TeamSnap.init(
|
76
|
+
:url => ROOT_TEST_URL,
|
77
|
+
:client_id => client_id,
|
78
|
+
:client_secret => client_secret
|
79
|
+
)
|
80
|
+
end
|
119
81
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
82
|
+
client = TeamSnap::Client.new({
|
83
|
+
:url => ROOT_TEST_URL,
|
84
|
+
:client_id => client_id,
|
85
|
+
:client_secret => client_secret
|
86
|
+
})
|
87
|
+
via = :get
|
88
|
+
href = "/"
|
89
|
+
args = {}
|
90
|
+
|
91
|
+
expect(TeamSnap.run(client, via, href, args).fetch(:links)).to_not be_empty
|
92
|
+
expect(TeamSnap.run(client, via, href, args).fetch(:queries)).to_not be_empty
|
93
|
+
expect(TeamSnap.run(client, via, href, args).fetch(:commands)).to_not be_empty
|
94
|
+
expect(TeamSnap.run(client, via, href, args).fetch(:href)).to eq(ROOT_TEST_URL + href)
|
95
|
+
end
|
127
96
|
end
|
128
97
|
|
129
|
-
|
130
|
-
|
98
|
+
describe ".client_send" do
|
99
|
+
let(:client) {
|
100
|
+
TeamSnap::Client.new({
|
101
|
+
:url => ROOT_TEST_URL,
|
102
|
+
:client_id => client_id,
|
103
|
+
:client_secret => client_secret
|
104
|
+
})
|
105
|
+
}
|
106
|
+
|
107
|
+
context "when sent a known `via`" do
|
108
|
+
it "calls GET on the given client" do
|
109
|
+
via = :get
|
110
|
+
href = "/"
|
111
|
+
args = {}
|
112
|
+
|
113
|
+
expect(client).to receive(via).with(href, args).and_call_original
|
114
|
+
TeamSnap.client_send(client, via, href, args)
|
115
|
+
end
|
131
116
|
|
132
|
-
|
133
|
-
|
117
|
+
it "calls DELETE on the given client" do
|
118
|
+
via = :delete
|
119
|
+
href = "/"
|
120
|
+
args = {}
|
134
121
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
}.to raise_error(
|
139
|
-
TeamSnap::NotFound,
|
140
|
-
"Could not find a TeamSnap::Team with an id of '0'."
|
141
|
-
)
|
142
|
-
end
|
122
|
+
expect(client).to receive(via).with(href, args).and_call_original
|
123
|
+
TeamSnap.client_send(client, via, href, args)
|
124
|
+
end
|
143
125
|
|
144
|
-
|
145
|
-
|
146
|
-
|
126
|
+
it "calls POST on the given client" do
|
127
|
+
via = :post
|
128
|
+
href = "/"
|
129
|
+
args = {}
|
147
130
|
|
148
|
-
|
149
|
-
|
131
|
+
expect(client).to receive(via).with(href).and_call_original
|
132
|
+
TeamSnap.client_send(client, via, href, args)
|
133
|
+
end
|
150
134
|
|
151
|
-
|
152
|
-
|
153
|
-
|
135
|
+
it "calls PATCH on the given client" do
|
136
|
+
via = :patch
|
137
|
+
href = "/"
|
138
|
+
args = {}
|
154
139
|
|
155
|
-
|
156
|
-
|
140
|
+
expect(client).to receive(via).with(href).and_call_original
|
141
|
+
TeamSnap.client_send(client, via, href, args)
|
142
|
+
end
|
143
|
+
end
|
157
144
|
|
158
|
-
|
159
|
-
|
160
|
-
|
145
|
+
context "when sent unknown `via`" do
|
146
|
+
it "responds with an error" do
|
147
|
+
expect {
|
148
|
+
TeamSnap.client_send(client, :unknown, "/", {})
|
149
|
+
}.to raise_error(
|
150
|
+
TeamSnap::Error,
|
151
|
+
"Don't know how to run `unknown`"
|
152
|
+
)
|
153
|
+
end
|
161
154
|
|
162
|
-
|
163
|
-
|
155
|
+
it "responds with an error" do
|
156
|
+
expect {
|
157
|
+
TeamSnap.client_send(client, :head, "/", {})
|
158
|
+
}.to raise_error(
|
159
|
+
TeamSnap::Error,
|
160
|
+
"Don't know how to run `head`"
|
161
|
+
)
|
162
|
+
end
|
164
163
|
|
165
|
-
|
166
|
-
|
164
|
+
it "responds with an error" do
|
165
|
+
expect {
|
166
|
+
TeamSnap.client_send(client, :options, "/", {})
|
167
|
+
}.to raise_error(
|
168
|
+
TeamSnap::Error,
|
169
|
+
"Don't know how to run `options`"
|
170
|
+
)
|
171
|
+
end
|
167
172
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
173
|
+
it "responds with an error" do
|
174
|
+
expect {
|
175
|
+
TeamSnap.client_send(client, :trace, "/", {})
|
176
|
+
}.to raise_error(
|
177
|
+
TeamSnap::Error,
|
178
|
+
"Don't know how to run `trace`"
|
179
|
+
)
|
180
|
+
end
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
TeamSnap::Error,
|
189
|
-
"You must include a team_id parameter"
|
190
|
-
)
|
191
|
-
end
|
192
|
-
|
193
|
-
it "adds href to items" do
|
194
|
-
m = TeamSnap::Member.find(1)
|
195
|
-
|
196
|
-
expect(m.href).to eq("#{ROOT_TEST_URL}/members/1")
|
197
|
-
end
|
184
|
+
describe ".bulk_load" do
|
185
|
+
before(:all) do
|
186
|
+
VCR.use_cassette("apiv3-init") do
|
187
|
+
TeamSnap.init(
|
188
|
+
:url => ROOT_TEST_URL,
|
189
|
+
:client_id => "classic",
|
190
|
+
:client_secret => "dont_tell_the_cops"
|
191
|
+
)
|
192
|
+
end
|
193
|
+
end
|
198
194
|
|
199
|
-
|
200
|
-
|
195
|
+
it "can use bulk load" do
|
196
|
+
cs = TeamSnap.bulk_load(
|
197
|
+
TeamSnap.root_client,
|
198
|
+
:team_id => 1,
|
199
|
+
:types => "team,member"
|
200
|
+
)
|
201
201
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
202
|
+
expect(cs).to_not be_empty
|
203
|
+
expect(cs.size).to eq(18)
|
204
|
+
expect(cs[0]).to be_a(TeamSnap::Team)
|
205
|
+
expect(cs[0].id).to eq(1)
|
206
|
+
cs[3..17].each.with_index(4) do |c, idx|
|
207
|
+
expect(c).to be_a(TeamSnap::Member)
|
208
|
+
expect(c.id).to eq(idx)
|
207
209
|
end
|
210
|
+
end
|
208
211
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
212
|
+
it "can handle an empty bulk load" do
|
213
|
+
cs = TeamSnap.bulk_load(
|
214
|
+
TeamSnap.root_client,
|
215
|
+
:team_id => 0,
|
216
|
+
:types => "team,member"
|
217
|
+
)
|
218
|
+
|
219
|
+
expect(cs).to be_empty
|
214
220
|
end
|
215
221
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
222
|
+
it "expects a client as the first parameter" do
|
223
|
+
expect {
|
224
|
+
TeamSnap.bulk_load
|
225
|
+
}.to raise_error(
|
226
|
+
ArgumentError,
|
227
|
+
"wrong number of arguments (0 for 1+)"
|
228
|
+
)
|
229
|
+
end
|
221
230
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
231
|
+
it "can handle an error with bulk load" do
|
232
|
+
expect {
|
233
|
+
TeamSnap.bulk_load(TeamSnap.root_client)
|
234
|
+
}.to raise_error(
|
235
|
+
TeamSnap::Error,
|
236
|
+
"You must include a team_id parameter"
|
237
|
+
)
|
226
238
|
end
|
227
239
|
end
|
228
240
|
end
|