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.
This commit is contained in:
parent
4eac4ccd7a
commit
67696a72d7
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ class ApiLanguagesController < ApiController
|
|||
|
||||
def index
|
||||
@languages = Language.order(:description)
|
||||
respond_with @languages
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ class ApiSubjectsController < ApiController
|
|||
|
||||
def index
|
||||
@subjects = Subject.order(:description)
|
||||
respond_with @subjects
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue