Skip to content

Commit

Permalink
Merge pull request #2751 from stewart/fix/reports-static-translations
Browse files Browse the repository at this point in the history
Dynamically render ReportsController translations
  • Loading branch information
gmacdougall authored Jun 29, 2018
2 parents eea59bd + a737dd3 commit d24e3d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 5 additions & 1 deletion backend/app/controllers/spree/admin/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def add_available_report!(report_key, report_description_key = nil)
if report_description_key.nil?
report_description_key = "#{report_key}_description"
end
@@available_reports[report_key] = { name: I18n.t(report_key, scope: 'spree'), description: I18n.t(report_description_key, scope: 'spree') }

@@available_reports[report_key] = {
name: report_key,
description: report_description_key,
}
end
end

Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<tbody>
<% @reports.each do |key, value| %>
<tr data-hook="reports_row">
<td><%= link_to value[:name], send("#{key}_admin_reports_url".to_sym) %></td>
<td><%= value[:description] %></td>
<td><%= link_to t(value[:name], scope: 'spree'), send("#{key}_admin_reports_url".to_sym) %></td>
<td><%= t(value[:description], scope: 'spree') %></td>
</tr>
<% end %>
</tbody>
Expand Down
12 changes: 2 additions & 10 deletions backend/spec/controllers/spree/admin/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@
it 'should contain sales_total' do
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:sales_total)).to be true
end

it 'should have the proper sales total report description' do
expect(Spree::Admin::ReportsController.available_reports[:sales_total][:description]).to eql('Sales Total For All Orders')
end
end

describe 'ReportsController.add_available_report!' do
context 'when adding the report name' do
it 'should contain the report' do
I18n.backend.store_translations(:en, spree: {
some_report: 'Awesome Report',
some_report_description: 'This report is great!'
})
Spree::Admin::ReportsController.add_available_report!(:some_report)
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:some_report)).to be true
expect(Spree::Admin::ReportsController.available_reports[:some_report]).to eq(
name: 'Awesome Report',
description: 'This report is great!'
name: :some_report,
description: 'some_report_description'
)
end
end
Expand Down

0 comments on commit d24e3d5

Please sign in to comment.