<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../acceptance_helper')

feature "Tables JSON API" do

  scenario "Retrieve different pages of rows from a table" do

    user = create_user
    table = create_table :user_id => user.id

    user.in_database do |user_database|
      user_database.alter_table(table.db_table_name) do
        add_primary_key :identifier
        add_column :c1, String
        add_column :c2, Float
        add_column :c3, String, :text => true
      end
    end

    100.times do
      table.execute_sql("INSERT INTO #{table.db_table_name} (c1,c2,c3) VALUES ('#{String.random(10)}',#{rand(1000000.0)},'#{String.random(100)}')")
    end

    login_as user

    get_json "/api/json/table/#{table.id}?per_page=10"

    # last_response.should be_ok

    # get_json "/api/json/table/#{table.id}?per_page=10&page=1"
    #
    # get_json "/api/json/table/#{table.id}?per_page=30&page=20"
    #
    # get_json "/api/json/table/#{table.id}?per_page=300&page=20"
  end

end<commit_msg>Fixed acceptance tests of the API<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../acceptance_helper')

feature "Tables JSON API" do

  scenario "Retrieve different pages of rows from a table" do
    Capybara.current_driver = :rack_test

    user = create_user
    table = create_table :user_id => user.id

    100.times do
      table.execute_sql("INSERT INTO #{table.db_table_name} (Name,Location,Description) VALUES ('#{String.random(10)}','#{rand(1000000.0)}','#{String.random(100)}')")
    end

    content = table.execute_sql("select * from #{table.db_table_name}")

    login_as user

    get_json "/api/json/table/#{table.id}?rows_per_page=2"
    page.driver.last_response.should be_ok
    json_response = JSON(page.body)
    json_response['total_rows'].should == 100
    json_response['rows'][0].symbolize_keys.should == content[0]
    json_response['rows'][1].symbolize_keys.should == content[1]

    get_json "/api/json/table/#{table.id}?rows_per_page=2&page=2"
    page.driver.last_response.should be_ok
    json_response = JSON(page.body)
    json_response['rows'][0].symbolize_keys.should == content[2]
    json_response['rows'][1].symbolize_keys.should == content[3]
  end

end
{'fraction_non_alphanumeric': 0.144136078782453, 'fraction_numerical': 0.02954341987466428, 'mean_word_length': 3.9446902654867255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2536597', 'n_tokens_mistral': 810, 'n_tokens_neox': 766, 'n_words': 136}