<commit_before>require 'spec_helper'

RSpec.describe OneviewSDK::Enclosure do
  include_context 'shared context'

  describe '#initialize' do
    context 'OneView 1.2' do
      it 'sets the defaults correctly' do
        profile = OneviewSDK::Enclosure.new(@client_120)
        expect(profile[:type]).to eq('EnclosureV2')
      end
    end

    context 'OneView 2.0' do
      it 'sets the defaults correctly' do
        profile = OneviewSDK::Enclosure.new(@client)
        expect(profile[:type]).to eq('EnclosureV200')
      end
    end
  end

  describe '#create' do
    context 'with valid data' do
      before :each do
        allow_any_instance_of(OneviewSDK::Enclosure).to receive(:save).and_return(true)
        allow_any_instance_of(OneviewSDK::Client).to receive(:rest_api).and_return(true)
        allow_any_instance_of(OneviewSDK::Client).to receive(:response_handler).and_return(name: 'Encl1', serialNumber: 'Fake', uri: '/rest/fake')

        @data = {
          'name' => 'Fake-Enclosure',
          'hostname' => '1.1.1.1',
          'username' => 'Admin',
          'password' => '<PASSWORD>',
          'enclosureGroupUri' => '/rest/enclosure-groups/fake',
          'licensingIntent' => 'OneView',
          'force' => true
        }
        @profile = OneviewSDK::Enclosure.new(@client, @data)
      end

      it 'only sends certain attributes on the POST' do
        expect(@client).to receive(:rest_post).with('/rest/enclosures', { 'body' => @data.select { |k, _v| k != 'name' } }, anything)
        @profile.create
      end

      it 'sets the enclosure name correctly' do
        @profile.create
        expect(@profile[:name]).to eq('Fake-Enclosure')
      end

      it 'uses the given name if one is not specified' do
        @profile.data.delete('name')
        @profile.create
        expect(@profile[:name]).to eq('Encl1')
      end
    end

    context 'with invalid data' do
      it 'fails when certain attributes are not set' do
        profile = OneviewSDK::Enclosure.new(@client, {})
        expect { profile.create }.to raise_error(/Missing required attribute/)
      end
    end
  end
end<commit_msg>Update enclosure_spec.rb<commit_after>require 'spec_helper'

RSpec.describe OneviewSDK::Enclosure do
  include_context 'shared context'

  describe '#initialize' do
    context 'OneView 1.2' do
      it 'sets the defaults correctly' do
        enclosure = OneviewSDK::Enclosure.new(@client_120)
        expect(enclosure[:type]).to eq('EnclosureV2')
      end
    end

    context 'OneView 2.0' do
      it 'sets the defaults correctly' do
        enclosure = OneviewSDK::Enclosure.new(@client)
        expect(enclosure[:type]).to eq('EnclosureV200')
      end
    end
  end

  describe '#create' do
    context 'with valid data' do
      before :each do
        allow_any_instance_of(OneviewSDK::Enclosure).to receive(:save).and_return(true)
        allow_any_instance_of(OneviewSDK::Client).to receive(:rest_api).and_return(true)
        allow_any_instance_of(OneviewSDK::Client).to receive(:response_handler).and_return(name: 'Encl1', serialNumber: 'Fake', uri: '/rest/fake')

        @data = {
          'name' => 'Fake-Enclosure',
          'hostname' => '1.1.1.1',
          'username' => 'Admin',
          'password' => '<PASSWORD>',
          'enclosureGroupUri' => '/rest/enclosure-groups/fake',
          'licensingIntent' => 'OneView',
          'force' => true
        }
        @enclosure = OneviewSDK::Enclosure.new(@client, @data)
      end

      it 'only sends certain attributes on the POST' do
        expect(@client).to receive(:rest_post).with('/rest/enclosures', { 'body' => @data.select { |k, _v| k != 'name' } }, anything)
        @enclosure.create
      end

      it 'sets the enclosure name correctly' do
        @enclosure.create
        expect(@enclosure[:name]).to eq('Fake-Enclosure')
      end

      it 'uses the given name if one is not specified' do
        @enclosure.data.delete('name')
        @enclosure.create
        expect(@enclosure[:name]).to eq('Encl1')
      end
    end

    context 'with invalid data' do
      it 'fails when certain attributes are not set' do
        enclosure = OneviewSDK::Enclosure.new(@client, {})
        expect { enclosure.create }.to raise_error(/Missing required attribute/)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12815758980301276, 'fraction_numerical': 0.007879490150637311, 'mean_word_length': 2.7174849267872525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4902438', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1283, 'n_words': 318}