Remove half-baked methods
We'll think of something better later on.
This commit is contained in:
parent
f5249be3d4
commit
adb5ca34b6
|
@ -12,38 +12,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
default_scope { order id: :desc }
|
||||
|
||||
def duplicate_last_personal_profile(conference)
|
||||
if personal_profiles.any?
|
||||
new_personal_profile = personal_profiles.last.dup
|
||||
new_personal_profile.conference = conference
|
||||
new_personal_profile
|
||||
end
|
||||
end
|
||||
|
||||
def find_or_initialize_personal_profile(conference)
|
||||
if personal_profile(conference).present?
|
||||
personal_profile(conference)
|
||||
elsif personal_profiles.any?
|
||||
duplicate_last_personal_profile(conference)
|
||||
else
|
||||
personal_profiles.build(conference: conference)
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_admin!
|
||||
update admin: !admin
|
||||
end
|
||||
|
||||
def clone_recent_profile(new_conference)
|
||||
recent_profile = personal_profiles.order('created_at DESC').first
|
||||
|
||||
personal_profiles.build(conference: new_conference) do |new_profile|
|
||||
if recent_profile.present?
|
||||
new_profile.attributes = recent_profile.attributes.except(
|
||||
"id", "created_at", "updated_at", "conference_id"
|
||||
)
|
||||
new_profile.remote_picture_url = recent_profile.picture.url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,63 +4,4 @@ RSpec.describe User do
|
|||
it 'lets Devise handle email and password validations' do
|
||||
expect(build(:user)).to be_a Devise::Models::Validatable
|
||||
end
|
||||
|
||||
it "can clone a previous profile for use in a different conference" do
|
||||
user = create :user
|
||||
old_conference = create :conference
|
||||
new_conference = create :conference
|
||||
|
||||
old_profile = create :personal_profile, {
|
||||
user: user,
|
||||
biography: "Old profile bio",
|
||||
conference: old_conference
|
||||
}
|
||||
|
||||
expect(user.personal_profile(old_conference)).to eq old_profile
|
||||
expect(user.personal_profile(new_conference)).to be_nil
|
||||
|
||||
new_profile = user.clone_recent_profile(new_conference)
|
||||
expect(new_profile.biography).to eq old_profile.biography
|
||||
|
||||
user.reload
|
||||
user.personal_profiles << new_profile
|
||||
|
||||
expect(user.personal_profile(old_conference)).to eq old_profile
|
||||
expect(user.personal_profile(new_conference)).to eq new_profile
|
||||
end
|
||||
|
||||
describe '#find_or_initialize_personal_profile' do
|
||||
context 'when the user has a personal profile for the specified conference' do
|
||||
it 'returns the existing personal profile' do
|
||||
user = create :user
|
||||
conference = create :conference
|
||||
personal_profile = create :personal_profile, user: user, conference: conference
|
||||
|
||||
expect(user.find_or_initialize_personal_profile(conference)).to eq personal_profile
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user has a personal profile for a previous conference' do
|
||||
it 'returns a duplicate of the old profile' do
|
||||
user = create :user
|
||||
old_conference = create :conference
|
||||
conference = create :conference
|
||||
personal_profile = create :personal_profile, user: user, conference: old_conference
|
||||
|
||||
expect(user.find_or_initialize_personal_profile(conference).public_email).to be_present
|
||||
expect(user.find_or_initialize_personal_profile(conference).public_email).to eq personal_profile.public_email
|
||||
expect(user.find_or_initialize_personal_profile(conference)).to be_new_record
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user has no personal profiles' do
|
||||
it 'returns a new personal profile' do
|
||||
user = create :user
|
||||
conference = create :conference
|
||||
|
||||
expect(user.find_or_initialize_personal_profile(conference)).to be_new_record
|
||||
expect(user.find_or_initialize_personal_profile(conference).conference).to eq conference
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue