public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add user to current site when creating

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2143 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Sep 10 18:16:29 -0700 2006
commit  8507eda7a81c9e4c5c3e6a4a060ec875269b0116
tree    547181388cdde77767e61ef568bc149af368bb06
parent  634babde6dc5dc356f0dba9ff07df782a65732ff
...
14
15
16
17
18
19
20
21
22
23
 
 
 
 
 
 
 
24
25
26
...
14
15
16
 
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
26
0
@@ -14,13 +14,13 @@ class Admin::UsersController < Admin::BaseController
0
 
0
   def create
0
     @user = User.new params[:user]
0
- if @user.save
0
- flash[:notice] = "User created."
0
- redirect_to :action => 'index'
0
- else
0
- flash[:error] = "Save failed."
0
- render :action => 'new'
0
- end
0
+ @user.save!
0
+ @user.sites << site
0
+ flash[:notice] = "User created."
0
+ redirect_to :action => 'index'
0
+ rescue ActiveRecord::RecordInvalid
0
+ flash[:error] = "Save failed."
0
+ render :action => 'new'
0
   end
0
 
0
   def update
...
44
45
46
47
 
48
49
50
...
44
45
46
 
47
48
49
50
0
@@ -44,7 +44,7 @@ class Site < ActiveRecord::Base
0
   has_many :assets, :as => :attachable, :order => 'created_at desc'
0
   has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
0
 
0
- has_many :memberships
0
+ has_many :memberships, :dependent => :destroy
0
   has_many :members, :through => :memberships, :source => :user
0
   has_many :admins, :through => :memberships, :source => :user, :conditions => ['memberships.admin = ? or users.admin = ?', true, true]
0
 
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@ class User < UserAuth
0
   has_many :articles
0
   acts_as_paranoid
0
 
0
- has_many :memberships
0
+ has_many :memberships, :dependent => :destroy
0
   has_many :sites, :through => :memberships, :order => 'title, host'
0
 
0
   def self.find_admins(*args)
...
39
40
41
42
43
44
45
 
 
 
 
 
 
 
46
47
48
...
39
40
41
 
 
 
 
42
43
44
45
46
47
48
49
50
51
0
@@ -39,10 +39,13 @@ class Admin::UsersControllerTest < Test::Unit::TestCase
0
   def test_should_create_user
0
     login_as :quentin
0
     assert_difference User, :count do
0
- post :create, :user => { :login => 'bob', :email => 'foo', :password => 'testy', :password_confirmation => 'testy', :admin => true }
0
- assert_equal assigns(:user), User.authenticate_for(sites(:first), 'bob', 'testy')
0
- assert_redirected_to :action => 'index'
0
- assert flash[:notice]
0
+ assert_difference Membership, :count do
0
+ post :create, :user => { :login => 'bob', :email => 'foo', :password => 'testy', :password_confirmation => 'testy', :admin => true }
0
+ assert_models_equal [sites(:first)], assigns(:user).sites
0
+ assert_equal assigns(:user), User.authenticate_for(sites(:first), 'bob', 'testy')
0
+ assert_redirected_to :action => 'index'
0
+ assert flash[:notice]
0
+ end
0
     end
0
   end
0
 

Comments

    No one has commented yet.