bigbroda 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.pryrc +3 -0
  4. data/.rspec +2 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +18 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +408 -0
  9. data/Rakefile +12 -0
  10. data/google_bigquery.gemspec +30 -0
  11. data/lib/.DS_Store +0 -0
  12. data/lib/active_record/.DS_Store +0 -0
  13. data/lib/active_record/connection_adapters/bigquery_adapter.rb +949 -0
  14. data/lib/active_record/tasks/bigquery_database_tasks.rb +42 -0
  15. data/lib/generators/.DS_Store +0 -0
  16. data/lib/generators/google_bigquery/.DS_Store +0 -0
  17. data/lib/generators/google_bigquery/install/install_generator.rb +21 -0
  18. data/lib/generators/templates/README +11 -0
  19. data/lib/generators/templates/bigquery.rb.erb +7 -0
  20. data/lib/google_bigquery/auth.rb +27 -0
  21. data/lib/google_bigquery/client.rb +52 -0
  22. data/lib/google_bigquery/config.rb +17 -0
  23. data/lib/google_bigquery/dataset.rb +77 -0
  24. data/lib/google_bigquery/engine.rb +21 -0
  25. data/lib/google_bigquery/jobs.rb +173 -0
  26. data/lib/google_bigquery/project.rb +16 -0
  27. data/lib/google_bigquery/railtie.rb +39 -0
  28. data/lib/google_bigquery/table.rb +63 -0
  29. data/lib/google_bigquery/table_data.rb +23 -0
  30. data/lib/google_bigquery/version.rb +3 -0
  31. data/lib/google_bigquery.rb +27 -0
  32. data/spec/.DS_Store +0 -0
  33. data/spec/dummy/.DS_Store +0 -0
  34. data/spec/dummy/.gitignore +20 -0
  35. data/spec/dummy/README.rdoc +261 -0
  36. data/spec/dummy/Rakefile +7 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css.scss +13 -0
  39. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +3 -0
  41. data/spec/dummy/app/mailers/.gitkeep +0 -0
  42. data/spec/dummy/app/models/log_data.rb +3 -0
  43. data/spec/dummy/app/models/post.rb +3 -0
  44. data/spec/dummy/app/models/user.rb +4 -0
  45. data/spec/dummy/app/views/layouts/application.html.haml +32 -0
  46. data/spec/dummy/config/application.rb +23 -0
  47. data/spec/dummy/config/boot.rb +11 -0
  48. data/spec/dummy/config/database.yml +32 -0
  49. data/spec/dummy/config/environment.rb +6 -0
  50. data/spec/dummy/config/environments/development.rb +29 -0
  51. data/spec/dummy/config/environments/production.rb +80 -0
  52. data/spec/dummy/config/environments/test.rb +36 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  54. data/spec/dummy/config/initializers/bigquery.rb +19 -0
  55. data/spec/dummy/config/initializers/inflections.rb +16 -0
  56. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  57. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  58. data/spec/dummy/config/initializers/session_store.rb +9 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +15 -0
  60. data/spec/dummy/config/locales/devise.en.yml +58 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/locales/simple_form.en.yml +26 -0
  63. data/spec/dummy/config/routes.rb +4 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/db/migrate/20140224051640_create_users.rb +11 -0
  66. data/spec/dummy/db/migrate/20140224063709_add_last_name_to_user.rb +5 -0
  67. data/spec/dummy/db/migrate/20140225014314_create_log_data.rb +12 -0
  68. data/spec/dummy/db/migrate/20140227015551_create_posts.rb +9 -0
  69. data/spec/dummy/db/schema.rb +39 -0
  70. data/spec/dummy/db/schema_migrations.json +1 -0
  71. data/spec/dummy/lib/assets/.gitkeep +0 -0
  72. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  73. data/spec/dummy/log/.gitkeep +0 -0
  74. data/spec/dummy/public/404.html +26 -0
  75. data/spec/dummy/public/422.html +26 -0
  76. data/spec/dummy/public/500.html +25 -0
  77. data/spec/dummy/public/favicon.ico +0 -0
  78. data/spec/dummy/script/rails +6 -0
  79. data/spec/dummy/test/fixtures/log_data.yml +9 -0
  80. data/spec/dummy/test/fixtures/posts.yml +11 -0
  81. data/spec/dummy/test/fixtures/users.yml +11 -0
  82. data/spec/dummy/test/models/log_data_test.rb +7 -0
  83. data/spec/dummy/test/models/post_test.rb +7 -0
  84. data/spec/dummy/test/models/user_test.rb +7 -0
  85. data/spec/fixtures/.DS_Store +0 -0
  86. data/spec/fixtures/configs/account_config.yml-example +6 -0
  87. data/spec/fixtures/keys/.DS_Store +0 -0
  88. data/spec/fixtures/keys/example-privatekey-p12 +0 -0
  89. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/.DS_Store +0 -0
  90. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/adapter/simple_quering.yml +324 -0
  91. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/after_each.yml +154 -0
  92. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/authorize_config.yml +367 -0
  93. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/create_each.yml +195 -0
  94. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/_down/adds_the_email_at_utc_hour_column.yml +575 -0
  95. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/_up/adds_the_created_at_updated_at_column.yml +644 -0
  96. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/add_column/adds_published_column.yml +779 -0
  97. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/associations/users_posts.yml +1464 -0
  98. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/remove_column/should_raise_error.yml +713 -0
  99. data/spec/fixtures/vcr_cassettes/Dataset/_list.yml +64 -0
  100. data/spec/fixtures/vcr_cassettes/Dataset/authorize_config.yml +367 -0
  101. data/spec/fixtures/vcr_cassettes/Dataset/operations/_get_delete.yml +237 -0
  102. data/spec/fixtures/vcr_cassettes/Dataset/operations/_patch_delete.yml +240 -0
  103. data/spec/fixtures/vcr_cassettes/Dataset/operations/_update_delete.yml +297 -0
  104. data/spec/fixtures/vcr_cassettes/Dataset/operations/create_delete.yml +173 -0
  105. data/spec/fixtures/vcr_cassettes/Project/_list.yml +64 -0
  106. data/spec/fixtures/vcr_cassettes/Project/authorize_config.yml +2166 -0
  107. data/spec/fixtures/vcr_cassettes/Table/authorize_config.yml +367 -0
  108. data/spec/fixtures/vcr_cassettes/Table/operations/creation_edition/_create_delete.yml +404 -0
  109. data/spec/fixtures/vcr_cassettes/Table/operations/creation_edition/_create_update_delete.yml +471 -0
  110. data/spec/fixtures/vcr_cassettes/Table/operations/list.yml +232 -0
  111. data/spec/fixtures/vcr_cassettes/TableData/authorize_config.yml +2166 -0
  112. data/spec/fixtures/vcr_cassettes/TableData/create_each.yml +135 -0
  113. data/spec/fixtures/vcr_cassettes/TableData/delete_each.yml +154 -0
  114. data/spec/fixtures/vcr_cassettes/TableData/insertAll2.yml +189 -0
  115. data/spec/fixtures/vcr_cassettes/auth.yml +2168 -0
  116. data/spec/fixtures/vcr_cassettes/authorize_config.yml +2166 -0
  117. data/spec/fixtures/vcr_cassettes/datasets.yml +119 -0
  118. data/spec/fixtures/vcr_cassettes/delete_each_dataset.yml +48 -0
  119. data/spec/functional/adapter/adapter_spec.rb +213 -0
  120. data/spec/functional/auth_spec.rb +24 -0
  121. data/spec/functional/client_spec.rb +9 -0
  122. data/spec/functional/config_spec.rb +24 -0
  123. data/spec/functional/dataset_spec.rb +77 -0
  124. data/spec/functional/project_spec.rb +24 -0
  125. data/spec/functional/table_data_spec.rb +61 -0
  126. data/spec/functional/table_spec.rb +105 -0
  127. data/spec/models/user_spec.rb +0 -0
  128. data/spec/spec_helper.rb +48 -0
  129. data/spec/support/models.rb +11 -0
  130. data/spec/support/schema.rb +43 -0
  131. metadata +370 -0
@@ -0,0 +1,119 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.googleapis.com/bigquery/v2/projects/985884699512/datasets
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"datasetReference":{"datasetId":"rspec-schema"}}'
9
+ headers:
10
+ User-Agent:
11
+ - |-
12
+ google-api-ruby-client/0.7.1 Mac OS X/10.9
13
+ (gzip)
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip
18
+ Authorization:
19
+ - Bearer ya29.1.AADtN_Wg4Sg29lGgLuTYiuQYm942Z0_LCwqQ9Jg0OS4RVbh8wzOygJS7_Pe-1y7K
20
+ Cache-Control:
21
+ - no-store
22
+ Accept:
23
+ - '*/*'
24
+ response:
25
+ status:
26
+ code: 400
27
+ message: Bad Request
28
+ headers:
29
+ Content-Type:
30
+ - application/json; charset=UTF-8
31
+ Content-Encoding:
32
+ - gzip
33
+ Date:
34
+ - Wed, 26 Feb 2014 00:34:44 GMT
35
+ Expires:
36
+ - Wed, 26 Feb 2014 00:34:44 GMT
37
+ Cache-Control:
38
+ - private, max-age=0
39
+ X-Content-Type-Options:
40
+ - nosniff
41
+ X-Frame-Options:
42
+ - SAMEORIGIN
43
+ X-Xss-Protection:
44
+ - 1; mode=block
45
+ Content-Length:
46
+ - '198'
47
+ Server:
48
+ - GSE
49
+ Alternate-Protocol:
50
+ - 443:quic
51
+ body:
52
+ encoding: ASCII-8BIT
53
+ string: !binary |-
54
+ H4sIAAAAAAAAAM2OOw6DQAxEe05hbZVICSIRVWoazhBSmF0LkPaD7CUN4u5Z
55
+ IJ8rpLE8b6Z4cwaKmAOrG8wZvIOkdE9pQwma4HDwCarOhhatOu2cCSVsfPBP
56
+ tIP5FI5EsKO1qfcGDEYUilBX0CiWkfRZdE8OG5VD9S0F3CQRWgK0Y49+csSD
57
+ hsNoJ4HJG2LRgUmOgN78thFcSO+luJage2TUMS3BBt/lanVa0nmsdkoHs4qV
58
+ RbHFf1NdsiV7AbxkedaWAQAA
59
+ http_version:
60
+ recorded_at: Wed, 26 Feb 2014 00:34:44 GMT
61
+ - request:
62
+ method: delete
63
+ uri: https://www.googleapis.com/bigquery/v2/projects/985884699512/datasets/rspec-schema
64
+ body:
65
+ encoding: UTF-8
66
+ string: ''
67
+ headers:
68
+ User-Agent:
69
+ - |-
70
+ google-api-ruby-client/0.7.1 Mac OS X/10.9
71
+ (gzip)
72
+ Accept-Encoding:
73
+ - gzip
74
+ Content-Type:
75
+ - ''
76
+ Authorization:
77
+ - Bearer ya29.1.AADtN_Wg4Sg29lGgLuTYiuQYm942Z0_LCwqQ9Jg0OS4RVbh8wzOygJS7_Pe-1y7K
78
+ Cache-Control:
79
+ - no-store
80
+ Accept:
81
+ - '*/*'
82
+ response:
83
+ status:
84
+ code: 400
85
+ message: Bad Request
86
+ headers:
87
+ Content-Type:
88
+ - application/json; charset=UTF-8
89
+ Content-Encoding:
90
+ - gzip
91
+ Date:
92
+ - Wed, 26 Feb 2014 00:34:45 GMT
93
+ Expires:
94
+ - Wed, 26 Feb 2014 00:34:45 GMT
95
+ Cache-Control:
96
+ - private, max-age=0
97
+ X-Content-Type-Options:
98
+ - nosniff
99
+ X-Frame-Options:
100
+ - SAMEORIGIN
101
+ X-Xss-Protection:
102
+ - 1; mode=block
103
+ Content-Length:
104
+ - '198'
105
+ Server:
106
+ - GSE
107
+ Alternate-Protocol:
108
+ - 443:quic
109
+ body:
110
+ encoding: ASCII-8BIT
111
+ string: !binary |-
112
+ H4sIAAAAAAAAAM2OOw6DQAxEe05hbZVICSIRVWoazhBSmF0LkPaD7CUN4u5Z
113
+ IJ8rpLE8b6Z4cwaKmAOrG8wZvIOkdE9pQwma4HDwCarOhhatOu2cCSVsfPBP
114
+ tIP5FI5EsKO1qfcGDEYUilBX0CiWkfRZdE8OG5VD9S0F3CQRWgK0Y49+csSD
115
+ hsNoJ4HJG2LRgUmOgN78thFcSO+luJage2TUMS3BBt/lanVa0nmsdkoHs4qV
116
+ RbHFf1NdsiV7AbxkedaWAQAA
117
+ http_version:
118
+ recorded_at: Wed, 26 Feb 2014 00:34:45 GMT
119
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://www.googleapis.com/bigquery/v2/projects/985884699512/datasets/rspec_schema
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - |-
12
+ google-api-ruby-client/0.7.1 Mac OS X/10.9
13
+ (gzip)
14
+ Accept-Encoding:
15
+ - gzip
16
+ Content-Type:
17
+ - ''
18
+ Authorization:
19
+ - Bearer ya29.1.AADtN_VHikWnQmc17jxgAZiFSL0I58Xs9zF1BB935LWssQalVVpP8ri-FoGEmcU9
20
+ Cache-Control:
21
+ - no-store
22
+ Accept:
23
+ - '*/*'
24
+ response:
25
+ status:
26
+ code: 204
27
+ message: No Content
28
+ headers:
29
+ Cache-Control:
30
+ - no-cache, no-store, max-age=0, must-revalidate
31
+ Pragma:
32
+ - no-cache
33
+ Expires:
34
+ - Fri, 01 Jan 1990 00:00:00 GMT
35
+ Date:
36
+ - Wed, 26 Feb 2014 01:02:20 GMT
37
+ Etag:
38
+ - '"YElLezYfBS2yoouJ_U61l1GQsXY/vyGp6PvFo4RvsFtPoIWeCReyIC8"'
39
+ Server:
40
+ - GSE
41
+ Alternate-Protocol:
42
+ - 443:quic
43
+ body:
44
+ encoding: UTF-8
45
+ string: ''
46
+ http_version:
47
+ recorded_at: Wed, 26 Feb 2014 01:02:20 GMT
48
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,213 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ require "active_record"
4
+ require "active_record/connection_adapters/bigquery_adapter.rb"
5
+
6
+ class CreateUsers < ActiveRecord::Migration
7
+ def self.up
8
+ create_table :users do |t|
9
+ t.string :name
10
+ t.record :nested_data
11
+ t.references :taggable, :polymorphic => true
12
+ t.boolean :admin
13
+ t.timestamps
14
+ end
15
+ end
16
+
17
+ def self.down
18
+ drop_table :users
19
+ end
20
+ end
21
+
22
+ class CreatePosts < ActiveRecord::Migration
23
+ def self.up
24
+ create_table :posts do |t|
25
+ t.string :title
26
+ t.references :user
27
+ t.boolean :admin
28
+ t.timestamps
29
+ end
30
+ end
31
+
32
+ def self.down
33
+ drop_table :users
34
+ end
35
+ end
36
+
37
+ class AddPublishedToUser < ActiveRecord::Migration
38
+ def change
39
+ add_column :users, :published, :boolean, default: true
40
+ end
41
+ end
42
+
43
+ class RemovePublishedToUser < ActiveRecord::Migration
44
+ def change
45
+ remove_column :users, :published
46
+ end
47
+ end
48
+
49
+ class User < ActiveRecord::Base
50
+ validates :name, presence: true
51
+ has_many :posts
52
+
53
+ scope :admins , ->{where(admin: true)}
54
+ end
55
+
56
+ class Post < ActiveRecord::Base
57
+ validates :title, presence: true
58
+ belongs_to :user
59
+ end
60
+
61
+ def create_tables
62
+ @table = GoogleBigquery::Table.create(@project, @name, @table_body )
63
+
64
+ @rows = {"rows"=> [
65
+ {
66
+ "insertId"=> Time.now.to_i.to_s,
67
+ "json"=> {
68
+ "name"=> "User #{Time.now.to_s}"
69
+ }
70
+ }
71
+ ]}
72
+
73
+ GoogleBigquery::TableData.create(@project, @name, @table_name , @rows )
74
+ end
75
+
76
+ describe "ActiveRecord Adapter", :vcr => { :allow_unused_http_interactions => true } do
77
+
78
+ let(:migration) { CreateUsers.new}
79
+ let(:posts_migration) { CreatePosts.new}
80
+ let(:add_col_migration) { AddPublishedToUser.new}
81
+ let(:remove_col_migration) { RemovePublishedToUser.new}
82
+
83
+ before :all do
84
+
85
+ VCR.use_cassette("ActiveRecord_Adapter/authorize_config") do
86
+ config_setup
87
+ @auth = GoogleBigquery::Auth.new
88
+ @auth.authorize
89
+ @name = "rspec_schema"
90
+ @project = config_options["email"].match(/(\d*)/)[0]
91
+
92
+ @table_name = "users"
93
+ @table_body = { "tableReference"=> {
94
+ "projectId"=> @project,
95
+ "datasetId"=> @name,
96
+ "tableId"=> @table_name},
97
+ "schema"=> [:fields=>[
98
+ {:name=> "id", :type=> "string"},
99
+ {:name=> "name", :type=> "string", :mode => "REQUIRED"},
100
+ {:name=> "age", :type=> "integer"},
101
+ {:name=> "weight", :type=> "float"},
102
+ {:name=> "is_magic", :type=> "boolean"}
103
+ ]
104
+ ]
105
+ }
106
+
107
+ ActiveRecord::Base.establish_connection(
108
+ :adapter => 'bigquery',
109
+ :project => @project,
110
+ :database => @name
111
+ )
112
+ end
113
+ end
114
+
115
+ before :each do
116
+ VCR.use_cassette("ActiveRecord_Adapter/create_each") do
117
+ GoogleBigquery::Dataset.create(@project,
118
+ {"datasetReference"=> { "datasetId" => @name }} )
119
+ create_tables
120
+ end
121
+ end
122
+
123
+ after :each do
124
+ VCR.use_cassette("ActiveRecord_Adapter/after_each") do
125
+ GoogleBigquery::Dataset.delete(@project, @name)
126
+ end
127
+ end
128
+
129
+ describe "adapter" do
130
+
131
+ it "simple quering", :vcr do
132
+ #sleep 50
133
+ #binding.pry
134
+ #User.select("name, id").where("name contains ?", "frank").count
135
+ #User.select("name, id").where("name contains ?", "frank")
136
+ #User.select("name, id")
137
+ #User.create(name: "frank capra")
138
+ #User.find_by(id: "some-id-1393025921")
139
+ #User.where("id =? and name= ?", "some-id-1393025921", "User 2014-02-21 20:38:41 -0300")
140
+ expect(User.count).to be 1
141
+ expect(User.first).to be_an_instance_of User
142
+ expect(User.all.size).to be 1
143
+ end
144
+ end
145
+
146
+ describe "migrations" do
147
+
148
+ before :each do
149
+ VCR.use_cassette("ActiveRecord_Adapter/after_each") do
150
+ GoogleBigquery::Table.delete(@project, @name, "users")
151
+ migration.up; User.reset_column_information
152
+ end
153
+ end
154
+
155
+ describe '#up', vcr: {:record => :new_episodes} do
156
+ it 'adds the created_at & updated_at column', :vcr do
157
+ User.columns_hash.should have_key('created_at')
158
+ User.columns_hash.should have_key('updated_at')
159
+ end
160
+ end
161
+
162
+ describe '#down', vcr: {:record => :new_episodes} do
163
+ before {
164
+ migration.down; User.reset_column_information
165
+ }
166
+
167
+ it 'adds the email_at_utc_hour column' do
168
+ User.should_not be_table_exists
169
+ end
170
+
171
+ end
172
+
173
+ #describe "add column", vcr: {:record => :new_episodes} do
174
+ # before {
175
+ # add_col_migration.change; User.reset_column_information
176
+ # }
177
+
178
+ # it 'adds published column' do
179
+ # #binding.pry
180
+ # User.columns_hash.should have_key('published')
181
+ # end
182
+ #end
183
+
184
+ describe "remove column", vcr: {:record => :new_episodes} do
185
+ before {
186
+ add_col_migration.change; User.reset_column_information
187
+ }
188
+
189
+ it 'should raise error' do
190
+ expect{remove_col_migration.change}.to raise_error
191
+ end
192
+ end
193
+
194
+ describe "associations", vcr: {:record => :new_episodes} do
195
+ before {
196
+ posts_migration.up; Post.reset_column_information
197
+ }
198
+
199
+ it "users_posts" do
200
+ User.create(name: "ALF")
201
+ #sleep 50
202
+ post = User.first.posts.create(title: "yeah")
203
+ #sleep 50
204
+ expect(User.first).to respond_to(:id)
205
+ expect(User.first.posts.first).to be_an_instance_of Post
206
+ expect(User.joins(:posts).first.posts.count).to be 1
207
+ end
208
+
209
+ end
210
+
211
+ end
212
+
213
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Config" do
4
+ before(:all) do
5
+ config_setup
6
+ @auth = GoogleBigquery::Auth.new
7
+ end
8
+
9
+ it "authorization object" do
10
+ VCR.use_cassette('auth') do
11
+ @auth.authorize
12
+ @auth.api.class.should be Google::APIClient::API
13
+ GoogleBigquery::Auth.api.class.should be Google::APIClient::API
14
+ GoogleBigquery::Auth.client.class.should be Google::APIClient
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+
21
+
22
+
23
+
24
+
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+
4
+ describe "Client" do
5
+ before :each do
6
+ config_setup
7
+ end
8
+
9
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Config class" do
4
+ before(:all) do
5
+
6
+ GoogleBigquery::Config.setup do |config|
7
+ config.pass_phrase = config_options["pass_phrase"]
8
+ config.key_file = config_options["key_file"]
9
+ config.client_id = config_options["client_id"]
10
+ config.scope = config_options["scope"]
11
+ config.profile_id = config_options["profile_id"]
12
+ config.email = config_options["email"]
13
+ end
14
+ end
15
+
16
+ it "has all the keys required" do
17
+ GoogleBigquery::Config.pass_phrase.should_not be_empty
18
+ GoogleBigquery::Config.key_file.should_not be_empty
19
+ GoogleBigquery::Config.scope.should_not be_empty
20
+ GoogleBigquery::Config.profile_id.should_not be_empty
21
+ GoogleBigquery::Config.email.should_not be_empty
22
+ end
23
+
24
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Dataset", :vcr => { :allow_unused_http_interactions => true } do
4
+
5
+ before(:all) do
6
+ VCR.use_cassette("Dataset/authorize_config") do
7
+ config_setup
8
+ @auth = GoogleBigquery::Auth.new
9
+ @auth.authorize
10
+ @project = config_options["email"].match(/(\d*)/)[0]
11
+ end
12
+ end
13
+
14
+ before :each do
15
+ @name = "rspec_schema"
16
+ end
17
+
18
+ it ".list", :vcr do
19
+ expect(GoogleBigquery::Dataset.list(@project)["datasets"]).to_not be_empty
20
+ end
21
+
22
+ context "operations" do
23
+ after(:each) do
24
+ VCR.use_cassette('delete_each_dataset') do
25
+ GoogleBigquery::Dataset.delete(@project, @name)
26
+ end
27
+ end
28
+
29
+ it "create & .delete", :vcr do
30
+ expect(
31
+ GoogleBigquery::Dataset.create(@project,
32
+ {"datasetReference"=> { "datasetId" => @name }} )["id"]
33
+ ).to include @name
34
+ end
35
+
36
+ it ".update & delete", :vcr do
37
+ expect(
38
+ GoogleBigquery::Dataset.create(@project,
39
+ {"datasetReference"=> { "datasetId" =>@name }} )["id"]
40
+ ).to include @name
41
+
42
+ expect(
43
+ GoogleBigquery::Dataset.update(@project, @name,
44
+ {"datasetReference"=> {
45
+ "datasetId" =>@name },
46
+ "description"=> "foobar"} )["description"]
47
+ ).to include "foobar"
48
+ end
49
+
50
+ it ".patch & delete", :vcr do
51
+ expect(
52
+ GoogleBigquery::Dataset.create(@project,
53
+ {"datasetReference"=> { "datasetId" =>@name }} )["id"]
54
+ ).to include @name
55
+
56
+ expect(
57
+ GoogleBigquery::Dataset.patch(@project, @name,
58
+ {"datasetReference"=> {
59
+ "datasetId" =>@name },
60
+ "description"=> "foobar"} )["description"]
61
+ ).to include "foobar"
62
+ end
63
+
64
+ it ".get & delete", :vcr do
65
+ expect(
66
+ GoogleBigquery::Dataset.create(@project,
67
+ {"datasetReference"=> { "datasetId" =>@name }} )["id"]
68
+ ).to include @name
69
+
70
+ expect(
71
+ GoogleBigquery::Dataset.get(@project, @name )["id"]
72
+ ).to include @name
73
+ end
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Project", :vcr => { :allow_unused_http_interactions => true } do
4
+
5
+ before(:all) do
6
+ VCR.use_cassette("Project/authorize_config") do
7
+ config_setup
8
+ @auth = GoogleBigquery::Auth.new
9
+ @auth.authorize
10
+ @project = config_options["email"].match(/(\d*)/)[0]
11
+ end
12
+ end
13
+
14
+ before :each do
15
+ @name = "rspec_schema"
16
+ end
17
+
18
+ it ".list", :vcr do
19
+ expect(
20
+ GoogleBigquery::Project.list["projects"].class
21
+ ).to be Array
22
+ end
23
+
24
+ end
@@ -0,0 +1,61 @@
1
+
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
4
+
5
+ describe "TableData", :vcr => { :allow_unused_http_interactions => true } do
6
+ before(:all) do
7
+ VCR.use_cassette("TableData/authorize_config") do
8
+ config_setup
9
+ @auth = GoogleBigquery::Auth.new
10
+ @auth.authorize
11
+ @project = config_options["email"].match(/(\d*)/)[0]
12
+ end
13
+ end
14
+
15
+ before :each do
16
+ @name = "rspec_schema"
17
+ VCR.use_cassette("TableData/create_each", :record => :new_episodes) do
18
+ GoogleBigquery::Dataset.create(@project, {"datasetReference"=> { "datasetId" => @name }} )["id"]
19
+ @table_name = "users"
20
+ @table_body = { "tableReference"=> {
21
+ "projectId"=> @project,
22
+ "datasetId"=> @name,
23
+ "tableId"=> @table_name},
24
+ "schema"=> [:fields=>[
25
+ {:name=> "name", :type=> "string", :mode => "REQUIRED"},
26
+ {:name=> "age", :type=> "integer"},
27
+ {:name=> "weight", :type=> "float"},
28
+ {:name=> "is_magic", :type=> "boolean"}
29
+ ]
30
+ ]
31
+ }
32
+ @table = GoogleBigquery::Table.create(@project, @name, @table_body )
33
+
34
+ @rows = {"rows"=> [
35
+ {
36
+ "insertId"=> Time.now.to_i.to_s,
37
+ "json"=> {
38
+ "name"=> "User #{Time.now.to_s}"
39
+ }
40
+ }
41
+ ]}
42
+ end
43
+ end
44
+
45
+ after(:each) do
46
+ VCR.use_cassette("TableData/delete_each") do
47
+ GoogleBigquery::Dataset.delete(@project, @name)
48
+ end
49
+ end
50
+
51
+ it "insertAll" do
52
+ VCR.use_cassette("TableData/insertAll2", :record => :new_episodes) do
53
+ GoogleBigquery::TableData.create(@project, @name, @table_name , @rows )
54
+ #sleep 60
55
+ expect(GoogleBigquery::Jobs.query(@project, {"query"=> "SELECT * FROM [#{@name}.#{@table_name}] LIMIT 1000" })["rows"].empty?).to be false
56
+ expect(GoogleBigquery::TableData.list(@project, @name, @table_name)["rows"].empty?).to be false
57
+ end
58
+ end
59
+
60
+
61
+ end