Controller test for users#show
This commit is contained in:
parent
786d2c7985
commit
4b225f321c
5 changed files with 71 additions and 17 deletions
|
|
@ -217,8 +217,8 @@ module Admin
|
|||
def get_users(role_name)
|
||||
@role_users = {}
|
||||
# Initialize @role variable, so that view can show the role description
|
||||
@role = Role.find_by(name: role_name, resource: @conference) || []
|
||||
@role.blank? ? @role_users[role_name] = [] : (@role_users[role_name] = (User.with_role @role.name, @role.resource).to_a)
|
||||
@role = Role.where(name: role_name, resource: @conference) || []
|
||||
@role.blank? ? @role_users[role_name] = [] : (@role_users[role_name] = (User.with_role @role.first.name, @role.first.resource).to_a)
|
||||
|
||||
@role_users
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ Rolify.configure do |config|
|
|||
|
||||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
|
||||
# Enable this feature _after_ running rake db:migrate as it relies on the roles table
|
||||
config.use_dynamic_shortcuts
|
||||
# config.use_dynamic_shortcuts
|
||||
end
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ describe Admin::ConferenceController do
|
|||
end
|
||||
|
||||
it 'finds the correct role' do
|
||||
expect(assigns(:role)).to eq(organizer_role)
|
||||
expect(assigns(:role)).to eq([organizer_role])
|
||||
end
|
||||
|
||||
it 'properly assigns role_users hash' do
|
||||
|
|
@ -237,7 +237,7 @@ describe Admin::ConferenceController do
|
|||
|
||||
it 'sets role variable' do
|
||||
post :roles, id: conference.short_title, user: { roles: 'Organizer' }
|
||||
expect(assigns(:role)).to eq(organizer_role)
|
||||
expect(assigns(:role)).to eq([organizer_role])
|
||||
end
|
||||
|
||||
it 'sets role variable (returns blank for nil role)' do
|
||||
|
|
|
|||
66
spec/controllers/users_controller_spec.rb
Normal file
66
spec/controllers/users_controller_spec.rb
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe UsersController do
|
||||
let!(:first_user) { create(:user) }
|
||||
let!(:user) { create(:user, name: 'My Name') }
|
||||
|
||||
describe 'GET #show' do
|
||||
before :each do
|
||||
get :show, id: user.id
|
||||
end
|
||||
|
||||
it 'renders show template' do
|
||||
expect(response).to render_template :show
|
||||
end
|
||||
|
||||
it 'assigns the right value to @user' do
|
||||
expect(assigns(:user)).to eq user
|
||||
end
|
||||
|
||||
it 'assigns [] to @events, when user does not have any submissions' do
|
||||
expect(assigns(:events)).to eq []
|
||||
end
|
||||
|
||||
it 'assigns the correct value to @events, when the user has submissions' do
|
||||
conference = create(:conference)
|
||||
event = create(:event, state: 'confirmed', program: conference.program)
|
||||
event.event_users = [create(:event_user, user: user, event_role: 'submitter')]
|
||||
|
||||
expect(assigns(:events)).to eq [event]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
it 'assigns the right value to @user' do
|
||||
sign_in user
|
||||
get :edit, id: user.id
|
||||
expect(assigns(:user)).to eq user
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
context 'with valid attributes' do
|
||||
before :each do
|
||||
sign_in user
|
||||
patch :update, id: user.id, user: attributes_for(:user, name: 'My Test Name')
|
||||
user.reload
|
||||
end
|
||||
|
||||
it 'assigns the right value to @user' do
|
||||
expect(assigns(:user)).to eq user
|
||||
end
|
||||
|
||||
it 'changes user attributes' do
|
||||
expect(user.name).to eq 'My Test Name'
|
||||
end
|
||||
|
||||
it 'redirects to show' do
|
||||
expect(response).to redirect_to(user_path(user))
|
||||
end
|
||||
|
||||
it 'shows flash message' do
|
||||
expect(flash[:notice]).to eq 'User was successfully updated.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature User do
|
||||
|
||||
shared_examples 'admin ability' do
|
||||
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'admin ability', :admin
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue