From 9810ede714433a3ae0c2d19fa806b2a7a53f8d42 Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Tue, 10 Jul 2012 12:11:29 +0200 Subject: [PATCH] working json api acceptance tests --- app/controllers/application_controller.rb | 3 +- config/app_config.yml.sample | 39 ----------------------- config/database.yml.sample | 27 ---------------- config/initializers/carto_db.rb | 2 +- spec/acceptance/api/columns_spec.rb | 6 ++-- spec/acceptance/support/helpers.rb | 2 +- spec/acceptance/support/paths.rb | 14 ++++++-- 7 files changed, 17 insertions(+), 76 deletions(-) delete mode 100644 config/app_config.yml.sample delete mode 100644 config/database.yml.sample diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6d3980a1ba..4338edb71e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -60,7 +60,8 @@ class ApplicationController < ActionController::Base authenticated?(request.subdomain) || not_authorized end - def api_authorization_required + def api_authorization_required + Rails.logger.info "MAH LOVERLY COOKIE #{cookies}" authenticate!(:api_key, :api_authentication, :scope => request.subdomain) end diff --git a/config/app_config.yml.sample b/config/app_config.yml.sample deleted file mode 100644 index 7576b61a43..0000000000 --- a/config/app_config.yml.sample +++ /dev/null @@ -1,39 +0,0 @@ -development: - session_domain: '.localhost.lan' - secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - account_host: 'localhost.lan:4000' - account_path: '/account' - tile_host: 'localhost.lan' - tile_port: '8181' - developers_host: 'http://developers.localhost.lan:3000' - secret_token: "some_secret" - amazon_access_key: '' - amazon_secret_key: '' - varnish_management: - host: '127.0.0.1' - post: 6082 - redis: - host: '127.0.0.1' - port: 6379 - superadmin: - username: "superadmin" - password: "monkey" - -test: - session_domain: '.localhost.lan' - secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - account_host: 'testhost.lan' - account_path: '/account' - developers_host: 'http://developers.testhost.lan:53716' - secret_token: "some_secret" - amazon_access_key: '' - amazon_secret_key: '' - varnish_management: - host: '127.0.0.1' - post: 6082 - redis: - host: '127.0.0.1' - port: 6380 - superadmin: - username: "superadmin" - password: "monkeytest" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 56c25309de..0000000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,27 +0,0 @@ -production: - adapter: postgres - encoding: unicode - host: localhost - port: 5432 - database: carto_db_production - username: postgres - password: - -development: - adapter: postgres - encoding: unicode - host: localhost - port: 5432 - database: carto_db_development - username: postgres - password: - -test: - adapter: postgres - encoding: unicode - database: carto_db_test - host: localhost - port: 5432 - username: postgres - password: - diff --git a/config/initializers/carto_db.rb b/config/initializers/carto_db.rb index 369db405a7..2c8aa6cab7 100644 --- a/config/initializers/carto_db.rb +++ b/config/initializers/carto_db.rb @@ -14,7 +14,7 @@ module CartoDB elsif Rails.env.development? "vizzuality#{session_domain}" else - "vizzuality#{session_domain}" + "test#{session_domain}" end end diff --git a/spec/acceptance/api/columns_spec.rb b/spec/acceptance/api/columns_spec.rb index 8ef30e7c70..36eeb95e3f 100644 --- a/spec/acceptance/api/columns_spec.rb +++ b/spec/acceptance/api/columns_spec.rb @@ -6,13 +6,11 @@ feature "API 1.0 columns management" do background do Capybara.current_driver = :rack_test - @user = create_user + @user = create_user({:username => 'test'}) @table = create_table :user_id => @user.id - - login_as @user end - scenario "Get the columns from a table" do + scenario "Get the columns from a table" do get_json api_table_columns_url(@table.name) do |response| response.status.should be_success (response.body - default_schema).should be_empty diff --git a/spec/acceptance/support/helpers.rb b/spec/acceptance/support/helpers.rb index 3c98647f74..b71f9777e4 100644 --- a/spec/acceptance/support/helpers.rb +++ b/spec/acceptance/support/helpers.rb @@ -8,7 +8,7 @@ module HelperMethods visit login_path fill_in 'email', :with => user.email fill_in 'password', :with => user.password || user.email.split('@').first - click_link_or_button 'Log in' + click_link_or_button 'Sign in' end def authenticate_api(user) diff --git a/spec/acceptance/support/paths.rb b/spec/acceptance/support/paths.rb index b88964bc16..1808c18271 100644 --- a/spec/acceptance/support/paths.rb +++ b/spec/acceptance/support/paths.rb @@ -4,7 +4,7 @@ module NavigationHelpers end def login_path - "/login" + "#{CartoDB.hostname}/login" end def logout_path @@ -48,11 +48,11 @@ module NavigationHelpers end def api_table_columns_url(table_identifier) - "#{api_url_prefix}/tables/#{table_identifier}/columns" + api_req "#{api_url_prefix}/tables/#{table_identifier}/columns" end def api_table_column_url(table_identifier, column_name) - "#{api_url_prefix}/tables/#{table_identifier}/columns/#{column_name}" + api_req "#{api_url_prefix}/tables/#{table_identifier}/columns/#{column_name}" end def api_table_record_column_url(table_identifier, row_identifier, column_name) @@ -84,6 +84,14 @@ module NavigationHelpers def api_url_prefix "#{CartoDB.hostname}/api/#{CartoDB::API::VERSION_1}" end + + def api_key + "api_key=#{$users_metadata.HMGET("rails:users:test", 'map_key').first}" + end + + def api_req url + "#{url}?#{api_key}" + end end