Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions spec/requests/air_conditioner_models_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand All @@ -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:)
Expand Down
117 changes: 117 additions & 0 deletions spec/requests/air_conditioners_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,4 +96,107 @@
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: { air_conditioner_model_id: 999 } } }

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

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
68 changes: 68 additions & 0 deletions spec/requests/architectures_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
38 changes: 0 additions & 38 deletions test/controllers/air_conditioners_controller_test.rb

This file was deleted.

16 changes: 0 additions & 16 deletions test/controllers/architectures_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading