Sha256: 48188127bf09cdfa3b64ddbf5ce91d7f18c1820ea70ae63308f3f543deb46b75

Contents?: true

Size: 1.66 KB

Versions: 19

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

module OpenStax::Accounts
  describe Group do
    context 'validation' do
      it 'requires a unique openstax_uid' do
        group = FactoryGirl.build(:openstax_accounts_group, openstax_uid: nil)
        expect(group).not_to be_valid
        expect(group.errors[:openstax_uid]).to eq(['can\'t be blank'])

        group.openstax_uid = 1
        group.save!

        group_2 = FactoryGirl.build(:openstax_accounts_group, openstax_uid: 1)
        expect(group_2).not_to be_valid
        expect(group_2.errors[:openstax_uid]).to eq(['has already been taken'])
      end
    end

    context 'no stubbing' do
      before(:all)     do
        @stubbing = OpenStax::Accounts.configuration.enable_stubbing?
        OpenStax::Accounts.configuration.enable_stubbing = false
      end

      after(:all)      { OpenStax::Accounts.configuration.enable_stubbing = @stubbing }

      let!(:requestor) { FactoryGirl.create(:openstax_accounts_account) }
      let!(:group)     do
        FactoryGirl.build(:openstax_accounts_group).tap{ |group| group.requestor = requestor }
      end

      it 'calls OpenStax Accounts when created' do
        expect(OpenStax::Accounts::Api).to receive(:create_group).with(requestor, group)
        group.save!
      end

      it 'fails to save if the requestor is nil' do
        group.requestor = nil
        expect(OpenStax::Accounts::Api).not_to receive(:create_group)
        expect(group.save).to eq false
      end

      it 'does not call OpenStax Accounts if the requestor is temp' do
        group.requestor.access_token = nil
        expect(OpenStax::Accounts::Api).not_to receive(:create_group)
        group.save!
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
openstax_accounts-7.8.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.7.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.6.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.5.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.4.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.3.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.2.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.1.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.0.1 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-7.0.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.4.2 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.4.1 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.4.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.3.2 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.3.1 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.3.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.2.0 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.1.7 spec/models/openstax/accounts/group_spec.rb
openstax_accounts-6.1.6 spec/models/openstax/accounts/group_spec.rb