<commit_before>require 'spec_helper'

describe "Options API" do
  before :each do
    @api_key = create(:api_key)
    @options = FactoryGirl.create_list(:option, 5)
    get "/api/v1/projects/#{@options.first.question.project.id}/options?access_token=#{@api_key.access_token}"
    @json = JSON.parse(response.body)
  end

  it 'returns a successful response' do
    expect(response).to be_success
  end

  it 'receives the correct number of options' do
    expect(@json.length).to eq(5)
  end

  it 'has a text attribute' do
    @json.first.should have_key('text')
  end

  it 'has a translations attribute' do
    @json.first.should have_key('translations')
    @json.first['translations'].should be_a Array
  end

  it "has a question_id attribute" do
    @json.first.should have_key('question_id')
  end

  it "has a next_question attribute" do
    @json.first.should have_key('next_question')
  end

  it "has a instrument_version attribute" do
    @json.first.should have_key('instrument_version')
  end

  describe "translation text" do
    before :each do
      @translation = create(:option_translation)
      get "/api/v1/projects/#{@options.first.question.project.id}/options?access_token=#{@api_key.access_token}"
      @json = JSON.parse(response.body)
    end

    it "should add a new option for the translation" do
      expect(@json.length).to eq(6)
    end

    it "has the correct translation text" do<commit_msg>Add spec to test for number in question for options api<commit_after>require 'spec_helper'

describe "Options API" do
  before :each do
    @api_key = create(:api_key)
    @options = FactoryGirl.create_list(:option, 5)
    get "/api/v1/projects/#{@options.first.question.project.id}/options?access_token=#{@api_key.access_token}"
    @json = JSON.parse(response.body)
  end

  it 'returns a successful response' do
    expect(response).to be_success
  end

  it 'receives the correct number of options' do
    expect(@json.length).to eq(5)
  end

  it 'has a text attribute' do
    @json.first.should have_key('text')
  end

  it 'has a translations attribute' do
    @json.first.should have_key('translations')
    @json.first['translations'].should be_a Array
  end

  it "has a question_id attribute" do
    @json.first.should have_key('question_id')
  end

  it "has a next_question attribute" do
    @json.first.should have_key('next_question')
  end

  it "has a number_in_question attribute" do
    @json.first.should have_key('number_in_question')
  end

  it "has a instrument_version attribute" do
    @json.first.should have_key('instrument_version')
  end

  describe "translation text" do
    before :each do
      @translation = create(:option_translation)
      get "/api/v1/projects/#{@options.first.question.project.id}/options?access_token=#{@api_key.access_token}"
      @json = JSON.parse(response.body)
    end

    it "should add a new option for the translation" do
      expect(@json.length).to eq(6)
    end

    it "has the correct translation text" do
{'fraction_non_alphanumeric': 0.11003989361702128, 'fraction_numerical': 0.003324468085106383, 'mean_word_length': 3.708920187793427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4873957', 'n_tokens_mistral': 975, 'n_tokens_neox': 945, 'n_words': 260}