Sha256: 3d77aeec9ef11b3f5676958d014baf4b10e693abba29c97bbd27c43722e761ce

Contents?: true

Size: 1.58 KB

Versions: 42

Compression:

Stored size: 1.58 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_admin_id) }
    it { should validate_uniqueness_of(:canvas_admin_id) }
  end

  describe '.create_or_update' 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(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.user_data).to eq(admin_params['user'])
        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_admin_id: admin_params['id']) }

      it 'updates it' do
        expect {
          Admin.create_or_update(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.user_data).to eq(admin_params['user'])
        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

42 entries across 42 versions & 1 rubygems

Version Path
canvas_sync-0.9.4 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.9.3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.9.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.9.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.9.0 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.8.4 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.8.3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.8.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.8.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.8.0 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.7.3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.7.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.7.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.7.0 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.6.4 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.6.3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.6.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.6.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.6.0 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.5.4 spec/canvas_sync/models/admins_spec.rb