From 5fa873a780a131f0bbfb48de6fe6cff13a543c42 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Thu, 24 Oct 2024 15:40:25 +0200 Subject: [PATCH] Rubocop clean --- app/decorators/room_decorator.rb | 15 +++++++-------- spec/decorators/room_decorator_spec.rb | 10 +++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/decorators/room_decorator.rb b/app/decorators/room_decorator.rb index 796c3d9bf..dfc69ca19 100644 --- a/app/decorators/room_decorator.rb +++ b/app/decorators/room_decorator.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true class RoomDecorator < ApplicationDecorator + BADGE_COLORS = { + active: "text-bg-success", + passive: "text-bg-warning", + planned: "text-bg-primary" + }.freeze + class << self def statuses_for_options Room.statuses.keys.map { |status| [Room.human_attribute_name("status.#{status}"), status] } @@ -8,13 +14,6 @@ def statuses_for_options end def badge_color_for_status - case status - when "active" - "text-bg-success" - when "passive" - "text-bg-warning" - when "planned" - "text-bg-primary" - end + BADGE_COLORS[status.to_sym] end end diff --git a/spec/decorators/room_decorator_spec.rb b/spec/decorators/room_decorator_spec.rb index 82ef75af3..e2a8ca415 100644 --- a/spec/decorators/room_decorator_spec.rb +++ b/spec/decorators/room_decorator_spec.rb @@ -8,28 +8,28 @@ end describe "#badge_color_for_status" do - let(:subject) { rooms(:one).decorated } + subject(:badge_color) { rooms(:one).decorated.badge_color_for_status } context "with status = active" do - it { expect(subject.badge_color_for_status).to eq "text-bg-success" } + it { is_expected.to eq "text-bg-success" } end context "with status = passive" do before { rooms(:one).status = :passive } - it { expect(subject.badge_color_for_status).to eq "text-bg-warning" } + it { is_expected.to eq "text-bg-warning" } end context "with status = planned" do before { rooms(:one).status = :planned } - it { expect(subject.badge_color_for_status).to eq "text-bg-primary" } + it { is_expected.to eq "text-bg-primary" } end context "with status = unknown" do before { rooms(:one).status = :unknown } - it { expect(subject.badge_color_for_status).to be_nil } + it { is_expected.to be_nil } end end end