activerecord-postgres-earthdistance 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66511eae5a8cb2b504b1040cb1339974295916c5
4
- data.tar.gz: 2700f96a4817f91aeee66f461cc80638b56fb44b
3
+ metadata.gz: 94eb40debf0a4955024e1c8c4213b88530b294b1
4
+ data.tar.gz: ec0ec0eb7d2472ebe8bad60197bbf0a7b45f1d36
5
5
  SHA512:
6
- metadata.gz: f44686c1e06bb4d226a2c6327d1b604b060bb6437d54361de421ead725fe90adb2c3071c493dd6b3a6aecdda81da9cbb1d852ec2996060d219fecfd91d555893
7
- data.tar.gz: b5bf876569b00f5ef302bbabc4199f143fb59d22841999f2778fee56680dc6f67f2ae560f35d475b90e3dc8334a04a9fd27f6636459ea2eca24acb88333734f6
6
+ metadata.gz: c9818e3e89ae5b0906c30fa097b26eb7445541541dbce5b31e633641f13d8a1ba797c500f4e420b0b6fad88315914e35c345971540043626ef1d1b589f5ecc35
7
+ data.tar.gz: b6dfb3232de9828d812589a01a4f199ee36af6dbdda53064373253e5000370982465eec956f122e9efcdb3fdb9029f1c24e3e5cc820653146d01f56208ae5384
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-postgres-earthdistance (0.5.1)
4
+ activerecord-postgres-earthdistance (0.5.2)
5
5
  activerecord (>= 3.1)
6
6
  pg
7
7
  rake
@@ -9,44 +9,47 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activemodel (5.0.0.1)
13
- activesupport (= 5.0.0.1)
14
- activerecord (5.0.0.1)
15
- activemodel (= 5.0.0.1)
16
- activesupport (= 5.0.0.1)
12
+ activemodel (5.0.2)
13
+ activesupport (= 5.0.2)
14
+ activerecord (5.0.2)
15
+ activemodel (= 5.0.2)
16
+ activesupport (= 5.0.2)
17
17
  arel (~> 7.0)
18
- activesupport (5.0.0.1)
18
+ activesupport (5.0.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (~> 0.7)
21
21
  minitest (~> 5.1)
22
22
  tzinfo (~> 1.1)
23
23
  arel (7.1.4)
24
24
  coderay (1.1.1)
25
- concurrent-ruby (1.0.2)
26
- diff-lcs (1.2.5)
27
- i18n (0.7.0)
28
- json (1.8.3)
25
+ concurrent-ruby (1.0.5)
26
+ diff-lcs (1.3)
27
+ i18n (0.8.1)
29
28
  method_source (0.8.2)
30
- minitest (5.9.1)
31
- pg (0.19.0)
29
+ minitest (5.10.1)
30
+ pg (0.20.0)
32
31
  pry (0.10.4)
33
32
  coderay (~> 1.1.0)
34
33
  method_source (~> 0.8.1)
35
34
  slop (~> 3.4)
36
- rake (11.3.0)
37
- rdoc (4.2.1)
38
- json (~> 1.4)
39
- rspec (2.99.0)
40
- rspec-core (~> 2.99.0)
41
- rspec-expectations (~> 2.99.0)
42
- rspec-mocks (~> 2.99.0)
43
- rspec-core (2.99.2)
44
- rspec-expectations (2.99.2)
45
- diff-lcs (>= 1.1.3, < 2.0)
46
- rspec-mocks (2.99.4)
35
+ rake (12.0.0)
36
+ rdoc (5.1.0)
37
+ rspec (3.5.0)
38
+ rspec-core (~> 3.5.0)
39
+ rspec-expectations (~> 3.5.0)
40
+ rspec-mocks (~> 3.5.0)
41
+ rspec-core (3.5.4)
42
+ rspec-support (~> 3.5.0)
43
+ rspec-expectations (3.5.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.5.0)
46
+ rspec-mocks (3.5.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-support (3.5.0)
47
50
  slop (3.6.0)
48
- thread_safe (0.3.5)
49
- tzinfo (1.2.2)
51
+ thread_safe (0.3.6)
52
+ tzinfo (1.2.3)
50
53
  thread_safe (~> 0.1)
51
54
 
52
55
  PLATFORMS
@@ -57,7 +60,7 @@ DEPENDENCIES
57
60
  bundler
58
61
  pry
59
62
  rdoc
60
- rspec (~> 2.11)
63
+ rspec
61
64
 
62
65
  BUNDLED WITH
63
- 1.13.6
66
+ 1.14.3
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "activerecord-postgres-earthdistance"
7
- s.version = "0.5.1"
7
+ s.version = "0.5.2"
8
8
 
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.license = "MIT"
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "pg"
24
24
  s.add_development_dependency "bundler"
25
25
  s.add_development_dependency "rdoc"
26
- s.add_development_dependency "rspec", "~> 2.11"
26
+ s.add_development_dependency "rspec"
27
27
  s.add_development_dependency "pry"
28
28
 
29
29
  git_files = begin
@@ -37,8 +37,6 @@ module ActiveRecordPostgresEarthdistance
37
37
  joins(through_table).order("#{earth_distance.to_sql} #{order}")
38
38
  end
39
39
 
40
- private
41
-
42
40
  def through_table_klass
43
41
  if through_table.present?
44
42
  reflections[through_table.to_s].klass
@@ -84,11 +82,12 @@ module ActiveRecordPostgresEarthdistance
84
82
  module QueryMethods
85
83
  def selecting_distance_from(lat, lng, name = "distance", include_default_columns = true)
86
84
  clone.tap do |relation|
85
+ relation.joins!(through_table)
87
86
  values = []
88
87
  if relation.select_values.empty? && include_default_columns
89
88
  values << relation.arel_table[Arel.star]
90
89
  end
91
- values << Utils.earth_distance(self, lat, lng, name)
90
+ values << Utils.earth_distance(through_table_klass, lat, lng, name)
92
91
 
93
92
  relation.select_values = values
94
93
  end
@@ -7,7 +7,7 @@ describe "ActiveRecord::Base.act_as_geolocated" do
7
7
  subject { Place.where("id = ?", place).first }
8
8
  after { place.destroy! }
9
9
 
10
- it { should == place }
10
+ it { is_expected.to eq place }
11
11
  end
12
12
  end
13
13
 
@@ -20,34 +20,34 @@ describe "ActiveRecord::Base.act_as_geolocated" do
20
20
  after(:all) { @place.destroy }
21
21
 
22
22
  context "when query with null data" do
23
- it { should be_empty }
23
+ it { is_expected.to be_empty }
24
24
  end
25
25
 
26
26
  context "when query for the exact same point with radius 0" do
27
27
  let(:test_data) { { lat: -30.0277041, lng: -51.2287346, radius: 0 } }
28
28
 
29
- it { should == [@place] }
29
+ it { is_expected.to eq [@place] }
30
30
  end
31
31
 
32
32
  context "when query for place within the box" do
33
33
  let(:test_data) { { radius: 4_000_000, lat: -27.5969039, lng: -48.5494544 } }
34
34
 
35
- it { should == [@place] }
35
+ it { is_expected.to eq [@place] }
36
36
  end
37
37
 
38
38
  context "when query for place within the box, but outside the radius" do
39
39
  let(:test_data) { { radius: 300_000, lat: -27.5969039, lng: -48.5494544 } }
40
40
 
41
41
  it "the place shouldn't be within the radius" do
42
- Place.within_radius(test_data[:radius], test_data[:lat], test_data[:lng]).should be_empty
42
+ expect(Place.within_radius(test_data[:radius], test_data[:lat], test_data[:lng])).to be_empty
43
43
  end
44
44
 
45
- it { should == [@place] }
45
+ it { is_expected.to eq [@place] }
46
46
  end
47
47
 
48
48
  context "when query for place outside the box" do
49
49
  let(:test_data) { { radius: 1000, lat: -27.5969039, lng: -48.5494544 } }
50
- it { should be_empty }
50
+ it { is_expected.to be_empty }
51
51
  end
52
52
 
53
53
  context "when joining tables that are also geoloacted" do
@@ -85,22 +85,22 @@ describe "ActiveRecord::Base.act_as_geolocated" do
85
85
  end
86
86
 
87
87
  context "when query with null data" do
88
- it { should == [] }
88
+ it { is_expected.to eq [] }
89
89
  end
90
90
 
91
91
  context "when query for the exact same point with radius 0" do
92
92
  let(:test_data) { { lat: -30.0277041, lng: -51.2287346, radius: 0 } }
93
- it { should == [@place] }
93
+ it { is_expected.to eq [@place] }
94
94
  end
95
95
 
96
96
  context "when query for place within radius" do
97
97
  let(:test_data) { { radius: 4_000_000, lat: -27.5969039, lng: -48.5494544 } }
98
- it { should == [@place] }
98
+ it { is_expected.to eq [@place] }
99
99
  end
100
100
 
101
101
  context "when query for place outside the radius" do
102
102
  let(:test_data) { { radius: 1000, lat: -27.5969039, lng: -48.5494544 } }
103
- it { should == [] }
103
+ it { is_expected.to eq [] }
104
104
  end
105
105
 
106
106
  context "uses lat and long of through table" do
@@ -119,22 +119,22 @@ describe "ActiveRecord::Base.act_as_geolocated" do
119
119
  end
120
120
 
121
121
  context "when query with null data" do
122
- it { should == [] }
122
+ it { is_expected.to eq [] }
123
123
  end
124
124
 
125
125
  context "when query for the exact same point with radius 0" do
126
126
  let(:test_data) { { lat: -30.0277041, lng: -51.2287346, radius: 0 } }
127
- it { should == [@job] }
127
+ it { is_expected.to eq [@job] }
128
128
  end
129
129
 
130
130
  context "when query for place within radius" do
131
131
  let(:test_data) { { radius: 4_000_000, lat: -27.5969039, lng: -48.5494544 } }
132
- it { should == [@job] }
132
+ it { is_expected.to eq [@job] }
133
133
  end
134
134
 
135
135
  context "when query for place outside the radius" do
136
136
  let(:test_data) { { radius: 1000, lat: -27.5969039, lng: -48.5494544 } }
137
- it { should == [] }
137
+ it { is_expected.to eq [] }
138
138
  end
139
139
  end
140
140
  end
@@ -168,17 +168,17 @@ describe "ActiveRecord::Base.act_as_geolocated" do
168
168
  end
169
169
 
170
170
  let(:current_location) { { lat: 51.511214, lng: 0.119824 } } # London
171
- it { should == [@amsterdam_job, @berlin_job] }
171
+ it { is_expected.to eq [@amsterdam_job, @berlin_job] }
172
172
  end
173
173
 
174
174
  context "when sorting on distance" do
175
175
  let(:current_location) { { lat: 51.511214, lng: 0.119824 } } # London
176
- it { should == [@amsterdam, @berlin] }
176
+ it { is_expected.to eq [@amsterdam, @berlin] }
177
177
  end
178
178
 
179
179
  context "when sorting on distance from another location" do
180
180
  let(:current_location) { { lat: 52.229676, lng: 21.012229 } } # Warsaw
181
- it { should == [@berlin, @amsterdam] }
181
+ it { is_expected.to eq [@berlin, @amsterdam] }
182
182
  end
183
183
  end
184
184
 
@@ -199,7 +199,26 @@ describe "ActiveRecord::Base.act_as_geolocated" do
199
199
  end
200
200
  context "when selecting distance" do
201
201
  let(:current_location) { { lat: 52.229676, lng: 21.012229 } } # Warsaw
202
- it { should == ["Amsterdam", 1_095_013.87438311] }
202
+ it { is_expected.to eq ["Amsterdam", 1_095_013.87438311] }
203
+ end
204
+
205
+ context "through table" do
206
+
207
+ subject { Job.all.selecting_distance_from(current_location[:lat], current_location[:lng]).first }
208
+
209
+ before(:all) do
210
+ @event = Event.create!(lat: -30.0277041, lng: -51.2287346)
211
+ @job = Job.create!(event: @event)
212
+ end
213
+
214
+ after(:all) do
215
+ @event.destroy
216
+ @job.destroy
217
+ end
218
+
219
+ context "when selecting distance" do
220
+ it { is_expected.to respond_to :distance }
221
+ end
203
222
  end
204
223
  end
205
224
  end
@@ -1,7 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "rspec"
4
- require "rspec/autorun"
5
4
  require "activerecord-postgres-earthdistance"
6
5
  require "active_record"
7
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres-earthdistance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diogo Biazus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.11'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.11'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement