Sha256: 5ea6a153a485870b502961acd257af9485eb0e94d24766cfe6a6dd052ef5bc1a

Contents?: true

Size: 1.55 KB

Versions: 44

Compression:

Stored size: 1.55 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_role_id) }
    it { should validate_uniqueness_of(:canvas_role_id) }
  end

  describe '.create_or_update' 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(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.account).to eq(role_params['account'])
        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_role_id: role_params['id']) }

      it 'updates it' do
        expect {
          Role.create_or_update(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.account).to eq(role_params['account'])
        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

44 entries across 44 versions & 1 rubygems

Version Path
canvas_sync-0.5.3 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.5.2 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.5.1 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.4.1 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.4.0 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.23 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.22 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.21 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.20 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.19 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.18 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.17 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.16 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.15 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.14 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.13 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.12 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.11 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.10 spec/canvas_sync/models/roles_spec.rb
canvas_sync-0.3.9 spec/canvas_sync/models/roles_spec.rb