Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix tabular form builder specs, also scope the localized label inference to the form's object name.

Dombi Attila72c0b93eb772
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 3e5e2d4d6a8..e7f92f79b2c 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -332,7 +332,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
elsif @object.class.respond_to?(:human_attribute_name)
@object.class.human_attribute_name(field)
else
- I18n.t(field)
+ I18n.t(field, scope: sanitized_object_name)
end
end
diff --git a/spec/lib/tabular_form_builder_spec.rb b/spec/lib/tabular_form_builder_spec.rb
index 991d11e437f..46c5921c065 100644
--- a/spec/lib/tabular_form_builder_spec.rb
+++ b/spec/lib/tabular_form_builder_spec.rb
@@ -614,7 +614,7 @@ JJ Abrams</textarea>
end
context 'with a label specified as symbol' do
- let(:text) { :name }
+ let(:text) { :label_name }
before do
options[:label] = text
@@ -626,10 +626,16 @@ JJ Abrams</textarea>
end
context 'without ActiveModel and specified label' do
+ # This is a hypotethical resource that does not have an existing translation
+ # key, therefore stubbing the translation is allowed.
+ before do
+ allow(I18n).to receive(:t).with(:name, scope: 'user').and_return('Name')
+ end
+
let(:resource) { OpenStruct.new name: 'Deadpool' }
it 'falls back to the I18n name' do
- expected_label_like(I18n.t(:name))
+ expected_label_like(I18n.t(:name, scope: 'user'))
end
end
@@ -669,7 +675,7 @@ JJ Abrams</textarea>
end
context 'when required, with a label specified as symbol' do
- let(:text) { :name }
+ let(:text) { :label_name }
before do
options[:label] = text
@@ -677,7 +683,7 @@ JJ Abrams</textarea>
end
it 'uses the label' do
- expected_form_label_like(I18n.t(:name), 'form--label')
+ expected_form_label_like(I18n.t(:label_name), 'form--label')
end
end
end