<commit_before>require File.dirname(__FILE__) + '/../test_helper'
require 'maps_controller'

# Re-raise errors caught by the controller.
class MapsController; def rescue_action(e) raise e end; end

class MapsControllerTest < ActionController::TestCase

  def setup
    @controller = MapsController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new

    @profile = create_user('test_profile').person
    login_as(@profile.identifier)
  end

  attr_reader :profile

  should 'save profile address' do
    post :edit_location, :profile => profile.identifier, :profile_data => { 'address' => 'new address' }
    assert_equal 'new address', Profile['test_profile'].address
  end

  should 'save profile national_region_code' do

    national_region_code = '355030'
    city = 'Santo Afonso'
    state = 'Mato Grosso'

    parent_region = fast_create(NationalRegion, :name => state,
                                :national_region_code => '35',
                                :national_region_type_id => NationalRegionType::STATE)

    fast_create(NationalRegion, :name =>  city,
                                :national_region_code => national_region_code,
                                :national_region_type_id => NationalRegionType::CITY,
                                :parent_national_region_code => parent_region.national_region_code)

    post :edit_location, :profile => profile.identifier, :profile_data => { 
    :address => 'new address',
    :country => 'BR',
    :city => city,
    :state => state
    }

    assert_equal national_region_code, Profile['test_profile'].national_region_code
  end

  should 'back when update address fail' do
    Profile.any_instance.stubs(:update_attributes!).returns(false)
    post :edit_location, :profile => profile.identifier, :profile_data => { 'address' => 'new address' }
    assert_nil profile.address
    assert_template 'edit_location'
  end

  should 'show page to edit location' do
    get :edit_location, :profile => profile.identifier
    assert_response :success
    assert_template 'edit_location'
  end

  should 'dispĺay form for address with profile address' do
    env = Environment.default
    env.custom_person_fields = { 'city' => { 'active' => 'true' } }<commit_msg>Added country code to MapsControllerTest<commit_after>require File.dirname(__FILE__) + '/../test_helper'
require 'maps_controller'

# Re-raise errors caught by the controller.
class MapsController; def rescue_action(e) raise e end; end

class MapsControllerTest < ActionController::TestCase

  def setup
    @controller = MapsController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new

    @profile = create_user('test_profile').person
    login_as(@profile.identifier)

  end

  attr_reader :profile

  should 'save profile address' do
    post :edit_location, :profile => profile.identifier, :profile_data => { 'address' => 'new address' }
    assert_equal 'new address', Profile['test_profile'].address
  end

  should 'save profile national_region_code' do

    national_region_code = '355030'
    city = 'Santo Afonso'
    state = 'Mato Grosso'

    fast_create(NationalRegion, :name => 'Brasil', 
      :national_region_code => 'BR', 
      :national_region_type_id => NationalRegionType::COUNTRY)

    parent_region = fast_create(NationalRegion, :name => state,
                                :national_region_code => '35',
                                :national_region_type_id => NationalRegionType::STATE)

    fast_create(NationalRegion, :name =>  city,
                                :national_region_code => national_region_code,
                                :national_region_type_id => NationalRegionType::CITY,
                                :parent_national_region_code => parent_region.national_region_code)

    post :edit_location, :profile => profile.identifier, :profile_data => { 
      :address => 'new address',
      :country => 'BR',
      :city => city,
      :state => state
    }

    assert_equal national_region_code, Profile['test_profile'].national_region_code
  end

  should 'back when update address fail' do
    Profile.any_instance.stubs(:update_attributes!).returns(false)
    post :edit_location, :profile => profile.identifier, :profile_data => { 'address' => 'new address' }
    assert_nil profile.address
    assert_template 'edit_location'
  end

  should 'show page to edit location' do
    get :edit_location, :profile => profile.identifier
    assert_response :success
    assert_template 'edit_location'
  end

  should 'dispĺay form for address with profile address' do
    env = Environment.default
    env.custom_person_fields = { 'city' => { 'active' => 'true' } }
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0033472803347280333, 'mean_word_length': 3.2497777777777777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '2635934', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1296, 'n_words': 319}