ppe_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ppe_api/abstract_pa.rb +5 -0
- data/lib/ppe_api/alternative_name.rb +5 -0
- data/lib/ppe_api/apa_relation.rb +5 -0
- data/lib/ppe_api/country.rb +29 -0
- data/lib/ppe_api/dataset.rb +23 -0
- data/lib/ppe_api/designation.rb +28 -0
- data/lib/ppe_api/iucn_category.rb +29 -0
- data/lib/ppe_api/jurisdiction.rb +15 -0
- data/lib/ppe_api/language.rb +15 -0
- data/lib/ppe_api/legal_status.rb +29 -0
- data/lib/ppe_api/point_geom.rb +15 -0
- data/lib/ppe_api/polygon_geom.rb +15 -0
- data/lib/ppe_api/protected_area.rb +108 -0
- data/lib/ppe_api/region.rb +16 -0
- data/lib/ppe_api/search.rb +5 -0
- data/lib/ppe_api/site.rb +31 -0
- data/lib/ppe_api/user.rb +40 -0
- data/lib/ppe_api.rb +17 -0
- data/test/factories.rb +106 -0
- data/test/test_helper.rb +62 -0
- metadata +83 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Country
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :iso, String
|
9
|
+
element :iso_3, String, :tag=>'iso-3'
|
10
|
+
element :the_geom, String, :tag=>'the-geom'
|
11
|
+
element :numareas, Integer
|
12
|
+
element :name, String
|
13
|
+
has_one :region, Region
|
14
|
+
|
15
|
+
def geometry_json
|
16
|
+
JSON.parse(@the_geom)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_by_iso(iso)
|
20
|
+
res, data = ::DR::Config.http.get("/api/country/iso/#{iso}")
|
21
|
+
Country.parse(data) unless data.nil? || data.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xml(options={})
|
25
|
+
self.as_json.to_xml({:root => "country"}.merge(options))
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Dataset
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :author, String
|
9
|
+
element :year, Integer
|
10
|
+
element :citation, String
|
11
|
+
has_one :user, User
|
12
|
+
|
13
|
+
def ==(data)
|
14
|
+
return false if data.nil?
|
15
|
+
data.author==self.author && data.year = self.year && data.citation==self.citation && self.user.id == data.user.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_xml(options={})
|
19
|
+
self.as_json.to_xml({:root => "dataset"}.merge(options))
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Designation
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :name, String
|
8
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
9
|
+
has_one :jurisdiction, Jurisdiction
|
10
|
+
|
11
|
+
def self.get_by_name(name)
|
12
|
+
res, data = ::DR::Config.http.post("/api/designation/name", "name=#{name}")
|
13
|
+
return Designation.parse(data) unless data.nil? || data.empty?
|
14
|
+
return nil
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(des)
|
19
|
+
return false if des.nil?
|
20
|
+
des.name==self.name
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml(options={})
|
24
|
+
self.as_json.to_xml({:root => "designation"}.merge(options))
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class IucnCategory
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
tag 'iucn-category'
|
6
|
+
element :id, Integer
|
7
|
+
element :created_at, DateTime, :tag=>'created-at'
|
8
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
9
|
+
element :name, String
|
10
|
+
element :value, Integer
|
11
|
+
|
12
|
+
def self.get_by_name(name)
|
13
|
+
res, data = ::DR::Config.http.get("/api/iucn_category/name/#{name}")
|
14
|
+
return IucnCategory.parse(data) unless data.nil? || data.empty?
|
15
|
+
return nil
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(iucn)
|
20
|
+
return false if iucn.nil?
|
21
|
+
iucn.name==self.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xml(options={})
|
25
|
+
self.as_json.to_xml({:root => "iucn-category"}.merge(options))
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Jurisdiction
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :name, String
|
8
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
9
|
+
|
10
|
+
def to_xml(options={})
|
11
|
+
self.as_json.to_xml({:root => "jurisdiction"}.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Language
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :name, String
|
9
|
+
|
10
|
+
def to_xml(options={})
|
11
|
+
self.as_json.to_xml({:root => "language"}.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class LegalStatus
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
tag 'legal-status'
|
6
|
+
element :id, Integer
|
7
|
+
element :created_at, DateTime, :tag=>'created-at'
|
8
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
9
|
+
element :name, String
|
10
|
+
|
11
|
+
def self.get_by_name(name)
|
12
|
+
unless name.nil? || name.empty?
|
13
|
+
res, data = ::DR::Config.http.post("/api/legal_status/name", "name=#{name}")
|
14
|
+
return LegalStatus.parse(data) unless data.nil? || data.empty?
|
15
|
+
end
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(legal_status)
|
20
|
+
return false if legal_status.nil?
|
21
|
+
legal_status.name==self.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xml(options={})
|
25
|
+
self.as_json.to_xml({:root => "legal-status"}.merge(options))
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class PointGeom
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :the_geom, String
|
9
|
+
|
10
|
+
def geometry_json
|
11
|
+
JSON.parse(@the_geom)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class PolygonGeom
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :the_geom, String
|
9
|
+
|
10
|
+
def geometry_json
|
11
|
+
JSON.parse(@the_geom)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class ProtectedArea
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
@@simple_atts = ["english_name", "id", "local_name", "state", "status_date", "total_area", "total_area_marine", "valid_from", "legally_reclassified", "legally_reduced", "legally_extended"]
|
6
|
+
@@xml_atts = ["english_name", "id", "local_name", "status_date", "total_area", "total_area_marine", "legally_reclassified", "legally_reduced", "legally_extended", "geometry_as_hex_ewkb", "countries", "dataset", "iucn_category", "designation"]
|
7
|
+
|
8
|
+
tag 'protected-area'
|
9
|
+
element :id, Integer
|
10
|
+
element :created_at, DateTime, :tag=>'created-at'
|
11
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
12
|
+
element :state, String
|
13
|
+
element :english_name, String, :tag=>"english-name"
|
14
|
+
element :local_name, String, :tag=>"local-name"
|
15
|
+
element :total_area, Float, :tag=>"total-area"
|
16
|
+
element :total_area_marine, Float, :tag=>"total-area-marine"
|
17
|
+
element :status_date, DateTime, :tag=>"status-date"
|
18
|
+
element :valid_from, DateTime, :tag=>"valid-from"
|
19
|
+
has_one :iucn_category, IucnCategory, :tag=>"iucn-category"
|
20
|
+
has_one :legal_status, LegalStatus, :tag=>"legal-status"
|
21
|
+
has_one :designation, Designation
|
22
|
+
element :legally_extended, Boolean, :tag=>"legally-extended"
|
23
|
+
element :legally_reduced, Boolean, :tag=>"legally-reduced"
|
24
|
+
element :legally_reclassified, Boolean, :tag=>"legally-reclassified"
|
25
|
+
element :geometry_as_hex_ewkb, String, :tag=>"geometry-as-hex-ewkb"
|
26
|
+
has_many :countries, Country
|
27
|
+
has_one :user, User
|
28
|
+
has_one :dataset, Dataset
|
29
|
+
has_one :site, Site
|
30
|
+
|
31
|
+
def countries_iso
|
32
|
+
countries.collect{|a| a.iso+", "}.to_s.chop.chop
|
33
|
+
end
|
34
|
+
|
35
|
+
def geometry
|
36
|
+
puts "in protected area looking at what i am #{self.inspect}"
|
37
|
+
@geometry = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(@geometry_as_hex_ewkb) if (!@geometry.nil? && !@geometry_as_hex_ewkb.nil?)
|
38
|
+
@geometry
|
39
|
+
end
|
40
|
+
|
41
|
+
def geometry_geo_json
|
42
|
+
unless (geometry.nil?)
|
43
|
+
if geometry.is_a? GeoRuby::SimpleFeatures::MultiPolygon
|
44
|
+
geo = TempGeometry.create(:polygon=>geometry)
|
45
|
+
else
|
46
|
+
geo = TempGeometry.create(:point=>geometry)
|
47
|
+
end
|
48
|
+
geo.save!
|
49
|
+
json = geo.get_json
|
50
|
+
geo.destroy
|
51
|
+
json
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_obj_attributes(attr)
|
57
|
+
if attr == "wdpa_code"
|
58
|
+
return self.site
|
59
|
+
elsif attr == "geometry"
|
60
|
+
return self.geometry_as_hex_ewkb
|
61
|
+
else
|
62
|
+
return self.send(attr)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#returns printable attributes
|
67
|
+
def get_nonnil_writable_attribute(attr)
|
68
|
+
if @@simple_atts.count(attr) > 0
|
69
|
+
return self.send(attr)
|
70
|
+
elsif attr == "iucn_category"
|
71
|
+
return iucn_category ? iucn_category.name : ""
|
72
|
+
elsif attr == "designation"
|
73
|
+
return designation ? designation.name : ""
|
74
|
+
elsif attr == "legal_status"
|
75
|
+
return legal_status ? legal_status.name : ""
|
76
|
+
elsif attr == "countries"
|
77
|
+
return countries.length > 0 ? countries.collect{|a| a.iso+", "}.to_s.chop.chop : ""
|
78
|
+
elsif attr == "citation"
|
79
|
+
return self.dataset.citation
|
80
|
+
elsif attr == "author"
|
81
|
+
return self.dataset.author
|
82
|
+
elsif attr == "wdpa_code"
|
83
|
+
return self.site.id
|
84
|
+
end
|
85
|
+
return ""
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def self.get_by_id(id, has_geom=true)
|
90
|
+
if id.to_i != 0
|
91
|
+
path = "/api/protected_area/#{id}"
|
92
|
+
path = path + "?has_geometry=true" if has_geom
|
93
|
+
res, data = ::DR::Config.http.get(path)
|
94
|
+
return ProtectedArea.parse(data) unless data.nil? || data.empty?
|
95
|
+
end
|
96
|
+
return nil
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def self.exists?(id)
|
101
|
+
!self.get_by_id(id).nil?
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_xml(options={})
|
105
|
+
self.as_json.to_xml({:root => "protected-area"}.merge(options))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Region
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :name, String
|
9
|
+
element :code, String
|
10
|
+
|
11
|
+
def to_xml(options={})
|
12
|
+
self.as_json.to_xml({:root => "region"}.merge(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/ppe_api/site.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class Site
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :abstract_pa_id, Integer
|
9
|
+
element :state, String
|
10
|
+
|
11
|
+
def self.get_by_id(id)
|
12
|
+
res, data = ::DR::Config.http.get("/api/site/#{id}")
|
13
|
+
return Site.parse(data) unless data.nil? || data.empty?
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.exists?(id)
|
18
|
+
return !self.get_by_id(id).nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(site)
|
22
|
+
return false if site.nil?
|
23
|
+
return self.id==site.id
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_xml(options={})
|
27
|
+
self.as_json.to_xml({:root => "site"}.merge(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/ppe_api/user.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module PPE_API
|
2
|
+
class User
|
3
|
+
include ::HappyMapper
|
4
|
+
|
5
|
+
element :id, Integer
|
6
|
+
element :created_at, DateTime, :tag=>'created-at'
|
7
|
+
element :updated_at, DateTime, :tag=>'updated-at'
|
8
|
+
element :title, String
|
9
|
+
element :first_name, String
|
10
|
+
element :last_name, String
|
11
|
+
element :organization, String
|
12
|
+
element :username, String
|
13
|
+
element :email, String
|
14
|
+
|
15
|
+
|
16
|
+
def exports
|
17
|
+
Export.find_all_by_user_id(id)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def completed_tasks
|
22
|
+
exports.inject(0) do |sum,ex|
|
23
|
+
if ex.task_status == DR::Config.import_state_map[:completed]
|
24
|
+
sum+=1
|
25
|
+
end
|
26
|
+
sum
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def imports
|
31
|
+
Import.find_all_by_user_id(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_xml(options={})
|
35
|
+
self.as_json.to_xml({:root => "user"}.merge(options))
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/ppe_api.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
require 'ppe_api/abstract_pa'
|
3
|
+
require 'ppe_api/alternative_name'
|
4
|
+
require 'ppe_api/apa_relation'
|
5
|
+
require 'ppe_api/country'
|
6
|
+
require 'ppe_api/dataset'
|
7
|
+
require 'ppe_api/designation'
|
8
|
+
require 'ppe_api/iucn_category'
|
9
|
+
require 'ppe_api/jurisdiction'
|
10
|
+
require 'ppe_api/language'
|
11
|
+
require 'ppe_api/legal_status'
|
12
|
+
require 'ppe_api/point_geom'
|
13
|
+
require 'ppe_api/protected_area'
|
14
|
+
require 'ppe_api/region'
|
15
|
+
require 'ppe_api/search'
|
16
|
+
require 'ppe_api/site'
|
17
|
+
require 'ppe_api/user'
|
data/test/factories.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
Factory.define :abstract_pa, :default_strategy => :build do |t|
|
2
|
+
end
|
3
|
+
|
4
|
+
Factory.define :designation, :default_strategy => :build do |t|
|
5
|
+
t.name "World Heritage Site"
|
6
|
+
end
|
7
|
+
|
8
|
+
Factory.define :iucn_category, :default_strategy => :build do |t|
|
9
|
+
t.name "Ia"
|
10
|
+
t.value 1
|
11
|
+
end
|
12
|
+
|
13
|
+
Factory.define :legal_status, :default_strategy => :build do |t|
|
14
|
+
t.name "created"
|
15
|
+
end
|
16
|
+
|
17
|
+
Factory.define :country, :default_strategy => :build do |t|
|
18
|
+
t.name "United Kingdom"
|
19
|
+
t.iso "GB"
|
20
|
+
t.iso_3 "GBR"
|
21
|
+
t.association :region
|
22
|
+
end
|
23
|
+
|
24
|
+
Factory.define :region, :default_strategy => :build do |t|
|
25
|
+
t.name "Europe"
|
26
|
+
t.code "EU"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
Factory.define :polygon_geom, :default_strategy => :build do |t|
|
33
|
+
t.the_geom MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]])], 4326)
|
34
|
+
end
|
35
|
+
|
36
|
+
Factory.define :point_geom, :default_strategy => :build do |t|
|
37
|
+
t.the_geom Point.from_coordinates([1,2], 4326)
|
38
|
+
end
|
39
|
+
|
40
|
+
Factory.define :dataset, :default_strategy => :build do |t|
|
41
|
+
t.citation "Some dataset name"
|
42
|
+
t.author "Galt, J. & Timmy, L."
|
43
|
+
t.association :user
|
44
|
+
end
|
45
|
+
|
46
|
+
Factory.define :user, :default_strategy => :build do |t|
|
47
|
+
t.title "Mr"
|
48
|
+
t.first_name "simon"
|
49
|
+
t.last_name "tokumine"
|
50
|
+
t.sequence(:username) {|n| "simon#{n}"}
|
51
|
+
t.sequence(:email) {|n| "simon#{n}@tokumine.com"}
|
52
|
+
t.password "secret"
|
53
|
+
t.password_confirmation "secret"
|
54
|
+
t.first_login_ip "88.96.173.198"
|
55
|
+
t.latitude 53.6167
|
56
|
+
t.longitude -2.15
|
57
|
+
t.association :country
|
58
|
+
end
|
59
|
+
|
60
|
+
Factory.define :species, :default_strategy => :build do |t|
|
61
|
+
t.name "elephant"
|
62
|
+
t.url "http://somwere.com"
|
63
|
+
t.association :site
|
64
|
+
end
|
65
|
+
|
66
|
+
Factory.define :point_of_interest, :default_strategy => :build do |t|
|
67
|
+
t.title "waterfall"
|
68
|
+
t.summary "nice waterfall"
|
69
|
+
t.url "http://www.google.com"
|
70
|
+
end
|
71
|
+
|
72
|
+
Factory.define :image, :default_strategy => :build do |u|
|
73
|
+
u.photo { ActionController::TestUploadedFile.new(File.join(RAILS_ROOT, 'test', 'resources', 'chewie.jpg')) }
|
74
|
+
end
|
75
|
+
|
76
|
+
Factory.define :image_han, :class => :image, :default_strategy => :build do |u|
|
77
|
+
u.photo { ActionController::TestUploadedFile.new(File.join(RAILS_ROOT, 'test', 'resources', 'han.jpg')) }
|
78
|
+
end
|
79
|
+
|
80
|
+
Factory.define :site, :default_strategy => :build do |t|
|
81
|
+
t.association :abstract_pa
|
82
|
+
end
|
83
|
+
|
84
|
+
Factory.define :protected_area, :default_strategy => :build do |t|
|
85
|
+
t.state "complete"
|
86
|
+
t.english_name "Yosemite"
|
87
|
+
t.local_name "Yosemite"
|
88
|
+
t.total_area 123123
|
89
|
+
t.total_area_marine 32432
|
90
|
+
t.status_date 10.years.ago
|
91
|
+
t.legally_extended true
|
92
|
+
t.legally_reduced false
|
93
|
+
t.legally_reclassified false
|
94
|
+
t.association :site
|
95
|
+
t.association :designation
|
96
|
+
t.association :iucn_category
|
97
|
+
t.association :legal_status
|
98
|
+
t.association :polygon_geom
|
99
|
+
t.association :point_geom
|
100
|
+
t.association :dataset
|
101
|
+
t.association :user
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
39
|
+
|
40
|
+
class PGconn
|
41
|
+
def PGconn.quote_ident(name)
|
42
|
+
%("#{name}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Test::Unit::TestCase
|
47
|
+
def self.should_have_attached_file(attachment)
|
48
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
49
|
+
|
50
|
+
context "To support a paperclip attachment named #{attachment}, #{klass}" do
|
51
|
+
should_have_db_column("#{attachment}_file_name", :type => :string)
|
52
|
+
should_have_db_column("#{attachment}_content_type", :type => :string)
|
53
|
+
should_have_db_column("#{attachment}_file_size", :type => :integer)
|
54
|
+
end
|
55
|
+
|
56
|
+
should "have a paperclip attachment named ##{attachment}" do
|
57
|
+
assert klass.new.respond_to?(attachment.to_sym),
|
58
|
+
"@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
|
59
|
+
assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ppe_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Liz Schwartz
|
8
|
+
autorequire: data_rec_gem
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-19 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: happymapper
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: ""
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/ppe_api/abstract_pa.rb
|
35
|
+
- lib/ppe_api/alternative_name.rb
|
36
|
+
- lib/ppe_api/apa_relation.rb
|
37
|
+
- lib/ppe_api/country.rb
|
38
|
+
- lib/ppe_api/dataset.rb
|
39
|
+
- lib/ppe_api/designation.rb
|
40
|
+
- lib/ppe_api/iucn_category.rb
|
41
|
+
- lib/ppe_api/jurisdiction.rb
|
42
|
+
- lib/ppe_api/language.rb
|
43
|
+
- lib/ppe_api/legal_status.rb
|
44
|
+
- lib/ppe_api/point_geom.rb
|
45
|
+
- lib/ppe_api/polygon_geom.rb
|
46
|
+
- lib/ppe_api/protected_area.rb
|
47
|
+
- lib/ppe_api/region.rb
|
48
|
+
- lib/ppe_api/search.rb
|
49
|
+
- lib/ppe_api/site.rb
|
50
|
+
- lib/ppe_api/user.rb
|
51
|
+
- lib/ppe_api.rb
|
52
|
+
- test/factories.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage:
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: A package for reading ppe api requests
|
82
|
+
test_files: []
|
83
|
+
|