<commit_before>#encoding: UTF-8
require_relative '../../acceptance_helper' # TODO: is this used?
require_relative '../../spec_helper'

describe "Tables API" do

  before(:all) do
    CartoDB::Varnish.any_instance.stubs(:send_command).returns(true)
    @user = create_user(:username => 'test', :email => "<EMAIL>", :password => "<PASSWORD>")
    @another_user = create_user
  end

  before(:each) do
    CartoDB::Varnish.any_instance.stubs(:send_command).returns(true)
    delete_user_data @user
    host! 'test.localhost.lan'
    @headers = { 
      'CONTENT_TYPE'  => 'application/json',
    }
    host! 'test.localhost.lan'
  end

  after(:all) do
    @user.destroy
    @another_user.destroy
  end

  let(:params) { { :api_key => @user.api_key } }

  describe 'GET /api/v1/tables' do
    it 'returns ordered results based on query params' do
      table1  = create_table(name: 'bogus_table_1', user_id: @user.id)
      table2  = create_table(name: 'bogus_table_2', user_id: @user.id)
      order_params = Addressable::URI.new
      order_params.query_values = { o: { name: 'asc' } }

      get "/api/v1/tables?api_key=#{@user.api_key}&#{order_params.query}",
        {}, @headers

      last_response.status.should == 200
    end
  end # GET /api/v1/tables

  describe 'GET /api/v1/tables/:id' do
    it 'returns table attributes' do
      table = create_table(
        user_id:      @user.id,
        name:         'My table #1',
        privacy:      UserTable::PRIVACY_PRIVATE,
        tags:         "tag 1, tag 2,tag 3, tag 3",
        description:  'Testing is awesome'
      )

      get "/api/v1/tables/#{table.id}?api_key=#{@user.api_key}",
        {}, @headers

      last_response.status.should == 200
      response = JSON.parse(last_response.body)
      response.fetch('visualization_ids').should_not be_empty
    end
  end # GET /api/v1/tables/:id

  it "creates a new table without schema" do<commit_msg>Delete old legacy test #3280<commit_after>#encoding: UTF-8
require_relative '../../acceptance_helper' # TODO: is this used?
require_relative '../../spec_helper'

describe "Tables API" do

  before(:all) do
    CartoDB::Varnish.any_instance.stubs(:send_command).returns(true)
    @user = create_user(:username => 'test', :email => "<EMAIL>", :password => "<PASSWORD>")
    @another_user = create_user
  end

  before(:each) do
    CartoDB::Varnish.any_instance.stubs(:send_command).returns(true)
    delete_user_data @user
    host! 'test.localhost.lan'
    @headers = { 
      'CONTENT_TYPE'  => 'application/json',
    }
    host! 'test.localhost.lan'
  end

  after(:all) do
    @user.destroy
    @another_user.destroy
  end

  let(:params) { { :api_key => @user.api_key } }

  describe 'GET /api/v1/tables/:id' do
    it 'returns table attributes' do
      table = create_table(
        user_id:      @user.id,
        name:         'My table #1',
        privacy:      UserTable::PRIVACY_PRIVATE,
        tags:         "tag 1, tag 2,tag 3, tag 3",
        description:  'Testing is awesome'
      )

      get "/api/v1/tables/#{table.id}?api_key=#{@user.api_key}",
        {}, @headers

      last_response.status.should == 200
      response = JSON.parse(last_response.body)
      response.fetch('visualization_ids').should_not be_empty
    end
  end # GET /api/v1/tables/:id

  it "creates a new table without schema" do
{'fraction_non_alphanumeric': 0.14225941422594143, 'fraction_numerical': 0.011356843992827256, 'mean_word_length': 2.8559907834101383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '224697', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1128, 'n_words': 241}