Skip to content

Commit

Permalink
Create cooling_mode_to_human method in IsletDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Rass committed Oct 29, 2024
1 parent 2fbb737 commit cca5638
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/decorators/islet_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ def cooling_modes_options_for_select
end
end
end

def cooling_mode_to_human
return Islet.human_attribute_name("cooling_mode.blank") unless (c_m = cooling_mode.presence)

Islet.human_attribute_name("cooling_mode.#{c_m}")
end
end
8 changes: 1 addition & 7 deletions app/views/islets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
<% end %>

<dt class="pb-2"><%= Islet.human_attribute_name(:cooling_mode) %></dt>
<dd class="mb-0 pb-2 ps-3">
<% if @islet.cooling_mode.present? %>
<%= Islet.human_attribute_name("cooling_mode.#{@islet.cooling_mode}") %>
<% else %>
<%= Islet.human_attribute_name("cooling_mode.blank") %>
<% end %>
</dd>
<dd class="mb-0 pb-2 ps-3"><%= @islet.decorated.cooling_mode_to_human %></dd>
</dl>
<% end %>
</div>
Expand Down
17 changes: 17 additions & 0 deletions spec/decorators/islet_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require "rails_helper"

RSpec.describe IsletDecorator, type: :decorator do
let(:islet) { islets(:one) }
let(:decorated_islet) { islet.decorated }

describe ".grouped_by_sites_options_for_select" do
let(:expected_response) do
{
Expand All @@ -16,4 +19,18 @@
describe ".cooling_modes_options_for_select" do
it { expect(described_class.cooling_modes_options_for_select.pluck(1)).to match_array(Islet.cooling_modes.keys) }
end

describe "#cooling_mode_to_human" do
subject(:cooling_mode_sentence) { decorated_islet.cooling_mode_to_human }

context "with no cooling mode" do
it { is_expected.to eq("Pas de confinement") }
end

context "with cooling mode set" do
before { islet.cooling_mode = "hot_containment" }

it { is_expected.to eq("Confinement chaud") }
end
end
end

0 comments on commit cca5638

Please sign in to comment.