Sha256: 93e3a8476c0abcd360df79309f7607d369858fd3ce8240d47b63fb5937fef98a

Contents?: true

Size: 1.69 KB

Versions: 126

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

RSpec.describe RockRMS::Response::Group, type: :model do
  let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_members.json')) }

  describe '.format' do
    subject(:result) { described_class.format(parsed) }

    context 'when response is array' do
      it 'returns an array' do
        expect(described_class.format([])).to be_a(Array)
      end
    end

    it 'translates keys' do
      result.zip(parsed) do |r, p|
        expect(r[:id]).to eq(p['Id'])
        expect(r[:name]).to eq(p['Name'])
        expect(r[:group_type_id]).to eq(p['GroupTypeId'])
        expect(r[:parent_group_id]).to eq(p['ParentGroupId'])
        expect(r[:campus_id]).to eq(p['CampusId'])
        expect(r[:is_active]).to eq(p['IsActive'])
        expect(r[:guid]).to eq(p['Guid'])
        expect(r[:members]).to eq(p['Members'])
      end
    end

    context 'when locations are included' do
      let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_locations.json')) }

      it 'formats with GroupLocations' do
        expect(RockRMS::Response::GroupLocation).to receive(:format)
          .with(parsed.first['GroupLocations'])
          .and_return([{ some_key: :value }])
        result
        expect(result.first[:group_locations]).to eq([{ some_key: :value }])
      end
    end

    context 'when campus is included' do
      let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_campus.json')) }

      it 'formats with Campus' do
        expect(RockRMS::Response::Campus).to receive(:format)
          .with(parsed.first['Campus'])
          .and_return([{ some_key: :value }])
        result
        expect(result.first[:campus]).to eq([{ some_key: :value }])
      end
    end
  end
end

Version data entries

126 entries across 126 versions & 1 rubygems

Version Path
rock_rms-9.15.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.14.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.13.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.12.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.11.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.10.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.9.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.8.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.7.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.6.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.5.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.4.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.3.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.2.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.1.0 spec/rock_rms/response/group_spec.rb
rock_rms-9.0.0 spec/rock_rms/response/group_spec.rb
rock_rms-8.23.0 spec/rock_rms/response/group_spec.rb
rock_rms-8.22.0 spec/rock_rms/response/group_spec.rb
rock_rms-8.21.0 spec/rock_rms/response/group_spec.rb
rock_rms-8.20.0 spec/rock_rms/response/group_spec.rb