* VRFS-149; bootstrap dev users
This commit is contained in:
parent
21f09ecd69
commit
af8bee6084
|
|
@ -389,6 +389,67 @@ module JamRuby
|
|||
return user
|
||||
end
|
||||
|
||||
# this is intended to be development-mode or test-mode only; VRFS-149
|
||||
# it creates or updates one user per developer, so that we aren't in the business
|
||||
# of constantly recreating users as we create new dev environments
|
||||
|
||||
# We guard against this code running in production mode,
|
||||
# because otherwise it's a bit of uncomfortable code
|
||||
# to have sitting around
|
||||
def self.create_dev_user(first_name, last_name, email, password,
|
||||
city, state, country, instruments, photo_url)
|
||||
|
||||
if Environment.mode == "production"
|
||||
# short-circuit out
|
||||
return
|
||||
end
|
||||
|
||||
user = User.find_or_create_by_email(email)
|
||||
|
||||
User.transaction do
|
||||
user.first_name = first_name
|
||||
user.last_name = last_name
|
||||
user.email = email
|
||||
user.password = password
|
||||
user.password_confirmation = password
|
||||
user.admin = true
|
||||
user.email_confirmed = true
|
||||
user.musician = true
|
||||
user.city = city
|
||||
user.state = state
|
||||
user.country = country
|
||||
|
||||
if instruments.nil?
|
||||
instruments = [{:instrument_id => "acoustic guitar", :proficiency_level => 3, :priority => 1}]
|
||||
end
|
||||
|
||||
unless user.new_record?
|
||||
MusicianInstrument.delete_all(["user_id = ?", user.id])
|
||||
end
|
||||
|
||||
instruments.each do |musician_instrument_param|
|
||||
instrument = Instrument.find(musician_instrument_param[:instrument_id])
|
||||
musician_instrument = MusicianInstrument.new
|
||||
musician_instrument.user = user
|
||||
musician_instrument.instrument = instrument
|
||||
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
|
||||
musician_instrument.priority = musician_instrument_param[:priority]
|
||||
musician_instrument.save
|
||||
user.musician_instruments << musician_instrument
|
||||
end
|
||||
|
||||
user.photo_url = photo_url
|
||||
user.signup_token = nil
|
||||
user.save
|
||||
|
||||
if user.errors.any?
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
return user
|
||||
end
|
||||
|
||||
# throws RecordNotFound if signup token is invalid; i.e., if it's nil, empty string, or not belonging to a user
|
||||
def self.signup_confirm(signup_token)
|
||||
if signup_token.nil? || signup_token.empty?
|
||||
|
|
|
|||
|
|
@ -169,4 +169,27 @@ describe User do
|
|||
it { User.authenticate("", "").should be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe "create_dev_user" do
|
||||
before { @dev_user = User.create_dev_user("Seth", "Call", "seth@jamkazam.com", "Jam123", "Austin", "Texas", "USA", nil, nil) }
|
||||
|
||||
subject { @dev_user }
|
||||
|
||||
describe "creates a valid record" do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
describe "should not be a new record" do
|
||||
it { should be_persisted }
|
||||
end
|
||||
|
||||
describe "updates record" do
|
||||
before { @dev_user = User.create_dev_user("Seth", "Call2", "seth@jamkazam.com", "Jam123", "Austin", "Texas", "USA", nil, nil) }
|
||||
|
||||
it { should be_valid }
|
||||
|
||||
its(:last_name) { should == "Call2" }
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue