activerecord-postgres-earthdistance 0.1.0 → 0.2.0

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 (69) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +4 -10
  5. data/Gemfile.lock +92 -69
  6. data/README.md +124 -0
  7. data/Rakefile +12 -40
  8. data/activerecord-postgres-earthdistance.gemspec +24 -117
  9. data/lib/activerecord-postgres-earthdistance.rb +5 -46
  10. data/lib/activerecord-postgres-earthdistance/activerecord.rb +9 -10
  11. data/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb +24 -0
  12. data/lib/activerecord-postgres-earthdistance/railties.rb +40 -0
  13. data/lib/templates/setup_earthdistance.rb +4 -427
  14. data/spec/act_as_geolocated_spec.rb +29 -0
  15. data/{test/app/app/models → spec/fixtures}/place.rb +0 -0
  16. data/spec/spec_helper.rb +46 -0
  17. metadata +67 -109
  18. data/README.rdoc +0 -17
  19. data/VERSION +0 -1
  20. data/test/app/.gitignore +0 -4
  21. data/test/app/Gemfile +0 -5
  22. data/test/app/Gemfile.lock +0 -83
  23. data/test/app/README +0 -256
  24. data/test/app/Rakefile +0 -7
  25. data/test/app/app/controllers/application_controller.rb +0 -3
  26. data/test/app/app/helpers/application_helper.rb +0 -2
  27. data/test/app/app/views/layouts/application.html.erb +0 -14
  28. data/test/app/config.ru +0 -4
  29. data/test/app/config/application.rb +0 -42
  30. data/test/app/config/boot.rb +0 -13
  31. data/test/app/config/database.yml +0 -25
  32. data/test/app/config/environment.rb +0 -5
  33. data/test/app/config/environments/development.rb +0 -26
  34. data/test/app/config/environments/production.rb +0 -49
  35. data/test/app/config/environments/test.rb +0 -35
  36. data/test/app/config/initializers/backtrace_silencers.rb +0 -7
  37. data/test/app/config/initializers/inflections.rb +0 -10
  38. data/test/app/config/initializers/mime_types.rb +0 -5
  39. data/test/app/config/initializers/secret_token.rb +0 -7
  40. data/test/app/config/initializers/session_store.rb +0 -8
  41. data/test/app/config/initializers/use_sql_schema.rb +0 -3
  42. data/test/app/config/locales/en.yml +0 -5
  43. data/test/app/config/routes.rb +0 -58
  44. data/test/app/db/development_structure.sql +0 -807
  45. data/test/app/db/migrate/20110225205046_setup_earthdistance.rb +0 -434
  46. data/test/app/db/migrate/20110225205131_create_places.rb +0 -15
  47. data/test/app/db/schema.rb +0 -24
  48. data/test/app/db/seeds.rb +0 -7
  49. data/test/app/doc/README_FOR_APP +0 -2
  50. data/test/app/lib/tasks/.gitkeep +0 -0
  51. data/test/app/public/404.html +0 -26
  52. data/test/app/public/422.html +0 -26
  53. data/test/app/public/500.html +0 -26
  54. data/test/app/public/favicon.ico +0 -0
  55. data/test/app/public/images/rails.png +0 -0
  56. data/test/app/public/index.html +0 -239
  57. data/test/app/public/javascripts/application.js +0 -2
  58. data/test/app/public/javascripts/controls.js +0 -965
  59. data/test/app/public/javascripts/dragdrop.js +0 -974
  60. data/test/app/public/javascripts/effects.js +0 -1123
  61. data/test/app/public/javascripts/prototype.js +0 -6001
  62. data/test/app/public/javascripts/rails.js +0 -175
  63. data/test/app/public/robots.txt +0 -5
  64. data/test/app/public/stylesheets/.gitkeep +0 -0
  65. data/test/app/script/rails +0 -6
  66. data/test/app/test/performance/browsing_test.rb +0 -9
  67. data/test/app/test/test_helper.rb +0 -13
  68. data/test/app/test/unit/place_test.rb +0 -27
  69. data/test/app/vendor/plugins/.gitkeep +0 -0
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ActiveRecord::Base.act_as_geolocated" do
4
+ describe "#within_radius" do
5
+ let(:test_data){ {lat: nil, lng: nil, radius: nil} }
6
+ subject{ Place.within_radius(test_data[:radius], test_data[:lat], test_data[:lng]) }
7
+ before(:all) do
8
+ @place = Place.create!(:lat => -30.0277041, :lng => -51.2287346)
9
+ end
10
+
11
+ context "when query with null data" do
12
+ it{ should == [] }
13
+ end
14
+
15
+ context "when query for the exact same point with radius 0" do
16
+ let(:test_data){{lat: -30.0277041, lng: -51.2287346 , radius: 0}}
17
+ it{ should == [@place] }
18
+ end
19
+
20
+ context "when query for place within radius" do
21
+ let(:test_data){ {radius: 4000000, lat: -27.5969039, lng: -48.5494544} }
22
+ it{ should == [@place] }
23
+ end
24
+
25
+ context "when query for place outside the radius" do
26
+ let(:test_data){ {radius: 1000, lat: -27.5969039, lng: -48.5494544} }
27
+ end
28
+ end
29
+ end
File without changes
@@ -0,0 +1,46 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rspec'
4
+ require 'rspec/autorun'
5
+ require 'activerecord-postgres-earthdistance'
6
+ require 'active_record'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:suite) do
10
+ # we create a test database if it does not exist
11
+ # I do not use database users or password for the tests, using ident authentication instead
12
+ begin
13
+ ActiveRecord::Base.establish_connection(
14
+ :adapter => "postgresql",
15
+ :host => "localhost",
16
+ :username => "postgres",
17
+ :password => "postgres",
18
+ :port => 5432,
19
+ :database => "ar_pg_earthdistance_test"
20
+ )
21
+ ActiveRecord::Base.connection.execute %{
22
+ SET client_min_messages TO warning;
23
+ CREATE EXTENSION IF NOT EXISTS cube;
24
+ CREATE EXTENSION IF NOT EXISTS earthdistance;
25
+ DROP TABLE IF EXISTS places;
26
+ CREATE TABLE places (id serial PRIMARY KEY, data text, lat float8, lng float8);
27
+ }
28
+ rescue Exception => e
29
+ puts "Exception: #{e}"
30
+ ActiveRecord::Base.establish_connection(
31
+ :adapter => "postgresql",
32
+ :host => "localhost",
33
+ :username => "postgres",
34
+ :password => "postgres",
35
+ :port => 5432,
36
+ :database => "postgres"
37
+ )
38
+ ActiveRecord::Base.connection.execute "CREATE DATABASE ar_pg_earthdistance_test"
39
+ retry
40
+ end
41
+
42
+ # Load model used in spec
43
+ require 'fixtures/place'
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,76 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres-earthdistance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Juan Maiz
9
8
  - Diogo Biazus
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2011-06-23 00:00:00.000000000 -03:00
14
- default_executable:
12
+ date: 2013-02-07 00:00:00.000000000 Z
15
13
  dependencies:
16
14
  - !ruby/object:Gem::Dependency
17
15
  name: rails
18
- requirement: &11148630 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
18
  requirements:
21
19
  - - ! '>='
22
20
  - !ruby/object:Gem::Version
23
- version: 3.0.0
21
+ version: '3.1'
24
22
  type: :runtime
25
23
  prerelease: false
26
- version_requirements: *11148630
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
27
30
  - !ruby/object:Gem::Dependency
28
- name: pg
29
- requirement: &11148380 !ruby/object:Gem::Requirement
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
34
  requirements:
32
35
  - - ! '>='
33
36
  - !ruby/object:Gem::Version
34
- version: '0.11'
37
+ version: '0'
35
38
  type: :runtime
36
39
  prerelease: false
37
- version_requirements: *11148380
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
38
46
  - !ruby/object:Gem::Dependency
39
- name: shoulda
40
- requirement: &11148110 !ruby/object:Gem::Requirement
47
+ name: pg
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
50
  requirements:
43
51
  - - ! '>='
44
52
  - !ruby/object:Gem::Version
45
53
  version: '0'
46
- type: :development
54
+ type: :runtime
47
55
  prerelease: false
48
- version_requirements: *11148110
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
49
62
  - !ruby/object:Gem::Dependency
50
63
  name: bundler
51
- requirement: &11147860 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
66
  requirements:
54
- - - ~>
67
+ - - ! '>='
55
68
  - !ruby/object:Gem::Version
56
- version: 1.0.0
69
+ version: '0'
57
70
  type: :development
58
71
  prerelease: false
59
- version_requirements: *11147860
60
- - !ruby/object:Gem::Dependency
61
- name: jeweler
62
- requirement: &11147600 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
63
73
  none: false
64
74
  requirements:
65
- - - ~>
75
+ - - ! '>='
66
76
  - !ruby/object:Gem::Version
67
- version: 1.6.2
68
- type: :development
69
- prerelease: false
70
- version_requirements: *11147600
77
+ version: '0'
71
78
  - !ruby/object:Gem::Dependency
72
- name: rcov
73
- requirement: &11147340 !ruby/object:Gem::Requirement
79
+ name: rdoc
80
+ requirement: !ruby/object:Gem::Requirement
74
81
  none: false
75
82
  requirements:
76
83
  - - ! '>='
@@ -78,103 +85,57 @@ dependencies:
78
85
  version: '0'
79
86
  type: :development
80
87
  prerelease: false
81
- version_requirements: *11147340
82
- - !ruby/object:Gem::Dependency
83
- name: pg
84
- requirement: &11147090 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
85
89
  none: false
86
90
  requirements:
87
91
  - - ! '>='
88
92
  - !ruby/object:Gem::Version
89
93
  version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: *11147090
93
94
  - !ruby/object:Gem::Dependency
94
- name: rails
95
- requirement: &11146840 !ruby/object:Gem::Requirement
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
98
- - - ! '>='
99
+ - - ~>
99
100
  - !ruby/object:Gem::Version
100
- version: '0'
101
- type: :runtime
101
+ version: '2.11'
102
+ type: :development
102
103
  prerelease: false
103
- version_requirements: *11146840
104
- description: I'll write it tomorrow
105
- email: diogob@gmail.com
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.11'
110
+ description: This gem enables your model to query the database using the earthdistance
111
+ extension. This should be much faster than using trigonometry functions over standart
112
+ indexs.
113
+ email: diogo@biazus.me
106
114
  executables: []
107
115
  extensions: []
108
- extra_rdoc_files:
109
- - LICENSE
110
- - README.rdoc
116
+ extra_rdoc_files: []
111
117
  files:
112
118
  - .document
119
+ - .gitignore
120
+ - .rspec
121
+ - .travis.yml
113
122
  - Gemfile
114
123
  - Gemfile.lock
115
124
  - LICENSE
116
- - README.rdoc
125
+ - README.md
117
126
  - Rakefile
118
- - VERSION
119
127
  - activerecord-postgres-earthdistance.gemspec
120
128
  - lib/activerecord-postgres-earthdistance.rb
121
129
  - lib/activerecord-postgres-earthdistance/activerecord.rb
130
+ - lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb
131
+ - lib/activerecord-postgres-earthdistance/railties.rb
122
132
  - lib/templates/cube.sql
123
133
  - lib/templates/earthdistance.sql
124
134
  - lib/templates/setup_earthdistance.rb
125
- - test/app/.gitignore
126
- - test/app/Gemfile
127
- - test/app/Gemfile.lock
128
- - test/app/README
129
- - test/app/Rakefile
130
- - test/app/app/controllers/application_controller.rb
131
- - test/app/app/helpers/application_helper.rb
132
- - test/app/app/models/place.rb
133
- - test/app/app/views/layouts/application.html.erb
134
- - test/app/config.ru
135
- - test/app/config/application.rb
136
- - test/app/config/boot.rb
137
- - test/app/config/database.yml
138
- - test/app/config/environment.rb
139
- - test/app/config/environments/development.rb
140
- - test/app/config/environments/production.rb
141
- - test/app/config/environments/test.rb
142
- - test/app/config/initializers/backtrace_silencers.rb
143
- - test/app/config/initializers/inflections.rb
144
- - test/app/config/initializers/mime_types.rb
145
- - test/app/config/initializers/secret_token.rb
146
- - test/app/config/initializers/session_store.rb
147
- - test/app/config/initializers/use_sql_schema.rb
148
- - test/app/config/locales/en.yml
149
- - test/app/config/routes.rb
150
- - test/app/db/development_structure.sql
151
- - test/app/db/migrate/20110225205046_setup_earthdistance.rb
152
- - test/app/db/migrate/20110225205131_create_places.rb
153
- - test/app/db/schema.rb
154
- - test/app/db/seeds.rb
155
- - test/app/doc/README_FOR_APP
156
- - test/app/lib/tasks/.gitkeep
157
- - test/app/public/404.html
158
- - test/app/public/422.html
159
- - test/app/public/500.html
160
- - test/app/public/favicon.ico
161
- - test/app/public/images/rails.png
162
- - test/app/public/index.html
163
- - test/app/public/javascripts/application.js
164
- - test/app/public/javascripts/controls.js
165
- - test/app/public/javascripts/dragdrop.js
166
- - test/app/public/javascripts/effects.js
167
- - test/app/public/javascripts/prototype.js
168
- - test/app/public/javascripts/rails.js
169
- - test/app/public/robots.txt
170
- - test/app/public/stylesheets/.gitkeep
171
- - test/app/script/rails
172
- - test/app/test/performance/browsing_test.rb
173
- - test/app/test/test_helper.rb
174
- - test/app/test/unit/place_test.rb
175
- - test/app/vendor/plugins/.gitkeep
176
- has_rdoc: true
177
- homepage: http://github.com/softa/activerecord-postgres-earthdistance
135
+ - spec/act_as_geolocated_spec.rb
136
+ - spec/fixtures/place.rb
137
+ - spec/spec_helper.rb
138
+ homepage: http://github.com/diogob/activerecord-postgres-earthdistance
178
139
  licenses:
179
140
  - MIT
180
141
  post_install_message:
@@ -186,20 +147,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
147
  requirements:
187
148
  - - ! '>='
188
149
  - !ruby/object:Gem::Version
189
- version: '0'
190
- segments:
191
- - 0
192
- hash: -433114031
150
+ version: 1.8.7
193
151
  required_rubygems_version: !ruby/object:Gem::Requirement
194
152
  none: false
195
153
  requirements:
196
154
  - - ! '>='
197
155
  - !ruby/object:Gem::Version
198
- version: '0'
156
+ version: 1.3.6
199
157
  requirements: []
200
158
  rubyforge_project:
201
- rubygems_version: 1.6.2
159
+ rubygems_version: 1.8.24
202
160
  signing_key:
203
161
  specification_version: 3
204
- summary: Now you can filter records within a radius
162
+ summary: Check distances with latitude and longitude using PostgreSQL special indexes
205
163
  test_files: []
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = activerecord-postgres-earthdistance
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Juan Maiz. See LICENSE for details.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
data/test/app/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .bundle
2
- db/*.sqlite3
3
- log/*.log
4
- tmp/**/*
data/test/app/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails', '3.0.7'
4
- gem 'pg'
5
- gem 'activerecord-postgres-earthdistance', :path => '../../'
@@ -1,83 +0,0 @@
1
- PATH
2
- remote: ../../
3
- specs:
4
- activerecord-postgres-earthdistance (0.0.0)
5
- pg
6
- pg (>= 0.11)
7
- rails
8
- rails (>= 3.0.0)
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- abstract (1.0.0)
14
- actionmailer (3.0.7)
15
- actionpack (= 3.0.7)
16
- mail (~> 2.2.15)
17
- actionpack (3.0.7)
18
- activemodel (= 3.0.7)
19
- activesupport (= 3.0.7)
20
- builder (~> 2.1.2)
21
- erubis (~> 2.6.6)
22
- i18n (~> 0.5.0)
23
- rack (~> 1.2.1)
24
- rack-mount (~> 0.6.14)
25
- rack-test (~> 0.5.7)
26
- tzinfo (~> 0.3.23)
27
- activemodel (3.0.7)
28
- activesupport (= 3.0.7)
29
- builder (~> 2.1.2)
30
- i18n (~> 0.5.0)
31
- activerecord (3.0.7)
32
- activemodel (= 3.0.7)
33
- activesupport (= 3.0.7)
34
- arel (~> 2.0.2)
35
- tzinfo (~> 0.3.23)
36
- activeresource (3.0.7)
37
- activemodel (= 3.0.7)
38
- activesupport (= 3.0.7)
39
- activesupport (3.0.7)
40
- arel (2.0.10)
41
- builder (2.1.2)
42
- erubis (2.6.6)
43
- abstract (>= 1.0.0)
44
- i18n (0.5.0)
45
- mail (2.2.19)
46
- activesupport (>= 2.3.6)
47
- i18n (>= 0.4.0)
48
- mime-types (~> 1.16)
49
- treetop (~> 1.4.8)
50
- mime-types (1.16)
51
- pg (0.11.0)
52
- polyglot (0.3.1)
53
- rack (1.2.3)
54
- rack-mount (0.6.14)
55
- rack (>= 1.0.0)
56
- rack-test (0.5.7)
57
- rack (>= 1.0)
58
- rails (3.0.7)
59
- actionmailer (= 3.0.7)
60
- actionpack (= 3.0.7)
61
- activerecord (= 3.0.7)
62
- activeresource (= 3.0.7)
63
- activesupport (= 3.0.7)
64
- bundler (~> 1.0)
65
- railties (= 3.0.7)
66
- railties (3.0.7)
67
- actionpack (= 3.0.7)
68
- activesupport (= 3.0.7)
69
- rake (>= 0.8.7)
70
- thor (~> 0.14.4)
71
- rake (0.9.2)
72
- thor (0.14.6)
73
- treetop (1.4.9)
74
- polyglot (>= 0.3.1)
75
- tzinfo (0.3.27)
76
-
77
- PLATFORMS
78
- ruby
79
-
80
- DEPENDENCIES
81
- activerecord-postgres-earthdistance!
82
- pg
83
- rails (= 3.0.7)