fluke/devops-service/spec/models/user_spec.rb

44 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2015-11-03 11:46:54 +03:00
require 'db/mongo/models/user'
2018-04-04 22:44:39 +03:00
require 'auth/devops_auth'
require 'app/api3/routes/v3.0'
2015-11-03 11:46:54 +03:00
2018-04-04 22:44:39 +03:00
module Devops::Model
RSpec.describe User, type: :model do
2015-11-03 11:46:54 +03:00
let(:user) { build(:user) }
it 'is valid with correct attrs' do
expect(user).to be_valid
end
describe 'validation' do
2018-04-04 22:44:39 +03:00
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
2015-11-03 11:46:54 +03:00
end
2018-04-04 22:44:39 +03:00
it '#to_hash returns id, email and roles' do
expect(user.to_hash.keys).to match_array(%w(id email roles))
2015-11-03 11:46:54 +03:00
end
2018-04-04 22:44:39 +03:00
describe '.create_root', clean_db_after_example: true do
subject { User.create_root }
2015-11-03 11:46:54 +03:00
2018-04-04 22:44:39 +03:00
it 'create a user' do
expect { subject }.to change { User.count }
2015-11-03 11:46:54 +03:00
end
it 'his name is root' do
2018-04-04 22:44:39 +03:00
expect(subject.id).to eq User::ROOT_USER_NAME
2015-11-03 11:46:54 +03:00
end
it 'his password is root password' do
2018-04-04 22:44:39 +03:00
expect(subject.password).to eq User::ROOT_PASSWORD
2015-11-03 11:46:54 +03:00
end
2018-04-04 22:44:39 +03:00
it "doesn't create another user if root already exists" do
User.create_root
expect { subject }.not_to change { User.count }
2015-11-03 11:46:54 +03:00
end
end
end
2018-04-04 22:44:39 +03:00
end