<commit_before># encoding: utf-8

require 'spec_helper'

shared_examples_for "geocoding controllers" do

  describe 'legacy behaviour tests' do

    before(:all) do
      @user = create_user(username: 'test')
    end

    before(:each) do
      CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get).returns(nil)
      delete_user_data @user
      host! 'test.localhost.lan'
      login_as(@user)
    end

    after(:all) do
      @user.destroy
    end

    describe 'GET /api/v1/geocodings' do
      let(:params) { { :api_key => @user.api_key } }

      it 'returns every geocoding belonging to current_user' do
        FactoryGirl.create(:geocoding, table_name: 'a', formatter: 'b', user: @user, state: 'wadus')
        FactoryGirl.create(:geocoding, table_name: 'a', formatter: 'b', user_id: UUIDTools::UUID.timestamp_create.to_s)
        get_json api_v1_geocodings_index_url(params) do |response|
          response.status.should be_success
          response.body[:geocodings].size.should == 1
        end
      end
    end

    describe 'GET /api/v1/geocodings/:id' do
      let(:params) { { :api_key => @user.api_key } }

      it 'returns a geocoding' do
        geocoding = FactoryGirl.create(:geocoding, table_id: UUIDTools::UUID.timestamp_create.to_s, formatter: 'b', user: @user, used_credits: 100, processed_rows: 100, kind: 'high-resolution')

        get_json api_v1_geocodings_show_url(params.merge(id: geocoding.id)) do |response|
          response.status.should be_success
          response.body[:id].should eq geocoding.id
          response.body[:used_credits].should eq 100
          response.body[:price].should eq 150
          response.body[:remaining_quota].should eq 900
        end
      end

      it 'does not return a geocoding owned by another user' do
        geocoding = FactoryGirl.create(:geocoding, table_id: UUIDTools::UUID.timestamp_create.to_s, formatter: 'b', user_id: UUIDTools::UUID.timestamp_create.to_s)

        get_json api_v1_geocodings_show_url(params.merge(id: geocoding.id)) do |response|
          response.status.should eq 404<commit_msg>get instead of get_json fixes test incompatibilities<commit_after># encoding: utf-8

require 'spec_helper'

shared_examples_for "geocoding controllers" do

  describe 'legacy behaviour tests' do

    before(:all) do
      @user = create_user(username: 'test')
    end

    before(:each) do
      CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get).returns(nil)
      delete_user_data @user
      host! 'test.localhost.lan'
      login_as(@user)
    end

    after(:all) do
      @user.destroy
    end

    describe 'GET /api/v1/geocodings' do
      let(:params) { { :api_key => @user.api_key } }

      it 'returns every geocoding belonging to current_user' do
        FactoryGirl.create(:geocoding, table_name: 'a', formatter: 'b', user: @user, state: 'wadus')
        FactoryGirl.create(:geocoding, table_name: 'a', formatter: 'b', user_id: UUIDTools::UUID.timestamp_create.to_s)
        get_json api_v1_geocodings_index_url(params) do |response|
          response.status.should be_success
          response.body[:geocodings].size.should == 1
        end
      end
    end

    describe 'GET /api/v1/geocodings/:id' do
      let(:params) { { :api_key => @user.api_key } }

      it 'returns a geocoding' do
        geocoding = FactoryGirl.create(:geocoding, table_id: UUIDTools::UUID.timestamp_create.to_s, formatter: 'b', user: @user, used_credits: 100, processed_rows: 100, kind: 'high-resolution')

        get_json api_v1_geocodings_show_url(params.merge(id: geocoding.id)) do |response|
          response.status.should be_success
          response.body[:id].should eq geocoding.id
          response.body[:used_credits].should eq 100
          response.body[:price].should eq 150
          response.body[:remaining_quota].should eq 900
        end
      end

      it 'does not return a geocoding owned by another user' do
        geocoding = FactoryGirl.create(:geocoding, table_id: UUIDTools::UUID.timestamp_create.to_s, formatter: 'b', user_id: UUIDTools::UUID.timestamp_create.to_s)

        get api_v1_geocodings_show_url(params.merge(id: geocoding.id)) do |response|
          last_response.status.should eq 404
{'fraction_non_alphanumeric': 0.11092754307292896, 'fraction_numerical': 0.011800802454566911, 'mean_word_length': 3.2592964824120605, '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': '5395235', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1386, 'n_words': 303}