2012-10-15 15:43:09 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Api::V1::UsersController, type: :controller do
|
2012-10-15 15:43:09 +01:00
|
|
|
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
|
|
|
|
2012-10-15 16:47:42 +01: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
|
2015-04-01 22:34:14 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-15 15:43:09 +01:00
|
|
|
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
|
2015-04-01 22:34:14 +01:00
|
|
|
expect(response).to render_template(:show)
|
2012-10-15 15:43:09 +01:00
|
|
|
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
|
2015-04-01 22:34:14 +01:00
|
|
|
expect(response).to_not be_success
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should not be able to perform update action for a current user' do
|
|
|
|
it 'ensures that user has not been updated' do
|
2015-04-01 22:34:14 +01:00
|
|
|
put :update, user: { company: 'test_company' }, format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(@user.reload.company).to_not eq 'test_company'
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should not be able to perform notifiers action for a current user' do
|
|
|
|
before do
|
|
|
|
end
|
|
|
|
it 'ensures that user notification settings have not been updated' do
|
2015-04-01 22:34:14 +01:00
|
|
|
put :notifiers, notifiers: { can_notify: false }, format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(@user.reload.notifier.can_notify).to be_truthy
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
|
|
|
before do
|
|
|
|
http_login(@user)
|
|
|
|
end
|
|
|
|
|
2012-10-15 16:47:42 +01:00
|
|
|
[: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
|
2015-04-01 22:34:14 +01:00
|
|
|
expect(response).to 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
|
2015-04-01 22:34:14 +01:00
|
|
|
expect(response).to render_template(:show)
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be able to perform update action for a current user' do
|
|
|
|
it 'ensures that user has been updated' do
|
2015-04-01 22:34:14 +01:00
|
|
|
put :update, user: { company: 'test_company' }, format: :json
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(@user.reload.company).to eq 'test_company'
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'should be able to perform notifiers action for a current user' do
|
|
|
|
it 'ensures that user notification settings have been updated' do
|
2015-04-01 22:34:14 +01:00
|
|
|
put :notifiers, notifiers: {can_notify: false }, format: :json
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(@user.reload.notifier.can_notify).to be_falsy
|
2012-10-15 15:43:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|