-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module KOSapiClient | ||
module Resource | ||
class DivisionsBuilder < RequestBuilder | ||
|
||
def courses | ||
raise 'Call #find({division_id}) before asking for courses' unless id_set? | ||
url_builder.set_path(id, 'courses') | ||
self | ||
end | ||
|
||
def subdivisions | ||
raise 'Call #find({division_id}) before asking for subdivisions' unless id_set? | ||
url_builder.set_path(id, 'subdivisions') | ||
self | ||
end | ||
|
||
def teachers | ||
raise 'Call #find({division_id}) before asking for teachers' unless id_set? | ||
url_builder.set_path(id, 'teachers') | ||
self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe KOSapiClient::Resource::DivisionsBuilder do | ||
|
||
let(:url_builder) { instance_double(KOSapiClient::URLBuilder, url: 'http://example.com') } | ||
let(:response) { double(foo: :bar) } | ||
let(:http_client) { double(send_request: response) } | ||
subject(:builder) { KOSapiClient::Resource::DivisionsBuilder.new('http://example.com', http_client, url_builder) } | ||
|
||
describe '#courses' do | ||
|
||
before { allow(url_builder).to receive(:set_path) } | ||
|
||
it 'throws error when division id is not set' do | ||
expect { builder.courses }.to raise_error(RuntimeError) | ||
end | ||
|
||
it 'return self' do | ||
builder.find(69) | ||
expect(builder.courses).to eq builder | ||
end | ||
|
||
it 'adds courses to URL' do | ||
expect(url_builder).to receive(:set_path).with(69, 'courses') | ||
builder.find(69).courses | ||
end | ||
end | ||
|
||
describe '#subdivisions' do | ||
|
||
before { allow(url_builder).to receive(:set_path) } | ||
|
||
it 'throws error when division id is not set' do | ||
expect { builder.subdivisions }.to raise_error(RuntimeError) | ||
end | ||
|
||
it 'return self' do | ||
builder.find(69) | ||
expect(builder.subdivisions).to eq builder | ||
end | ||
|
||
it 'adds subdivisions to URL' do | ||
expect(url_builder).to receive(:set_path).with(69, 'subdivisions') | ||
builder.find(69).subdivisions | ||
end | ||
end | ||
|
||
describe '#teachers' do | ||
|
||
before { allow(url_builder).to receive(:set_path) } | ||
|
||
it 'throws error when division id is not set' do | ||
expect { builder.teachers }.to raise_error(RuntimeError) | ||
end | ||
|
||
it 'return self' do | ||
builder.find(69) | ||
expect(builder.teachers).to eq builder | ||
end | ||
|
||
it 'adds teachers to URL' do | ||
expect(url_builder).to receive(:set_path).with(69, 'teachers') | ||
builder.find(69).teachers | ||
end | ||
end | ||
end |