mirror of
https://github.com/openSUSE/osem.git
synced 2026-05-11 17:20:09 -04:00
Merge pull request #114 from gopesht/testing
some basic tests and fixed bug to display users
This commit is contained in:
@@ -2,7 +2,11 @@ class Admin::UsersController < ApplicationController
|
||||
before_filter :verify_admin
|
||||
|
||||
def index
|
||||
@users = User.joins(:person).order('people.last_name ASC')
|
||||
@users = User.joins(:person).order("people.last_name ASC").select("users.*,
|
||||
people.last_name AS last_name,
|
||||
people.first_name AS first_name,
|
||||
people.public_name AS public_name,
|
||||
people.email AS email")
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -18,7 +18,6 @@ describe Admin::ConferenceController do
|
||||
it 'locates the requested conference' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con')
|
||||
|
||||
expect(assigns(:conference)).to eq(conference)
|
||||
end
|
||||
|
||||
55
spec/controllers/admin/users_controller_spec.rb
Normal file
55
spec/controllers/admin/users_controller_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'spec_helper'
|
||||
describe Admin::UsersController do
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:user) { create(:user) }
|
||||
before(:each) do
|
||||
sign_in(admin)
|
||||
end
|
||||
describe 'GET #index' do
|
||||
it 'populates an array of users' do
|
||||
user1 = create(:user, email: 'gopesh.7500@gmail.com')
|
||||
user2 = create(:user, email: 'gopesh_750@gmail.com')
|
||||
get :index
|
||||
expect(assigns(:users)).to match_array([user, admin, user1, user2])
|
||||
end
|
||||
it 'renders index template' do
|
||||
get :index
|
||||
expect(response).to render_template :index
|
||||
end
|
||||
end
|
||||
describe 'PATCH #update' do
|
||||
context 'valid attributes' do
|
||||
it 'locates requested @user' do
|
||||
patch :update, id: user.id
|
||||
expect(build(:user, id: user.id)).to eq(user)
|
||||
end
|
||||
it 'changes @users attributes' do
|
||||
patch :update, id: user.id
|
||||
expect(build(
|
||||
:user, email: 'example@incoherent.de', id: user.id).email).
|
||||
to eq('example@incoherent.de')
|
||||
end
|
||||
it "redirects to the updated user" do
|
||||
patch :update, id: user.id
|
||||
expect(response).to redirect_to admin_users_path
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'DELETE #destroy' do
|
||||
before :each do
|
||||
@user = create(:user)
|
||||
end
|
||||
context 'valid attributes' do
|
||||
it 'it deletes the contact' do
|
||||
expect { delete :destroy, id: @user.id }.to change(User, :count).by(-1)
|
||||
end
|
||||
it 'redirects to users#index' do
|
||||
delete :destroy, id: @user
|
||||
expect(response).to redirect_to admin_users_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -8,4 +8,5 @@ FactoryGirl.define do
|
||||
maximum_abstract_length 500
|
||||
conference
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
email 'example@example.com'
|
||||
sequence(:email) { |n| "example#{n}@example.com" }
|
||||
password 'changeme'
|
||||
password_confirmation 'changeme'
|
||||
confirmed_at Time.now
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
RSpec.configure do |config|
|
||||
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
@@ -7,8 +6,8 @@ RSpec.configure do |config|
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
|
||||
config.before(:each, js: true) do
|
||||
|
||||
config.before(:each, :js => true) do
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user