OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/controllers/principal_roles_controller_...

78 lines
2.3 KiB

require File.dirname(__FILE__) + '/../spec_helper'
describe PrincipalRolesController do
before(:each) do
@controller.stub!(:require_admin).and_return(true)
@principal_role = mock_model PrincipalRole
disable_flash_sweep
end
describe :post do
before :each do
@params = {"principal_role"=>{"principal_id"=>"3", "role_ids"=>["7"]}}
end
describe :create do
before :each do
end
describe "SUCCESS" do
before :each do
@global_role = mock_model(GlobalRole)
@global_role.stub!(:id).and_return(42)
Role.stub!(:find).and_return([@global_role])
PrincipalRole.stub!(:new).and_return(@principal_role)
@principal_role.stub!(:role=)
@principal_role.stub!(:role).and_return(@global_role)
@principal_role.stub!(:save)
end
describe "js" do
before :each do
response_should_render :remove, "principal_role_option_#{@global_role.id}"
response_should_render :insert_html,
:top, 'table_principal_roles_body',
:partial => "principal_roles/show_table_row",
:locals => {:principal_role => anything()}
xhr :post, :create, @params
end
it { response.should be_success }
end
end
end
end
describe :delete do
before :each do
PrincipalRole.stub!(:find).and_return @principal_role
@principal_role.stub!(:principal_id).and_return(1)
Principal.stub(:find).and_return(mock_model User)
@principal_role.stub!(:destroy)
@params = {"id" => "1"}
end
describe :destroy do
describe "SUCCESS" do
before :each do
response_should_render :remove, "principal_role_1"
response_should_render :replace,
"available_principal_roles",
:partial => "users/available_global_roles",
:locals => {:global_roles => anything(),
:user => anything()}
end
describe "js" do
before :each do
xhr :delete, :destroy, @params
end
it { response.should be_success }
end
end
end
end
end