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" When I select "Boolean" from "custom_field_field_format"
Then there should be the following localizations: Then there should be the following localizations:
| locale | name | default_value | possible_values | | locale | name | default_value | possible_values |
| en | | 0 | | | en | | 0 | nil |
And there should be a "custom_field_tracker_ids_1" field visible And there should be a "custom_field_tracker_ids_1" field visible
And I should see "Bug" And I should see "Bug"
And there should be a "custom_field_tracker_ids_2" field visible And there should be a "custom_field_tracker_ids_2" field visible

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

@ -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

Loading…
Cancel
Save