<commit_before>require 'spec_helper'

describe SubjectsController do
  describe 'GET #index' do
    before { make_request }

    def make_request
      get :index, format: :json
    end

    its(:response) { should be_success }
  end

  describe 'GET #show' do
    let!(:property) { create(:property, name: '123 Main Street') }

    def make_request(property_id = property.id)
      get :show, id: property_id
    end

    context 'when requesting a subject by property id' do
      before { make_request }

      its(:response) { should be_success }

      it 'assigns subject' do
        expect(assigns(:subject)).to eq(property)
      end

      it 'assigns content' do
        expect(assigns(:content)).to_not be_nil
      end

      context 'when there is a numerical response for the property' do
        let(:question) { create(:question, :number) }
        before do
          create(:feedback_input, property: property, question: question, numerical_response: 1)
          make_request
        end

        it 'assigns numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_true
        end

        it 'assigns numerical responses' do
          expect(assigns(:numerical_responses)).to have(1).numerical_response
        end

        it 'assigns a numerical response for the question' do
          expect(assigns(:numerical_responses).first.short_name).to eq(question.short_name)
        end

        it 'assigns numerical response with a response hash for the question' do
          expect(assigns(:numerical_responses).first.response_hash).to eq({"Repair"=>1, "Remove"=>0})
        end
      end

      context 'when there is a voice response for the property' do
        let(:question) { create(:question, :voice) }
        let!(:feedback_input) { create(:feedback_input, :with_voice_file, property: property, question: question) }

        before do
          make_request
        end

        it 'does not assign the numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_nil
        end

        it 'assigns user voice responses' do
          expect(assigns(:user_voice_messages)).to eq([feedback_input])
        end
      end

      context 'when there is no response for the property' do
        it 'does not assign the numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_nil
        end
      end
    end

    context 'when requesting a subject by name' do
      before { make_request('123-Main-Street') }

      its(:response) { should be_success }

      it 'assigns subject' do
        expect(assigns(:subject)).to eq(property)
      end
    end
  end
end<commit_msg>loosen restriction on SubjectsController#index nmerical_responses_exist<commit_after>require 'spec_helper'

describe SubjectsController do
  describe 'GET #index' do
    before { make_request }

    def make_request
      get :index, format: :json
    end

    its(:response) { should be_success }
  end

  describe 'GET #show' do
    let!(:property) { create(:property, name: '123 Main Street') }

    def make_request(property_id = property.id)
      get :show, id: property_id
    end

    context 'when requesting a subject by property id' do
      before { make_request }

      its(:response) { should be_success }

      it 'assigns subject' do
        expect(assigns(:subject)).to eq(property)
      end

      it 'assigns content' do
        expect(assigns(:content)).to_not be_nil
      end

      context 'when there is a numerical response for the property' do
        let(:question) { create(:question, :number) }
        before do
          create(:feedback_input, property: property, question: question, numerical_response: 1)
          make_request
        end

        it 'assigns numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_true
        end

        it 'assigns numerical responses' do
          expect(assigns(:numerical_responses)).to have(1).numerical_response
        end

        it 'assigns a numerical response for the question' do
          expect(assigns(:numerical_responses).first.short_name).to eq(question.short_name)
        end

        it 'assigns numerical response with a response hash for the question' do
          expect(assigns(:numerical_responses).first.response_hash).to eq({"Repair"=>1, "Remove"=>0})
        end
      end

      context 'when there is a voice response for the property' do
        let(:question) { create(:question, :voice) }
        let!(:feedback_input) { create(:feedback_input, :with_voice_file, property: property, question: question) }

        before do
          make_request
        end

        it 'does not assign the numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_false
        end

        it 'assigns user voice responses' do
          expect(assigns(:user_voice_messages)).to eq([feedback_input])
        end
      end

      context 'when there is no response for the property' do
        it 'does not assign the numerical response existence flag' do
          expect(assigns(:numerical_responses_exist)).to be_false
        end
      end
    end

    context 'when requesting a subject by name' do
      before { make_request('123-Main-Street') }

      its(:response) { should be_success }

      it 'assigns subject' do
        expect(assigns(:subject)).to eq(property)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08266715116279069, 'fraction_numerical': 0.003633720930232558, 'mean_word_length': 2.662674650698603, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6261706', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1469, 'n_words': 475}