repair custom_field cuke

pull/59/head
Philipp Tessenow 12 years ago
parent 081e349a56
commit bae697185d
  1. 2
      features/custom_fields/create_bool.feature
  2. 2
      features/step_definitions/custom_web_steps.rb
  3. 25
      features/step_definitions/i18n_steps.rb

@ -13,7 +13,7 @@ Feature: Localized boolean custom fields can be created
When I select "Boolean" from "custom_field_field_format"
Then there should be the following localizations:
| locale | name | default_value | possible_values |
| en | | 0 | |
| en | | 0 | nil |
And there should be a "custom_field_tracker_ids_1" field visible
And I should see "Bug"
And there should be a "custom_field_tracker_ids_2" field visible

@ -5,9 +5,7 @@ module Capybara::Node::Finders
tries = 0
begin
elements = all(*args)
raise Capybara::ElementNotFound.new if (elements.nil? || elements.empty?)
elements[0]
rescue Capybara::ElementNotFound => e
tries += 1

@ -74,6 +74,7 @@ Then /^there should be the following localizations:$/ do |table|
attributes = []
# collect al list of all custom field attributes
wait_until(5) do
attributes = page.all(:css, "[name*=\"translations_attributes\"]:not([disabled=disabled])")
attributes.size > 0
@ -81,6 +82,7 @@ Then /^there should be the following localizations:$/ do |table|
name_regexp = /\[(\d)+\]\[(\w+)\]$/
# group custom field attributes by their id ($1)
attribute_group = attributes.inject({}) do |h, element|
if element['name'] =~ name_regexp
h[$1] ||= []
@ -89,25 +91,30 @@ Then /^there should be the following localizations:$/ do |table|
h
end
# filter some attributes out, and set the correct value for checkboxes
actual_localizations = attribute_group.inject([]) do |a, (k, group)|
a << group.inject({}) do |h, element|
if element['name'] =~ name_regexp
if $2 != "id" and
$2 != "_destroy" and
(element['type'] != 'checkbox' or (element['type'] == 'checkbox' and element.checked?))
h[$2] = element['value']
if $2 != "id" and $2 != "_destroy"
if element['type'] == 'checkbox'
h[$2] = (element.checked? ? '1' : '0')
else
h[$2] = element['value']
end
end
end
h
end
a
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
end

Loading…
Cancel
Save