VRFS-2689 user model changes for musician profile enhancements

This commit is contained in:
Brian Smith 2015-01-29 00:45:47 -05:00
parent 8556aaac13
commit 5a2fbab21c
6 changed files with 80 additions and 1 deletions

View File

@ -243,3 +243,6 @@ bpms_on_tap_in.sql
jamtracks_job.sql
text_messages.sql
text_message_migration.sql
user_model_about_changes.sql
performance_samples.sql
user_presences.sql

View File

@ -0,0 +1,10 @@
CREATE TABLE performance_samples (
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
url VARCHAR(4000) NULL,
type VARCHAR(100) NOT NULL,
claimed_recording_id VARCHAR(64) REFERENCES claimed_recordings(id) ON DELETE CASCADE,
service_id VARCHAR(100) NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

View File

@ -0,0 +1,25 @@
ALTER TABLE users ADD COLUMN website varchar(4000) NULL;
ALTER TABLE users ADD COLUMN skill_level smallint NULL;
ALTER TABLE users ADD COLUMN concert_count smallint NULL;
ALTER TABLE users ADD COLUMN studio_session_count smallint NULL;
-- virtual band
ALTER TABLE users ADD COLUMN virtual_band boolean NOT NULL DEFAULT FALSE;
ALTER TABLE users ADD COLUMN virtual_band_commitment smallint NULL;
-- traditional band
ALTER TABLE users ADD COLUMN traditional_band boolean NOT NULL DEFAULT FALSE;
ALTER TABLE users ADD COLUMN traditional_band_commitment smallint NULL;
ALTER TABLE users ADD COLUMN traditional_band_touring boolean NULL;
-- paid sessions
ALTER TABLE users ADD COLUMN paid_sessions boolean NOT NULL DEFAULT FALSE;
ALTER TABLE users ADD COLUMN paid_sessions_hourly_rate int NULL;
ALTER TABLE users ADD COLUMN paid_sessions_daily_rate int NULL;
-- free sessions
ALTER TABLE users ADD COLUMN free_sessions boolean NOT NULL DEFAULT FALSE;
-- cowriting
ALTER TABLE users ADD COLUMN cowriting boolean NOT NULL DEFAULT FALSE;
ALTER TABLE users ADD COLUMN cowriting_purpose smallint NULL;

8
db/up/user_presences.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE TABLE user_presences (
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
type VARCHAR(100) NOT NULL,
username VARCHAR(100) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

View File

@ -342,6 +342,11 @@ module JamRuby
self.recordings.size
end
def age
now = Time.now.utc.to_date
self.birth_date.nil? ? "unspecified" : now.year - self.birth_date.year - (self.birth_date.to_date.change(:year => now.year) > now ? 1 : 0)
end
def session_count
MusicSession.where("user_id = ? AND started_at IS NOT NULL", self.id).size
end

View File

@ -25,6 +25,22 @@ describe User do
should respond_to(:can_invite)
should respond_to(:mods)
should respond_to(:last_jam_audio_latency)
should respond_to(:website)
should respond_to(:age)
should respond_to(:skill_level)
should respond_to(:concert_count)
should respond_to(:studio_session_count)
should respond_to(:virtual_band)
should respond_to(:virtual_band_commitment)
should respond_to(:traditional_band)
should respond_to(:traditional_band_commitment)
should respond_to(:traditional_band_touring)
should respond_to(:paid_sessions)
should respond_to(:paid_sessions_hourly_rate)
should respond_to(:paid_sessions_daily_rate)
should respond_to(:free_sessions)
should respond_to(:cowriting)
should respond_to(:cowriting_purpose)
should be_valid
should_not be_admin
}
@ -649,6 +665,18 @@ describe User do
end
end
describe "age" do
let(:user) {FactoryGirl.create(:user)}
it "should calculate age based on birth_date" do
user.birth_date = Time.now - 10.years
user.age.should == 10
user.birth_date = Time.now - 10.years + 3.months
user.age.should == 9
end
end
describe "mods_merge" do
let(:user) {FactoryGirl.create(:user)}