44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require 'db/mongo/models/user'
 | |
| require 'auth/devops_auth'
 | |
| require 'app/api3/routes/v3.0'
 | |
| 
 | |
| module Devops::Model
 | |
| RSpec.describe User, type: :model do
 | |
|   let(:user) { build(:user) }
 | |
| 
 | |
|   it 'is valid with correct attrs' do
 | |
|     expect(user).to be_valid
 | |
|   end
 | |
| 
 | |
|   describe 'validation' do
 | |
|     include_examples 'field type validation', :id, :not_nil, :non_empty_string, :only_word_symbols
 | |
|     include_examples 'field type validation', :password, :not_nil
 | |
|     include_examples 'field type validation', :email, :not_nil
 | |
|   end
 | |
| 
 | |
|   it '#to_hash returns id, email and roles' do
 | |
|     expect(user.to_hash.keys).to match_array(%w(id email roles))
 | |
|   end
 | |
| 
 | |
|   describe '.create_root', clean_db_after_example: true do
 | |
|     subject { User.create_root }
 | |
| 
 | |
|     it 'create a user' do
 | |
|       expect { subject }.to change { User.count }
 | |
|     end
 | |
| 
 | |
|     it 'his name is root' do
 | |
|       expect(subject.id).to eq User::ROOT_USER_NAME
 | |
|     end
 | |
| 
 | |
|     it 'his password is root password' do
 | |
|       expect(subject.password).to eq User::ROOT_PASSWORD
 | |
|     end
 | |
| 
 | |
|     it "doesn't create another user if root already exists" do
 | |
|       User.create_root
 | |
|       expect { subject }.not_to change { User.count }
 | |
|     end
 | |
|   end
 | |
| end
 | |
| end | 
