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.17.3.beta1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.2 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta15 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta14 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta13 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta12 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta11 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta10 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta9 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta8 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta7 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta6 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta5 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.11.1 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta4 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.16.5 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta3 spec/canvas_sync/models/admins_spec.rb
canvas_sync-0.17.0.beta2 spec/canvas_sync/models/admins_spec.rb