rosa-build/spec/controllers/api/v1/users_controller_spec.rb

94 lines
2.7 KiB
Ruby
Raw Normal View History

2012-10-15 15:43:09 +01:00
require 'spec_helper'
describe Api::V1::UsersController do
before(:all) { User.destroy_all }
before do
stub_symlink_methods
@user = FactoryGirl.create(:user)
end
context 'for guest' do
2014-01-21 04:51:49 +00:00
[:show_current_user, :notifiers].each do |action|
2012-10-15 15:43:09 +01:00
it "should not be able to perform #{ action } action for a current user" do
2014-01-21 04:51:49 +00:00
get action, format: :json
2012-10-15 15:43:09 +01:00
response.should_not be_success
end
end
it 'should be able to perform show action for a single user', :anonymous_access => true do
2014-01-21 04:51:49 +00:00
get :show, id: @user.id, format: :json
2012-10-15 15:43:09 +01:00
response.should render_template(:show)
end
it 'should not be able to perform show action for a single user', :anonymous_access => false do
2014-01-21 04:51:49 +00:00
get :show, id: @user.id, format: :json
2012-10-15 15:43:09 +01:00
response.should_not be_success
end
context 'should not be able to perform update action for a current user' do
before do
2014-01-21 04:51:49 +00:00
put :update, {user: {company: 'test_company'}}, format: :json
2012-10-15 15:43:09 +01:00
end
it { response.should_not be_success }
it 'ensures that user has not been updated' do
@user.reload
@user.company.should_not == 'test_company'
end
end
context 'should not be able to perform notifiers action for a current user' do
before do
2014-01-21 04:51:49 +00:00
put :notifiers, {notifiers: {can_notify: false}}, format: :json
2012-10-15 15:43:09 +01:00
end
it { response.should_not be_success }
it 'ensures that user notification settings have not been updated' do
@user.reload
@user.notifier.can_notify.should be_true
end
end
end
context 'for simple user' do
before do
http_login(@user)
end
[:show_current_user, :notifiers].each do |action|
2012-10-15 15:43:09 +01:00
it "should be able to perform #{ action } action for a current user" do
2014-01-21 04:51:49 +00:00
get action, format: :json
response.should be_success
2012-10-15 15:43:09 +01:00
end
end
it 'should be able to perform show action for a single user' do
2014-01-21 04:51:49 +00:00
get :show, id: @user.id, format: :json
2012-10-15 15:43:09 +01:00
response.should render_template(:show)
end
context 'should be able to perform update action for a current user' do
before do
2014-01-21 04:51:49 +00:00
put :update, {user: {company: 'test_company'}}, format: :json
2012-10-15 15:43:09 +01:00
end
it { response.should be_success }
it 'ensures that user has been updated' do
@user.reload
@user.company.should == 'test_company'
end
end
context 'should be able to perform notifiers action for a current user' do
before do
2014-01-21 04:51:49 +00:00
put :notifiers, {notifiers: {can_notify: false}}, format: :json
2012-10-15 15:43:09 +01:00
end
it { response.should be_success }
it 'ensures that user notification settings have been updated' do
@user.reload
@user.notifier.can_notify.should be_false
end
end
end
end