Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.dirname(__FILE__) + '/../spec_helper'
- module UserSpecHelper
- def valid_user_attributes
- {
- :login => 'giams',
- :email => 'ge.iams@gmail.com',
- :password => 'password',
- :password_confirmation => 'password',
- }
- end
- def admin_role
- create_right = mock(Right)
- create_right.stub!(:controller).and_return('users')
- create_right.stub!(:action).and_return('create')
- delete_right = mock(Right)
- delete_right.stub!(:controller).and_return('users')
- delete_right.stub!(:action).and_return('delete')
- Role.stub!(:rights).and_return([create_right, delete_right])
- end
- def user_role
- list_right = mock(Right)
- list_right.stub!(:controller).and_return('conferences')
- list_right.stub!(:action).and_return('list')
- Role.stub!(:rights).and_return(list_right)
- end
- def mock_role(name)
- mock(Role).stub!(:name).and_return(name)
- end
- def mock_rights(controller, *actions)
- rights = []
- actions.each do |a|
- r = mock(Right).stub!(:controller).and_return(controller)
- r.stub!(:action).and_return(a)
- rights << r
- end
- rights
- end
- end
- describe User, ' authorization' do
- include UserSpecHelper
- before(:each) do
- @user = User.new
- end
- # TODO: implement unit tests as spec cases
- it "should succeed if their role supports the action they attempt" do
- @user.attributes = valid_user_attributes.merge({ :role => 'admin' })
- admin = mock_role('admin')
- admin.stub!(:rights).and_return(mock_rights('users', 'create', 'destroy'))
- @user.has_right_for?('users', 'create').should be_true
- end
- it "should fail if their role doesn't support the action they attempt" do
- @user.attributes = valid_user_attributes.merge({ :role => 'user' })
- user = mock_role('user')
- user.stub!(:rights).and_return(mock_rights('conferences', 'list'))
- @user.has_right_for?('users', 'create').should be_false
- end
- # it "should be valid" do
- # @user.should be_valid
- # end
- end
Add Comment
Please, Sign In to add comment