rosa-build/spec/controllers/users_controller_spec.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
2011-03-10 11:35:46 +00:00
require 'spec_helper'
describe UsersController do
2011-12-15 17:08:29 +00:00
before(:each) do
stub_rsync_methods
@simple_user = FactoryGirl.create(:user)
@other_user = FactoryGirl.create(:user)
@admin = FactoryGirl.create(:admin)
2011-12-15 17:08:29 +00:00
%w[user1 user2 user3].each do |uname|
FactoryGirl.create(:user, :uname => uname, :email => "#{ uname }@nonexistanceserver.com")
2011-12-15 17:08:29 +00:00
end
2012-03-21 20:05:27 +00:00
@update_params = {:email => 'new_email@test.com'}
2011-12-15 17:08:29 +00:00
end
context 'for guest' do
2012-03-21 20:05:27 +00:00
it 'should not be able to view profile' do
get :profile
response.should redirect_to(new_user_session_path)
end
it 'should not be able to update other profile' do
get :update, {:id => @other_user.id}.merge(@update_params)
2011-12-15 17:08:29 +00:00
response.should redirect_to(new_user_session_path)
2012-03-21 20:05:27 +00:00
@other_user.reload.email.should_not == @update_params[:email]
2011-12-15 17:08:29 +00:00
end
end
context 'for simple user' do
before(:each) do
set_session_for(@simple_user)
end
2011-03-10 11:35:46 +00:00
2012-03-21 20:05:27 +00:00
it 'should be able to view profile' do
get :profile
response.code.should eq('200')
end
context 'with mass assignment' do
it 'should not be able to update role' do
@simple_user.should_not allow_mass_assignment_of :role
end
it 'should not be able to update other user' do
@simple_user.should_not allow_mass_assignment_of :id
end
end
2011-12-15 17:08:29 +00:00
end
2011-03-10 11:35:46 +00:00
end