muve 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/muve/model.rb +11 -11
- data/lib/muve/version.rb +1 -1
- data/spec/location_spec.rb +21 -41
- data/spec/model_spec.rb +13 -5
- data/spec/movement_spec.rb +22 -19
- data/spec/traveller_spec.rb +7 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83efb234b5e0adc0d47b9d3d6263e03068a35631
|
4
|
+
data.tar.gz: 45802b059dcb15e55f077e6530df7268e21c3e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbcbd69dd00b52e288a46d6c0d61db502f9e655bb6e2437aea3ac799c4863ee2cb86ef1b029a8161697d29f81147d0746aa12b542b0c2cf0a9c4d2a40aed96d
|
7
|
+
data.tar.gz: b8717958986af1366ede7c2e22676c0d6aa8bd92fd94a7c89c76c99c10369775247b7bbe0474e7cfa604c714624d470e96b29ec6b0776ca526bc6fe5eabbf992
|
data/lib/muve/model.rb
CHANGED
@@ -58,7 +58,7 @@ module Muve
|
|
58
58
|
|
59
59
|
# Destroy a resource
|
60
60
|
def destroy
|
61
|
-
if adaptor.delete(container, id) == true
|
61
|
+
if adaptor.delete(self.class.container, id) == true
|
62
62
|
@destroyed = true
|
63
63
|
end
|
64
64
|
end
|
@@ -107,7 +107,7 @@ module Muve
|
|
107
107
|
|
108
108
|
details.each do |attr, value|
|
109
109
|
next if invalid_attributes.include? attr.to_s
|
110
|
-
self.public_send "#{attr}=", value
|
110
|
+
self.public_send "#{attr}=", value if fields.include? attr.to_sym
|
111
111
|
end
|
112
112
|
|
113
113
|
@new_record = false if details.key? :id
|
@@ -121,32 +121,32 @@ module Muve
|
|
121
121
|
# NOTE: not sure we need this
|
122
122
|
def attributes
|
123
123
|
data = {}
|
124
|
-
fields.
|
124
|
+
fields.select{ |k| k != invalid_attributes }.each { |k|
|
125
|
+
data[k.to_sym] = self.public_send(k)
|
126
|
+
}
|
125
127
|
data
|
126
128
|
end
|
127
129
|
|
130
|
+
def fields
|
131
|
+
[]
|
132
|
+
end
|
133
|
+
|
128
134
|
# Creates the record and performs the necessary housekeeping (e.g.: setting
|
129
135
|
# the new id and un-marking the new_record?
|
130
136
|
def create(attr)
|
131
|
-
@id = adaptor.create(container, attr)
|
137
|
+
@id = adaptor.create(self.class.container, attr)
|
132
138
|
@new_record = false
|
133
139
|
end
|
134
140
|
|
135
141
|
# TODO: Update the record and return the number of modified rows
|
136
142
|
def update(attr)
|
137
|
-
adaptor.update(container, id, attr)
|
143
|
+
adaptor.update(self.class.container, id, attr)
|
138
144
|
end
|
139
145
|
|
140
146
|
def adaptor
|
141
147
|
self.class.adaptor
|
142
148
|
end
|
143
149
|
|
144
|
-
def container
|
145
|
-
end
|
146
|
-
|
147
|
-
def details
|
148
|
-
end
|
149
|
-
|
150
150
|
# Class methods exposed to all Muve models
|
151
151
|
module ClassMethods
|
152
152
|
# Configure the adaptor to take care of handling persistence for this
|
data/lib/muve/version.rb
CHANGED
data/spec/location_spec.rb
CHANGED
@@ -1,51 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Muve::Location do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
it
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'sets the longitude through its aliases' do
|
24
|
-
location = Muve::Location.new(@lat, @lng)
|
25
|
-
|
26
|
-
longitude = Faker::Geolocation.lng
|
27
|
-
location.lng = longitude
|
28
|
-
expect(location.longitude).to eq(longitude)
|
29
|
-
|
30
|
-
longitude = Faker::Geolocation.lng
|
31
|
-
location.long = longitude
|
32
|
-
expect(location.longitude).to eq(longitude)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'sets the latitude through its aliases' do
|
36
|
-
location = Muve::Location.new(@lat, @lng)
|
37
|
-
latitude = Faker::Geolocation.lat
|
38
|
-
location.lat = latitude
|
39
|
-
expect(location.latitude).to eq(latitude)
|
40
|
-
end
|
4
|
+
let(:latitude) { Faker::Geolocation.lat }
|
5
|
+
let(:longitude) { Faker::Geolocation.lng }
|
6
|
+
|
7
|
+
subject { Muve::Location.new(latitude, longitude) }
|
8
|
+
it { expect(subject.latitude).to eq(latitude) }
|
9
|
+
it { expect(subject.longitude).to eq(longitude) }
|
10
|
+
it { expect(subject.lat).to eq(latitude) }
|
11
|
+
it { expect(subject.long).to eq(longitude) }
|
12
|
+
it { expect(subject.lng).to eq(longitude) }
|
13
|
+
|
14
|
+
let(:new_latitude) { Faker::Geolocation.lat }
|
15
|
+
let(:new_longitude) { Faker::Geolocation.lng }
|
16
|
+
it { expect { subject.latitude = new_latitude }.to change{subject.latitude}.to(new_latitude) }
|
17
|
+
it { expect { subject.lat = new_latitude }.to change{subject.latitude}.to(new_latitude) }
|
18
|
+
it { expect { subject.longitude = new_longitude }.to change{subject.longitude}.to(new_longitude) }
|
19
|
+
it { expect { subject.long = new_longitude }.to change{subject.longitude}.to(new_longitude) }
|
20
|
+
it { expect { subject.lng = new_longitude }.to change{subject.longitude}.to(new_longitude) }
|
41
21
|
|
42
22
|
it 'is invalid when latitude exceeds bounds' do
|
43
|
-
expect(Muve::Location.new(-91,
|
44
|
-
expect(Muve::Location.new( 91,
|
23
|
+
expect(Muve::Location.new(-91, longitude)).to be_invalid
|
24
|
+
expect(Muve::Location.new( 91, longitude)).to be_invalid
|
45
25
|
end
|
46
26
|
|
47
27
|
it 'is invalid when longitude exceeds bounds' do
|
48
|
-
expect(Muve::Location.new(
|
49
|
-
expect(Muve::Location.new(
|
28
|
+
expect(Muve::Location.new(latitude, -181)).to be_invalid
|
29
|
+
expect(Muve::Location.new(latitude, 181)).to be_invalid
|
50
30
|
end
|
51
31
|
end
|
data/spec/model_spec.rb
CHANGED
@@ -8,6 +8,7 @@ describe 'Model' do
|
|
8
8
|
'resources'
|
9
9
|
end
|
10
10
|
|
11
|
+
private
|
11
12
|
def fields
|
12
13
|
[:name, :version]
|
13
14
|
end
|
@@ -21,6 +22,7 @@ describe 'Model' do
|
|
21
22
|
'other_resources'
|
22
23
|
end
|
23
24
|
|
25
|
+
private
|
24
26
|
def fields
|
25
27
|
[:name, :version, :description]
|
26
28
|
end
|
@@ -50,6 +52,7 @@ describe 'Model' do
|
|
50
52
|
|
51
53
|
it 'knows the identifier of its repository' do
|
52
54
|
expect(Resource).to respond_to(:container)
|
55
|
+
expect(Resource.container).to eq('resources')
|
53
56
|
end
|
54
57
|
|
55
58
|
it 'allows the setting of the adaptor' do
|
@@ -222,11 +225,16 @@ describe 'Model' do
|
|
222
225
|
it 'is not a new record' do
|
223
226
|
expect { @res.destroy }.to change{ @res.destroyed? }.to(true)
|
224
227
|
end
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
228
|
+
|
229
|
+
it 'calls the delete handler upon remove' do
|
230
|
+
expect(GenericAdaptor).to receive(:delete).once
|
231
|
+
@res.destroy
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'calls the delete handler with the proper details' do
|
235
|
+
expect(GenericAdaptor).to receive(:delete).with('other_resources', @id).once
|
236
|
+
@res.destroy
|
237
|
+
end
|
230
238
|
end
|
231
239
|
|
232
240
|
it 'calls the update handler upon save on a resource with an id' do
|
data/spec/movement_spec.rb
CHANGED
@@ -1,37 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Muve::Movement do
|
4
|
-
|
5
|
-
expect(Muve::Movement.new).to respond_to(:traveller)
|
6
|
-
expect(Muve::Movement.new).to respond_to(:location)
|
7
|
-
expect(Muve::Movement.new).to respond_to(:time)
|
8
|
-
end
|
4
|
+
subject { Muve::Movement.new }
|
9
5
|
|
10
|
-
it
|
11
|
-
|
12
|
-
|
6
|
+
it { is_expected.to respond_to(:traveller) }
|
7
|
+
it { is_expected.to respond_to(:location) }
|
8
|
+
it { is_expected.to respond_to(:time) }
|
13
9
|
|
14
|
-
|
15
|
-
|
10
|
+
shared_examples "a invalid resource" do
|
11
|
+
it { is_expected.to be_invalid }
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
context "without traveller" do
|
15
|
+
subject { build(Muve::Movement, traveller: nil) }
|
16
|
+
it_behaves_like "a invalid resource"
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
context "without location" do
|
20
|
+
subject { build(Muve::Movement, location: nil) }
|
21
|
+
it_behaves_like "a invalid resource"
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
context "with explicitely set time" do
|
25
|
+
let(:time_of_interest) { Time.now - rand(500000) }
|
26
|
+
subject { build(Muve::Movement, time: time_of_interest) }
|
27
|
+
it { expect(subject.time).to eq(time_of_interest) }
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
context "new movement" do
|
31
|
+
subject { build(Muve::Movement) }
|
32
|
+
it { expect(subject.time).to be_within(2).of(Time.now) }
|
33
|
+
it { is_expected.to be_valid }
|
33
34
|
end
|
34
35
|
|
36
|
+
it { is_expected.to respond_to(:connection) }
|
37
|
+
|
35
38
|
it 'shares the connection among other models' do
|
36
39
|
connection = Object.new
|
37
40
|
Muve.init(connection)
|
data/spec/traveller_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Muve::Traveller do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
subject { Muve::Traveller.new }
|
5
|
+
|
6
|
+
it { is_expected.to respond_to(:id) }
|
7
|
+
it { is_expected.to be_invalid }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
context "linked to an existing traveller" do
|
10
|
+
subject { Muve::Traveller.new(SecureRandom.uuid) }
|
11
|
+
it { is_expected.to be_valid }
|
11
12
|
end
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Asabina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Basic helpers to be used with Muvement
|
14
14
|
email:
|