Rename instantiate! to build, no more raising in build, no saving in build, no seeding of aspects in build.
This commit is contained in:
parent
f97f63e2d1
commit
961510a8ed
7 changed files with 44 additions and 43 deletions
|
|
@ -4,15 +4,10 @@
|
||||||
|
|
||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
def create
|
def create
|
||||||
begin
|
@user = User.build(params[:user])
|
||||||
@user = User.instantiate!(params[:user])
|
|
||||||
rescue MongoMapper::DocumentNotValid => e
|
|
||||||
flash[:error] = e.message
|
|
||||||
redirect_to new_user_registration_path
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if @user.save
|
if @user.save
|
||||||
flash[:notice] = I18n.t 'registrations.create.success'
|
flash[:notice] = I18n.t 'registrations.create.success'
|
||||||
|
@user.seed_aspects
|
||||||
sign_in_and_redirect(:user, @user)
|
sign_in_and_redirect(:user, @user)
|
||||||
else
|
else
|
||||||
flash[:error] = @user.errors.full_messages.join(', ')
|
flash[:error] = @user.errors.full_messages.join(', ')
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,7 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
###Helpers############
|
###Helpers############
|
||||||
def self.instantiate!(opts = {})
|
def self.build(opts = {})
|
||||||
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
|
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
|
||||||
opts[:person][:url] = APP_CONFIG[:pod_url]
|
opts[:person][:url] = APP_CONFIG[:pod_url]
|
||||||
|
|
||||||
|
|
@ -387,8 +387,6 @@ class User
|
||||||
opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key
|
opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key
|
||||||
|
|
||||||
u = User.new(opts)
|
u = User.new(opts)
|
||||||
u.seed_aspects
|
|
||||||
u.save!
|
|
||||||
u
|
u
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ def create
|
||||||
require File.join(File.dirname(__FILE__), "..", "..", "config", "initializers", "_load_app_config.rb")
|
require File.join(File.dirname(__FILE__), "..", "..", "config", "initializers", "_load_app_config.rb")
|
||||||
|
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.instantiate!(:email => "#{username}@#{username}.joindiaspora.com",
|
user = User.build(:email => "#{username}@#{username}.joindiaspora.com",
|
||||||
:username => username,
|
:username => username,
|
||||||
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
||||||
:password_confirmation => "#{username+backer_info[backer_number]['pin'].to_s}",
|
:password_confirmation => "#{username+backer_info[backer_number]['pin'].to_s}",
|
||||||
:person => Person.new(
|
:person => Person.new(
|
||||||
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'],
|
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'],
|
||||||
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg")
|
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg")
|
||||||
))
|
)).save
|
||||||
user.person.save!
|
user.person.save!
|
||||||
|
|
||||||
user.aspect(:name => "Presidents")
|
user.aspect(:name => "Presidents")
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,25 @@ username = "tom"
|
||||||
set_app_config username
|
set_app_config username
|
||||||
|
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
user = User.build( :email => "tom@tom.joindiaspora.com",
|
||||||
:username => "tom",
|
:username => "tom",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:password_confirmation => "evankorth",
|
:password_confirmation => "evankorth",
|
||||||
:person => Person.new(
|
:person => Person.new(
|
||||||
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
|
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
|
||||||
)
|
).save
|
||||||
user.person.save!
|
user.person.save!
|
||||||
|
user.seed_aspects
|
||||||
|
|
||||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
user2 = User.build( :email => "korth@tom.joindiaspora.com",
|
||||||
:username => "korth",
|
:username => "korth",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:password_confirmation => "evankorth",
|
:password_confirmation => "evankorth",
|
||||||
:person => Person.new(
|
:person => Person.new(
|
||||||
:profile => Profile.new( :first_name => "Evan", :last_name => "Korth")))
|
:profile => Profile.new( :first_name => "Evan", :last_name => "Korth"))).save
|
||||||
|
|
||||||
user2.person.save!
|
user2.person.save!
|
||||||
|
user2.seed_aspects
|
||||||
|
|
||||||
# friending users
|
# friending users
|
||||||
aspect = user.aspect(:name => "other dudes")
|
aspect = user.aspect(:name => "other dudes")
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,24 @@ set_app_config "tom"
|
||||||
require 'config/initializers/_load_app_config.rb'
|
require 'config/initializers/_load_app_config.rb'
|
||||||
|
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
user = User.build( :email => "tom@tom.joindiaspora.com",
|
||||||
:username => "tom",
|
:username => "tom",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:password_confirmation => "evankorth",
|
:password_confirmation => "evankorth",
|
||||||
:person => {
|
:person => {
|
||||||
:profile => { :first_name => "Alexander", :last_name => "Hamiltom",
|
:profile => { :first_name => "Alexander", :last_name => "Hamiltom",
|
||||||
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}}
|
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}}
|
||||||
)
|
).save!
|
||||||
|
user.seed_aspects
|
||||||
user.person.save!
|
user.person.save!
|
||||||
|
|
||||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
user2 = User.build( :email => "korth@tom.joindiaspora.com",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:password_confirmation => "evankorth",
|
:password_confirmation => "evankorth",
|
||||||
:username => "korth",
|
:username => "korth",
|
||||||
:person => {:profile => { :first_name => "Evan", :last_name => "Korth",
|
:person => {:profile => { :first_name => "Evan", :last_name => "Korth",
|
||||||
:image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}})
|
:image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}})
|
||||||
|
user2.seed_aspects
|
||||||
user2.person.save!
|
user2.person.save!
|
||||||
|
|
||||||
# friending users
|
# friending users
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ describe RegistrationsController do
|
||||||
lambda { get :create, @invalid_params }.should_not change(User, :count)
|
lambda { get :create, @invalid_params }.should_not change(User, :count)
|
||||||
end
|
end
|
||||||
it "assigns @user" do
|
it "assigns @user" do
|
||||||
pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail"
|
|
||||||
get :create, @valid_params
|
get :create, @valid_params
|
||||||
assigns(:user).should_not be_nil
|
assigns(:user).should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
@ -57,9 +56,8 @@ describe RegistrationsController do
|
||||||
flash[:error].should_not be_blank
|
flash[:error].should_not be_blank
|
||||||
end
|
end
|
||||||
it "goes back to the form" do
|
it "goes back to the form" do
|
||||||
pending "GAAAH stupid mongo mapper. Figure out why it thinks it's persisted when validations fail"
|
|
||||||
get :create, @invalid_params
|
get :create, @invalid_params
|
||||||
response.should be_success
|
response.should be_redirect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -86,17 +86,29 @@ describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".instantiate!" do
|
describe ".build" do
|
||||||
it "creates the user if params are valid" do
|
context 'with valid params' do
|
||||||
User.find_by_username("ohai").should be_nil
|
before do
|
||||||
user = User.instantiate!({
|
params = {:username => "ohai",
|
||||||
:username => "ohai",
|
|
||||||
:email => "ohai@example.com",
|
:email => "ohai@example.com",
|
||||||
:password => "password",
|
:password => "password",
|
||||||
:password_confirmation => "password",
|
:password_confirmation => "password",
|
||||||
:person => {:profile => {:first_name => "O", :last_name => "Hai"}}})
|
:person =>
|
||||||
user.should be_valid
|
{:profile =>
|
||||||
User.find_by_username("ohai").should == user
|
{:first_name => "O",
|
||||||
|
:last_name => "Hai"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@user = User.build(params)
|
||||||
|
end
|
||||||
|
it "makes a valid user" do
|
||||||
|
@user.should be_valid
|
||||||
|
User.find_by_username("ohai").should be_nil
|
||||||
|
end
|
||||||
|
it 'saves successfully' do
|
||||||
|
@user.save.should be_true
|
||||||
|
User.find_by_username("ohai").should == @user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
describe "with invalid params" do
|
describe "with invalid params" do
|
||||||
before do
|
before do
|
||||||
|
|
@ -107,16 +119,11 @@ describe User do
|
||||||
:password_confirmation => "password",
|
:password_confirmation => "password",
|
||||||
:person => {:profile => {:first_name => "", :last_name => ""}}}
|
:person => {:profile => {:first_name => "", :last_name => ""}}}
|
||||||
end
|
end
|
||||||
it "raises an error" do
|
it "raises no error" do
|
||||||
lambda { User.instantiate!(@invalid_params) }.should raise_error
|
lambda { User.build(@invalid_params) }.should_not raise_error
|
||||||
end
|
end
|
||||||
it "does not create the user" do
|
it "does not save" do
|
||||||
User.find_by_username("ohai").should be_nil
|
User.build(@invalid_params).save.should be_false
|
||||||
begin
|
|
||||||
User.instantiate!(@invalid_params)
|
|
||||||
rescue
|
|
||||||
end
|
|
||||||
User.find_by_username("ohai").should be_nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue