Sha256: 521e5f2e3743299744c782a900a291e8590be15c568756d8f45f42248c4eeb83
Contents?: true
Size: 1.61 KB
Versions: 131
Compression:
Stored size: 1.61 KB
Contents
require 'spec_helper' RSpec.describe Role, type: :model do let(:subject) { FactoryGirl.create(:role) } 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(:role_params) { open_canvas_fixture('roles')[0] } context 'the role does not already exist' do it 'creates it' do expect { Role.create_or_update_from_api_params(role_params) }.to change { Role.count }.by(1) role = Role.last expect(role.label).to eq(role_params['label']) expect(role.base_role_type).to eq(role_params['base_role_type']) expect(role.canvas_account_id).to eq(role_params['account']['id']) expect(role.permissions).to eq(role_params['permissions']) expect(role.workflow_state).to eq(role_params['workflow_state']) end end context 'the role already exists' do let!(:existing_role) { FactoryGirl.create(:role, canvas_id: role_params['id']) } it 'updates it' do expect { Role.create_or_update_from_api_params(role_params) }.to_not change { Role.count } existing_role.reload expect(existing_role.label).to eq(role_params['label']) expect(existing_role.base_role_type).to eq(role_params['base_role_type']) expect(existing_role.canvas_account_id).to eq(role_params['account']['id']) expect(existing_role.permissions).to eq(role_params['permissions']) expect(existing_role.workflow_state).to eq(role_params['workflow_state']) end end end end
Version data entries
131 entries across 131 versions & 1 rubygems