From e59cf45d9e4aa9e4f4de90e58006e6af7a058d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Filmont?= Date: Wed, 6 May 2026 10:47:37 +0200 Subject: [PATCH 1/3] wip --- ...ir_conditioners_controller_request_spec.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/spec/requests/air_conditioners_controller_request_spec.rb b/spec/requests/air_conditioners_controller_request_spec.rb index e659d35b0..1c008d862 100644 --- a/spec/requests/air_conditioners_controller_request_spec.rb +++ b/spec/requests/air_conditioners_controller_request_spec.rb @@ -26,6 +26,20 @@ end end + describe "GET #show" do + subject(:response) do + get air_conditioner_path(air_conditioner) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + include_context "with authenticated admin" + + it { expect(response).to have_http_status(:success) } + it { expect(response).to render_template(:show) } + end + describe "GET #new" do subject(:response) do get new_air_conditioner_path @@ -82,4 +96,70 @@ it { expect { response }.to raise_error(ActionController::ParameterMissing) } end end + + describe "GET #edit" do + subject(:response) do + get edit_air_conditioner_path(air_conditioner) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + include_context "with authenticated admin" + + it { expect(response).to have_http_status(:success) } + it { expect(response).to render_template(:edit) } + end + + describe "PATCH #update" do + subject(:response) do + patch(air_conditioner_path(air_conditioner), params:) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + let(:params) do + { air_conditioner: { status: :on } } + end + + include_context "with authenticated admin" + + context "with valid parameters" do + it { expect(response).to have_http_status(:redirect) } + it { expect(response).to redirect_to(air_conditioner_path(assigns(:air_conditioner))) } + + it do + expect do + response + air_conditioner.reload + end.to change(air_conditioner, :status).to(:on) + end + end + + context "with invalid parameters" do + let(:params) { { air_conditioner: { status: :on, position: "invalid" } } } + + it { expect(response).to render_template(:edit) } + + it do + expect do + response + air_conditioner.reload + end.not_to change(air_conditioner, :status) + end + end + + context "without attributes" do + let(:params) { { air_conditioner: {} } } + + it { expect { response }.to raise_error(ActionController::ParameterMissing) } + end + + context "without parameters" do + let(:params) { {} } + + it { expect { response }.to raise_error(ActionController::ParameterMissing) } + end + end end From d9027ee2c12227123ce3a2832fe8039ea580695b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Filmont?= Date: Wed, 6 May 2026 12:21:19 +0200 Subject: [PATCH 2/3] migrating air conditionner controller minitest to rspec --- ...ir_conditioners_controller_request_spec.rb | 41 ++++++++++++++++++- .../air_conditioners_controller_test.rb | 38 ----------------- 2 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 test/controllers/air_conditioners_controller_test.rb diff --git a/spec/requests/air_conditioners_controller_request_spec.rb b/spec/requests/air_conditioners_controller_request_spec.rb index 1c008d862..e30ea476d 100644 --- a/spec/requests/air_conditioners_controller_request_spec.rb +++ b/spec/requests/air_conditioners_controller_request_spec.rb @@ -133,12 +133,12 @@ expect do response air_conditioner.reload - end.to change(air_conditioner, :status).to(:on) + end.to change(air_conditioner, :status).to("on") end end context "with invalid parameters" do - let(:params) { { air_conditioner: { status: :on, position: "invalid" } } } + let(:params) { { air_conditioner: { air_conditioner_model_id: 999 } } } it { expect(response).to render_template(:edit) } @@ -162,4 +162,41 @@ it { expect { response }.to raise_error(ActionController::ParameterMissing) } end end + + describe "DELETE #destroy" do + subject(:response) do + delete air_conditioner_path(air_conditioner, confirm: true, params:) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + let(:params) { {} } + + include_context "with authenticated admin" + + context "without confirm" do + subject(:response) do + delete(air_conditioner_path(air_conditioner), params:) + @response # rubocop:disable RSpec/InstanceVariable + end + + it { expect { response }.not_to change(AirConditioner, :count) } + it { expect(response).to have_http_status(:success) } + it { expect(AirConditioner.exists?(air_conditioner.id)).to be true } + end + + context "with confirm" do + it { expect { response }.to change(AirConditioner, :count) } + it { expect(response).to have_http_status(:redirect) } + it { expect(response).to redirect_to(air_conditioners_path) } + end + + context "when request back on succes" do + let(:params) { { back_to: "/some_path" } } + + it { expect(response).to redirect_to("/some_path") } + it { expect { response }.to change(AirConditioner, :count).by(-1) } + end + end end diff --git a/test/controllers/air_conditioners_controller_test.rb b/test/controllers/air_conditioners_controller_test.rb deleted file mode 100644 index 13006ec44..000000000 --- a/test/controllers/air_conditioners_controller_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class AirConditionersControllerTest < ActionDispatch::IntegrationTest - setup do - sign_in users(:admin) - @air_conditioner = air_conditioners(:one) - end - - test "should show air_conditioner" do - get air_conditioner_url(@air_conditioner) - assert_response :success - end - - test "should get edit" do - get edit_air_conditioner_url(@air_conditioner) - assert_response :success - end - - test "should update air_conditioner" do - patch air_conditioner_url(@air_conditioner), params: { air_conditioner: { name: @air_conditioner.name, - bay: @air_conditioner.bay, - last_service: @air_conditioner.last_service, - position: @air_conditioner.position, - status: "on", - air_conditioner_model: @air_conditioner.air_conditioner_model } } - assert_redirected_to air_conditioner_path(@air_conditioner) - end - - test "should destroy air_conditioner" do - assert_difference("AirConditioner.count", -1) do - delete air_conditioner_url(@air_conditioner, confirm: true) - end - - assert_redirected_to air_conditioners_url - end -end From 512ecdfd14ec5dcd23c915cc2ee8b044d2389726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Filmont?= Date: Wed, 6 May 2026 15:28:43 +0200 Subject: [PATCH 3/3] wip --- ...ditioner_models_controller_request_spec.rb | 24 +++---- .../architectures_controller_request_spec.rb | 68 +++++++++++++++++++ .../architectures_controller_test.rb | 16 ----- 3 files changed, 80 insertions(+), 28 deletions(-) diff --git a/spec/requests/air_conditioner_models_controller_request_spec.rb b/spec/requests/air_conditioner_models_controller_request_spec.rb index bf91c509f..9a26ef43c 100644 --- a/spec/requests/air_conditioner_models_controller_request_spec.rb +++ b/spec/requests/air_conditioner_models_controller_request_spec.rb @@ -43,18 +43,6 @@ it { expect(response).to render_template(:new) } end - describe "GET #edit" do - subject(:response) do - get edit_air_conditioner_model_url(air_conditioner_model) - @response # rubocop:disable RSpec/InstanceVariable - end - - include_context "with authenticated admin" - - it { expect(response).to have_http_status(:success) } - it { expect(response).to render_template(:edit) } - end - describe "POST #create" do subject(:response) do post(air_conditioner_models_url, params:) @@ -79,6 +67,18 @@ end end + describe "GET #edit" do + subject(:response) do + get edit_air_conditioner_model_url(air_conditioner_model) + @response # rubocop:disable RSpec/InstanceVariable + end + + include_context "with authenticated admin" + + it { expect(response).to have_http_status(:success) } + it { expect(response).to render_template(:edit) } + end + describe "PATCH #update" do subject(:response) do patch(air_conditioner_model_url(air_conditioner_model), params:) diff --git a/spec/requests/architectures_controller_request_spec.rb b/spec/requests/architectures_controller_request_spec.rb index 252b90e29..0a1f0b809 100644 --- a/spec/requests/architectures_controller_request_spec.rb +++ b/spec/requests/architectures_controller_request_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe ArchitecturesController do + let(:architecture) { architectures(:three) } + describe "GET #index" do subject(:response) do get architectures_path @@ -18,6 +20,20 @@ it { expect { response }.to have_rubanok_processed(Architecture.all).with(ArchitecturesProcessor) } end + describe "GET #show" do + subject(:response) do + get architecture_path(architecture) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + include_context "with authenticated admin" + + it { expect(response).to have_http_status(:success) } + it { expect(response).to render_template(:show) } + end + describe "GET #new" do subject(:response) do get new_architecture_path @@ -63,4 +79,56 @@ it { expect { response }.to raise_error(ActionController::ParameterMissing) } end end + + describe "GET #edit" do + subject(:response) do + get edit_architecture_path(architecture) + + # NOTE: used to simplify usage and custom test done in final spec file. + @response # rubocop:disable RSpec/InstanceVariable + end + + include_context "with authenticated admin" + + it { expect(response).to have_http_status(:success) } + it { expect(response).to render_template(:show) } + end + + describe "PATCH #update" do + subject(:response) do + patch(architecture_url(architecture), params:) + @response # rubocop:disable RSpec/InstanceVariable + end + + let(:manufacturer) { manufacturers(:juniper) } + let(:params) { { air_conditioner_model: { name: "New name", manufacturer_id: manufacturer.id } } } + + include_context "with authenticated admin" + + context "with valid parameters" do + it { expect(response).to have_http_status(:redirect) } + it { expect(response).to redirect_to(air_conditioner_model_url(air_conditioner_model)) } + + it do + expect do + response + air_conditioner_model.reload + end.to change(air_conditioner_model, :name).to("New name") + end + end + + context "with invalid parameters" do + let(:params) { { air_conditioner_model: { name: "new name", manufacturer_id: -1 } } } + + it { expect(response).to have_http_status(:unprocessable_content) } + it { expect(response).to render_template(:edit) } + + it do + expect do + response + air_conditioner_model.reload + end.not_to change(air_conditioner_model, :name) + end + end + end end diff --git a/test/controllers/architectures_controller_test.rb b/test/controllers/architectures_controller_test.rb index e62b3954a..a360c07ac 100644 --- a/test/controllers/architectures_controller_test.rb +++ b/test/controllers/architectures_controller_test.rb @@ -8,22 +8,6 @@ class ArchitecturesControllerTest < ActionController::TestCase @architecture = architectures(:rackable) end - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:architectures) - end - - test "should show architecture" do - get :show, params: { id: @architecture } - assert_response :success - end - - test "should get edit" do - get :edit, params: { id: @architecture } - assert_response :success - end - test "should update architecture" do patch :update, params: { id: @architecture, architecture: { description: @architecture.description, name: @architecture.name } } assert_redirected_to architecture_path(assigns(:architecture))