Skip to content

Commit

Permalink
Disabled validations where object contained a RGeo object.
Browse files Browse the repository at this point in the history
  • Loading branch information
TuckerJD committed Feb 26, 2014
1 parent afc2cd6 commit a02f032
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 27 deletions.
13 changes: 7 additions & 6 deletions app/models/geographic_area.rb
Expand Up @@ -20,13 +20,14 @@ class GeographicArea < ActiveRecord::Base
validates_presence_of :data_origin
validates_presence_of :name
validates :geographic_area_type, presence: true
#validates :level0, presence: true, unless: 'self.name == "Earth"'
#validates :level1, presence: true, allow_nil: true
#validates :level2, presence: true, allow_nil: true
#validates :parent, presence: true, unless: 'self.name == "Earth"'
#validates :tdwg_parent, presence: true, allow_nil: true
validates :level0, presence: true, unless: 'self.name == "Earth"'
validates :level1, presence: true, allow_nil: true
validates :level2, presence: true, allow_nil: true
validates :parent, presence: true, unless: 'self.name == "Earth"'
# TODO: still need to figure out why the validations of RGeo object associations fail. These xxx_geo_item entry are commented out for this reason.
#validates :ne_geo_item, presence: true, allow_nil: true
validates :gadm_geo_item, presence: true, allow_nil: true
#validates :gadm_geo_item, presence: true, allow_nil: true
validates :tdwg_parent, presence: true, allow_nil: true
#validates :tdwg_geo_item, presence: true, allow_nil: true

scope :descendants_of, -> (geographic_area) {where('(geographic_areas.lft >= ?) and (geographic_areas.lft <= ?) and (geographic_areas.id != ?)', geographic_area.lft, geographic_area.rgt, geographic_area.id ).order(:lft)}
Expand Down
2 changes: 0 additions & 2 deletions app/models/geographic_item.rb
Expand Up @@ -39,13 +39,11 @@ def geo_object
end

def contains?(item)
#item.object.within?(self.object)
self.geo_object.contains?(item.geo_object)
#true
end

def within?(item)
#self.object.contains?(item.object)
self.geo_object.within?(item.geo_object)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/georeference.rb
Expand Up @@ -62,7 +62,7 @@ def proper_data_is_provided
# errors.add(:georef, 'ID must be from item of class Geographic_Item.') # THis isn't necessary, we'll have an index on the db
# when CollectingEvent.find(collecting_event_id) == nil
# errors.add(:georef, 'ID must be from item of class CollectingEvent.')
# when GeographicItem.find(error_geographic_item_id).object.geometry_type.type_name != 'Polygon'
# when GeographicItem.find(error_geographic_item_id).geo_object.geometry_type.type_name != 'Polygon'
# errors.add(:georef, 'ID must be from item of class Geographic_Item of type \'POLYGON\'.')
# when GeoreferenceHash[*arr]Type.find(type).to_s != 'Georeference::GeoreferenceType'
# errors.add(:georef, 'type must be of class Georeference::GeoreferenceType.')
Expand Down
7 changes: 5 additions & 2 deletions spec/factories/geographic_area_factory.rb
Expand Up @@ -8,6 +8,7 @@
FactoryGirl.build(:earth_geographic_area)
end
}
tdwg_parent { parent }
end

trait :parent_country do
Expand All @@ -18,6 +19,7 @@
FactoryGirl.build(:level0_geographic_area)
end
}
tdwg_parent { parent }
level0 { parent }
end

Expand All @@ -30,6 +32,7 @@
FactoryGirl.build(:level1_geographic_area)
end
}
tdwg_parent { parent }
level1 { parent }
end

Expand All @@ -48,8 +51,8 @@

factory :level2_geographic_area do
name 'Champaign'
parent_state
association :geographic_area_type, factory: :county_geographic_area_type
parent_state
association :geographic_area_type, factory: :county_geographic_area_type
after(:build) {|o| o.level2 = o}
end

Expand Down
2 changes: 2 additions & 0 deletions spec/factories/geographic_area_type_factory.rb
Expand Up @@ -3,9 +3,11 @@
FactoryGirl.define do

factory :geographic_area_type, traits: [:creator_and_updater] do

factory :valid_geographic_area_type do
name 'AnyPlace'
end

factory :planet_geographic_area_type do
name 'Planet'
end
Expand Down
31 changes: 17 additions & 14 deletions spec/models/geographic_area_spec.rb
Expand Up @@ -40,10 +40,10 @@

context 'associations' do
context 'belongs_to' do
specify "parent" do
specify 'parent' do
expect(geographic_area).to respond_to(:parent)
end
specify "tdwg_parent" do
specify 'tdwg_parent' do
expect(geographic_area).to respond_to(:tdwg_parent)
end
specify 'level0' do
Expand Down Expand Up @@ -93,6 +93,12 @@
expect(@champaign.parent.parent.parent.name).to eq('Earth')
end

specify 'TDWG parent string' do
expect(@champaign.tdwg_parent.name).to eq('Illinois')
expect(@champaign.parent.tdwg_parent.name).to eq('United States')
expect(@champaign.parent.parent.tdwg_parent.name).to eq('Earth')
end

specify 'ancestors' do
expect(@champaign.ancestors).to eq([@champaign.root, @champaign.parent.parent, @champaign.parent])
end
Expand All @@ -114,7 +120,7 @@
}

specify 'should be able to find a country by ISO_A3' do
expect(GeographicArea.where(:iso_3166_a3 => 'USA').first.name).to eq("United States")
expect(GeographicArea.where(:iso_3166_a3 => 'USA').first.name).to eq('United States')
end

context 'scopes/AREL' do
Expand Down Expand Up @@ -156,8 +162,7 @@

context 'interaction with geographic_items' do
before(:each) {
@geographic_area = FactoryGirl.build(:valid_geographic_area)
#@champaign = FactoryGirl.create(:level2_geographic_area)
@geographic_area = FactoryGirl.build(:level2_geographic_area)
listK = GEO_FACTORY.line_string([GEO_FACTORY.point(-33, -11),
GEO_FACTORY.point(-33, -23),
GEO_FACTORY.point(-21, -23),
Expand All @@ -170,22 +175,20 @@

specify 'saving GADM Shape' do
expect(@geographic_area.gadm_geo_item = @gi).to be_true

#@champaign.gadm_geo_item_id = @gi.id
@geographic_area.save!
expect(@geographic_area.save).to be_true

end

specify 'saving NaturalEarth Shape' do
@champaign.ne_geo_item = @gi
@champaign.save

expect(@geographic_area.ne_geo_item = @gi).to be_true
expect(@geographic_area.save).to be_true
@geographic_area
end

specify 'saving TDWG Shape' do
@champaign.tdwg_geo_item = @gi
@champaign.save

expect(@geographic_area.tdwg_geo_item = @gi).to be_true
expect(@geographic_area.save).to be_true
@geographic_area
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/geographic_item_spec.rb
Expand Up @@ -178,7 +178,7 @@
end

context 'That GeographicItems provide certain methods.' do
specify 'self.object returns stored data' do
specify 'self.geo_object returns stored data' do
p1 = GEO_FACTORY.point(-88.241413, 40.091655, 757)
geographic_item.point = p1
geographic_item.save
Expand Down
2 changes: 1 addition & 1 deletion spec/models/georeference_spec.rb
Expand Up @@ -59,7 +59,7 @@
end
end

context 'the GeographicItem.object.to_a returns a properly formed array' do
context 'the GeographicItem.geo_object.to_a returns a properly formed array' do
specify 'for point' do

geo_locate = Georeference::GeoLocate.new(request: {country: 'USA', locality: 'Urbana', state: 'IL', doPoly: 'true'})
Expand Down

0 comments on commit a02f032

Please sign in to comment.