<commit_before>require 'spec_helper'
require 'rails_helper'

describe SelectPhoneForm do
  # invalid
  it 'should be invalid if all inputs are empty' do
    form = SelectPhoneForm.new({})
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  it 'should be invalid if user has mobile phone but does not specify which type' do
    form = SelectPhoneForm.new(mobile_phone: 'true')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  it 'should be invalid if user has no mobile phone and does not specify landline' do
    form = SelectPhoneForm.new(mobile_phone: 'false')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  it 'should be invalid if user has no mobile phone but can install apps' do
    form = SelectPhoneForm.new(mobile_phone: 'false', smart_phone: 'true')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please check your selection']
  end

  it 'should be invalid if user only answers landline' do
    form = SelectPhoneForm.new(landline: 'false')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  it 'should be invalid if user answers yes to mobile phone but does not answer smartphone question' do
    form = SelectPhoneForm.new(mobile_phone: 'true')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  it 'should be invalid if user answers no to mobile phone and no to smart phone, but does not answer landline' do
    form = SelectPhoneForm.new(mobile_phone: 'false', smart_phone: 'false')
    expect(form).to_not be_valid
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  # valid

  it 'should be valid if user has mobile phone and answers no to smart phone question' do
    form = SelectPhoneForm.new(mobile_phone: 'true', smart_phone: 'false')
    expect(form).to be_valid
  end

  it 'should be valid if user has landline and no mobile phone' do
    form = SelectPhoneForm.new(mobile_phone: 'false', landline: 'true')
    expect(form).to be_valid
  end

  it 'should be valid if user has landline and smartphone' do
    form = SelectPhoneForm.new(smart_phone: 'true', landline: 'true')
    expect(form).to be_valid
  end

  it 'should be valid if user has smartphone' do
    form = SelectPhoneForm.new(smart_phone: 'true')
    expect(form).to be_valid
  end
end<commit_msg>3491: Refactor select phone validation tests<commit_after>require 'spec_helper'
require 'rails_helper'

describe SelectPhoneForm do
  it 'should be invalid when neither mobile nor smartphone answered' do
    test_form_missing_data
    test_form_missing_data landline: 'false'
    test_form_missing_data landline: 'true'
  end

  it 'should be valid when smartphone is answered and mobile phone is unanswered' do
    test_form_valid smart_phone: 'false'
    test_form_valid smart_phone: 'false', landline: 'false'
    test_form_valid smart_phone: 'false', landline: 'true'
    test_form_valid smart_phone: 'true'
    test_form_valid smart_phone: 'true', landline: 'false'
    test_form_valid smart_phone: 'true', landline: 'true'
  end

  it 'should be invalid when mobile answered no and landline is not answered' do
    test_form_missing_data mobile_phone: 'false'
    test_form_missing_data mobile_phone: 'false', smart_phone: 'false'
  end

  it 'should be valid when mobile is answered no and landline is answered' do
    test_form_valid mobile_phone: 'false', landline: 'false'
    test_form_valid mobile_phone: 'false', landline: 'true'
    test_form_valid mobile_phone: 'false', smart_phone: 'false', landline: 'false'
    test_form_valid mobile_phone: 'false', smart_phone: 'false', landline: 'true'
  end

  it 'should be invalid when mobile is answered no and smartphone is answered yes' do
    test_form_inconsistent_data mobile_phone: 'false', smart_phone: 'true'
    test_form_inconsistent_data mobile_phone: 'false', smart_phone: 'true', landline: 'false'
    test_form_inconsistent_data mobile_phone: 'false', smart_phone: 'true', landline: 'true'
  end

  it 'should be invalid when mobile is answered yes and smartphone is unanswered' do
    test_form_missing_data mobile_phone: 'true'
    test_form_missing_data mobile_phone: 'true', landline: 'false'
    test_form_missing_data mobile_phone: 'true', landline: 'true'
  end

  it 'should be valid when mobile is answered yes and smartphone is answered' do
    test_form_valid mobile_phone: 'true', smart_phone: 'false'
    test_form_valid mobile_phone: 'true', smart_phone: 'false', landline: 'false'
    test_form_valid mobile_phone: 'true', smart_phone: 'false', landline: 'true'
    test_form_valid mobile_phone: 'true', smart_phone: 'true'
    test_form_valid mobile_phone: 'true', smart_phone: 'true', landline: 'false'
    test_form_valid mobile_phone: 'true', smart_phone: 'true', landline: 'true'
  end

  def test_form_valid(form_fields = {})
    form = SelectPhoneForm.new(form_fields)
    expect(form.valid?).to eql true
    expect(form.errors.full_messages).to eql []
  end

  def test_form_missing_data(form_fields = {})
    form = SelectPhoneForm.new(form_fields)
    expect(form.valid?).to eql false
    expect(form.errors.full_messages).to eql ['Please answer the question']
  end

  def test_form_inconsistent_data(form_fields = {})
    form = SelectPhoneForm.new(form_fields)
    expect(form.valid?).to eql false
    expect(form.errors.full_messages).to eql ['Please check your selection']
  end
end
{'fraction_non_alphanumeric': 0.08858753082071152, 'fraction_numerical': 0.0007044734061289186, 'mean_word_length': 4.535087719298246, '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': '915216', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1718, 'n_words': 572}