Created
August 18, 2009 00:11
-
-
Save dscataglini/169454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_user(user_options = {}, other_options = {}) | |
base_options = { :login => 'unique', :email => 'unique@example.com', | |
:first_name => 'bob', :last_name => 'testerperson', :address => "123 Main St", | |
:city => "Santa Carla", :state => "CA", :zip => "95000", :subscription => "Tier 1", | |
:role => 'Member', | |
:password => 'quire69', :password_confirmation => 'quire69',:accept_terms => true } | |
post :create, {:user => (base_options.merge(user_options))}.merge(other_options) | |
end | |
it 'should set permissions on create' do | |
pretend_to_be_authenticated("Administrator") | |
quentin = users( :quentin) | |
quentin.stub!( :match_permissions_with_subscription!) | |
rebecca = content_categories(:rebecca) | |
todd = content_categories(:todd) | |
howard = content_categories(:howard) | |
brian = content_categories(:brian) | |
ContentCategory.should_receive(:find_by_name).with("REBECCA RUNKLE").and_return(rebecca) | |
ContentCategory.should_receive(:find_by_name).with("TODD JORDAN").and_return(todd) | |
ContentCategory.should_receive(:find_by_name).with("HOWARD PENNEY").and_return(howard) | |
ContentCategory.should_receive(:find_by_name).with("BRIAN McGOUGH").and_return(brian) | |
quentin.should_receive(:set_permission).with(rebecca, Permission::TIER_1, nil, nil) | |
quentin.should_receive(:set_permission).with(todd, Permission::TIER_2, nil, nil) | |
quentin.should_receive(:set_permission).with(howard, Permission::TRIAL_FULL_TEXT, "1/1/2011", "1/7/2011") | |
quentin.should_receive(:set_permission).with(brian, Permission::TRIAL_REWIND, "1/8/2011", "1/15/2011") | |
quentin.should_receive(:permissions_valid?).and_return(true) | |
quentin.stub!(:valid?).and_return(true) | |
quentin.stub!(:credit_card_subscriber?).and_return(false) | |
quentin.should_receive(:activate) | |
quentin.should_receive(:save!) | |
User.stub!(:find_by_email).and_return(quentin) | |
create_user({:subscription => "Tier 1" }, | |
{ | |
:permissions => { | |
"REBECCA RUNKLE" => {:permission_type => Permission::TIER_1}, | |
"TODD JORDAN" => {:permission_type => Permission::TIER_2}, | |
"HOWARD PENNEY" => {:permission_type => Permission::TRIAL_FULL_TEXT, :trial_start => "1/1/2011", :trial_end => "1/7/2011"}, | |
"BRIAN McGOUGH" => {:permission_type => Permission::TRIAL_REWIND, :trial_start => "1/8/2011", :trial_end => "1/15/2011"} | |
} | |
}) | |
end | |
it 'should remove specified permissions on create' do | |
pretend_to_be_authenticated("Administrator") | |
quentin = users( :quentin) | |
quentin.stub!( :match_permissions_with_subscription!) | |
rebecca = content_categories(:rebecca) | |
todd = content_categories(:todd) | |
howard = content_categories(:howard) | |
brian = content_categories(:brian) | |
ContentCategory.should_receive(:find_by_name).with("REBECCA RUNKLE").and_return(rebecca) | |
ContentCategory.should_receive(:find_by_name).with("TODD JORDAN").and_return(todd) | |
ContentCategory.should_receive(:find_by_name).with("HOWARD PENNEY").and_return(howard) | |
ContentCategory.should_receive(:find_by_name).with("BRIAN McGOUGH").and_return(brian) | |
quentin.should_receive(:set_permission).with(rebecca, Permission::NONE, nil, nil) | |
quentin.should_receive(:set_permission).with(todd, Permission::NONE, nil, nil) | |
quentin.should_receive(:set_permission).with(howard, Permission::TRIAL_FULL_TEXT, "1/1/2011", "1/7/2011") | |
quentin.should_receive(:set_permission).with(brian, Permission::TRIAL_REWIND, "1/8/2011", "1/15/2011") | |
quentin.should_receive(:permissions_valid?).and_return(true) | |
quentin.stub!(:valid?).and_return(true) | |
quentin.stub!(:credit_card_subscriber?).and_return(false) | |
quentin.should_receive(:activate) | |
quentin.should_receive(:save!) | |
User.stub!(:find_by_email).and_return(quentin) | |
create_user({:subscription => "Tier 1" }, | |
{ | |
:permissions => { | |
"REBECCA RUNKLE" => {:permission_type => Permission::NONE}, | |
"TODD JORDAN" => {:permission_type => Permission::NONE}, | |
"HOWARD PENNEY" => {:permission_type => Permission::TRIAL_FULL_TEXT, :trial_start => "1/1/2011", :trial_end => "1/7/2011"}, | |
"BRIAN McGOUGH" => {:permission_type => Permission::TRIAL_REWIND, :trial_start => "1/8/2011", :trial_end => "1/15/2011"} | |
} | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment