Skip to content

Instantly share code, notes, and snippets.

@kusumandaru
Created March 14, 2020 08:51
Show Gist options
  • Save kusumandaru/57de95c5248452c6e9df80d694d6678d to your computer and use it in GitHub Desktop.
Save kusumandaru/57de95c5248452c6e9df80d694d6678d to your computer and use it in GitHub Desktop.
RSpec.shared_context 'big query user example' do
let(:oauth_json) {
file = File.read("spec/fixtures/bigquery/oauth.json")
}
let(:dataset_json) {
file = File.read("spec/fixtures/bigquery/dataset.json")
}
let(:table_user_json) {
file = File.read("spec/fixtures/bigquery/users_table.json")
}
let(:credential_path) {
File.join(Rails.root, "spec/fixtures/hra/credential.json")
}
before do
stub_const('ENV', {'PROJECT_ID' => 'bigquery-test-123456', 'BIGQUERY_CREDENTIAL_PATH' => credential_path})
stub_request(:post, "https://oauth2.googleapis.com/token").
to_return(status: 200, body: oauth_json, headers: {'Content-Type' => 'application/json'})
stub_request(:get, "https://bigquery.googleapis.com/bigquery/v2/projects/bigquery-test-123456/datasets/bigquery").
to_return(status: 200, body: dataset_json, headers: {'Content-Type' => 'application/json'})
stub_request(:get, "https://bigquery.googleapis.com/bigquery/v2/projects/bigquery-test-123456/datasets/bigquery/tables/hra_data_users").
to_return(status: 200, body: table_user_json, headers: {'Content-Type' => 'application/json'})
stub_request(:post, "https://bigquery.googleapis.com/bigquery/v2/projects/bigquery-test-123456/datasets/bigquery/tables/hra_data_users/insertAll").
to_return(status: 200, body: insert_json, headers: {'Content-Type' => 'application/json'})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment