Skip to content

Commit

Permalink
Merge 420cfc9 into 30f49fa
Browse files Browse the repository at this point in the history
  • Loading branch information
simactom committed Jan 21, 2018
2 parents 30f49fa + 420cfc9 commit f20dcdc
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/kosapi_client/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ApiClient
include ResourceMapper

# accessible resources definition
resource :branches
resource :courses
resource :course_events
resource :divisions
Expand Down
1 change: 1 addition & 0 deletions lib/kosapi_client/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
require 'kosapi_client/entity/semester'
require 'kosapi_client/entity/student'
require 'kosapi_client/entity/exam'
require 'kosapi_client/entity/branch'
15 changes: 15 additions & 0 deletions lib/kosapi_client/entity/branch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module KOSapiClient
module Entity
class Branch < BaseEntity
map_data :abbrev
map_data :capacity, Integer
map_data :code
map_data :description, MLString
map_data :diploma_name, MLString
map_data :division, Link
map_data :guarantor, Link
map_data :name, MLString
map_data :open_for_admission, Boolean
end
end
end
1 change: 1 addition & 0 deletions lib/kosapi_client/resource.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'kosapi_client/request_builder'
require 'kosapi_client/resource/branches_builder'
require 'kosapi_client/resource/courses_builder'
require 'kosapi_client/resource/parallels_builder'
require 'kosapi_client/resource/exams_builder'
Expand Down
11 changes: 11 additions & 0 deletions lib/kosapi_client/resource/branches_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module KOSapiClient
module Resource
class BranchesBuilder < RequestBuilder
def study_plans
raise 'Call #find before asking for branch\'s study plans' unless id_set?
url_builder.set_path(id, 'studyPlans')
self
end
end
end
end
25 changes: 25 additions & 0 deletions spec/kosapi_client/entity/branch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe KOSapiClient::Entity::Branch do
let(:attributes) { { capacity: '60',
code: '3902R031',
division: {:xlink_href=>"divisions/13136/", :__content__=>"katedra počítačů"},
diploma_name: [{:xml_lang=>"cs", :__content__=>"Softwarové inženýrství"}, {:xml_lang=>"en", :__content__=>"Software Engineering"}],
guarantor: {:xlink_href=>"people/jelinek/", :__content__=>"doc. Ing. Ivan Jelínek CSc."},
name: [{:xml_lang=>"cs", :__content__=>"Softwarové inženýrství"}, {:xml_lang=>"en", :__content__=>"Software Engineering"}],
open_for_admission: "true"

} }

it 'parses branch attributes' do
branch = KOSapiClient::Entity::Branch.parse(attributes)
expect(branch.capacity).to eq 60
expect(branch.code).to eq '3902R031'
expect(branch.division).to be_an_instance_of KOSapiClient::Entity::Link
expect(branch.division.link_href).to eq 'divisions/13136/'
expect(branch.division.link_title).to eq 'katedra počítačů'
expect(branch.guarantor).to be_an_instance_of KOSapiClient::Entity::Link
expect(branch.guarantor.link_href).to eq 'people/jelinek/'
expect(branch.guarantor.link_title).to eq 'doc. Ing. Ivan Jelínek CSc.'
end
end
28 changes: 28 additions & 0 deletions spec/kosapi_client/resource/branches_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

describe KOSapiClient::Resource::BranchesBuilder 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::BranchesBuilder.new('http://example.com', http_client, url_builder)}

describe '#study_plans' do

before { allow(url_builder).to receive(:set_path) }

it 'throws error when branch id is not set' do
expect { builder.study_plans }.to raise_error(RuntimeError)
end

it 'return self' do
builder.find(69)
expect(builder.study_plans).to eq builder
end

it 'adds studyPlans to URL' do
expect(url_builder).to receive(:set_path).with(69, 'studyPlans')
builder.find(69).study_plans
end
end
end

0 comments on commit f20dcdc

Please sign in to comment.