mundo-pepino 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +32 -0
- data/README.markdown +12 -1
- data/README_es.markdown +126 -60
- data/lib/mundo_pepino/en_US/definitions.rb +8 -0
- data/lib/mundo_pepino/en_US/mappings.rb +1 -3
- data/lib/mundo_pepino/en_US/matchers.rb +9 -0
- data/lib/mundo_pepino/en_US.rb +1 -1
- data/lib/mundo_pepino/es_ES/definitions.rb +28 -74
- data/lib/mundo_pepino/es_ES/mappings.rb +53 -8
- data/lib/mundo_pepino/es_ES/matchers.rb +24 -6
- data/lib/mundo_pepino/es_ES.rb +1 -1
- data/lib/mundo_pepino/implementations.rb +22 -4
- data/lib/mundo_pepino/implementations_api.rb +77 -65
- data/lib/mundo_pepino/resources_history.rb +23 -15
- data/lib/mundo_pepino/version.rb +1 -1
- data/lib/mundo_pepino.rb +5 -10
- data/rails_generators/mundo_pepino/templates/mundo_pepino_es_ES.rb +16 -0
- data/rails_generators/mundo_pepino_steps/templates/mundo_pepino_es_ES.rb +16 -0
- metadata +2 -2
@@ -1,8 +1,4 @@
|
|
1
1
|
# MundoPepino's step definitions in es_ES
|
2
|
-
Dado /^que estoy en (?!#{_pagina_desde_rutas_})(.+)$/ do |pagina|
|
3
|
-
do_visit pagina.to_unquoted.to_url
|
4
|
-
end
|
5
|
-
|
6
2
|
# Creación simple con nombre opcional
|
7
3
|
Dado /^(?:que tenemos )?(#{_numero_}) (?!.+ #{_cuyo_})(.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |numero, modelo, nombre|
|
8
4
|
given_we_have_a_number_of_instances_called numero, modelo, nombre
|
@@ -44,94 +40,57 @@ Dado /^que dich[oa]s? (.+) tienen? como (.+) ['"](.+)["'](?:.+)?$/i do |modelo,
|
|
44
40
|
end
|
45
41
|
end
|
46
42
|
|
47
|
-
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, nombre_del_padre, numero,
|
43
|
+
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, nombre_del_padre, numero, campo_hijos, nombres|
|
48
44
|
given_resource_has_many_children(
|
49
45
|
:resource_model => modelo_padre,
|
50
46
|
:resource_name => nombre_del_padre,
|
51
47
|
:number_of_children => numero,
|
52
|
-
:
|
48
|
+
:children_field => campo_hijos,
|
53
49
|
:children_names => nombres)
|
54
50
|
end
|
55
51
|
|
56
|
-
Dado /^que dich[oa]s? (.+) tienen? (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, numero,
|
52
|
+
Dado /^que dich[oa]s? (.+) tienen? (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, numero, campo_hijos, nombres|
|
57
53
|
given_resource_has_many_children(
|
58
54
|
:resource_model => modelo_padre,
|
59
55
|
:number_of_children => numero,
|
60
|
-
:
|
56
|
+
:children_field => campo_hijos,
|
61
57
|
:children_names => nombres)
|
62
58
|
end
|
63
59
|
|
64
|
-
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, nombre_del_padre,
|
60
|
+
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, nombre_del_padre, campo_hijos, tabla|
|
65
61
|
given_resource_has_many_children_from_step_table(
|
66
62
|
:resource_model => modelo_padre,
|
67
63
|
:resource_name => nombre_del_padre,
|
68
|
-
:
|
64
|
+
:children_field => campo_hijos,
|
69
65
|
:step_table => tabla)
|
70
66
|
end
|
71
67
|
|
72
|
-
Dado /^que dich[ao]s? (.+) tienen? (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre,
|
68
|
+
Dado /^que dich[ao]s? (.+) tienen? (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, campo_hijos, tabla|
|
73
69
|
given_resource_has_many_children_from_step_table(
|
74
70
|
:resource_model => modelo_padre,
|
75
|
-
:
|
71
|
+
:children_field => campo_hijos,
|
76
72
|
:step_table => tabla)
|
77
73
|
end
|
78
74
|
|
79
75
|
|
80
76
|
###############################################################################
|
81
77
|
|
82
|
-
Cuando /^(?:que )
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
Cuando /^(?:que )?visito (?:el|la) #{_pagina_} (?:del|de la) (.+) ['"](.+)["']$/i do |modelo, nombre|
|
87
|
-
if resource = last_mentioned_of(modelo, nombre)
|
88
|
-
do_visit send("#{resource.class.name.underscore}_path", resource)
|
89
|
-
else
|
90
|
-
raise MundoPepino::ResourceNotFound.new("model #{modelo}, name #{nombre}")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
Cuando /^(?:que )?visito la p[áa]gina de (?!la)([\w\/]+) (?:de |de la |del )?(.+?)(?: (['"].+["']))?$/i do |accion, modelo, nombre|
|
95
|
-
action = accion.to_crud_action or raise(MundoPepino::CrudActionNotMapped.new(accion))
|
96
|
-
if action != 'new'
|
97
|
-
nombre, modelo = modelo, nil unless nombre
|
98
|
-
resource = if modelo && modelo.to_unquoted.to_model
|
99
|
-
last_mentioned_of(modelo, nombre.to_unquoted)
|
100
|
-
else
|
101
|
-
last_mentioned_called(nombre.to_unquoted)
|
102
|
-
end
|
103
|
-
if resource
|
104
|
-
do_visit send("#{action}_#{resource.mr_singular}_path", resource)
|
105
|
-
else
|
106
|
-
MundoPepino::ResourceNotFound.new("model #{modelo}, name #{nombre}")
|
107
|
-
end
|
108
|
-
else
|
109
|
-
model = modelo.to_unquoted.to_model or raise(MundoPepino::ModelNotMapped.new(modelo))
|
110
|
-
pile_up model.new
|
111
|
-
do_visit send("#{action}_#{model.name.underscore}_path")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
Cuando /^(?:que )?visito su (?:p[áa]gina|portada)$/i do
|
116
|
-
do_visit last_mentioned_url
|
117
|
-
end
|
118
|
-
|
119
|
-
Cuando /^(?:que )?visito (?!#{_pagina_desde_rutas_})(.+)$/i do |pagina|
|
120
|
-
do_visit pagina.to_unquoted.to_url
|
78
|
+
Cuando /^(?:que )?#{_visito_} (.+)$/i do |pagina|
|
79
|
+
given_or_when_i_do_a_page_request pagina
|
121
80
|
end
|
122
81
|
|
123
82
|
Cuando /^(?:que )?#{_pulso_} (?:en )?el bot[oó]n (.+)$/i do |boton|
|
124
83
|
click_button(boton.to_unquoted.to_translated)
|
125
84
|
end
|
126
85
|
|
127
|
-
Cuando /^(?:que )?#{_pulso_} (?:en )?
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
else
|
86
|
+
Cuando /^(?:que )?#{_pulso_} (?:en )?(#{_el_enlace_}) (.+?)(?:#{_que_existe_} #{_dentro_de_} ['"]?(.+?)["']?)?$/i do |el_enlace, enlace, selector|
|
87
|
+
if selector.nil? and
|
88
|
+
href = (enlace.to_url || "#{el_enlace} #{enlace}".to_url)
|
89
|
+
Entonces "veo el enlace #{href}"
|
90
|
+
Y "visito #{href}"
|
91
|
+
else
|
92
|
+
given_or_when_i_follow_the_link enlace.to_unquoted.to_translated, selector
|
133
93
|
end
|
134
|
-
click_link(enlace.to_unquoted.to_translated, options)
|
135
94
|
end
|
136
95
|
|
137
96
|
Cuando /^(?:que )?#{_pulso_} (?:en )?los (?:siguientes )?(?:enlaces|botones)(?: y (?:enlaces|botones))?:$/i do |tabla|
|
@@ -153,19 +112,19 @@ Cuando /^(?:que )?(?:completo|relleno) (?!#{_localizador_de_atributo_anidado_(fa
|
|
153
112
|
find_field_and_do_with_webrat :fill_in, campo, :with => valor
|
154
113
|
end
|
155
114
|
|
156
|
-
Cuando /^(?:que )?(?:completo|relleno)
|
115
|
+
Cuando /^(?:que )?(?:completo|relleno)(?: los(?: siguientes)? campos)?:$/i do |tabla|
|
157
116
|
tabla.raw[1..-1].each do |row|
|
158
117
|
Cuando "relleno \"#{row[0].gsub('"', '\"')}\" con \"#{row[1].gsub('"', '\"')}\""
|
159
118
|
end
|
160
119
|
end
|
161
120
|
|
162
|
-
Cuando /^(?:que )?(?:completo|relleno) #{_localizador_de_atributo_anidado_} con (?:el valor )?['"](.+)["']$/i do |campo,
|
163
|
-
field_id = nested_field_id(
|
121
|
+
Cuando /^(?:que )?(?:completo|relleno) #{_localizador_de_atributo_anidado_} con (?:el valor )?['"](.+)["']$/i do |campo, modelo, nombre, valor|
|
122
|
+
field_id = nested_field_id(last_mentioned, modelo, campo, nombre)
|
164
123
|
find_field_and_do_with_webrat :fill_in, field_id, :with => valor
|
165
124
|
end
|
166
125
|
|
167
126
|
Cuando /^(?:que )?elijo (?:la|el)? ?(.+) ['"](.+)["']$/i do |campo, valor|
|
168
|
-
choose(
|
127
|
+
choose(convert_to_field(campo).to_s + '_' + valor.downcase.to_underscored)
|
169
128
|
end
|
170
129
|
|
171
130
|
Cuando /^(?:que )?marco (?:la|el)? ?(.+)$/i do |campo|
|
@@ -189,7 +148,7 @@ Cuando /^(?:que )?selecciono ["']([^"']+?)["'](?: (?:en (?:el listado de )?|como
|
|
189
148
|
select valor
|
190
149
|
end
|
191
150
|
rescue Webrat::NotFoundError
|
192
|
-
select(valor, :from =>
|
151
|
+
select(valor, :from => convert_to_field(campo)) # Sin label
|
193
152
|
end
|
194
153
|
end
|
195
154
|
|
@@ -222,8 +181,8 @@ Cuando /^borro (?:el|la|el\/la) (.+) en (?:la )?(\w+|\d+)(?:ª|º)? posición$/
|
|
222
181
|
end
|
223
182
|
|
224
183
|
#############################################################################
|
225
|
-
Entonces /^(#{_veo_o_no_}) el texto (
|
226
|
-
|
184
|
+
Entonces /^(#{_veo_o_no_}) el texto (.+?)(?: #{_dentro_de_} ['"]?(.+?)["']?)?$/i do |should, text, selector|
|
185
|
+
then_i_see_or_not_the_text should, text, selector
|
227
186
|
end
|
228
187
|
|
229
188
|
Entonces /^(#{_leo_o_no_}) el texto (.+)?$/i do |should, text|
|
@@ -247,7 +206,7 @@ Entonces /^(#{_leo_o_no_}) los siguientes textos:$/i do |should, texts|
|
|
247
206
|
end
|
248
207
|
end
|
249
208
|
|
250
|
-
Entonces /^(#{_veo_o_no_})
|
209
|
+
Entonces /^(#{_veo_o_no_}) #{_la_etiqueta_} (["'].+?['"]|[^ ]+)(?:(?: con)? el (?:valor|texto) )?["']?([^"']+)?["']?$/ do |should, tag, value |
|
251
210
|
lambda {
|
252
211
|
if value
|
253
212
|
response.should have_tag(tag.to_unquoted, /.*#{value.to_translated}.*/i)
|
@@ -268,10 +227,9 @@ Entonces /^(#{_veo_o_no_}) (?:las|los) siguientes (?:etiquetas|selectores):$/i d
|
|
268
227
|
end
|
269
228
|
end
|
270
229
|
|
271
|
-
Entonces /^(#{_veo_o_no_}) un enlace (?:al
|
230
|
+
Entonces /^(#{_veo_o_no_}) (?:un|el) enlace (?:al? |para )?(.+)?$/i do |should, pagina|
|
272
231
|
lambda {
|
273
|
-
|
274
|
-
response.should have_tag('a[href=?]', href)
|
232
|
+
response.should have_tag('a[href=?]', pagina.to_unquoted.to_url)
|
275
233
|
}.send(not_shouldify(should), raise_error)
|
276
234
|
end
|
277
235
|
|
@@ -360,10 +318,6 @@ Entonces /^#{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |numero, mod
|
|
360
318
|
last_mentioned_should_have_n_children(modelo_hijo, numero)
|
361
319
|
end
|
362
320
|
|
363
|
-
Entonces /^#{_debo_estar_en_} (
|
364
|
-
URI.parse(current_url).path.should == resource_index_or_mapped_page(la_pagina_de, modelo_en_crudo)
|
365
|
-
end
|
366
|
-
|
367
|
-
Entonces /^#{_debo_estar_en_} (?!#{_pagina_desde_rutas_})(.+)$/i do |pagina|
|
321
|
+
Entonces /^#{_debo_estar_en_} (.+)$/i do |pagina|
|
368
322
|
URI.parse(current_url).path.should == pagina.to_unquoted.to_url
|
369
323
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module MundoPepino
|
2
2
|
class << self
|
3
|
+
include Matchers::Fragments
|
3
4
|
def language_specific_mappings
|
4
5
|
String.add_mapper(:real_value, {
|
5
6
|
/^verdader[oa]$/i => true,
|
6
7
|
/^fals[ao]$/i => false
|
7
8
|
}) { |value| value }
|
8
|
-
String.add_mapper(:field) { |str| :name if str =~
|
9
|
+
String.add_mapper(:field) { |str| :name if str =~ /^nombres?/i }
|
9
10
|
|
10
11
|
String.add_mapper(:number, {
|
11
12
|
/^un[oa]?$/i => 1,
|
@@ -25,9 +26,10 @@ module MundoPepino
|
|
25
26
|
:diez => 10
|
26
27
|
}) { |string| string.to_i }
|
27
28
|
String.add_mapper(:crud_action,
|
28
|
-
/^alta
|
29
|
-
/^creaci[óo]n
|
30
|
-
/^nuev(?:o|a|o\/a|a\/o)$/i
|
29
|
+
/^alta(?: de (?:una? )?nuev[ao])?$/i => 'new',
|
30
|
+
/^creaci[óo]n(?: de (?:una? )?nuev[ao])?$/i => 'new',
|
31
|
+
/^nuev(?:o|a|o\/a|a\/o)$/i => 'new',
|
32
|
+
/^inicio|comienzo$/i => 'new',
|
31
33
|
/^cambio$/i => 'edit',
|
32
34
|
/^modificaci[oó]n(?:es)?$/i => 'edit',
|
33
35
|
/^edici[oó]n$/i => 'edit')
|
@@ -44,10 +46,53 @@ module MundoPepino
|
|
44
46
|
:octubre => 'October',
|
45
47
|
:noviembre => 'November',
|
46
48
|
:diciembre => 'December')
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
String.url_mappings.merge!({
|
50
|
+
/^la (?:portada|home\s?(?:page)?)$/i => lambda{MundoPepino.world.root_path},
|
51
|
+
/^(#{_el_listado_de_}) ([\w]+|['"][\w ]+["'])$/i =>
|
52
|
+
lambda{ |el_listado_de, modelo|
|
53
|
+
MundoPepino.world.resource_index_or_mapped_page(el_listado_de, modelo)
|
54
|
+
},
|
55
|
+
/^su (p[áa]gina|portada)$/i => lambda{MundoPepino.world.last_mentioned_url},
|
56
|
+
/^(?:#{_la_pagina_}|#{_el_enlace_}) (?:del|de la) (.+) ['"](.+)["']$/i =>
|
57
|
+
lambda{|modelo, nombre|
|
58
|
+
if resource = MundoPepino.world.last_mentioned_of(modelo, nombre)
|
59
|
+
MundoPepino.world.send "#{resource.class.name.underscore}_path", resource
|
60
|
+
else
|
61
|
+
raise MundoPepino::ResourceNotFound.new("model #{modelo}, name #{nombre}")
|
62
|
+
end
|
63
|
+
},
|
64
|
+
/^(?:#{_la_pagina_}|#{_el_enlace_}) de (?!la)([\w\/]+(?: de (?:una? )?nuev[oa])?) (?:de |de la |del )?(.+?)(?: (['"].+["']))?$/i =>
|
65
|
+
lambda{|accion, modelo, nombre|
|
66
|
+
action = accion.to_crud_action or raise(MundoPepino::CrudActionNotMapped.new(accion))
|
67
|
+
if action != 'new'
|
68
|
+
nombre, modelo = modelo, nil unless nombre
|
69
|
+
resource = if modelo && modelo.to_unquoted.to_model
|
70
|
+
MundoPepino.world.last_mentioned_of(modelo, nombre.to_unquoted)
|
71
|
+
else
|
72
|
+
MundoPepino.world.last_mentioned_called(nombre.to_unquoted)
|
73
|
+
end
|
74
|
+
if resource
|
75
|
+
MundoPepino.world.send "#{action}_#{resource.mr_singular}_path", resource
|
76
|
+
else
|
77
|
+
MundoPepino::ResourceNotFound.new("model #{modelo}, name #{nombre}")
|
78
|
+
end
|
79
|
+
else
|
80
|
+
model = modelo.to_unquoted.to_model or raise(MundoPepino::ModelNotMapped.new(modelo))
|
81
|
+
MundoPepino.world.pile_up model.new
|
82
|
+
MundoPepino.world.send "#{action}_#{model.name.underscore}_path"
|
83
|
+
end
|
84
|
+
},
|
85
|
+
/la (anterior|siguiente|p[aá]gina) (anterior|siguiente|p[aá]gina)/i =>
|
86
|
+
lambda{|first, second|
|
87
|
+
head, current, tail = if MundoPepino.world.last_visited =~ /(.+page=)(\d+)(.*)/
|
88
|
+
[$1, $2.to_i, $3]
|
89
|
+
else
|
90
|
+
[MundoPepino.world.last_visited + '?page=', 1, '']
|
91
|
+
end
|
92
|
+
go_next = (first =~ /siguiente/i) || (second =~ /siguiente/i)
|
93
|
+
"#{head}#{go_next ? current + 1 : current - 1}#{tail}"
|
94
|
+
}
|
95
|
+
})
|
51
96
|
end
|
52
97
|
end
|
53
98
|
end
|
@@ -1,20 +1,26 @@
|
|
1
1
|
module MundoPepino
|
2
2
|
module Matchers
|
3
3
|
module Fragments
|
4
|
+
def _should_
|
5
|
+
'debo|debo ver|veo|deber[ií]a|deber[íi]a ver|leo|debo leer|deber[ií]a leer'
|
6
|
+
end
|
4
7
|
def _numero_
|
5
8
|
'un|una|dos|tres|cuatro|cinco|seis|siete|ocho|nueve|diez|\d+'
|
6
9
|
end
|
7
10
|
def _cuyo_
|
8
11
|
'(?:cuy[oa]s?|que tienen? como)'
|
9
12
|
end
|
10
|
-
def
|
11
|
-
'(?:
|
13
|
+
def _visito_
|
14
|
+
'(?:visito|estoy en)'
|
15
|
+
end
|
16
|
+
def _la_pagina_
|
17
|
+
'la (?:p[áa]gina|portada)'
|
12
18
|
end
|
13
|
-
def
|
14
|
-
'(?:la|
|
19
|
+
def _el_listado_de_
|
20
|
+
'(?:el|la|al|a la) (?:p[áa]gina|portada|[íi]ndice|listado|colecci[óo]n) de'
|
15
21
|
end
|
16
22
|
def _pulso_
|
17
|
-
'(?:pulso|pincho)'
|
23
|
+
'(?:pulso|pincho|sigo)'
|
18
24
|
end
|
19
25
|
def _fecha_y_o_hora_
|
20
26
|
'(?:(?:la )?fecha|hora)'
|
@@ -36,7 +42,19 @@ module MundoPepino
|
|
36
42
|
end
|
37
43
|
def _localizador_de_atributo_anidado_(capture=true)
|
38
44
|
o,c = capture ? ['(', ')'] : ['', '']
|
39
|
-
"(?:(?:el|la) )?#{o}.+?#{c} (?:
|
45
|
+
"(?:(?:el|la) )?#{o}.+?#{c} de(?:l| la| su nuev[oa]) #{o}.+?#{c}(?: ['\"]#{o}[^\"']+#{c}[\"'])?"
|
46
|
+
end
|
47
|
+
def _dentro_de_
|
48
|
+
'dentro de(?: la etiqueta|l selector)?'
|
49
|
+
end
|
50
|
+
def _el_enlace_
|
51
|
+
'el (?:enlace|(?:hiper)?-?v[íi]nculo)(?: a)?' #TODO: |enlace ajax|enlace con efectos'
|
52
|
+
end
|
53
|
+
def _que_existe_
|
54
|
+
'(?: que (?:hay|existe))?'
|
55
|
+
end
|
56
|
+
def _la_etiqueta_
|
57
|
+
'(?:en )?(?:(?:una?|el|la) (?:selector|etiqueta|tag))'
|
40
58
|
end
|
41
59
|
end
|
42
60
|
end
|
data/lib/mundo_pepino/es_ES.rb
CHANGED
@@ -12,12 +12,12 @@ module MundoPepino
|
|
12
12
|
|
13
13
|
def given_resource_has_many_children(params)
|
14
14
|
if mentioned = last_mentioned_of(params[:resource_model].to_unquoted, params[:resource_name])
|
15
|
-
children_model = params[:
|
15
|
+
children_model = params[:children_field].to_unquoted.to_model
|
16
16
|
resources = (mentioned.is_a?(Array) ? mentioned : [mentioned])
|
17
17
|
resources.each do |resource|
|
18
18
|
attribs = names_for_simple_creation(children_model,
|
19
19
|
params[:number_of_children].to_number, params[:children_names],
|
20
|
-
parent_options(resource, children_model))
|
20
|
+
parent_options(resource, children_model, params[:children_field]))
|
21
21
|
add_resource children_model, attribs, :force_creation => params[:children_names].nil?
|
22
22
|
end
|
23
23
|
pile_up mentioned
|
@@ -26,10 +26,10 @@ module MundoPepino
|
|
26
26
|
|
27
27
|
def given_resource_has_many_children_from_step_table(params)
|
28
28
|
if mentioned = last_mentioned_of(params[:resource_model].to_unquoted, params[:resource_name])
|
29
|
-
children_model = params[:
|
29
|
+
children_model = params[:children_field].to_unquoted.to_model
|
30
30
|
resources = (mentioned.is_a?(Array) ? mentioned : [mentioned])
|
31
31
|
resources.each do |resource|
|
32
|
-
options = parent_options(resource, children_model)
|
32
|
+
options = parent_options(resource, children_model, params[:children_field])
|
33
33
|
options[:model] = children_model
|
34
34
|
add_resource children_model,
|
35
35
|
translated_hashes(params[:step_table].raw, options)
|
@@ -37,6 +37,24 @@ module MundoPepino
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def given_or_when_i_do_a_page_request(page)
|
41
|
+
do_visit page.to_unquoted.to_url
|
42
|
+
end
|
43
|
+
|
44
|
+
def then_i_see_or_not_the_text(should, text, selector=nil)
|
45
|
+
within selector || 'html' do
|
46
|
+
response.send shouldify(should), contain(text.to_unquoted.to_translated.to_regexp)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def given_or_when_i_follow_the_link(link, selector=nil)
|
51
|
+
if selector
|
52
|
+
click_link_within selector, link
|
53
|
+
else
|
54
|
+
click_link link
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
40
58
|
# DB CHECKS
|
41
59
|
def then_we_have_a_number_of_instances_in_our_database(raw_number, raw_model, name)
|
42
60
|
model = raw_model.to_unquoted.to_model
|
@@ -2,6 +2,7 @@ require 'nokogiri'
|
|
2
2
|
|
3
3
|
module MundoPepino
|
4
4
|
module ImplementationsApi
|
5
|
+
MAX_NESTED_RESOURCES = 30 # TODO: move this to MP.configure
|
5
6
|
def real_value_for(v)
|
6
7
|
(v.is_a?(String) ? v.to_real_value : v )
|
7
8
|
end
|
@@ -26,41 +27,25 @@ module MundoPepino
|
|
26
27
|
if field
|
27
28
|
"#{model_name}#{field}".to_field || field.to_field
|
28
29
|
else
|
30
|
+
"#{model_name}name".to_field || 'name'.to_field ||
|
29
31
|
# The use of "nombre" the name field mapping is deprecated
|
30
|
-
"#{model_name}nombre".to_field || 'nombre'.to_field ||
|
31
|
-
# "Model::name" or "name" (for a global mapping) is the right use.
|
32
|
-
"#{model_name}name".to_field || 'name'.to_field || :name
|
32
|
+
"#{model_name}nombre".to_field || 'nombre'.to_field || :name
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def shouldify(should_or_not)
|
37
|
-
|
38
|
-
should_or_not =~ /^(#{affirmative})$/i ? :should : :should_not
|
37
|
+
should_or_not =~ /^(#{MundoPepino::Matchers::Bites._should_})$/i ? :should : :should_not
|
39
38
|
end
|
40
39
|
|
41
40
|
def not_shouldify(should_or_not)
|
42
41
|
shouldify(should_or_not) == :should ? :should_not : :should
|
43
42
|
end
|
44
43
|
|
45
|
-
def relative_page(pagina)
|
46
|
-
if pagina =~ /la siguiente p[aá]gina|la p[aá]gina anterior/i
|
47
|
-
head, current, tail = if last_visited =~ /(.+page=)(\d+)(.*)/
|
48
|
-
[$1, $2.to_i, $3]
|
49
|
-
else
|
50
|
-
[last_visited + '?page=', 1, '']
|
51
|
-
end
|
52
|
-
(pagina =~ /siguiente/ ? current += 1 : current -= 1)
|
53
|
-
head + current.to_s + tail
|
54
|
-
else
|
55
|
-
nil
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
44
|
# Cucumber::Model::Table's hashes traduciendo nombres de campo
|
60
45
|
def translated_hashes(step_table, options = {})
|
61
46
|
base_hash = base_hash_for(options)
|
62
|
-
header = step_table[0].map do |
|
63
|
-
field_for(options[:model],
|
47
|
+
header = step_table[0].map do |raw_field|
|
48
|
+
field_for(options[:model], raw_field) || raw_field
|
64
49
|
end
|
65
50
|
step_table[1..-1].map do |row|
|
66
51
|
h = base_hash.dup
|
@@ -79,12 +64,12 @@ module MundoPepino
|
|
79
64
|
{ "#{options[:polymorphic_as]}_id" => options[:parent].id,
|
80
65
|
"#{options[:polymorphic_as]}_type" => options[:parent].class.name }
|
81
66
|
else
|
82
|
-
field_prefix = options[:parent].class.name.underscore
|
67
|
+
field_prefix = options[:parent_field] || options[:parent].class.name.underscore
|
83
68
|
if options[:through]
|
84
69
|
{:through => {"model" => eval(options[:through].to_s.classify),
|
85
70
|
"attributes" => {"#{field_prefix}_id" => options[:parent].id}}}
|
86
71
|
else
|
87
|
-
{
|
72
|
+
{"#{field_prefix}_id" => options[:parent].id}
|
88
73
|
end
|
89
74
|
end
|
90
75
|
else
|
@@ -92,52 +77,57 @@ module MundoPepino
|
|
92
77
|
end
|
93
78
|
end
|
94
79
|
|
95
|
-
def
|
96
|
-
unless
|
97
|
-
if field = field_for(model,
|
80
|
+
def convert_to_field(raw_field, model = nil)
|
81
|
+
unless raw_field.nil?
|
82
|
+
if field = field_for(model, raw_field.to_unquoted)
|
98
83
|
field
|
99
84
|
else
|
100
|
-
raise MundoPepino::FieldNotMapped.new(
|
85
|
+
raise MundoPepino::FieldNotMapped.new(raw_field)
|
101
86
|
end
|
102
87
|
end
|
103
88
|
end
|
104
89
|
|
105
|
-
def
|
106
|
-
if child_model =
|
107
|
-
|
90
|
+
def last_mentioned_children(field_raw)
|
91
|
+
if child_model = field_raw.to_model
|
92
|
+
parent_model = last_mentioned.mr_model
|
93
|
+
last_mentioned.send field_for(parent_model, field_raw) ||
|
94
|
+
field_for(parent_model, child_model.table_name) ||
|
95
|
+
child_model.table_name
|
108
96
|
else
|
109
|
-
raise ModelNotMapped.new(child)
|
97
|
+
raise MundoPepino::ModelNotMapped.new(child)
|
110
98
|
end
|
111
99
|
end
|
100
|
+
|
101
|
+
def last_mentioned_should_have_n_children(field, number)
|
102
|
+
last_mentioned_children(field).size.should == number.to_number
|
103
|
+
end
|
112
104
|
|
113
|
-
def last_mentioned_should_have_value(
|
105
|
+
def last_mentioned_should_have_value(raw_field, valor)
|
114
106
|
res = last_mentioned
|
115
|
-
if child_model =
|
107
|
+
if child_model = raw_field.to_model
|
116
108
|
child = child_model.send "find_by_#{field_for(child_model)}", valor
|
117
|
-
child_field =
|
109
|
+
child_field = field_for(res.mr_model, raw_field) || child_model.name.underscore
|
118
110
|
(res.send child_field).should == child
|
119
|
-
elsif field = field_for(res.class,
|
111
|
+
elsif field = field_for(res.class, raw_field)
|
120
112
|
(res.send field).to_s.should == valor.to_s
|
121
113
|
else
|
122
|
-
raise FieldNotMapped.new(
|
114
|
+
raise MundoPepino::FieldNotMapped.new(raw_field)
|
123
115
|
end
|
124
116
|
end
|
125
117
|
|
126
|
-
def last_mentioned_should_have_child(
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end.should_not be_nil
|
132
|
-
else
|
133
|
-
raise ModelNotMapped.new(child)
|
118
|
+
def last_mentioned_should_have_child(field_raw, name)
|
119
|
+
children = last_mentioned_children(field_raw)
|
120
|
+
child = if children.any?
|
121
|
+
model = children.first.class
|
122
|
+
model.send("find_by_#{field_for(model)}", name)
|
134
123
|
end
|
124
|
+
children.detect {|c| c.id == child.id}.should_not be_nil
|
135
125
|
end
|
136
126
|
|
137
|
-
def find_field_and_do_with_webrat(action,
|
138
|
-
do_with_webrat action,
|
127
|
+
def find_field_and_do_with_webrat(action, raw_field, options = nil)
|
128
|
+
do_with_webrat action, raw_field.to_unquoted.to_translated, options # a pelo (localización vía labels)
|
139
129
|
rescue Webrat::NotFoundError
|
140
|
-
field =
|
130
|
+
field = convert_to_field(raw_field, last_mentioned_model)
|
141
131
|
begin
|
142
132
|
do_with_webrat action, field, options # campo traducido tal cual...
|
143
133
|
rescue Webrat::NotFoundError
|
@@ -161,14 +151,17 @@ module MundoPepino
|
|
161
151
|
end
|
162
152
|
end
|
163
153
|
|
164
|
-
def parent_options(parent,
|
165
|
-
|
166
|
-
|
167
|
-
|
154
|
+
def parent_options(parent, child_model, child_field)
|
155
|
+
options = {:parent => parent}
|
156
|
+
if child_field and
|
157
|
+
parent_field = "#{child_model.name}::#{child_field}".to_field
|
158
|
+
options[:parent_field] = parent_field
|
159
|
+
elsif reflections = parent.class.reflect_on_association(child_model.table_name.to_sym)
|
160
|
+
# many to many associations
|
168
161
|
if reflections.options[:as]
|
169
|
-
options
|
162
|
+
options[:polymorphic_as] = reflections.options[:as]
|
170
163
|
elsif reflections.options[:through]
|
171
|
-
options
|
164
|
+
options[:through] = reflections.options[:through]
|
172
165
|
end
|
173
166
|
end
|
174
167
|
options
|
@@ -178,39 +171,58 @@ module MundoPepino
|
|
178
171
|
unquoted_model = raw_model.to_unquoted
|
179
172
|
if model = unquoted_model.to_model
|
180
173
|
pile_up model.new
|
181
|
-
|
182
|
-
elsif url = "#{the_page_of}#{raw_model}".to_url
|
174
|
+
MundoPepino.world.send "#{model.table_name}_path"
|
175
|
+
elsif url = "#{the_page_of} #{raw_model}".to_url
|
183
176
|
url
|
184
177
|
else
|
185
178
|
raise MundoPepino::ModelNotMapped.new(unquoted_model)
|
186
179
|
end
|
187
180
|
end
|
188
181
|
|
189
|
-
def nested_field_id(
|
182
|
+
def nested_field_id(parent_resource, nested_model, nested_field, nested_name)
|
190
183
|
unquoted_model = nested_model.to_unquoted
|
191
184
|
if model = unquoted_model.to_model
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
185
|
+
field = field_for(parent_resource.mr_model, nested_field)
|
186
|
+
if nested_name.nil?
|
187
|
+
new_nested_field_id(parent_resource, model, field)
|
196
188
|
else
|
197
|
-
|
189
|
+
# Nested attrib. change
|
190
|
+
if res = model.send("find_by_#{field_for(model)}", nested_name)
|
191
|
+
if field_prefix = nested_field_id_prefix(parent_resource, res)
|
192
|
+
"#{field_prefix}#{field}"
|
193
|
+
else
|
194
|
+
# TODO: raise NestedAttributeNotFound
|
195
|
+
end
|
196
|
+
else
|
197
|
+
raise MundoPepino::ResourceNotFound.new("No '#{unquoted_model}' called '#{nested_name}'")
|
198
|
+
end
|
198
199
|
end
|
199
200
|
else
|
200
201
|
raise MundoPepino::ModelNotMapped.new(unquoted_model)
|
201
202
|
end
|
202
203
|
end
|
203
204
|
|
204
|
-
def nested_field_id_prefix(
|
205
|
-
|
206
|
-
children = resource.class.name.pluralize.underscore
|
207
|
-
preprefix = "#{parent}_#{children}_attributes"
|
205
|
+
def nested_field_id_prefix(parent_resource, resource)
|
206
|
+
preprefix = nested_field_prefix_prefix(parent_resource.mr_model, resource.class)
|
208
207
|
Nokogiri::HTML.parse(response.body).xpath(
|
209
208
|
"//input[@type='hidden' and @value=#{resource.id}]"
|
210
209
|
).each do |input|
|
211
210
|
return "#{preprefix}_#{$1}_" if input.attributes['id'].to_s =~ /#{preprefix}_([0-9]+)_id/
|
212
211
|
end
|
213
212
|
end
|
213
|
+
|
214
|
+
def new_nested_field_id(parent_resource, model, field)
|
215
|
+
preprefix = nested_field_prefix_prefix(parent_resource.mr_model, model)
|
216
|
+
(0..MAX_NESTED_RESOURCES).each do |index|
|
217
|
+
if Nokogiri::HTML.parse(response.body).css("##{preprefix}_#{index}_id").empty?
|
218
|
+
return "#{preprefix}_#{index}_#{field}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
# TODO: raise too many nested resources
|
222
|
+
end
|
223
|
+
def nested_field_prefix_prefix(parent_model, child_model)
|
224
|
+
"#{parent_model.name.underscore}_#{child_model.name.pluralize.underscore}_attributes"
|
225
|
+
end
|
214
226
|
end
|
215
227
|
end
|
216
228
|
|