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

Version Path
canvas_sync-0.18.5 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.18.3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.18.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.18.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.18.0.beta2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.18.0.beta1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.43 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.42 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.41 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.40 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.39 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.38 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.37 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.36 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.35 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.34 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.33 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.32 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.31 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.30 spec/canvas_sync/models/admins_spec.rb