diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..c204bac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,6 @@ module ApplicationHelper + def t_hint(attribute_key, class_key=nil) + class_key ||= controller_name.singularize + t("activemodel.hints.#{class_key}.#{attribute_key}") + end end diff --git a/app/helpers/compound_metric_configurations_helper.rb b/app/helpers/compound_metric_configurations_helper.rb index 96b9100..21cb31d 100644 --- a/app/helpers/compound_metric_configurations_helper.rb +++ b/app/helpers/compound_metric_configurations_helper.rb @@ -2,4 +2,13 @@ module CompoundMetricConfigurationsHelper def scope_options [[t("scopes.METHOD"),"METHOD"], [t("scopes.CLASS"), "CLASS"], [t("scopes.PACKAGE"), "PACKAGE"], [t("scopes.SOFTWARE"), "SOFTWARE"]] end + + def compound_metric_human_name(count=1) + key = count > 1 ? 'other': 'one' + t("activemodel.models.compound_metric_configuration.#{key}") + end + + def compound_metric_human_attribute_name(attribute_key) + t("activemodel.attributes.compound_metric_configuration.#{attribute_key}") + end end diff --git a/app/views/compound_metric_configurations/_form.html.erb b/app/views/compound_metric_configurations/_form.html.erb index 3bcdbf6..9823454 100644 --- a/app/views/compound_metric_configurations/_form.html.erb +++ b/app/views/compound_metric_configurations/_form.html.erb @@ -8,7 +8,7 @@
- <%= f.label :weight, t('weight'), class: 'control-label' %> + <%= f.label :weight, compound_metric_human_attribute_name('weight'), class: 'control-label' %> <%= f.text_field :weight, :required => true, class: 'text-field form-control' %>
@@ -25,7 +25,7 @@ <% else %>
- <%= f.label :reading_group_id, t('reading_group'), class: 'control-label' %> + <%= f.label :reading_group_id, ReadingGroup.model_name.human, class: 'control-label' %> <%= f.select( :reading_group_id, reading_group_options, {class: 'form-control'} ) %>
diff --git a/app/views/compound_metric_configurations/_metric_options.html.erb b/app/views/compound_metric_configurations/_metric_options.html.erb index 6b2858b..4782f58 100644 --- a/app/views/compound_metric_configurations/_metric_options.html.erb +++ b/app/views/compound_metric_configurations/_metric_options.html.erb @@ -1,42 +1,42 @@
- <%= f.label :name, t('name'), class: 'control-label' %> + <%= f.label :name, compound_metric_human_attribute_name('name'), class: 'control-label' %> <%= f.text_field :name, :required => true, class: 'text-field form-control', value: (metric.name unless metric.nil?) %>

- <%= t('body1_compound_metric_options') %> + <%= t_hint(:name) %>

- <%= f.label :description, t('description'), class: 'control-label' %> + <%= f.label :description, compound_metric_human_attribute_name('description'), class: 'control-label' %> <%= f.text_field :description, class: 'text-field form-control', value: (metric.description unless metric.nil?) %>

- <%= t('body2_compound_metric_options') %> + <%= t_hint(:description) %>

- <%= f.label :script, t('script'), class: 'control-label' %> + <%= f.label :script, compound_metric_human_attribute_name('script'), class: 'control-label' %> <%= f.text_area :script, :required => true, class: 'text-area form-control', value: (metric.script unless metric.nil?) %>

- <%= t('body3_compound_metric_options') %> + <%= t_hint(:script) %>

- <%= f.label :scope, t('scope'), class: 'control-label' %> + <%= f.label :scope, compound_metric_human_attribute_name('scope'), class: 'control-label' %> <%= f.select( :scope, scope_options, {class: 'form-control', selected: (metric.scope unless metric.nil?)} ) %>
@@ -48,16 +48,16 @@
- <%= f.label :code, t('code'), class: 'control-label' %> + <%= f.label :code, compound_metric_human_attribute_name('code'), class: 'control-label' %> <%= f.text_field :code, :required => true, class: 'text-field form-control' %>

- <%= t('body1_compound_form') %> + <%= t_hint('code.description') %>


- <%= t('body1_compound_form_example') %> + <%= t_hint('code.example') %>

diff --git a/app/views/compound_metric_configurations/edit.html.erb b/app/views/compound_metric_configurations/edit.html.erb index 382954a..c760768 100644 --- a/app/views/compound_metric_configurations/edit.html.erb +++ b/app/views/compound_metric_configurations/edit.html.erb @@ -1,5 +1,5 @@ diff --git a/app/views/compound_metric_configurations/new.html.erb b/app/views/compound_metric_configurations/new.html.erb index d296321..4887a93 100644 --- a/app/views/compound_metric_configurations/new.html.erb +++ b/app/views/compound_metric_configurations/new.html.erb @@ -1,5 +1,5 @@ <%= render partial: 'created_metrics', locals: {metric_configurations: @metric_configurations} %> diff --git a/config/locales/views/compound_metric_configuration/en.yml b/config/locales/views/compound_metric_configuration/en.yml index 9cbe916..e01566c 100644 --- a/config/locales/views/compound_metric_configuration/en.yml +++ b/config/locales/views/compound_metric_configuration/en.yml @@ -1,11 +1,23 @@ en: - body1_compound_form: "A variable that holds the value of a metric calculation. It can be used in the script of another compound metric." - body2_compound_form: " It is used to calculate the weighted average of a" - body1_compound_form_example: "Example: Code foo := 10" - body1_compound_metric_options: "A custom name for your compound metric." - body2_compound_metric_options: "A short description of your compound metric." - body3_compound_metric_options: "A mathematical expression (in javascript) to calculate your compound metric. It needs a return statement. The codes of already created metrics can be used inside the script." - title_compound_edit: "Edit Compound Metric Configuration" - title_compound_new: "New Compound Metric Configuration" - compound_metric: "Compound Metric" - + activemodel: + models: + compound_metric_configuration: + one: "Compound Metric Configuration" + other: "Compound Metric Configurations" + attributes: + compound_metric_configuration: + name: "Name" + description: "Description" + script: "Script" + scope: "Scope" + code: "Code" + weight: "Weight" + hints: + compound_metric_configuration: + name: "A custom name for your compound metric." + description: "A short description of your compound metric." + script: "A mathematical expression (in javascript) to calculate your compound metric. It needs a return statement. The codes of already created metrics can be used inside the script." + code: + description: "A variable that holds the value of a metric calculation. It can be used in the script of another compound metric." + example: "Example: Code foo := 10" + weight: "It is used to calculate the weighted average of a" diff --git a/config/locales/views/compound_metric_configuration/pt.yml b/config/locales/views/compound_metric_configuration/pt.yml index dc6925a..c53a579 100644 --- a/config/locales/views/compound_metric_configuration/pt.yml +++ b/config/locales/views/compound_metric_configuration/pt.yml @@ -1,9 +1,23 @@ pt: - body1_compound_form: "Uma variável que contém o valor de um cálculo de métrica. Ele pode ser utilizado no script de outra métrica composta." - body1_compound_form_example: "Exemplo: Código foo := 10" - body1_compound_metric_options: "Um nome personalizado para a sua métrica composta." - body2_compound_metric_options: "Uma breve descrição de sua métrica composta." - body3_compound_metric_options: "A expressão matemática (em javascript) para calcular a sua métrica composta. Ela precisa de uma instrução de retorno (por exemplo, 'return resultado;'). Os códigos de métricas já criadas podem ser usados dentro do script." - title_compound_edit: "Editar Configuração de Métrica Composta" - title_compound_new: "Nova Configuração de Métrica Composta" - compound_metric: "Métrica Composta" + activemodel: + models: + compound_metric_configuration: + one: "Configuração de Métrica Composta" + other: "Configurações de Métricas Compostas" + attributes: + compound_metric_configuration: + name: "Nome" + description: "Descrição" + script: "Script" + scope: "Escopo" + code: "Código" + weight: "Peso" + hints: + compound_metric_configuration: + name: "Um nome personalizado para sua métrica composta." + description: "Uma descrição curta de sua métrica composta." + script: "Uma expressão matemática (em JavaScript) para calcular sua métrica composta. Ela precisa de uma cláusula de retorno. O código de suas demais métricas pode ser utilizado dentro deste script." + code: + description: "Uma variável que contém o valor do cálculo da métrica. Ela pode ser usada no script de outra métrica composa." + example: "Examplo: Código foo := 10" + weight: "ele é usado para o cálculo de uma média ponderada de um" diff --git a/features/compound_metric_configuration/create.feature b/features/compound_metric_configuration/create.feature index fa3fdc8..0cfa918 100644 --- a/features/compound_metric_configuration/create.feature +++ b/features/compound_metric_configuration/create.feature @@ -13,18 +13,18 @@ Feature: Compound Metric Configuration Creation And I am at the Sample Configuration page And I click the Add Metric link And I click the Compound Metric link - When I click the "Created Metrics" h3 Then I see the sample metric configuration name And I see the sample metric configuration code When I fill the Name field with "My Compound Metric" And I fill the Description field with "Some description" And I fill the Code field with "mcm" - And I fill the Script field with "8*8;" + And I fill the Script field with "return 8*8;" And I fill the Weight field with "8" And I set the select field "Scope" as "Class" And I set the select field "Reading Group" as "Scholar" And I press the Save button - When I click the show link of "My Compound Metric" + Then I should see "Compound Metric Configuration was successfully created." + And I click the show link of "My Compound Metric" Then I should see "My Compound Metric" And I should see "mcm" And I should see "8" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 35fa2c4..7a2ae88 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -7,11 +7,11 @@ When(/^I press the (.+) button$/) do |text| end When(/^I fill the (.+) field with "(.+)"$/) do |field, text| - fill_in I18n.t(field.gsub(" ", "_").downcase), :with => text + fill_in field, :with => text end Then(/^the field "(.*?)" should be filled with "(.*?)"$/) do |field, value| - expect(page.find_field(I18n.t(field.gsub(" ", "_").downcase)).value).to eq(value) + expect(page.find_field(field).value).to eq(value) end Then(/^my name should have changed to (.+)$/) do |text| diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..f4d4288 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +describe ApplicationHelper, :type => :helper do + describe 't_hint' do + let(:class_key) { :compound_metric_configuration } + let(:attribute_key) { :script } + + context 'without class_key' do + let!(:translation) { "translated test" } + + before :each do + helper.expects(:t).with("activemodel.hints.#{helper.controller_name}.#{attribute_key}").returns(translation) + end + + it 'is expected to return the hint for the given attribute' do + expect(helper.t_hint(attribute_key)).to eq(translation) + end + end + + context 'with class_key' do + it 'is expected to return the hint for the given attribute' do + expect(helper.t_hint(attribute_key, class_key)).to eq(I18n.t("activemodel.hints.#{class_key}.#{attribute_key}")) + end + end + end +end \ No newline at end of file diff --git a/spec/helpers/compound_metric_configurations_helper_spec.rb b/spec/helpers/compound_metric_configurations_helper_spec.rb index 045732d..2763a3a 100644 --- a/spec/helpers/compound_metric_configurations_helper_spec.rb +++ b/spec/helpers/compound_metric_configurations_helper_spec.rb @@ -6,4 +6,27 @@ describe CompoundMetricConfigurationsHelper, :type => :helper do expect(helper.scope_options).to eq [["Method","METHOD"], ["Class", "CLASS"], ["Package", "PACKAGE"], ["Software", "SOFTWARE"]] end end + + describe 'compound_metric_human_name' do + context 'with one' do + it 'is expected to return the class name internationalized' do + expect(helper.compound_metric_human_name).to eq(I18n.t('activemodel.models.compound_metric_configuration.one')) + end + end + + context 'with more than one' do + it 'is expected to return the class name internationalized and pluralized' do + expect(helper.compound_metric_human_name(2)).to eq(I18n.t('activemodel.models.compound_metric_configuration.other')) + expect(helper.compound_metric_human_name(50)).to eq(I18n.t('activemodel.models.compound_metric_configuration.other')) + end + end + end + + describe 'compound_metric_human_attribute_name' do + let(:attribute) { :name } + + it 'is expected to return the attribute name internationalized' do + expect(helper.compound_metric_human_attribute_name(attribute)).to eq(I18n.t("activemodel.attributes.compound_metric_configuration.#{attribute}")) + end + end end -- libgit2 0.21.2