cartodb-rb-client-rails-322 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +15 -0
  5. data/LICENSE +28 -0
  6. data/README.markdown +365 -0
  7. data/Rakefile +10 -0
  8. data/cartodb-rb-client.gemspec +34 -0
  9. data/lib/cartodb-rb-client.rb +18 -0
  10. data/lib/cartodb-rb-client/cartodb.rb +6 -0
  11. data/lib/cartodb-rb-client/cartodb/client.rb +4 -0
  12. data/lib/cartodb-rb-client/cartodb/client/authorization.rb +92 -0
  13. data/lib/cartodb-rb-client/cartodb/client/cache.rb +14 -0
  14. data/lib/cartodb-rb-client/cartodb/client/connection.rb +4 -0
  15. data/lib/cartodb-rb-client/cartodb/client/connection/base.rb +44 -0
  16. data/lib/cartodb-rb-client/cartodb/client/connection/cartodb.rb +280 -0
  17. data/lib/cartodb-rb-client/cartodb/client/connection/postgres.rb +255 -0
  18. data/lib/cartodb-rb-client/cartodb/client/error.rb +68 -0
  19. data/lib/cartodb-rb-client/cartodb/client/utils.rb +20 -0
  20. data/lib/cartodb-rb-client/cartodb/helpers.rb +1 -0
  21. data/lib/cartodb-rb-client/cartodb/helpers/sql_helper.rb +36 -0
  22. data/lib/cartodb-rb-client/cartodb/init.rb +30 -0
  23. data/lib/cartodb-rb-client/cartodb/libs.rb +2 -0
  24. data/lib/cartodb-rb-client/cartodb/libs/object.rb +15 -0
  25. data/lib/cartodb-rb-client/cartodb/libs/string.rb +116 -0
  26. data/lib/cartodb-rb-client/cartodb/model.rb +11 -0
  27. data/lib/cartodb-rb-client/cartodb/model/base.rb +20 -0
  28. data/lib/cartodb-rb-client/cartodb/model/constants.rb +30 -0
  29. data/lib/cartodb-rb-client/cartodb/model/defaults.rb +15 -0
  30. data/lib/cartodb-rb-client/cartodb/model/geo.rb +101 -0
  31. data/lib/cartodb-rb-client/cartodb/model/getters.rb +75 -0
  32. data/lib/cartodb-rb-client/cartodb/model/persistence.rb +69 -0
  33. data/lib/cartodb-rb-client/cartodb/model/query.rb +66 -0
  34. data/lib/cartodb-rb-client/cartodb/model/schema.rb +121 -0
  35. data/lib/cartodb-rb-client/cartodb/model/scope.rb +163 -0
  36. data/lib/cartodb-rb-client/cartodb/model/setters.rb +37 -0
  37. data/lib/cartodb-rb-client/cartodb/types.rb +2 -0
  38. data/lib/cartodb-rb-client/cartodb/types/metadata.rb +97 -0
  39. data/lib/cartodb-rb-client/cartodb/types/pg_result.rb +17 -0
  40. data/lib/cartodb-rb-client/install_utils.rb +19 -0
  41. data/lib/cartodb-rb-client/version.rb +7 -0
  42. data/run_tests.sh +6 -0
  43. data/spec/client_spec.rb +357 -0
  44. data/spec/fixtures/cassettes/CartoDB_client/should_add_and_remove_colums_in_a_previously_created_table.yml +635 -0
  45. data/spec/fixtures/cassettes/CartoDB_client/should_allow_reserved_words_in_columns_names.yml +284 -0
  46. data/spec/fixtures/cassettes/CartoDB_client/should_change_a_previously_created_column.yml +362 -0
  47. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_and_get_its_table_definition.yml +1634 -0
  48. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_forcing_the_schema_and_get_its_table_definition.yml +298 -0
  49. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_from_a_csv_file.yml +2947 -0
  50. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_MULTILINESTRING_type_geometry.yml +299 -0
  51. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_MULTIPOLYGON_type_geometry.yml +298 -0
  52. data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_POINT_type_geometry.yml +580 -0
  53. data/spec/fixtures/cassettes/CartoDB_client/should_delete_a_table_s_row.yml +410 -0
  54. data/spec/fixtures/cassettes/CartoDB_client/should_drop_a_table.yml +380 -0
  55. data/spec/fixtures/cassettes/CartoDB_client/should_escape_properly_input_data_in_insert_queries.yml +295 -0
  56. data/spec/fixtures/cassettes/CartoDB_client/should_execute_a_select_query_and_return_results.yml +987 -0
  57. data/spec/fixtures/cassettes/CartoDB_client/should_get_a_table_by_its_name.yml +298 -0
  58. data/spec/fixtures/cassettes/CartoDB_client/should_import_any_kind_of_data_file.yml +6951 -0
  59. data/spec/fixtures/cassettes/CartoDB_client/should_insert_a_row_in_a_table.yml +357 -0
  60. data/spec/fixtures/cassettes/CartoDB_client/should_paginate_records.yml +3642 -0
  61. data/spec/fixtures/cassettes/CartoDB_client/should_rename_an_existing_table.yml +299 -0
  62. data/spec/fixtures/cassettes/CartoDB_client/should_return_errors_on_invalid_queries.yml +132 -0
  63. data/spec/fixtures/cassettes/CartoDB_client/should_return_nil_when_requesting_a_table_which_does_not_exists.yml +218 -0
  64. data/spec/fixtures/cassettes/CartoDB_client/should_return_user_s_table_list.yml +244 -0
  65. data/spec/fixtures/cassettes/CartoDB_client/should_update_a_row_in_a_table.yml +347 -0
  66. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_destroy_a_previously_created_record.yml +1920 -0
  67. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_initialize_attributes_of_the_model_without_persisting_them.yml +963 -0
  68. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_persist_into_cartodb_using_the_save_method.yml +1946 -0
  69. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_persist_into_cartodb_using_the_static_create_method.yml +1796 -0
  70. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_save_polygons_in_different_formats.yml +1801 -0
  71. data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_update_an_existing_record.yml +2856 -0
  72. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_add_more_columns_if_the_table_previously_exists.yml +1509 -0
  73. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_contain_an_array_of_columns.yml +2007 -0
  74. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_a_table_with_custom_name_if_specified.yml +357 -0
  75. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_model_with_custom_data_types_columns.yml +565 -0
  76. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_model_with_polygon_type_geometry_columns.yml +493 -0
  77. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_the_table_in_cartodb_if_it_doesn_t_exists.yml +1048 -0
  78. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_have_a_valid_CartoDB_Client_instance_as_a_connection_object.yml +971 -0
  79. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_have_a_valid_table_name.yml +970 -0
  80. data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_return_only_data_columns.yml +1096 -0
  81. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_allow_to_select_the_specified_fiels.yml +25828 -0
  82. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_count_all_records.yml +22401 -0
  83. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_find_a_record_by_its_id.yml +21852 -0
  84. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_order_results.yml +23701 -0
  85. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_paginate_results.yml +35644 -0
  86. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_return_all_records_paginated.yml +23699 -0
  87. data/spec/fixtures/cassettes/CartoDB_model_scopes/should_search_records_by_certain_filters.yml +7080 -0
  88. data/spec/fixtures/cassettes/cartodb_spec_models.yml +3409 -0
  89. data/spec/fixtures/cassettes/clean_tables.yml +224 -0
  90. data/spec/model/data_spec.rb +157 -0
  91. data/spec/model/metadata_spec.rb +124 -0
  92. data/spec/model/scopes_spec.rb +171 -0
  93. data/spec/model_specs_helper.rb +2 -0
  94. data/spec/spec_helper.rb +54 -0
  95. data/spec/support/cartodb_config.yml +11 -0
  96. data/spec/support/cartodb_config.yml.sample +16 -0
  97. data/spec/support/cartodb_factories.rb +33 -0
  98. data/spec/support/cartodb_helpers.rb +14 -0
  99. data/spec/support/cartodb_models.rb +29 -0
  100. data/spec/support/data/110m-glaciated-areas.zip +0 -0
  101. data/spec/support/data/CartoDB_csv_export.zip +0 -0
  102. data/spec/support/data/CartoDB_shp_export.zip +0 -0
  103. data/spec/support/data/rmnp.kml +51 -0
  104. data/spec/support/data/states.kml.zip +0 -0
  105. data/spec/support/database.yml +5 -0
  106. data/spec/support/shp/cereal.dbf +0 -0
  107. data/spec/support/shp/cereal.shp +0 -0
  108. data/spec/support/shp/cereal.shx +0 -0
  109. data/spec/support/shp/cereal.zip +0 -0
  110. data/spec/support/shp/parcelas.dbf +0 -0
  111. data/spec/support/shp/parcelas.shp +0 -0
  112. data/spec/support/shp/parcelas.shx +0 -0
  113. data/spec/support/shp/parcelas.zip +0 -0
  114. data/spec/support/shp/zonas.dbf +0 -0
  115. data/spec/support/shp/zonas.shp +0 -0
  116. data/spec/support/shp/zonas.shx +0 -0
  117. data/spec/support/shp/zonas.zip +0 -0
  118. data/spec/support/whs_features.csv +315 -0
  119. data/spec/support/whs_features.csv.zip +0 -0
  120. data/spec/support/whs_features_temp.csv +315 -0
  121. metadata +400 -0
@@ -0,0 +1,224 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cartodb-rb-client.cartodb.com/api/v1/tables?api_key=242015a0c60666b5cdff0ce614334668817b52ac
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - &70175296087520 !ruby/object:MIME::Type
12
+ content_type: application/json
13
+ raw_media_type: application
14
+ raw_sub_type: json
15
+ simplified: application/json
16
+ media_type: application
17
+ sub_type: json
18
+ extensions:
19
+ - json
20
+ encoding: 8bit
21
+ system:
22
+ registered: true
23
+ url:
24
+ - IANA
25
+ - RFC4627
26
+ obsolete:
27
+ docs:
28
+ response:
29
+ status:
30
+ code: 200
31
+ message: !binary |-
32
+ T0s=
33
+ headers:
34
+ !binary "U2VydmVy":
35
+ - !binary |-
36
+ bmdpbng=
37
+ !binary "RGF0ZQ==":
38
+ - !binary |-
39
+ TW9uLCAyMCBBdWcgMjAxMiAxMDo1ODoyOSBHTVQ=
40
+ !binary "Q29udGVudC1UeXBl":
41
+ - !binary |-
42
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
43
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
44
+ - !binary |-
45
+ Y2h1bmtlZA==
46
+ !binary "Q29ubmVjdGlvbg==":
47
+ - !binary |-
48
+ a2VlcC1hbGl2ZQ==
49
+ !binary "VmFyeQ==":
50
+ - !binary |-
51
+ QWNjZXB0LUVuY29kaW5n
52
+ !binary "U3RhdHVz":
53
+ - !binary |-
54
+ MjAwIE9L
55
+ !binary "RXRhZw==":
56
+ - !binary |-
57
+ IjIxZTZhOWFhMDg0NmUzYmJlZGNiYjhmMzhkYzQwZjNmIg==
58
+ !binary "Q2FjaGUtQ29udHJvbA==":
59
+ - !binary |-
60
+ bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
61
+ !binary "WC1VYS1Db21wYXRpYmxl":
62
+ - !binary |-
63
+ SUU9RWRnZSxjaHJvbWU9MQ==
64
+ !binary "U2V0LUNvb2tpZQ==":
65
+ - !binary |-
66
+ X2NhcnRvZGJfc2Vzc2lvbj1CQWg3QjBraUQzTmxjM05wYjI1ZmFXUUdPZ1pG
67
+ UmlJbE9HWmpPR1ZqWTJSaVpqUTRaRFF4WVRFeFpETmtPVFV4WVRZME9HRXpO
68
+ akJKSWlaM1lYSmtaVzR1ZFhObGNpNWpZWEowYjJSaUxYSmlMV05zYVdWdWRD
69
+ NXJaWGtHT3dCVVNTSVdZMkZ5ZEc5a1lpMXlZaTFqYkdsbGJuUUdPd0JVLS1h
70
+ OTg5ZTcxNjBhYjc1MzJkNjYwMjIzOTE3YWFhYzAwNjI2NWIyZTczOyBkb21h
71
+ aW49LmNhcnRvZGIuY29tOyBwYXRoPS87IEh0dHBPbmx5
72
+ !binary "WC1SdW50aW1l":
73
+ - !binary |-
74
+ MC4wMTExOTk=
75
+ !binary "Q29udGVudC1FbmNvZGluZw==":
76
+ - !binary |-
77
+ Z3ppcA==
78
+ body:
79
+ encoding: ASCII-8BIT
80
+ string: !binary |-
81
+ eyJ0b3RhbF9lbnRyaWVzIjoyLCJ0YWJsZXMiOlt7ImlkIjo4MjI0LCJuYW1l
82
+ IjoidGFibGVfMiIsInByaXZhY3kiOiJQVUJMSUMiLCJ0YWdzIjoiIiwic2No
83
+ ZW1hIjpbWyJjYXJ0b2RiX2lkIiwibnVtYmVyIl0sWyJ0aGVfZ2VvbSIsImdl
84
+ b21ldHJ5IiwiZ2VvbWV0cnkiLCJwb2ludCJdLFsiZGVzY3JpcHRpb24iLCJz
85
+ dHJpbmciXSxbIm5hbWUiLCJzdHJpbmciXSxbImNyZWF0ZWRfYXQiLCJkYXRl
86
+ Il0sWyJ1cGRhdGVkX2F0IiwiZGF0ZSJdXSwidXBkYXRlZF9hdCI6IjIwMTIt
87
+ MDgtMjBUMTI6NTg6MDcrMDI6MDAiLCJyb3dzX2NvdW50ZWQiOjB9LHsiaWQi
88
+ OjgyMjMsIm5hbWUiOiJ0YWJsZV8xIiwicHJpdmFjeSI6IlBVQkxJQyIsInRh
89
+ Z3MiOiIiLCJzY2hlbWEiOltbImNhcnRvZGJfaWQiLCJudW1iZXIiXSxbInRo
90
+ ZV9nZW9tIiwiZ2VvbWV0cnkiLCJnZW9tZXRyeSIsInBvaW50Il0sWyJkZXNj
91
+ cmlwdGlvbiIsInN0cmluZyJdLFsibmFtZSIsInN0cmluZyJdLFsiY3JlYXRl
92
+ ZF9hdCIsImRhdGUiXSxbInVwZGF0ZWRfYXQiLCJkYXRlIl1dLCJ1cGRhdGVk
93
+ X2F0IjoiMjAxMi0wOC0yMFQxMjo1ODowNiswMjowMCIsInJvd3NfY291bnRl
94
+ ZCI6MH1dfQ==
95
+ http_version: !binary |-
96
+ MS4x
97
+ recorded_at: Mon, 20 Aug 2012 10:58:29 GMT
98
+ - request:
99
+ method: delete
100
+ uri: https://cartodb-rb-client.cartodb.com/api/v1/tables/table_2?api_key=242015a0c60666b5cdff0ce614334668817b52ac
101
+ body:
102
+ encoding: US-ASCII
103
+ string: ''
104
+ headers:
105
+ Accept:
106
+ - *70175296087520
107
+ response:
108
+ status:
109
+ code: 200
110
+ message: !binary |-
111
+ T0s=
112
+ headers:
113
+ !binary "U2VydmVy":
114
+ - !binary |-
115
+ bmdpbng=
116
+ !binary "RGF0ZQ==":
117
+ - !binary |-
118
+ TW9uLCAyMCBBdWcgMjAxMiAxMDo1ODozMCBHTVQ=
119
+ !binary "Q29udGVudC1UeXBl":
120
+ - !binary |-
121
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
122
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
123
+ - !binary |-
124
+ Y2h1bmtlZA==
125
+ !binary "Q29ubmVjdGlvbg==":
126
+ - !binary |-
127
+ a2VlcC1hbGl2ZQ==
128
+ !binary "VmFyeQ==":
129
+ - !binary |-
130
+ QWNjZXB0LUVuY29kaW5n
131
+ !binary "U3RhdHVz":
132
+ - !binary |-
133
+ MjAwIE9L
134
+ !binary "Q2FjaGUtQ29udHJvbA==":
135
+ - !binary |-
136
+ bm8tY2FjaGU=
137
+ !binary "WC1VYS1Db21wYXRpYmxl":
138
+ - !binary |-
139
+ SUU9RWRnZSxjaHJvbWU9MQ==
140
+ !binary "U2V0LUNvb2tpZQ==":
141
+ - !binary |-
142
+ X2NhcnRvZGJfc2Vzc2lvbj1CQWg3QjBraUQzTmxjM05wYjI1ZmFXUUdPZ1pG
143
+ UmlJbE16TXhNakE1T1dGalkyVTNaVFk1TWpFd01ETTFOR0poTnpVek0yWXdP
144
+ VEJKSWlaM1lYSmtaVzR1ZFhObGNpNWpZWEowYjJSaUxYSmlMV05zYVdWdWRD
145
+ NXJaWGtHT3dCVVNTSVdZMkZ5ZEc5a1lpMXlZaTFqYkdsbGJuUUdPd0JVLS1m
146
+ MDMzNTY2MTc0NjhiNmE0MzYxMjY4ZjkxNzA0M2VjYTVkZDg0MTczOyBkb21h
147
+ aW49LmNhcnRvZGIuY29tOyBwYXRoPS87IEh0dHBPbmx5
148
+ !binary "WC1SdW50aW1l":
149
+ - !binary |-
150
+ MC4xODAzMDI=
151
+ !binary "Q29udGVudC1FbmNvZGluZw==":
152
+ - !binary |-
153
+ Z3ppcA==
154
+ body:
155
+ encoding: ASCII-8BIT
156
+ string: !binary |-
157
+ IA==
158
+ http_version: !binary |-
159
+ MS4x
160
+ recorded_at: Mon, 20 Aug 2012 10:58:30 GMT
161
+ - request:
162
+ method: delete
163
+ uri: https://cartodb-rb-client.cartodb.com/api/v1/tables/table_1?api_key=242015a0c60666b5cdff0ce614334668817b52ac
164
+ body:
165
+ encoding: US-ASCII
166
+ string: ''
167
+ headers:
168
+ Accept:
169
+ - *70175296087520
170
+ response:
171
+ status:
172
+ code: 200
173
+ message: !binary |-
174
+ T0s=
175
+ headers:
176
+ !binary "U2VydmVy":
177
+ - !binary |-
178
+ bmdpbng=
179
+ !binary "RGF0ZQ==":
180
+ - !binary |-
181
+ TW9uLCAyMCBBdWcgMjAxMiAxMDo1ODozMCBHTVQ=
182
+ !binary "Q29udGVudC1UeXBl":
183
+ - !binary |-
184
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
185
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
186
+ - !binary |-
187
+ Y2h1bmtlZA==
188
+ !binary "Q29ubmVjdGlvbg==":
189
+ - !binary |-
190
+ a2VlcC1hbGl2ZQ==
191
+ !binary "VmFyeQ==":
192
+ - !binary |-
193
+ QWNjZXB0LUVuY29kaW5n
194
+ !binary "U3RhdHVz":
195
+ - !binary |-
196
+ MjAwIE9L
197
+ !binary "Q2FjaGUtQ29udHJvbA==":
198
+ - !binary |-
199
+ bm8tY2FjaGU=
200
+ !binary "WC1VYS1Db21wYXRpYmxl":
201
+ - !binary |-
202
+ SUU9RWRnZSxjaHJvbWU9MQ==
203
+ !binary "U2V0LUNvb2tpZQ==":
204
+ - !binary |-
205
+ X2NhcnRvZGJfc2Vzc2lvbj1CQWg3QjBraUQzTmxjM05wYjI1ZmFXUUdPZ1pG
206
+ UmlJbE56Z3hZelJsT0RCbU9URTROak00WWpBNU5qQTROekkwTWpJd1l6TmtZ
207
+ V1JKSWlaM1lYSmtaVzR1ZFhObGNpNWpZWEowYjJSaUxYSmlMV05zYVdWdWRD
208
+ NXJaWGtHT3dCVVNTSVdZMkZ5ZEc5a1lpMXlZaTFqYkdsbGJuUUdPd0JVLS1i
209
+ OGRjYjRiMmM2NGIyZmY5N2Y0NDJmYWE4Y2Y1M2YxZDg2Y2VmMDZlOyBkb21h
210
+ aW49LmNhcnRvZGIuY29tOyBwYXRoPS87IEh0dHBPbmx5
211
+ !binary "WC1SdW50aW1l":
212
+ - !binary |-
213
+ MC4xODk1NTY=
214
+ !binary "Q29udGVudC1FbmNvZGluZw==":
215
+ - !binary |-
216
+ Z3ppcA==
217
+ body:
218
+ encoding: ASCII-8BIT
219
+ string: !binary |-
220
+ IA==
221
+ http_version: !binary |-
222
+ MS4x
223
+ recorded_at: Mon, 20 Aug 2012 10:58:30 GMT
224
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,157 @@
1
+ require 'model_specs_helper'
2
+
3
+ describe 'CartoDB model data methods', :vcr => true do
4
+
5
+ it "should initialize attributes of the model without persisting them" do
6
+
7
+ losail_circuit = new_circuit
8
+
9
+ records = CartoDB::Connection.records 'moto_gp_circuit'
10
+ records.total_rows.should == 0
11
+ records.rows.should be_empty
12
+
13
+ losail_circuit.name.should be == 'Losail Circuit'
14
+ losail_circuit.description.should be == 'The fabulous Losail International Circuit lies on the outskirts of Doha, the capital city of Qatar. Built in little over a year, the track cost $58 million USD and required round-the-clock dedication from almost 1,000 workers in order to get it ready for the inaugural event - the Marlboro Grand Prix of Qatar on the 2nd October 2004.'
15
+ losail_circuit.latitude.should be == 25.488840
16
+ losail_circuit.longitude.should be == 51.453352
17
+ losail_circuit.length.should be == '5380m'
18
+ losail_circuit.width.should be == '12m'
19
+ losail_circuit.left_corners.should be == 6
20
+ losail_circuit.right_corners.should be == 10
21
+ losail_circuit.longest_straight.should be == '1068m'
22
+ losail_circuit.constructed.should be == Date.new(2004, 1, 1)
23
+ losail_circuit.modified.should be == Date.new(2004, 1, 1)
24
+ end
25
+
26
+ it "should persist into cartodb using the save method" do
27
+ losail_circuit = new_circuit
28
+
29
+ expect {
30
+ losail_circuit.save.should be_true
31
+ }.to change{CartoDB::Connection.records('moto_gp_circuit').total_rows}.from(0).to(1)
32
+
33
+ record = CartoDB::Connection.row 'moto_gp_circuit', losail_circuit.cartodb_id
34
+ record.cartodb_id.should be == 1
35
+ record.name.should be == 'Losail Circuit'
36
+ record.description.should match /The fabulous Losail International Circuit lies/
37
+ record.latitude.should be == 25.488840
38
+ record.longitude.should be == 51.453352
39
+ record.length.should be == '5380m'
40
+ record.width.should be == '12m'
41
+ record.left_corners.should be == 6
42
+ record.right_corners.should be == 10
43
+ record.longest_straight.should be == '1068m'
44
+ record.constructed.should be == DateTime.new(2004, 1, 1)
45
+ record.modified.should be == DateTime.new(2004, 1, 1)
46
+
47
+ losail_circuit.cartodb_id.should be == 1
48
+ losail_circuit.name.should be == 'Losail Circuit'
49
+ losail_circuit.description.should be == 'The fabulous Losail International Circuit lies on the outskirts of Doha, the capital city of Qatar. Built in little over a year, the track cost $58 million USD and required round-the-clock dedication from almost 1,000 workers in order to get it ready for the inaugural event - the Marlboro Grand Prix of Qatar on the 2nd October 2004.'
50
+ losail_circuit.latitude.should be == 25.488840
51
+ losail_circuit.longitude.should be == 51.453352
52
+ losail_circuit.length.should be == '5380m'
53
+ losail_circuit.width.should be == '12m'
54
+ losail_circuit.left_corners.should be == 6
55
+ losail_circuit.right_corners.should be == 10
56
+ losail_circuit.longest_straight.should be == '1068m'
57
+ losail_circuit.constructed.should be == Date.new(2004, 1, 1)
58
+ losail_circuit.modified.should be == Date.new(2004, 1, 1)
59
+ end
60
+
61
+ it "should persist into cartodb using the static create method" do
62
+ losail_circuit = MotoGPCircuit.create new_losail_circuit_attributes
63
+
64
+ record = CartoDB::Connection.row 'moto_gp_circuit', losail_circuit.cartodb_id
65
+ record.cartodb_id.should be == 1
66
+ record.name.should be == 'Losail Circuit'
67
+ record.description.should match /The fabulous Losail International Circuit lies/
68
+ record.latitude.should be == 25.488840
69
+ record.longitude.should be == 51.453352
70
+ record.length.should be == '5380m'
71
+ record.width.should be == '12m'
72
+ record.left_corners.should be == 6
73
+ record.right_corners.should be == 10
74
+ record.longest_straight.should be == '1068m'
75
+ record.constructed.should be == Date.new(2004, 1, 1)
76
+ record.modified.should be == Date.new(2004, 1, 1)
77
+
78
+ losail_circuit.cartodb_id.should be == 1
79
+ losail_circuit.name.should be == 'Losail Circuit'
80
+ losail_circuit.description.should be == 'The fabulous Losail International Circuit lies on the outskirts of Doha, the capital city of Qatar. Built in little over a year, the track cost $58 million USD and required round-the-clock dedication from almost 1,000 workers in order to get it ready for the inaugural event - the Marlboro Grand Prix of Qatar on the 2nd October 2004.'
81
+ losail_circuit.latitude.should be == 25.488840
82
+ losail_circuit.longitude.should be == 51.453352
83
+ losail_circuit.length.should be == '5380m'
84
+ losail_circuit.width.should be == '12m'
85
+ losail_circuit.left_corners.should be == 6
86
+ losail_circuit.right_corners.should be == 10
87
+ losail_circuit.longest_straight.should be == '1068m'
88
+ losail_circuit.constructed.should be == Date.new(2004, 1, 1)
89
+ losail_circuit.modified.should be == Date.new(2004, 1, 1)
90
+ end
91
+
92
+ it "should update an existing record" do
93
+ losail_circuit = MotoGPCircuit.create new_losail_circuit_attributes
94
+
95
+ losail_circuit.name = 'Prueba'
96
+ losail_circuit.description = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
97
+ losail_circuit.latitude = 40.582394
98
+ losail_circuit.longitude = -3.994131
99
+ losail_circuit.length = '1243m'
100
+
101
+ expect {
102
+ losail_circuit.save
103
+ }.to change{CartoDB::Connection.records('moto_gp_circuit').total_rows}.by(0)
104
+
105
+
106
+ record = CartoDB::Connection.row 'moto_gp_circuit', losail_circuit.cartodb_id
107
+ record.cartodb_id.should be == 1
108
+ record.name.should be == 'Prueba'
109
+ record.description.should match /Lorem ipsum dolor sit amet, consectetur adipisicing elit/
110
+ record.latitude.should be == 40.582394
111
+ record.longitude.should be == -3.994131
112
+ record.length.should be == '1243m'
113
+
114
+ losail_circuit.name.should be == 'Prueba'
115
+ losail_circuit.description.should match /Lorem ipsum dolor sit amet, consectetur adipisicing elit/
116
+ losail_circuit.latitude.should be == 40.582394
117
+ losail_circuit.longitude.should be == -3.994131
118
+ losail_circuit.length.should be == '1243m'
119
+ end
120
+
121
+ it "should destroy a previously created record" do
122
+ losail_circuit = MotoGPCircuit.create new_losail_circuit_attributes
123
+
124
+ expect {
125
+ losail_circuit.destroy
126
+ }.to change{CartoDB::Connection.records('moto_gp_circuit').total_rows}.by(-1)
127
+
128
+ end
129
+
130
+ it "should save polygons in different formats" do
131
+ polygon_json = '{"type":"MultiPolygon","coordinates":[[[[-3.779297,32.249974],[-8.525391,26.588527],[-2.021484,20.303418],[9.228516,23.563987],[6.943359,29.688053],[5.712891,32.546813]]]]}'
132
+
133
+ polygon_model = PolygonGeometryModel.new
134
+ polygon_model.the_geom = polygon_json
135
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
136
+ expect {
137
+ polygon_model.save.should be_true
138
+ }.to change{CartoDB::Connection.records('polygon_geometry_model').total_rows}.by(1)
139
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
140
+
141
+ polygon_model = PolygonGeometryModel.new(:the_geom => polygon_json)
142
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
143
+ expect {
144
+ polygon_model.save.should be_true
145
+ }.to change{CartoDB::Connection.records('polygon_geometry_model').total_rows}.by(1)
146
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
147
+
148
+ polygon_model = PolygonGeometryModel.new(:the_geom => ::JSON.parse(polygon_json))
149
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
150
+ expect {
151
+ polygon_model.save.should be_true
152
+ }.to change{CartoDB::Connection.records('polygon_geometry_model').total_rows}.by(1)
153
+ polygon_model.the_geom.should eql(RGeo::GeoJSON.decode(polygon_json, :json_parser => :json, :geo_factory => RGeo::Geographic.spherical_factory(:srid => 4326)))
154
+
155
+ end
156
+
157
+ end
@@ -0,0 +1,124 @@
1
+ require 'model_specs_helper'
2
+
3
+ describe 'CartoDB model metadata methods', :vcr => true do
4
+
5
+ it "should have a valid CartoDB::Client instance as a connection object" do
6
+ model = MotoGPCircuit.new
7
+ model.connection.should_not be_nil
8
+ table = model.connection.create_table 'model_connection_test'
9
+ table.should_not be_nil
10
+ table.name.should be == 'model_connection_test'
11
+ end
12
+
13
+ it "should have a valid table name" do
14
+ model = MotoGPCircuit.new
15
+ model.table_name.should be == 'moto_gp_circuit'
16
+ end
17
+
18
+ it "should create the table in cartodb if it doesn't exists" do
19
+ model = MotoGPCircuit.new
20
+
21
+ model.cartodb_table_exists?.should be_true
22
+ end
23
+
24
+ it "should create a table with custom name if specified" do
25
+ model = CustomTableName.new
26
+
27
+ model.table_name.should be == 'my_table_with_custom_name'
28
+ end
29
+
30
+ it "should contain an array of columns" do
31
+
32
+ model = MotoGPCircuit.new
33
+
34
+ model.columns.should_not be_nil
35
+ model.columns.should have(13).items
36
+ model.columns.should include({:name => 'cartodb_id', :type => 'number'})
37
+ model.columns.should include({:name => 'name', :type => 'string'})
38
+ model.columns.should include({:name => 'description', :type => 'string'})
39
+ model.columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
40
+ model.columns.should include({:name => 'created_at', :type => 'date'})
41
+ model.columns.should include({:name => 'updated_at', :type => 'date'})
42
+ model.columns.should include({:name => 'length', :type => 'string'})
43
+ model.columns.should include({:name => 'width', :type => 'string'})
44
+ model.columns.should include({:name => 'left_corners', :type => 'number'})
45
+ model.columns.should include({:name => 'right_corners', :type => 'number'})
46
+ model.columns.should include({:name => 'longest_straight', :type => 'string'})
47
+ model.columns.should include({:name => 'constructed', :type => 'date'})
48
+ model.columns.should include({:name => 'modified', :type => 'date'})
49
+ end
50
+
51
+ it "should add more columns if the table previously exists" do
52
+ table = CartoDB::Connection.create_table 'moto_gp_circuit'
53
+ table.schema.should include(["cartodb_id", "number"])
54
+ table.schema.should include(["name", "string"])
55
+ table.schema.should include(["the_geom", "geometry", "geometry", "point"])
56
+ table.schema.should include(["description", "string"])
57
+ table.schema.should include(["created_at", "date"])
58
+ table.schema.should include(["updated_at", "date"])
59
+ table.schema.should_not include(['length', 'string'])
60
+ table.schema.should_not include(['width','string'])
61
+ table.schema.should_not include(['left_corners', 'number'])
62
+ table.schema.should_not include(['right_corners', 'number'])
63
+ table.schema.should_not include(['longest_straight', 'string'])
64
+ table.schema.should_not include(['constructed', 'date'])
65
+ table.schema.should_not include(['modified', 'date'])
66
+
67
+ model = MotoGPCircuit.new
68
+
69
+ model.columns.should_not be_nil
70
+ model.columns.should have(13).items
71
+ model.columns.should include({:name => 'cartodb_id', :type => 'number'})
72
+ model.columns.should include({:name => 'name', :type => 'string'})
73
+ model.columns.should include({:name => 'description', :type => 'string'})
74
+ model.columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
75
+ model.columns.should include({:name => 'created_at', :type => 'date'})
76
+ model.columns.should include({:name => 'updated_at', :type => 'date'})
77
+ model.columns.should include({:name => 'length', :type => 'string'})
78
+ model.columns.should include({:name => 'width', :type => 'string'})
79
+ model.columns.should include({:name => 'left_corners', :type => 'number'})
80
+ model.columns.should include({:name => 'right_corners', :type => 'number'})
81
+ model.columns.should include({:name => 'longest_straight', :type => 'string'})
82
+ model.columns.should include({:name => 'constructed', :type => 'date'})
83
+ model.columns.should include({:name => 'modified', :type => 'date'})
84
+
85
+ end
86
+
87
+ it "should return only data columns" do
88
+ columns = MotoGPCircuit.data_columns
89
+ columns.should_not include({:name => 'cartodb_id', :type => 'number'})
90
+ columns.should_not include({:name => 'created_at', :type => 'date'})
91
+ columns.should_not include({:name => 'updated_at', :type => 'date'})
92
+ columns.should include({:name => 'name', :type => 'string'})
93
+ columns.should include({:name => 'description', :type => 'string'})
94
+ columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
95
+ columns.should include({:name => 'length', :type => 'string'})
96
+ columns.should include({:name => 'width', :type => 'string'})
97
+ columns.should include({:name => 'left_corners', :type => 'number'})
98
+ columns.should include({:name => 'right_corners', :type => 'number'})
99
+ columns.should include({:name => 'longest_straight', :type => 'string'})
100
+ columns.should include({:name => 'constructed', :type => 'date'})
101
+ columns.should include({:name => 'modified', :type => 'date'})
102
+
103
+ columns = StandardModel.data_columns
104
+ columns.should_not include({:name => 'cartodb_id', :type => 'number'})
105
+ columns.should_not include({:name => 'created_at', :type => 'date'})
106
+ columns.should_not include({:name => 'updated_at', :type => 'date'})
107
+ columns.should include({:name => 'name', :type => 'string'})
108
+ columns.should include({:name => 'description', :type => 'string'})
109
+ columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
110
+ end
111
+
112
+ it "should create model with custom data types columns" do
113
+ columns = CustomDataTypeColumnModel.data_columns
114
+ columns.should include({:name => 'test', :type => 'number'})
115
+ end
116
+
117
+ it "should create model with polygon type geometry columns" do
118
+ columns = PolygonGeometryModel.data_columns
119
+ columns.should have(4).items
120
+ columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'multipolygon'})
121
+ columns.should include({:name => 'another_column', :type => 'string'})
122
+ end
123
+
124
+ end