From 825df71df133599a171e5a9d5c6a62fdc5352fda Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 12 Aug 2016 19:58:02 +0200 Subject: [PATCH] Fixed controller tests. --- app/controllers/users_controller.rb | 2 +- db/seeds.rb | 16 ++++++++++++++++ .../user_organization_controller_test.rb | 13 +++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9ee81a255..9c621a3f8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 2efe9d784..a2ecac87b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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, ) diff --git a/test/controllers/user_organization_controller_test.rb b/test/controllers/user_organization_controller_test.rb index a24a3c387..3d3284096 100644 --- a/test/controllers/user_organization_controller_test.rb +++ b/test/controllers/user_organization_controller_test.rb @@ -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