jam-cloud/ruby/spec/jam_ruby/models/teacher_spec.rb

286 lines
8.1 KiB
Ruby

require 'spec_helper'
describe Teacher do
let(:user) { FactoryGirl.create(:user) }
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."
GOOD_YOUTUBE_URL = "http://youtube.com/watch?v=1234567890"
describe "can create" do
it "a simple teacher" do
teacher = Teacher.new
teacher.user = user;
teacher.biography = BIO
teacher.introductory_video = GOOD_YOUTUBE_URL
teacher.save.should be_true
t = Teacher.find(teacher.id)
t.biography.should == BIO
t.introductory_video.should == GOOD_YOUTUBE_URL
end
it "with instruments" do
teacher = Teacher.build_teacher(user, {})
teacher.instruments << instrument1
teacher.instruments << instrument2
teacher.save.should be_true
t = Teacher.find(teacher.id)
t.instruments.should have(2).items
end
end
describe "using save_teacher can create" do
it "introduction" do
teacher = Teacher.save_teacher(
user,
biography: BIO,
introductory_video: GOOD_YOUTUBE_URL,
years_teaching: 21,
years_playing: 12
)
teacher.should_not be_nil
teacher.errors.should be_empty
teacher.id.should_not be_nil
t = Teacher.find(teacher.id)
t.biography.should == BIO
t.introductory_video.should == GOOD_YOUTUBE_URL
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
)
teacher.should_not be_nil
teacher.errors.should be_empty
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 = [{
name: "Professor",
organization: "SHSU",
start_year: 1994,
end_year: 2004
}
]
teacher = Teacher.save_teacher(user, experiences_teaching: experience)
teacher.should_not be_nil
teacher.errors.should be_empty
t = Teacher.find(teacher.id)
t.should_not be_nil
t.teacher_experiences.should have(1).items
t.experiences_teaching.should have(1).items
t.experiences_education.should have(0).items
t.experiences_award.should have(0).items
# Save some awards and re-check teacher object:
teacher = Teacher.save_teacher(user, experiences_award: experience)
teacher.should_not be_nil
teacher.errors.should be_empty
t.reload
t.teacher_experiences.should have(2).items
t.experiences_teaching.should have(1).items
t.experiences_education.should have(0).items
t.experiences_award.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_30_cents: 3000,
price_per_lesson_45_cents: 3000,
price_per_lesson_60_cents: 3000,
price_per_lesson_90_cents: 3000,
price_per_lesson_120_cents: 3000,
price_per_month_30_cents: 5000,
price_per_month_45_cents: 5000,
price_per_month_60_cents: 5000,
price_per_month_90_cents: 5000,
price_per_month_120_cents: 5000
)
teacher.should_not be_nil
teacher.id.should_not be_nil
teacher.errors.should be_empty
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_30_cents.should == 3000
t.price_per_lesson_45_cents.should == 3000
t.price_per_lesson_60_cents.should == 3000
t.price_per_lesson_90_cents.should == 3000
t.price_per_lesson_120_cents.should == 3000
t.price_per_month_30_cents.should == 5000
t.price_per_month_45_cents.should == 5000
t.price_per_month_60_cents.should == 5000
t.price_per_month_90_cents.should == 5000
t.price_per_month_120_cents.should == 5000
end
end
describe "validates" do
it "introduction" do
teacher = Teacher.save_teacher(
user,
years_teaching: 21,
validate_introduction: true
)
teacher.should_not be_nil
teacher.id.should be_nil
teacher.errors.should_not be_empty
teacher.errors.should have_key(:biography)
end
it "introductory video" do
teacher = Teacher.save_teacher(
user,
biography: BIO,
introductory_video: "fubar.com/nothing",
validate_introduction: true
)
teacher.should_not be_nil
teacher.id.should be_nil
teacher.errors.should_not be_empty
teacher.errors.should have_key(:introductory_video)
teacher = Teacher.save_teacher(
user,
biography: BIO,
introductory_video: GOOD_YOUTUBE_URL,
validate_introduction: true
)
teacher.should_not be_nil
teacher.id.should_not be_nil
teacher.errors.should be_empty
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_beginner: true,
teaches_intermediate: false,
teaches_advanced: true,
validate_basics: true
)
teacher.should_not be_nil
teacher.id.should be_nil
teacher.errors.should have_key(:instruments)
teacher.errors.should have_key(:subjects)
teacher.errors.should have_key(:genres)
teacher.errors.should have_key(:languages)
end
it "pricing" do
teacher = Teacher.save_teacher(
user,
prices_per_lesson: false,
prices_per_month: false,
lesson_duration_30: false,
lesson_duration_45: false,
lesson_duration_60: false,
lesson_duration_90: false,
lesson_duration_120: false,
#price_per_lesson_30_cents: 3000,
price_per_lesson_45_cents: 3000,
#price_per_lesson_60_cents: 3000,
#price_per_lesson_90_cents: 3000,
price_per_lesson_120_cents: 3000,
validate_pricing:true
)
teacher.should_not be_nil
teacher.id.should be_nil
teacher.errors.should_not be_empty
teacher.errors.should have_key(:offer_pricing)
teacher.errors.should have_key(:offer_duration)
teacher = Teacher.save_teacher(
user,
prices_per_month: true,
lesson_duration_45: true,
validate_pricing:true
)
teacher.should_not be_nil
teacher.id.should_not be_nil
teacher.errors.should be_empty
end # pricing
end # validates
end # spec