VRFS-3359 : Save and test other segments of teacher profile.
This commit is contained in:
parent
460783a5aa
commit
98110f68bc
|
|
@ -6,13 +6,13 @@ CREATE TABLE teachers (
|
|||
years_playing SMALLINT NOT NULL DEFAULT 0,
|
||||
teaches_age_lower SMALLINT NOT NULL DEFAULT 0,
|
||||
teaches_age_upper SMALLINT NOT NULL DEFAULT 0,
|
||||
website VARCHAR(1024) NULL,
|
||||
biography VARCHAR(4096) NULL,
|
||||
teaches_beginner BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
teaches_intermediate BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
teaches_advanced BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
price_per_lesson BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
price_per_month BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
website VARCHAR(1024) NULL,
|
||||
biography VARCHAR(4096) NULL,
|
||||
prices_per_lesson BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
prices_per_month BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
lesson_duration_30 BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
lesson_duration_45 BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
lesson_duration_60 BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
|
|
@ -20,11 +20,11 @@ CREATE TABLE teachers (
|
|||
lesson_duration_120 BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
price_per_lesson_cents INT NULL,
|
||||
price_per_month_cents INT NULL,
|
||||
lesson_duration_30_cents INT NULL,
|
||||
lesson_duration_45_cents INT NULL,
|
||||
lesson_duration_60_cents INT NULL,
|
||||
lesson_duration_90_cents INT NULL,
|
||||
lesson_duration_120_cents INT NULL,
|
||||
price_duration_30_cents INT NULL,
|
||||
price_duration_45_cents INT NULL,
|
||||
price_duration_60_cents INT NULL,
|
||||
price_duration_90_cents INT NULL,
|
||||
price_duration_120_cents INT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -66,7 +66,7 @@ CREATE TABLE teachers_subjects(
|
|||
teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
|
||||
subject_id VARCHAR(64) REFERENCES subjects(id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE teacher_languages(
|
||||
CREATE TABLE teachers_languages(
|
||||
teacher_id VARCHAR(64) REFERENCES teachers(id) ON DELETE CASCADE,
|
||||
language_id VARCHAR(64) REFERENCES languages(id) ON DELETE CASCADE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,51 @@ module JamRuby
|
|||
teacher.website = params[:website] if params.key?(:website)
|
||||
teacher.biography = params[:biography] if params.key?(:biography)
|
||||
teacher.introductory_video = params[:introductory_video] if params.key?(:introductory_video)
|
||||
|
||||
teacher.introductory_video = params[:introductory_video] if params.key?(:introductory_video)
|
||||
teacher.years_teaching = params[:years_teaching] if params.key?(:years_teaching)
|
||||
teacher.years_playing = params[:years_playing] if params.key?(:years_playing)
|
||||
teacher.teaches_age_lower = params[:teaches_age_lower] if params.key?(:teaches_age_lower)
|
||||
teacher.teaches_age_upper = params[:teaches_age_upper] if params.key?(:teaches_age_upper)
|
||||
teacher.website = params[:website] if params.key?(:website)
|
||||
teacher.biography = params[:biography] if params.key?(:biography)
|
||||
teacher.teaches_beginner = params[:teaches_beginner] if params.key?(:teaches_beginner)
|
||||
teacher.teaches_intermediate = params[:teaches_intermediate] if params.key?(:teaches_intermediate)
|
||||
teacher.teaches_advanced = params[:teaches_advanced] if params.key?(:teaches_advanced)
|
||||
teacher.prices_per_lesson = params[:prices_per_lesson] if params.key?(:prices_per_lesson)
|
||||
teacher.prices_per_month = params[:prices_per_month] if params.key?(:prices_per_month)
|
||||
teacher.lesson_duration_30 = params[:lesson_duration_30] if params.key?(:lesson_duration_30)
|
||||
teacher.lesson_duration_45 = params[:lesson_duration_45] if params.key?(:lesson_duration_45)
|
||||
teacher.lesson_duration_60 = params[:lesson_duration_60] if params.key?(:lesson_duration_60)
|
||||
teacher.lesson_duration_90 = params[:lesson_duration_90] if params.key?(:lesson_duration_90)
|
||||
teacher.lesson_duration_120 = params[:lesson_duration_120] if params.key?(:lesson_duration_120)
|
||||
teacher.price_per_lesson_cents = params[:price_per_lesson_cents] if params.key?(:price_per_lesson_cents)
|
||||
teacher.price_per_month_cents = params[:price_per_month_cents] if params.key?(:price_per_month_cents)
|
||||
teacher.price_duration_30_cents = params[:price_duration_30_cents] if params.key?(:price_duration_30_cents)
|
||||
teacher.price_duration_45_cents = params[:price_duration_45_cents] if params.key?(:price_duration_45_cents)
|
||||
teacher.price_duration_60_cents = params[:price_duration_60_cents] if params.key?(:price_duration_60_cents)
|
||||
teacher.price_duration_90_cents = params[:price_duration_90_cents] if params.key?(:price_duration_90_cents)
|
||||
teacher.price_duration_120_cents = params[:price_duration_120_cents] if params.key?(:price_duration_120_cents)
|
||||
|
||||
# Many-to-many relations:
|
||||
teacher.genres = params[:genres].collect{|genre_id|Genre.find(genre_id)} if params[:genres].present?
|
||||
teacher.instruments = params[:instruments].collect{|instrument_id|Instrument.find(instrument_id)} if params[:instruments].present?
|
||||
teacher.subjects = params[:subjects].collect{|subject_id|Subject.find(subject_id)} if params[:subjects].present?
|
||||
teacher.languages = params[:languages].collect{|language_id|Language.find(language_id)} if params[:languages].present?
|
||||
|
||||
# Experience:
|
||||
if params[:experience].present?
|
||||
teacher.teacher_experiences = params[:experience].collect do |exp|
|
||||
TeacherExperience.new(
|
||||
name: exp[:name],
|
||||
experience_type: exp[:experience_type],
|
||||
organization: exp[:organization],
|
||||
start_year: exp[:start_year],
|
||||
end_year: exp[:end_year]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
teacher
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ module JamRuby
|
|||
# bands
|
||||
has_many :band_musicians, :class_name => "JamRuby::BandMusician"
|
||||
has_many :bands, :through => :band_musicians, :class_name => "JamRuby::Band"
|
||||
|
||||
has_one :teacher, :class_name => "JamRuby::Teacher"
|
||||
|
||||
# genres
|
||||
has_many :genre_players, as: :player, class_name: "JamRuby::GenrePlayer", dependent: :destroy
|
||||
has_many :genres, through: :genre_players, class_name: "JamRuby::Genre"
|
||||
|
|
|
|||
|
|
@ -223,6 +223,16 @@ FactoryGirl.define do
|
|||
description { |n| "Genre #{n}" }
|
||||
end
|
||||
|
||||
factory :language, :class => JamRuby::Language do
|
||||
name { |n| "Language #{n}" }
|
||||
description { |n| "Language #{n}" }
|
||||
end
|
||||
|
||||
factory :subject, :class => JamRuby::Subject do
|
||||
name { |n| "Subject #{n}" }
|
||||
description { |n| "Subject #{n}" }
|
||||
end
|
||||
|
||||
factory :join_request, :class => JamRuby::JoinRequest do
|
||||
text 'let me in to the session!'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,15 @@ describe Teacher do
|
|||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
let(:fan) { FactoryGirl.create(:fan) }
|
||||
let(:genre1) { FactoryGirl.create(:genre) }
|
||||
let(:genre2) { FactoryGirl.create(:genre) }
|
||||
let(:subject1) { FactoryGirl.create(:subject) }
|
||||
let(:subject2) { FactoryGirl.create(:subject) }
|
||||
let(:language1) { FactoryGirl.create(:language) }
|
||||
let(:language2) { FactoryGirl.create(:language) }
|
||||
let(:instrument1) { FactoryGirl.create(:instrument, :description => 'a great instrument')}
|
||||
let(:instrument2) { FactoryGirl.create(:instrument, :description => 'an ok instrument')}
|
||||
|
||||
BIO = "Once a man learned a guitar."
|
||||
describe "can create" do
|
||||
it "a simple teacher" do
|
||||
|
|
@ -17,14 +26,28 @@ describe Teacher do
|
|||
t.biography.should == BIO
|
||||
t.introductory_video.should == "youtube.com?xyz"
|
||||
end
|
||||
|
||||
|
||||
it "a simple teacher" do
|
||||
teacher = user.build_teacher
|
||||
teacher.instruments << instrument1
|
||||
teacher.instruments << instrument2
|
||||
teacher.save.should be_true
|
||||
puts teacher.errors.messages.inspect
|
||||
t = Teacher.find(teacher.id)
|
||||
t.instruments.should have(2).items
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "using save_teacher can create" do
|
||||
it "a simple teacher" do
|
||||
it "introduction" do
|
||||
teacher = Teacher.save_teacher(
|
||||
user,
|
||||
biography: BIO,
|
||||
introductory_video: "youtube.com?xyz"
|
||||
introductory_video: "youtube.com?xyz",
|
||||
years_teaching: 21,
|
||||
years_playing: 12
|
||||
)
|
||||
|
||||
teacher.should_not be_nil
|
||||
|
|
@ -32,6 +55,102 @@ describe Teacher do
|
|||
t = Teacher.find(teacher.id)
|
||||
t.biography.should == BIO
|
||||
t.introductory_video.should == "youtube.com?xyz"
|
||||
t.years_teaching.should == 21
|
||||
t.years_playing.should == 12
|
||||
end
|
||||
|
||||
it "basics" do
|
||||
teacher = Teacher.save_teacher(
|
||||
user,
|
||||
instruments: [instrument1, instrument2],
|
||||
subjects: [subject1, subject2],
|
||||
genres: [genre1, genre2],
|
||||
languages: [language1, language2],
|
||||
teaches_age_lower: 10,
|
||||
teaches_age_upper: 20,
|
||||
teaches_beginner: true,
|
||||
teaches_intermediate: false,
|
||||
teaches_advanced: true
|
||||
)
|
||||
|
||||
t = Teacher.find(teacher.id)
|
||||
|
||||
# Instruments
|
||||
t.instruments.should have(2).items
|
||||
|
||||
# Genres
|
||||
t.genres.should have(2).items
|
||||
|
||||
# Subjects
|
||||
t.subjects.should have(2).items
|
||||
|
||||
# Languages
|
||||
t.languages.should have(2).items
|
||||
|
||||
t.teaches_age_lower.should == 10
|
||||
t.teaches_age_upper.should == 20
|
||||
t.teaches_beginner.should be_true
|
||||
t.teaches_intermediate.should be_false
|
||||
t.teaches_advanced.should be_true
|
||||
|
||||
end
|
||||
|
||||
it "experience" do
|
||||
experience = [{
|
||||
experience_type: "teaching",
|
||||
name: "Professor",
|
||||
organization: "SHSU",
|
||||
start_year: 1994,
|
||||
end_year: 2004
|
||||
}
|
||||
]
|
||||
|
||||
teacher = Teacher.save_teacher(user, experience: experience)
|
||||
teacher.should_not be_nil
|
||||
t = Teacher.find(teacher.id)
|
||||
t.should_not be_nil
|
||||
|
||||
t.teacher_experiences.should have(1).items
|
||||
end
|
||||
|
||||
it "lesson pricing" do
|
||||
teacher = Teacher.save_teacher(
|
||||
user,
|
||||
prices_per_lesson: true,
|
||||
prices_per_month: true,
|
||||
lesson_duration_30: true,
|
||||
lesson_duration_45: true,
|
||||
lesson_duration_60: true,
|
||||
lesson_duration_90: true,
|
||||
lesson_duration_120: true,
|
||||
price_per_lesson_cents: 3000,
|
||||
price_per_month_cents: 3000,
|
||||
price_duration_30_cents: 3000,
|
||||
price_duration_45_cents: 3000,
|
||||
price_duration_60_cents: 3000,
|
||||
price_duration_90_cents: 3000,
|
||||
price_duration_120_cents: 3000
|
||||
)
|
||||
|
||||
teacher.should_not be_nil
|
||||
teacher.id.should_not be_nil
|
||||
t = Teacher.find(teacher.id)
|
||||
t.prices_per_lesson.should be_true
|
||||
t.prices_per_month.should be_true
|
||||
t.lesson_duration_30.should be_true
|
||||
t.lesson_duration_45.should be_true
|
||||
t.lesson_duration_60.should be_true
|
||||
t.lesson_duration_90.should be_true
|
||||
t.lesson_duration_120.should be_true
|
||||
t.price_per_lesson_cents.should == 3000
|
||||
t.price_per_month_cents.should == 3000
|
||||
t.price_duration_30_cents.should == 3000
|
||||
t.price_duration_45_cents.should == 3000
|
||||
t.price_duration_60_cents.should == 3000
|
||||
t.price_duration_90_cents.should == 3000
|
||||
t.price_duration_120_cents.should == 3000
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue