<commit_before>require 'transcribeme'
require 'securerandom'
require 'spec_helper'

describe TranscribeMe::Recording do

  describe 'Class Methods' do

    subject(:recordings) { TranscribeMe::Recording }

    describe '"respond_to"s' do

      [:all, :list, :to_a, :new_from_soap, :inspect, :to_s, :completed, 
        :in_progress, :processing_audio, :ready_for_transcription, :ready].each do |method|

        it "has a #{method.to_s} method" do
          expect(recordings).to respond_to method
        end

      end

      it 'aliases the all method to list' do
        expect(recordings.list).to eq recordings.all
      end

      it 'aliases the all method to to_a' do
        expect(recordings.to_a).to eq recordings.all
      end

      it 'aliases the inspect method to to_s' do
        expect(recordings.to_s).to eq recordings.inspect
      end

      it 'aliases the ready_for_transcription to ready' do
        expect(recordings.ready).to eq recordings.ready_for_transcription
      end

    end
  end

  describe 'instance methods' do

    before :all do
      ready_hash = {  date_created: DateTime.now, 
                      duration: 200.59, 
                      id: SecureRandom.uuid, 
                      name: "<NAME>", 
                      status: 10, 
                      state: "Ready for Transcription" }

      @recording = TranscribeMe::Recording.new(ready_hash)
    end

    [:date_created, :duration, :id, :name, :status, :state, :[], :keys].each do |method|
      it "has a #{method.to_s} method" do
        expect(@recording).to respond_to method
      end
    end

  end

  describe 'private setter methods' do

    before :each do
      @recording = TranscribeMe::Recording.new({})
    end

    describe 'typecasting the duration to a float' do

      it 'changes an integer to a float' do
        @recording.duration = 32
        expect(@recording.duration).to eq(32.0)
        expect(@recording.duration.class).to eq(Float)
      end

      it 'changes a string to a float' do
        @recording.duration = "32"
        expect(@recording.duration).to eq(32.0)
        expect(@recording.duration.class).to eq(Float)
      end

    end

    describe 'the status attribute sets a human readable state string' do

      describe 'typecasting the status to an integer' do

        it 'changes a string to an integer' do
          @recording.status = "10"
          expect(@recording.status).to eq(10)
          expect(@recording.status.class).to eq(Fixnum)
        end

      end

      describe 'setting the state string' do

        it 'sets the state string when the status code for ready' do
          @recording.status = 10
          expect(@recording.state).to eq('Ready for Transcription')
        end

        it 'sets the state string when the status code for Processing Audio' do
          @recording.status = 35
          expect(@recording.state).to eq('Processing Audio')
        end

        it 'sets the state string when the status code for In Progress' do
          @recording.status = 40
          expect(@recording.state).to eq('In Progress')
        end

        it 'sets the state string when the status code for Completed' do
          @recording.status = 50
          expect(@recording.state).to eq('Completed')
        end

      end

    end

  end

end<commit_msg>Tests for the internal contents of the recordings array<commit_after>require 'transcribeme'
require 'securerandom'
require 'spec_helper'

describe TranscribeMe::Recording do

  describe 'Class Methods' do

    subject(:recordings) { TranscribeMe::Recording }

    describe '"respond_to"s' do

      [:all, :list, :to_a, :new_from_soap, :inspect, :to_s, :completed, 
        :in_progress, :processing_audio, :ready_for_transcription, :ready].each do |method|

        it "has a #{method.to_s} method" do
          expect(recordings).to respond_to method
        end

      end

      it 'aliases the all method to list' do
        expect(recordings.list).to eq recordings.all
      end

      it 'aliases the all method to to_a' do
        expect(recordings.to_a).to eq recordings.all
      end

      it 'aliases the inspect method to to_s' do
        expect(recordings.to_s).to eq recordings.inspect
      end

      it 'aliases the ready_for_transcription to ready' do
        expect(recordings.ready).to eq recordings.ready_for_transcription
      end

    end
  end

  describe 'instance methods' do

    before :all do
      ready_hash = {  date_created: DateTime.now, 
                      duration: 200.59, 
                      id: SecureRandom.uuid, 
                      name: "<NAME>", 
                      status: 10, 
                      state: "Ready for Transcription" }

      @recording = TranscribeMe::Recording.new(ready_hash)
    end

    [:date_created, :duration, :id, :name, :status, :state, :[], :keys].each do |method|
      it "has a #{method.to_s} method" do
        expect(@recording).to respond_to method
      end
    end

  end

  describe 'private setter methods' do

    before :each do
      @recording = TranscribeMe::Recording.new({})
    end

    describe 'typecasting the duration to a float' do

      it 'changes an integer to a float' do
        @recording.duration = 32
        expect(@recording.duration).to eq(32.0)
        expect(@recording.duration.class).to eq(Float)
      end

      it 'changes a string to a float' do
        @recording.duration = "32"
        expect(@recording.duration).to eq(32.0)
        expect(@recording.duration.class).to eq(Float)
      end

    end

    describe 'the status attribute sets a human readable state string' do

      describe 'typecasting the status to an integer' do

        it 'changes a string to an integer' do
          @recording.status = "10"
          expect(@recording.status).to eq(10)
          expect(@recording.status.class).to eq(Fixnum)
        end

      end

      describe 'setting the state string' do

        it 'sets the state string when the status code for ready' do
          @recording.status = 10
          expect(@recording.state).to eq('Ready for Transcription')
        end

        it 'sets the state string when the status code for Processing Audio' do
          @recording.status = 35
          expect(@recording.state).to eq('Processing Audio')
        end

        it 'sets the state string when the status code for In Progress' do
          @recording.status = 40
          expect(@recording.state).to eq('In Progress')
        end

        it 'sets the state string when the status code for Completed' do
          @recording.status = 50
          expect(@recording.state).to eq('Completed')
        end

      end

    end

  end

  describe 'the internal array of recordings' do

    before :each do
      # Reset the list of recordings
      TranscribeMe::Recording::class_variable_set(:@@list, [])
      @list = TranscribeMe::Recording::class_variable_get(:@@list)

      @recording_factory = -> do 
        { date_created: DateTime.now, 
          duration: 200.59, 
          id: SecureRandom.uuid, 
          name: "<NAME>", 
          status: 10, 
          state: "Ready for Transcription" }
        end

      @recording = TranscribeMe::Recording.new_from_soap([@recording_factory.call])
    end

    # it "keeps an internal list of recordings" do
    #   expect do
    #     TranscribeMe::Recording.new_from_soap([@recording_factory.call])
    #   end.to change { @list.count }.by(1)
    # end

  end

end
{'fraction_non_alphanumeric': 0.09038641529616259, 'fraction_numerical': 0.008824709185720016, 'mean_word_length': 2.2227488151658767, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '784793', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2088, 'n_words': 674}