-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmoschus.rb
More file actions
160 lines (147 loc) · 3.95 KB
/
moschus.rb
File metadata and controls
160 lines (147 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
shared_context 'Moschus' do
{
bhutan: 'BT',
india: 'IN',
nepal: 'NP',
china: 'CH'
}.each do |name, iso_code|
define_method(name) do
name = name.to_s
var = instance_variable_get("@#{name}")
return var if var
country = create(
:geo_entity,
geo_entity_type: country_geo_entity_type,
name: name.capitalize,
iso_code2: iso_code
)
instance_variable_set("@#{name}", country)
end
end
before(:all) do
@order = create_cites_eu_order(
taxon_name: create(:taxon_name, scientific_name: 'Artiodactyla'),
parent: cites_eu_mammalia
)
@family = create_cites_eu_family(
taxon_name: create(:taxon_name, scientific_name: 'Moschidae'),
parent: @order
)
@genus = create_cites_eu_genus(
taxon_name: create(:taxon_name, scientific_name: 'Moschus'),
parent: @family
)
@species1 = create_cites_eu_species(
taxon_name: create(:taxon_name, scientific_name: 'leucogaster'),
parent: @genus
)
@species2 = create_cites_eu_species(
taxon_name: create(:taxon_name, scientific_name: 'moschiferus'),
parent: @genus
)
@subspecies = create_cites_eu_subspecies(
taxon_name: create(:taxon_name, scientific_name: 'moschiferus'),
parent: @species2
)
[ bhutan, india, nepal ].each do |country|
create(
:distribution,
taxon_concept: @species1,
geo_entity: country
)
end
[ @species2, @subspecies ].each do |taxon|
create(
:distribution,
taxon_concept: taxon,
geo_entity: china
)
end
create_cites_I_addition(
taxon_concept: @subspecies,
effective_at: '1975-07-01',
is_current: false
)
create_cites_II_addition(
taxon_concept: @genus,
effective_at: '1979-06-28',
is_current: false
)
lc = create_cites_I_addition(
taxon_concept: @species2,
effective_at: '1979-06-28',
is_current: false
)
create(
:listing_distribution,
geo_entity: china,
listing_change: lc,
is_party: false
)
create_cites_II_addition(
taxon_concept: @species2,
effective_at: '1979-06-28',
inclusion_taxon_concept_id: @genus.id,
is_current: false
)
create_cites_I_addition(
taxon_concept: @subspecies,
effective_at: '1979-06-28',
inclusion_taxon_concept_id: @species2.id,
is_current: true
)
cites_lc1 = create_cites_I_addition(
taxon_concept: @genus,
effective_at: '1983-07-29',
is_current: true
)
[ bhutan, india, nepal ].each do |country|
create(
:listing_distribution,
geo_entity: country,
listing_change: cites_lc1,
is_party: false
)
end
cites_lc2 = create_cites_II_addition(
taxon_concept: @genus,
effective_at: '1983-07-29',
is_current: true
)
cites_lc2_exc = create_cites_II_exception(
taxon_concept: @genus,
effective_at: '1983-07-29',
parent_id: cites_lc2.id
)
[ bhutan, india, nepal ].each do |country|
create(
:listing_distribution,
geo_entity: country,
listing_change: cites_lc2_exc,
is_party: false
)
end
cites_lc3 = create_cites_I_deletion(
taxon_concept: @species2,
effective_at: '1983-07-29',
is_current: false
)
create(
:listing_distribution,
geo_entity: china,
listing_change: cites_lc3,
is_party: false
)
SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings
self.instance_variables.each do |t|
# Skip old sapi context let statements,
# which are now instance variables starting with _
next if t.to_s.include?('@_')
var = self.instance_variable_get(t)
if var.kind_of? TaxonConcept
self.instance_variable_set(t, MTaxonConcept.find(var.id))
self.instance_variable_get(t).reload
end
end
end
end