From bae697185d83718d824b2d0e21a262cb81c84209 Mon Sep 17 00:00:00 2001 From: Philipp Tessenow Date: Mon, 25 Mar 2013 16:47:20 +0100 Subject: [PATCH] repair custom_field cuke --- features/custom_fields/create_bool.feature | 2 +- features/step_definitions/custom_web_steps.rb | 2 -- features/step_definitions/i18n_steps.rb | 25 ++++++++++++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/features/custom_fields/create_bool.feature b/features/custom_fields/create_bool.feature index 210f7dc6de..9c53a686c8 100644 --- a/features/custom_fields/create_bool.feature +++ b/features/custom_fields/create_bool.feature @@ -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 diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index cd1bef67e7..a2be3b8ad1 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -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 diff --git a/features/step_definitions/i18n_steps.rb b/features/step_definitions/i18n_steps.rb index f98cb2165e..2cc6988291 100644 --- a/features/step_definitions/i18n_steps.rb +++ b/features/step_definitions/i18n_steps.rb @@ -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