diff options
| author | mo khan <mo@mokhan.ca> | 2016-04-29 22:42:27 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-04-29 22:42:27 -0600 |
| commit | ea86df665164004eb742e983e0d65caecaebd085 (patch) | |
| tree | e3b5c0b79157be104dc416e1f3e5595aa246f4dd /spec | |
| parent | 808e0e0210e0f34907b753ae21441c0c1bb52328 (diff) | |
assign lat/long before save.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/gym_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/models/gym_spec.rb b/spec/models/gym_spec.rb new file mode 100644 index 0000000..29f2f82 --- /dev/null +++ b/spec/models/gym_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +describe Gym do + subject { build(:gym) } + + describe "#validations" do + it 'validates the presence of name' do + subject.name = nil + expect(subject).to be_invalid + expect(subject.errors[:name]).to be_present + end + end + + describe "#before_save" do + let(:latitude) { rand(90.0) } + let(:longitude) { rand(180.0) } + + it 'updates the latitude/logitude' do + allow(Location).to receive(:from).and_return([latitude, longitude]) + subject.assign_attributes( + address: '123 street sw', + city: 'edmonton', + state: 'alberta', + country: 'canada', + ) + subject.save! + subject.reload + + expect(subject.latitude).to eql(latitude) + expect(subject.longitude).to eql(longitude) + end + end +end |
