Fixed controller tests.

This commit is contained in:
Martin Edenhofer 2016-08-12 19:58:02 +02:00
parent 1a6a6b84a3
commit 825df71df1
3 changed files with 26 additions and 5 deletions

View file

@ -146,7 +146,7 @@ class UsersController < ApplicationController
# everybody else will go as customer per default
else
role_ids.push Role.signup_role_ids
role_ids = Role.signup_role_ids
end
user.role_ids = role_ids
user.group_ids = group_ids

View file

@ -2102,6 +2102,10 @@ Role.create_if_not_exists(
id: 1,
name: 'Admin',
note: 'To configure your system.',
preferences: {
not: ['Customer'],
},
default_at_signup: false,
updated_by_id: 1,
created_by_id: 1
)
@ -2109,6 +2113,10 @@ Role.create_if_not_exists(
id: 2,
name: 'Agent',
note: 'To work on Tickets.',
default_at_signup: false,
preferences: {
not: ['Customer'],
},
updated_by_id: 1,
created_by_id: 1
)
@ -2116,6 +2124,10 @@ Role.create_if_not_exists(
id: 3,
name: 'Customer',
note: 'People who create Tickets ask for help.',
preferences: {
not: %w(Agent Admin),
},
default_at_signup: true,
updated_by_id: 1,
created_by_id: 1
)
@ -2123,6 +2135,10 @@ Role.create_if_not_exists(
id: 4,
name: 'Report',
note: 'Access the report area.',
preferences: {
not: ['Customer'],
},
default_at_signup: false,
created_by_id: 1,
updated_by_id: 1,
)

View file

@ -102,7 +102,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert(result['error'])
assert_equal('User already exists!', result['error'])
# create user with enabled feature
# create user with enabled feature (take customer role)
params = { firstname: 'Me First', lastname: 'Me Last', email: 'new_here@example.com', signup: true }
post '/api/v1/users', params.to_json, @headers
assert_response(201)
@ -113,8 +113,12 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert_equal('Me Last', result['lastname'])
assert_equal('new_here@example.com', result['login'])
assert_equal('new_here@example.com', result['email'])
user = User.find(result['id'])
assert_not(user.role?('Admin'))
assert_not(user.role?('Agent'))
assert(user.role?('Customer'))
# create user with admin role
# create user with admin role (not allowed for signup, take customer role)
role = Role.lookup(name: 'Admin')
params = { firstname: 'Admin First', lastname: 'Admin Last', email: 'new_admin@example.com', role_ids: [ role.id ], signup: true }
post '/api/v1/users', params.to_json, @headers
@ -126,7 +130,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert_not(user.role?('Agent'))
assert(user.role?('Customer'))
# create user with agent role
# create user with agent role (not allowed for signup, take customer role)
role = Role.lookup(name: 'Agent')
params = { firstname: 'Agent First', lastname: 'Agent Last', email: 'new_agent@example.com', role_ids: [ role.id ], signup: true }
post '/api/v1/users', params.to_json, @headers
@ -138,7 +142,7 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert_not(user.role?('Agent'))
assert(user.role?('Customer'))
# no user
# no user (because of no session)
get '/api/v1/users', {}, @headers
assert_response(401)
result = JSON.parse(@response.body)
@ -439,4 +443,5 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert_equal( result['name'], nil)
end
end