Skip to content

Commit

Permalink
Improve surface_area suffix management
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Rass committed Oct 24, 2024
1 parent 8bcb501 commit d00fd87
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/helpers/rooms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ def calculated_menu_width(islet)
nb_of_lanes = islet.bays.map(&:lane).max
frame_width * (((nb_of_frames) / nb_of_lanes) + 1)
end

def surface_area_with_suffix(surface_area)
"#{surface_area} #{t("surface_area.unit")}"
end
end
2 changes: 1 addition & 1 deletion app/views/rooms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%= f.label :surface_area, class: "form-label" %>
<div class="input-group">
<%= f.number_field :surface_area, class: "form-control" %>
<span class="input-group-text"></span>
<span class="input-group-text"><%= t("surface_area.unit") %></span>
</div>
</fieldset>
<% end %>
Expand Down
10 changes: 6 additions & 4 deletions app/views/rooms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
<dt class="pb-2"><%= Site.model_name.human %></dt>
<dd class="mb-0 pb-2 ps-3"><%= link_to @room.site, site_path(@room.site) %></dd>

<% %i[surface_area].each do |attribute_name| %>
<dt class="pb-2"><%= Room.human_attribute_name(attribute_name) %></dt>
<dd class="mb-0 pb-2 ps-3"><%= "#{@room.public_send(attribute_name)} m²" %></dd>
<% end %>
<dt class="pb-2"><%= Room.human_attribute_name(:surface_area) %></dt>
<dd class="mb-0 pb-2 ps-3">
<% if @room.surface_area.present? %>
<%= surface_area_with_suffix(@room.surface_area) %>
<% end %>
</dd>
</dl>
<% end %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ fr:
boolean:
true: Oui
false: Non
surface_area:
unit:
form:
submit: Valider
action:
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/rooms_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe RoomsHelper do
describe "#surface_area_with_suffix" do
it { expect(helper.surface_area_with_suffix(300)).to eq("300 m²") }
end
end

0 comments on commit d00fd87

Please sign in to comment.