cartodb-rb-client 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +2 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE +28 -0
  5. data/README.markdown +324 -0
  6. data/Rakefile +10 -0
  7. data/cartodb-rb-client.gemspec +34 -0
  8. data/lib/cartodb-rb-client/cartodb/client/authorization.rb +58 -0
  9. data/lib/cartodb-rb-client/cartodb/client/cache.rb +14 -0
  10. data/lib/cartodb-rb-client/cartodb/client/connection/base.rb +44 -0
  11. data/lib/cartodb-rb-client/cartodb/client/connection/cartodb.rb +231 -0
  12. data/lib/cartodb-rb-client/cartodb/client/connection/postgres.rb +255 -0
  13. data/lib/cartodb-rb-client/cartodb/client/connection.rb +4 -0
  14. data/lib/cartodb-rb-client/cartodb/client/error.rb +68 -0
  15. data/lib/cartodb-rb-client/cartodb/client/utils.rb +20 -0
  16. data/lib/cartodb-rb-client/cartodb/client.rb +4 -0
  17. data/lib/cartodb-rb-client/cartodb/helpers/sql_helper.rb +30 -0
  18. data/lib/cartodb-rb-client/cartodb/helpers.rb +1 -0
  19. data/lib/cartodb-rb-client/cartodb/init.rb +30 -0
  20. data/lib/cartodb-rb-client/cartodb/libs/object.rb +15 -0
  21. data/lib/cartodb-rb-client/cartodb/libs/string.rb +116 -0
  22. data/lib/cartodb-rb-client/cartodb/libs.rb +2 -0
  23. data/lib/cartodb-rb-client/cartodb/model/base.rb +20 -0
  24. data/lib/cartodb-rb-client/cartodb/model/constants.rb +30 -0
  25. data/lib/cartodb-rb-client/cartodb/model/defaults.rb +15 -0
  26. data/lib/cartodb-rb-client/cartodb/model/geo.rb +73 -0
  27. data/lib/cartodb-rb-client/cartodb/model/getters.rb +79 -0
  28. data/lib/cartodb-rb-client/cartodb/model/persistence.rb +69 -0
  29. data/lib/cartodb-rb-client/cartodb/model/query.rb +66 -0
  30. data/lib/cartodb-rb-client/cartodb/model/schema.rb +111 -0
  31. data/lib/cartodb-rb-client/cartodb/model/scope.rb +163 -0
  32. data/lib/cartodb-rb-client/cartodb/model/setters.rb +42 -0
  33. data/lib/cartodb-rb-client/cartodb/model.rb +11 -0
  34. data/lib/cartodb-rb-client/cartodb/types/metadata.rb +89 -0
  35. data/lib/cartodb-rb-client/cartodb/types/pg_result.rb +17 -0
  36. data/lib/cartodb-rb-client/cartodb/types.rb +2 -0
  37. data/lib/cartodb-rb-client/cartodb.rb +6 -0
  38. data/lib/cartodb-rb-client/install_utils.rb +19 -0
  39. data/lib/cartodb-rb-client/version.rb +7 -0
  40. data/lib/cartodb-rb-client.rb +17 -0
  41. data/run_tests.sh +6 -0
  42. data/spec/client_spec.rb +278 -0
  43. data/spec/model/data_spec.rb +130 -0
  44. data/spec/model/metadata_spec.rb +116 -0
  45. data/spec/model/scopes_spec.rb +171 -0
  46. data/spec/spec_helper.rb +28 -0
  47. data/spec/support/cartodb_config.yml +15 -0
  48. data/spec/support/cartodb_factories.rb +33 -0
  49. data/spec/support/cartodb_helpers.rb +14 -0
  50. data/spec/support/cartodb_models.rb +22 -0
  51. data/spec/support/database.yml +5 -0
  52. data/spec/support/shp/cereal.dbf +0 -0
  53. data/spec/support/shp/cereal.shp +0 -0
  54. data/spec/support/shp/cereal.shx +0 -0
  55. data/spec/support/shp/cereal.zip +0 -0
  56. data/spec/support/shp/parcelas.dbf +0 -0
  57. data/spec/support/shp/parcelas.shp +0 -0
  58. data/spec/support/shp/parcelas.shx +0 -0
  59. data/spec/support/shp/parcelas.zip +0 -0
  60. data/spec/support/shp/zonas.dbf +0 -0
  61. data/spec/support/shp/zonas.shp +0 -0
  62. data/spec/support/shp/zonas.shx +0 -0
  63. data/spec/support/shp/zonas.zip +0 -0
  64. data/spec/support/whs_features.csv +33425 -0
  65. metadata +311 -0
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CartoDB model data methods' do
4
+
5
+ it "should initialize attributes of the model without persisting them into cartodb using the `new` method" 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 == Date.new(2004, 1, 1)
45
+ record.modified.should be == Date.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.9941309999999817
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
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CartoDB model metadata methods' 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
+ model = MotoGPCircuit.new
32
+
33
+ model.columns.should_not be_nil
34
+ model.columns.should have(13).items
35
+ model.columns.should include({:name => 'cartodb_id', :type => 'number'})
36
+ model.columns.should include({:name => 'name', :type => 'string'})
37
+ model.columns.should include({:name => 'description', :type => 'string'})
38
+ model.columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
39
+ model.columns.should include({:name => 'created_at', :type => 'date'})
40
+ model.columns.should include({:name => 'updated_at', :type => 'date'})
41
+ model.columns.should include({:name => 'length', :type => 'string'})
42
+ model.columns.should include({:name => 'width', :type => 'string'})
43
+ model.columns.should include({:name => 'left_corners', :type => 'number'})
44
+ model.columns.should include({:name => 'right_corners', :type => 'number'})
45
+ model.columns.should include({:name => 'longest_straight', :type => 'string'})
46
+ model.columns.should include({:name => 'constructed', :type => 'date'})
47
+ model.columns.should include({:name => 'modified', :type => 'date'})
48
+ end
49
+
50
+ it "should add more columns if the table previously exists and doesn't have all model columns" do
51
+ table = CartoDB::Connection.create_table 'moto_gp_circuit'
52
+ table.schema.should include(["cartodb_id", "number"])
53
+ table.schema.should include(["name", "string"])
54
+ table.schema.should include(["the_geom", "geometry", "geometry", "point"])
55
+ table.schema.should include(["description", "string"])
56
+ table.schema.should include(["created_at", "date"])
57
+ table.schema.should include(["updated_at", "date"])
58
+ table.schema.should_not include(['length', 'string'])
59
+ table.schema.should_not include(['width','string'])
60
+ table.schema.should_not include(['left_corners', 'number'])
61
+ table.schema.should_not include(['right_corners', 'number'])
62
+ table.schema.should_not include(['longest_straight', 'string'])
63
+ table.schema.should_not include(['constructed', 'date'])
64
+ table.schema.should_not include(['modified', 'date'])
65
+
66
+ model = MotoGPCircuit.new
67
+
68
+ model.columns.should_not be_nil
69
+ model.columns.should have(13).items
70
+ model.columns.should include({:name => 'cartodb_id', :type => 'number'})
71
+ model.columns.should include({:name => 'name', :type => 'string'})
72
+ model.columns.should include({:name => 'description', :type => 'string'})
73
+ model.columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
74
+ model.columns.should include({:name => 'created_at', :type => 'date'})
75
+ model.columns.should include({:name => 'updated_at', :type => 'date'})
76
+ model.columns.should include({:name => 'length', :type => 'string'})
77
+ model.columns.should include({:name => 'width', :type => 'string'})
78
+ model.columns.should include({:name => 'left_corners', :type => 'number'})
79
+ model.columns.should include({:name => 'right_corners', :type => 'number'})
80
+ model.columns.should include({:name => 'longest_straight', :type => 'string'})
81
+ model.columns.should include({:name => 'constructed', :type => 'date'})
82
+ model.columns.should include({:name => 'modified', :type => 'date'})
83
+
84
+ end
85
+
86
+ it "should return only data columns" do
87
+ columns = MotoGPCircuit.data_columns
88
+ columns.should_not include({:name => 'cartodb_id', :type => 'number'})
89
+ columns.should_not include({:name => 'created_at', :type => 'date'})
90
+ columns.should_not include({:name => 'updated_at', :type => 'date'})
91
+ columns.should include({:name => 'name', :type => 'string'})
92
+ columns.should include({:name => 'description', :type => 'string'})
93
+ columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
94
+ columns.should include({:name => 'length', :type => 'string'})
95
+ columns.should include({:name => 'width', :type => 'string'})
96
+ columns.should include({:name => 'left_corners', :type => 'number'})
97
+ columns.should include({:name => 'right_corners', :type => 'number'})
98
+ columns.should include({:name => 'longest_straight', :type => 'string'})
99
+ columns.should include({:name => 'constructed', :type => 'date'})
100
+ columns.should include({:name => 'modified', :type => 'date'})
101
+
102
+ columns = StandardModel.data_columns
103
+ columns.should_not include({:name => 'cartodb_id', :type => 'number'})
104
+ columns.should_not include({:name => 'created_at', :type => 'date'})
105
+ columns.should_not include({:name => 'updated_at', :type => 'date'})
106
+ columns.should include({:name => 'name', :type => 'string'})
107
+ columns.should include({:name => 'description', :type => 'string'})
108
+ columns.should include({:name => 'the_geom', :type => 'geometry', :geometry_type => 'point'})
109
+ end
110
+
111
+ it "should create model with custom data types columns" do
112
+ columns = CustomDataTypeColumnModel.data_columns
113
+ columns.should include({:name => 'test', :type => 'number'})
114
+ end
115
+
116
+ end
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CartoDB model scopes' do
4
+ it "should return all records paginated" do
5
+ create_random_circuits(20)
6
+
7
+ circuits = MotoGPCircuit.all
8
+
9
+ circuits.should have(10).circuits
10
+ circuits.first.should be_a_kind_of(MotoGPCircuit)
11
+ circuits.first.cartodb_id.should be == 1
12
+ circuits.first.name.should be == 'circuit #1'
13
+ circuits.first.description.should be == 'awesome circuit #1'
14
+ circuits.first.latitude.should be == 25.488840
15
+ circuits.first.longitude.should be == 51.453352
16
+ circuits.first.length.should be == '5380m'
17
+ circuits.first.width.should be == '12m'
18
+ circuits.first.left_corners.should be == 6
19
+ circuits.first.right_corners.should be == 10
20
+ circuits.first.longest_straight.should be == '1068m'
21
+ circuits.first.constructed.should be == DateTime.parse("2004-01-01").to_date
22
+ circuits.first.modified.should be == DateTime.parse("2004-01-01").to_date
23
+ end
24
+
25
+ it "should count all records" do
26
+ create_random_circuits(20)
27
+
28
+ MotoGPCircuit.count.should be == 20
29
+
30
+ create_random_circuit
31
+
32
+ MotoGPCircuit.count.should be == 21
33
+ end
34
+
35
+ it "should find a record by its id" do
36
+ create_random_circuits(20)
37
+
38
+ circuit = MotoGPCircuit.where(:cartodb_id => 1)
39
+
40
+ circuit.cartodb_id.should be == 1
41
+ circuit.name.should be == 'circuit #1'
42
+ circuit.description.should be == 'awesome circuit #1'
43
+ circuit.latitude.should be == 25.488840
44
+ circuit.longitude.should be == 51.453352
45
+ circuit.length.should be == '5380m'
46
+ circuit.width.should be == '12m'
47
+ circuit.left_corners.should be == 6
48
+ circuit.right_corners.should be == 10
49
+ circuit.longest_straight.should be == '1068m'
50
+ circuit.constructed.should be == DateTime.parse("2004-01-01").to_date
51
+ circuit.modified.should be == DateTime.parse("2004-01-01").to_date
52
+
53
+ same_circuit = MotoGPCircuit.find(1)
54
+
55
+ same_circuit.cartodb_id.should be == 1
56
+ same_circuit.name.should be == 'circuit #1'
57
+ same_circuit.description.should be == 'awesome circuit #1'
58
+ same_circuit.latitude.should be == 25.488840
59
+ same_circuit.longitude.should be == 51.453352
60
+ same_circuit.length.should be == '5380m'
61
+ same_circuit.width.should be == '12m'
62
+ same_circuit.left_corners.should be == 6
63
+ same_circuit.right_corners.should be == 10
64
+ same_circuit.longest_straight.should be == '1068m'
65
+ same_circuit.constructed.should be == DateTime.parse("2004-01-01").to_date
66
+ same_circuit.modified.should be == DateTime.parse("2004-01-01").to_date
67
+ end
68
+
69
+ it "should search records by certain filters" do
70
+
71
+ new_circuit(:name => 'Losail circuit', :left_corners => 6, :right_corners => 10).save
72
+ new_circuit(:name => 'Jerez', :left_corners => 5, :right_corners => 8).save
73
+ new_circuit(:name => 'Estoril', :left_corners => 4, :right_corners => 9).save
74
+ new_circuit(:name => 'Lemans', :left_corners => 4, :right_corners => 9).save
75
+ new_circuit(:name => 'Circuit de Catalunya', :left_corners => 5, :right_corners => 8).save
76
+
77
+ circuits = MotoGPCircuit.where(:left_corners => 4).where(:right_corners => 9)
78
+
79
+ circuits.should have(2).circuits
80
+ circuits.first.name.should be == 'Estoril'
81
+ circuits.last.name.should be == 'Lemans'
82
+ circuits.all.should have(2).circuits
83
+ circuits.all.first.name.should be == 'Estoril'
84
+ circuits.all.last.name.should be == 'Lemans'
85
+
86
+ circuits = MotoGPCircuit.where("left_corners = ?", 4).where("right_corners = ?", 9)
87
+
88
+ circuits.should have(2).circuits
89
+ circuits.first.name.should be == 'Estoril'
90
+ circuits.last.name.should be == 'Lemans'
91
+ circuits.all.should have(2).circuits
92
+ circuits.all.first.name.should be == 'Estoril'
93
+ circuits.all.last.name.should be == 'Lemans'
94
+ end
95
+
96
+ it "should paginate results" do
97
+ create_random_circuits(20)
98
+
99
+ circuits = MotoGPCircuit.page(1)
100
+
101
+ circuits.should have(10).circuits
102
+ circuits.first.cartodb_id.should be == 1
103
+ circuits.last.cartodb_id.should be == 10
104
+
105
+ circuits = MotoGPCircuit.page(2)
106
+
107
+ circuits.should have(10).circuits
108
+ circuits.first.cartodb_id.should be == 11
109
+ circuits.last.cartodb_id.should be == 20
110
+
111
+ circuits = MotoGPCircuit.page(1).per_page(20)
112
+
113
+ circuits.should have(20).circuits
114
+ circuits.first.cartodb_id.should be == 1
115
+ circuits.last.cartodb_id.should be == 20
116
+
117
+ circuits = MotoGPCircuit.where('CARTODB_ID > 0').page(1).per_page(20)
118
+
119
+ circuits.should have(20).circuits
120
+ circuits.first.cartodb_id.should be == 1
121
+ circuits.last.cartodb_id.should be == 20
122
+ end
123
+
124
+ it "should order results" do
125
+ create_random_circuits(20)
126
+
127
+ circuits = MotoGPCircuit.order('CARTODB_ID DESC')
128
+
129
+ circuits.should have(10).circuits
130
+ circuits.first.cartodb_id.should be == 20
131
+ circuits.last.cartodb_id.should be == 11
132
+ end
133
+
134
+ it "should allow to select the specified fiels" do
135
+ create_random_circuits(20)
136
+
137
+ circuits = MotoGPCircuit.select('cartodb_id, name').where('cartodb_id <= 10')
138
+
139
+ circuits.should have(10).circuits
140
+ circuits.first.cartodb_id.should be == 1
141
+ circuits.first.name.should be == 'circuit #1'
142
+ circuits.first.description.should be_nil
143
+ circuits.first.latitude.should be_nil
144
+ circuits.first.longitude.should be_nil
145
+ circuits.first.length.should be_nil
146
+ circuits.first.width.should be_nil
147
+ circuits.first.left_corners.should be_nil
148
+ circuits.first.right_corners.should be_nil
149
+ circuits.first.longest_straight.should be_nil
150
+ circuits.first.constructed.should be_nil
151
+ circuits.first.modified.should be_nil
152
+
153
+ circuits = MotoGPCircuit.select(:cartodb_id, :name).where('cartodb_id <= 10')
154
+
155
+ circuits.should have(10).circuits
156
+ circuits.first.cartodb_id.should be == 1
157
+ circuits.first.name.should be == 'circuit #1'
158
+ circuits.first.description.should be_nil
159
+ circuits.first.latitude.should be_nil
160
+ circuits.first.longitude.should be_nil
161
+ circuits.first.length.should be_nil
162
+ circuits.first.width.should be_nil
163
+ circuits.first.left_corners.should be_nil
164
+ circuits.first.right_corners.should be_nil
165
+ circuits.first.longest_straight.should be_nil
166
+ circuits.first.constructed.should be_nil
167
+ circuits.first.modified.should be_nil
168
+
169
+ end
170
+
171
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'yaml'
5
+ require 'cartodb-rb-client'
6
+ require 'cartodb-rb-client/cartodb'
7
+ require 'active_support/core_ext/array/random_access.rb'
8
+
9
+ CartoDB::Settings = YAML.load_file("#{File.dirname(__FILE__)}/support/cartodb_config.yml") unless defined? CartoDB::Settings
10
+ CartoDB::Connection = CartoDB::Client::Connection::Base.new unless defined? CartoDB::Connection
11
+ # CartoDB::Settings = YAML.load_file("#{File.dirname(__FILE__)}/support/database.yml") unless defined? CartoDB::Settings
12
+ # CartoDB::Connection = CartoDB::Client::Connection::Base.new unless defined? CartoDB::Connection
13
+
14
+ RgeoFactory = ::RGeo::Geographic.spherical_factory(:srid => 4326)
15
+
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories.
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
19
+
20
+ RSpec.configure do |config|
21
+ config.before(:each) do
22
+ drop_all_cartodb_tables
23
+ end
24
+
25
+ config.after(:all) do
26
+ drop_all_cartodb_tables
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ #############################
2
+ # CartoDB Credentials
3
+ #############################
4
+ host: https://cartodb-rb-client.cartodb.com
5
+ oauth_key: 0gRpcgKQK8bpcvSzM5ED4NqaSbNQ8ivS4q0pVdJF
6
+ oauth_secret: gE01QAOqvfTYuH9QcOZmToGtiLy8j99njENTazie
7
+ oauth_access_token: QLcGdmRFgVq2kybk5I97Wc4zj855LgoqUUub4QYr
8
+ oauth_access_token_secret: zHizyBxrUsTn2tu03C9Lkx4KFtPcbjvnPT3kQjQ7
9
+ # username: cartodb-rb-client
10
+ # password: cartodb-rb-client
11
+
12
+ # cache_timeout: 60
13
+ # debug: true
14
+ # ssl_peer_verification: true
15
+ # type_casting: true
@@ -0,0 +1,33 @@
1
+ module Factories
2
+ def new_circuit(values = {})
3
+ defaults = new_losail_circuit_attributes
4
+ defaults = defaults.merge(values)
5
+ MotoGPCircuit.new defaults
6
+ end
7
+
8
+ def create_random_circuits(ammount = 1)
9
+ ammount.times do |i|
10
+ new_circuit(:name => "circuit ##{i + 1}", :description => "awesome circuit ##{i + 1}").save
11
+ end
12
+ end
13
+
14
+ alias create_random_circuit create_random_circuits
15
+
16
+ def new_losail_circuit_attributes
17
+ {
18
+ :name => 'Losail Circuit',
19
+ :description => '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.',
20
+ :latitude => 25.488840,
21
+ :longitude => 51.453352,
22
+ :length => '5380m',
23
+ :width => '12m',
24
+ :left_corners => 6,
25
+ :right_corners => 10,
26
+ :longest_straight => '1068m',
27
+ :constructed => Date.new(2004, 1, 1),
28
+ :modified => Date.new(2004, 1, 1)
29
+ }
30
+ end
31
+ end
32
+
33
+ RSpec.configure{ include Factories }
@@ -0,0 +1,14 @@
1
+ module CartodbHelpers
2
+
3
+ def drop_all_cartodb_tables
4
+ return unless CartoDB::Connection
5
+
6
+ tables_list = CartoDB::Connection.tables || []
7
+
8
+ tables_list.tables.each do |table|
9
+ CartoDB::Connection.drop_table(table.name) if table && table.name
10
+ end
11
+ end
12
+
13
+ end
14
+ RSpec.configuration.include CartodbHelpers
@@ -0,0 +1,22 @@
1
+ class MotoGPCircuit < CartoDB::Model::Base
2
+ field :name
3
+ field :description
4
+ field :length
5
+ field :width
6
+ field :longest_straight
7
+ field :left_corners, :type => Integer
8
+ field :right_corners, :type => Integer
9
+ field :constructed, :type => Date
10
+ field :modified, :type => Date
11
+ end
12
+
13
+ class StandardModel < CartoDB::Model::Base
14
+ end
15
+
16
+ class CustomTableName < CartoDB::Model::Base
17
+ cartodb_table_name 'my_table_with_custom_name'
18
+ end
19
+
20
+ class CustomDataTypeColumnModel < CartoDB::Model::Base
21
+ field :test, :type => 'integer'
22
+ end
@@ -0,0 +1,5 @@
1
+ host: localhost
2
+ port: 5432
3
+ user: postgres
4
+ password:
5
+ database: cartodb-rb-client
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file