From 67696a72d7fc578e4d498cc02cf64b6991086269 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Fri, 28 Aug 2015 15:11:52 -0500 Subject: [PATCH] VRFS-3359 : Teacher API work * Return distinct experience collections for teaching, education, and awards. * Update tests for new behavior. * Responders for language and subject APIs. --- ruby/lib/jam_ruby/models/teacher.rb | 2 +- .../controllers/api_languages_controller.rb | 1 + .../controllers/api_subjects_controller.rb | 1 + web/app/views/api_teachers/detail.rabl | 43 +++++++++++++++++-- .../api_teachers_controller_spec.rb | 9 ++-- web/spec/factories.rb | 4 +- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ruby/lib/jam_ruby/models/teacher.rb b/ruby/lib/jam_ruby/models/teacher.rb index 625d26f7d..bb4a57bbc 100644 --- a/ruby/lib/jam_ruby/models/teacher.rb +++ b/ruby/lib/jam_ruby/models/teacher.rb @@ -3,7 +3,7 @@ module JamRuby include HtmlSanitize html_sanitize strict: [:biography, :website] attr_accessor :validate_introduction, :validate_basics, :validate_pricing - attr_accessible :teacher_experiences, :experiences_teaching, :experiences_education, :experiences_award + attr_accessible :genres, :teacher_experiences, :experiences_teaching, :experiences_education, :experiences_award has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "teachers_genres", :order=>"description" has_and_belongs_to_many :instruments, :class_name => "JamRuby::Instrument", :join_table => "teachers_instruments", :order=>"description" has_and_belongs_to_many :subjects, :class_name => "JamRuby::Subject", :join_table => "teachers_subjects", :order=>"description" diff --git a/web/app/controllers/api_languages_controller.rb b/web/app/controllers/api_languages_controller.rb index 9e5c3fa8c..9a47ce16a 100644 --- a/web/app/controllers/api_languages_controller.rb +++ b/web/app/controllers/api_languages_controller.rb @@ -4,6 +4,7 @@ class ApiLanguagesController < ApiController def index @languages = Language.order(:description) + respond_with @languages end def show diff --git a/web/app/controllers/api_subjects_controller.rb b/web/app/controllers/api_subjects_controller.rb index 8a343ce10..c2e46ba61 100644 --- a/web/app/controllers/api_subjects_controller.rb +++ b/web/app/controllers/api_subjects_controller.rb @@ -4,6 +4,7 @@ class ApiSubjectsController < ApiController def index @subjects = Subject.order(:description) + respond_with @subjects end def show diff --git a/web/app/views/api_teachers/detail.rabl b/web/app/views/api_teachers/detail.rabl index 0cb9af753..57cd5ce70 100644 --- a/web/app/views/api_teachers/detail.rabl +++ b/web/app/views/api_teachers/detail.rabl @@ -32,19 +32,54 @@ attributes :id, :errors -node :instruments do +node :instruments do @teacher.instruments.collect{|o|o.id} end -node :subjects do +node :subjects do @teacher.subjects.collect{|o|o.id} end -node :genres do +node :genres do @teacher.genres.collect{|o|o.id} end -node :languages do +node :languages do @teacher.languages.collect{|o|o.id} end +node :experience_teaching do + @teacher.experiences_teaching.collect do |o| + { + name: o.name, + experience_type: o.experience_type, + organization: o.organization, + start_year: o.start_year, + end_year: o.end_year + } + end # collect +end + +node :experience_education do + @teacher.experiences_education.collect do |o| + { + name: o.name, + experience_type: o.experience_type, + organization: o.organization, + start_year: o.start_year, + end_year: o.end_year + } + end # collect +end + +node :experience_award do + @teacher.experiences_award.collect do |o| + { + name: o.name, + experience_type: o.experience_type, + organization: o.organization, + start_year: o.start_year, + end_year: o.end_year + } + end # collect +end diff --git a/web/spec/controllers/api_teachers_controller_spec.rb b/web/spec/controllers/api_teachers_controller_spec.rb index 1e1d1f229..a7566b00b 100644 --- a/web/spec/controllers/api_teachers_controller_spec.rb +++ b/web/spec/controllers/api_teachers_controller_spec.rb @@ -120,16 +120,15 @@ describe ApiTeachersController do get :detail, {:format => 'json', teacher_id: @teacher.id} response.should be_success json = JSON.parse(response.body) - json["genres"].should have(2).items json["instruments"].should have(2).items json["subjects"].should have(2).items json["languages"].should have(2).items - json["genres"].first["description"].should eq(genre1.description) - json["instruments"].last["description"].should eq(instrument2.description) - json["subjects"].first["description"].should eq(subject1.description) - json["languages"].last["description"].should eq(language2.description) + json["genres"].first.should eq(genre1.id) + json["instruments"].last.should eq(instrument2.id) + json["subjects"].first.should eq(subject1.id) + json["languages"].last.should eq(language2.id) end end diff --git a/web/spec/factories.rb b/web/spec/factories.rb index 58feba086..c646f754b 100644 --- a/web/spec/factories.rb +++ b/web/spec/factories.rb @@ -259,12 +259,12 @@ FactoryGirl.define do end factory :language, :class => JamRuby::Language do - name { |n| "Language #{n}" } + id { |n| "Language #{n}" } description { |n| "Language #{n}" } end factory :subject, :class => JamRuby::Subject do - name { |n| "Subject #{n}" } + id { |n| "Subject #{n}" } description { |n| "Subject #{n}" } end