Skip to content

Commit

Permalink
added specs for Company#query_for_lonlat
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Apr 29, 2012
1 parent 8078ebb commit d09cdbd
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 11 deletions.
18 changes: 9 additions & 9 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ class Company < ActiveRecord::Base
before_save :query_for_lonlat
before_create :insert_private_slug
after_create :notify_company



QUERY_API = GoogleMaps


def address
"#{self.street}, #{self.zip} #{self.city}"
end

def query_for_lonlat
lonlat = QUERY_API.query_for_lonlat(self.address, options = {})

self.lon = lonlat.first
self.lat = lonlat.second
self.not_found = false
Expand All @@ -26,15 +29,12 @@ def query_for_lonlat
true
end

def address
"#{self.street}, #{self.zip} #{self.city}"
end

def insert_private_slug
self.private_slug = SecureRandom.hex(12)
end

def notify_company

end

end
40 changes: 40 additions & 0 deletions spec/cassettes/company-query-for-lonlat-not-found.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions spec/cassettes/company-query-for-lonlat-success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions spec/models/company_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,31 @@
it { should have_many :taggings }
it { should have_many(:tags).through(:taggings) }

describe "private slug" do
describe "when saved" do
context "and found via geo service" do
use_vcr_cassette "company-query-for-lonlat-success"

subject { Factory(:company, :lat => nil, :lon => nil, :not_found => nil) }

its(:lat) { should_not be_nil }
its(:lon) { should_not be_nil }
its(:not_found) { should be_false }
end

context "and not found via geo service" do
use_vcr_cassette "company-query-for-lonlat-not-found"

subject { Factory(:company, :city => "RockHeaven", :lat => nil, :lon => nil, :not_found => nil) }

its(:lat) { should be_nil }
its(:lon) { should be_nil }
its(:not_found) { should be_true }
end
end

describe "#insert_private_slug" do
subject { Factory(:company, :private_slug => nil) }
its(:private_slug) { should_not be_nil }

end

end

0 comments on commit d09cdbd

Please sign in to comment.