|
|
@ -74,6 +74,7 @@ Then /^there should be the following localizations:$/ do |table| |
|
|
|
|
|
|
|
|
|
|
|
attributes = [] |
|
|
|
attributes = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# collect al list of all custom field attributes |
|
|
|
wait_until(5) do |
|
|
|
wait_until(5) do |
|
|
|
attributes = page.all(:css, "[name*=\"translations_attributes\"]:not([disabled=disabled])") |
|
|
|
attributes = page.all(:css, "[name*=\"translations_attributes\"]:not([disabled=disabled])") |
|
|
|
attributes.size > 0 |
|
|
|
attributes.size > 0 |
|
|
@ -81,6 +82,7 @@ Then /^there should be the following localizations:$/ do |table| |
|
|
|
|
|
|
|
|
|
|
|
name_regexp = /\[(\d)+\]\[(\w+)\]$/ |
|
|
|
name_regexp = /\[(\d)+\]\[(\w+)\]$/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# group custom field attributes by their id ($1) |
|
|
|
attribute_group = attributes.inject({}) do |h, element| |
|
|
|
attribute_group = attributes.inject({}) do |h, element| |
|
|
|
if element['name'] =~ name_regexp |
|
|
|
if element['name'] =~ name_regexp |
|
|
|
h[$1] ||= [] |
|
|
|
h[$1] ||= [] |
|
|
@ -89,25 +91,30 @@ Then /^there should be the following localizations:$/ do |table| |
|
|
|
h |
|
|
|
h |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# filter some attributes out, and set the correct value for checkboxes |
|
|
|
actual_localizations = attribute_group.inject([]) do |a, (k, group)| |
|
|
|
actual_localizations = attribute_group.inject([]) do |a, (k, group)| |
|
|
|
a << group.inject({}) do |h, element| |
|
|
|
a << group.inject({}) do |h, element| |
|
|
|
if element['name'] =~ name_regexp |
|
|
|
if element['name'] =~ name_regexp |
|
|
|
|
|
|
|
if $2 != "id" and $2 != "_destroy" |
|
|
|
if $2 != "id" and |
|
|
|
if element['type'] == 'checkbox' |
|
|
|
$2 != "_destroy" and |
|
|
|
h[$2] = (element.checked? ? '1' : '0') |
|
|
|
(element['type'] != 'checkbox' or (element['type'] == 'checkbox' and element.checked?)) |
|
|
|
else |
|
|
|
|
|
|
|
h[$2] = element['value'] |
|
|
|
h[$2] = element['value'] |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
h |
|
|
|
h |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
a |
|
|
|
a |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
actual_localizations = actual_localizations.group_by{|e| e["locale"]}.collect{|(k, v)| v.inject({}){|a, x| a.merge(x)} } |
|
|
|
# group attributes by their locale |
|
|
|
|
|
|
|
# attributes without locale (nil) are general attritbutes, which are then included into each separate attribute hash |
|
|
|
|
|
|
|
actual_localizations = actual_localizations.group_by { |e| e["locale"] } |
|
|
|
|
|
|
|
general_attributes = (actual_localizations.delete(nil) || {}).inject({}){|a, x| a.merge(x)} |
|
|
|
|
|
|
|
actual_localizations = actual_localizations.collect do |(k, v)| |
|
|
|
|
|
|
|
v.inject(general_attributes.dup){|a, x| a.merge(x)} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
actual_localizations.should =~ cleaned_expectation |
|
|
|
actual_localizations.should =~ cleaned_expectation |
|
|
|
end |
|
|
|
end |
|
|
|