From 3f2fd94c586e4f73a82cfcc7d1731d46f7b809b0 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Thu, 3 Sep 2015 01:53:28 -0500 Subject: [PATCH] VRFS-3359 : Update schema and models with per-month and per-lesson price for each interval. Update tests to match. --- db/up/profile_teacher.sql | 55 ++++++++++++----------- ruby/lib/jam_ruby/models/teacher.rb | 17 ++++--- ruby/spec/jam_ruby/models/teacher_spec.rb | 46 ++++++++++--------- 3 files changed, 64 insertions(+), 54 deletions(-) diff --git a/db/up/profile_teacher.sql b/db/up/profile_teacher.sql index 8b4b51360..5e1155dc0 100644 --- a/db/up/profile_teacher.sql +++ b/db/up/profile_teacher.sql @@ -1,30 +1,33 @@ CREATE TABLE teachers ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, - introductory_video VARCHAR(1024) NULL, - years_teaching SMALLINT NOT NULL DEFAULT 0, - years_playing SMALLINT NOT NULL DEFAULT 0, - teaches_age_lower SMALLINT NOT NULL DEFAULT 0, - teaches_age_upper SMALLINT NOT NULL DEFAULT 0, - teaches_beginner BOOLEAN NOT NULL DEFAULT FALSE, - teaches_intermediate BOOLEAN NOT NULL DEFAULT FALSE, - teaches_advanced 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, - lesson_duration_90 BOOLEAN NOT NULL DEFAULT FALSE, - lesson_duration_120 BOOLEAN NOT NULL DEFAULT FALSE, - price_per_lesson_cents INT NULL, - price_per_month_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, + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + introductory_video VARCHAR(1024) NULL, + years_teaching SMALLINT NOT NULL DEFAULT 0, + years_playing SMALLINT NOT NULL DEFAULT 0, + teaches_age_lower SMALLINT NOT NULL DEFAULT 0, + teaches_age_upper SMALLINT NOT NULL DEFAULT 0, + teaches_beginner BOOLEAN NOT NULL DEFAULT FALSE, + teaches_intermediate BOOLEAN NOT NULL DEFAULT FALSE, + teaches_advanced 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, + lesson_duration_90 BOOLEAN NOT NULL DEFAULT FALSE, + lesson_duration_120 BOOLEAN NOT NULL DEFAULT FALSE, + price_per_lesson_30_cents INT NULL, + price_per_lesson_45_cents INT NULL, + price_per_lesson_60_cents INT NULL, + price_per_lesson_90_cents INT NULL, + price_per_lesson_120_cents INT NULL, + price_per_month_30_cents INT NULL, + price_per_month_45_cents INT NULL, + price_per_month_60_cents INT NULL, + price_per_month_90_cents INT NULL, + price_per_month_120_cents INT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); @@ -48,7 +51,7 @@ CREATE TABLE teacher_experiences( name VARCHAR(200) NOT NULL, organization VARCHAR(200) NOT NULL, start_year SMALLINT NOT NULL DEFAULT 0, - end_year SMALLINT NOT NULL DEFAULT 0 + end_year SMALLINT NULL ); -- Has many/through tables: diff --git a/ruby/lib/jam_ruby/models/teacher.rb b/ruby/lib/jam_ruby/models/teacher.rb index bb4a57bbc..102a32cef 100644 --- a/ruby/lib/jam_ruby/models/teacher.rb +++ b/ruby/lib/jam_ruby/models/teacher.rb @@ -67,13 +67,16 @@ module JamRuby 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) + teacher.price_per_lesson_30_cents = params[:price_per_lesson_30_cents] if params.key?(:price_per_lesson_30_cents) + teacher.price_per_lesson_45_cents = params[:price_per_lesson_45_cents] if params.key?(:price_per_lesson_45_cents) + teacher.price_per_lesson_60_cents = params[:price_per_lesson_60_cents] if params.key?(:price_per_lesson_60_cents) + teacher.price_per_lesson_90_cents = params[:price_per_lesson_90_cents] if params.key?(:price_per_lesson_90_cents) + teacher.price_per_lesson_120_cents = params[:price_per_lesson_120_cents] if params.key?(:price_per_lesson_120_cents) + teacher.price_per_month_30_cents = params[:price_per_month_30_cents] if params.key?(:price_per_month_30_cents) + teacher.price_per_month_45_cents = params[:price_per_month_45_cents] if params.key?(:price_per_month_45_cents) + teacher.price_per_month_60_cents = params[:price_per_month_60_cents] if params.key?(:price_per_month_60_cents) + teacher.price_per_month_90_cents = params[:price_per_month_90_cents] if params.key?(:price_per_month_90_cents) + teacher.price_per_month_120_cents = params[:price_per_month_120_cents] if params.key?(:price_per_month_120_cents) # Many-to-many relations: teacher.genres = params[:genres].collect{|genre_id|Genre.find(genre_id)} if params[:genres].present? diff --git a/ruby/spec/jam_ruby/models/teacher_spec.rb b/ruby/spec/jam_ruby/models/teacher_spec.rb index 9164829b2..17a333270 100644 --- a/ruby/spec/jam_ruby/models/teacher_spec.rb +++ b/ruby/spec/jam_ruby/models/teacher_spec.rb @@ -144,13 +144,16 @@ describe Teacher do 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 + 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 @@ -165,13 +168,16 @@ describe Teacher do 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 + 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 @@ -249,13 +255,11 @@ describe Teacher do lesson_duration_60: false, lesson_duration_90: false, lesson_duration_120: false, - 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, + #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 )