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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4f36cfe27c1f7f7ed994364976bc49c15c7e677
4
- data.tar.gz: 3115d65888228e346e5d079367aa18867ee19b78
3
+ metadata.gz: 83efb234b5e0adc0d47b9d3d6263e03068a35631
4
+ data.tar.gz: 45802b059dcb15e55f077e6530df7268e21c3e08
5
5
  SHA512:
6
- metadata.gz: cb4d0e4eddf27e19af900241cfc184d003b2ec84ed833d12bdfa7fe91bfd7f3623ab4f196d12b883b69e868584ec390eced54711f2fbddb64d4726702d0b3b8f
7
- data.tar.gz: 6ad01f4ad7c17805edb36165bfe8b223bb430ef6c1baf2d0421e6269acfa9e974193a3db5256b812244acde4f0f221b99da6bc4ef1d6eb36d155a4bbf7790e63
6
+ metadata.gz: 5fbcbd69dd00b52e288a46d6c0d61db502f9e655bb6e2437aea3ac799c4863ee2cb86ef1b029a8161697d29f81147d0746aa12b542b0c2cf0a9c4d2a40aed96d
7
+ data.tar.gz: b8717958986af1366ede7c2e22676c0d6aa8bd92fd94a7c89c76c99c10369775247b7bbe0474e7cfa604c714624d470e96b29ec6b0776ca526bc6fe5eabbf992
@@ -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.each { |k| data[k.to_sym] = self.public_send(k) }
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
@@ -1,3 +1,3 @@
1
1
  module Muve
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,51 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Muve::Location do
4
- before do
5
- @lat, @lng = Faker::Geolocation.lat, Faker::Geolocation.lng
6
- end
7
-
8
- it 'knows its latitude and longitude' do
9
- expect(Muve::Location.new(@lat, @lng).latitude).to eq(@lat)
10
- expect(Muve::Location.new(@lat, @lng).longitude).to eq(@lng)
11
- end
12
-
13
- it 'gets the longitude through its aliases' do
14
- location = Muve::Location.new(@lat, @lng)
15
- expect(location.lng).to eq(@lng)
16
- end
17
-
18
- it 'gets the latitude through aliases' do
19
- location = Muve::Location.new(@lat, @lng)
20
- expect(location.lat).to eq(@lat)
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, @lng)).to be_invalid
44
- expect(Muve::Location.new( 91, @lng)).to be_invalid
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(@lat, -181)).to be_invalid
49
- expect(Muve::Location.new(@lat, 181)).to be_invalid
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
@@ -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
- end
226
-
227
- it 'calls the delete handler upon remove' do
228
- expect(GenericAdaptor).to receive(:delete).once
229
- @res.destroy
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
@@ -1,37 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Muve::Movement do
4
- it 'knows a location and a traveller and possibly a time' do
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 'is invalid without a traveller' do
11
- expect(build(Muve::Movement, traveller: nil)).to be_invalid
12
- end
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
- it 'is invalid without a location' do
15
- expect(build(Muve::Movement, location: nil)).to be_invalid
10
+ shared_examples "a invalid resource" do
11
+ it { is_expected.to be_invalid }
16
12
  end
17
13
 
18
- it 'assumes the current time unless specified' do
19
- expect(build(Muve::Movement).time).to be_within(2).of(Time.now)
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
- it 'accepts keeps the specified' do
23
- last_time = Time.now - rand(500000)
24
- expect(build(Muve::Movement, time: last_time).time).to eq(last_time)
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
- it 'is valid with a traveller and location' do
28
- expect(build(Muve::Movement)).to be_valid
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
- it 'knows a connection' do
32
- expect(Muve::Movement.new).to respond_to(:connection)
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)
@@ -1,12 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Muve::Traveller do
4
- it 'has an id' do
5
- expect(Muve::Traveller.new).to respond_to(:id)
6
- end
4
+ subject { Muve::Traveller.new }
5
+
6
+ it { is_expected.to respond_to(:id) }
7
+ it { is_expected.to be_invalid }
7
8
 
8
- it 'is invalid without an id' do
9
- expect(Muve::Traveller.new).to be_invalid
10
- expect(Muve::Traveller.new(SecureRandom.uuid)).to be_valid
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.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-07-30 00:00:00.000000000 Z
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: