Sha256: 81baa2046d3a129a1066df57b5dcbda4ba1816383eb3b82c1f0c4b65dd5ad52d
Contents?: true
Size: 1.49 KB
Versions: 131
Compression:
Stored size: 1.49 KB
Contents
require 'spec_helper' RSpec.describe Admin, type: :model do let(:subject) { FactoryGirl.create(:admin) } describe 'validations' do it { should validate_presence_of(:canvas_id) } it { should validate_uniqueness_of(:canvas_id) } end describe '.create_or_update_from_api_params' do let(:admin_params) { open_canvas_fixture('admins')[0] } context 'the admin does not already exist' do it 'creates it' do expect { Admin.create_or_update_from_api_params(admin_params) }.to change { Admin.count }.by(1) admin = Admin.last expect(admin.role_name).to eq(admin_params['role']) expect(admin.canvas_role_id).to eq(admin_params['role_id']) expect(admin.canvas_user_id).to eq(admin_params['user']['id']) expect(admin.workflow_state).to eq(admin_params['workflow_state']) end end context 'the admin already exists' do let!(:existing_admin) { FactoryGirl.create(:admin, canvas_id: admin_params['id']) } it 'updates it' do expect { Admin.create_or_update_from_api_params(admin_params) }.to_not change { Admin.count } existing_admin.reload expect(existing_admin.role_name).to eq(admin_params['role']) expect(existing_admin.canvas_role_id).to eq(admin_params['role_id']) expect(existing_admin.canvas_user_id).to eq(admin_params['user']['id']) expect(existing_admin.workflow_state).to eq(admin_params['workflow_state']) end end end end
Version data entries
131 entries across 131 versions & 1 rubygems