Commit 5872ba10 authored by marcheing's avatar marcheing

Remove index and template tests from controllers

The previous assert_template and assigns were deprecated
https://github.com/rails/rails/issues/18950Signed-off-by: Diego de Araújo Martinez Camarinha's avatarDiego Araújo <[email protected]>
Signed-off-by: Rafael Reggiani Manzo's avatarRafael Reggiani Manzo <[email protected]>
parent 6a544ed4
......@@ -3,12 +3,6 @@ class ProfilesController < ApplicationController
before_action :set_carmen_locale, only: [:show, :edit, :new, :states]
before_action :authenticate_user!, except: [:states]
# GET /profiles
# GET /profiles.json
def index
@profiles = Profile.all
end
# GET /profiles/1
# GET /profiles/1.json
def show
......
......@@ -2,7 +2,7 @@ Rails.application.routes.draw do
scope '(:locale)', locale: /en|pt-BR/ do
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :profiles
resources :profiles, except: [:index]
get 'states' => 'profiles#states', as: 'states'
......
......@@ -50,34 +50,27 @@ RSpec.describe ProfilesController, type: :controller do
sign_in user
end
describe "GET #index" do
it "assigns all profiles as @profiles" do
profile = Profile.create! valid_attributes
get :index, params: {}, session: valid_session
expect(assigns(:profiles)).to eq([profile])
end
end
describe "GET #show" do
it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
get :show, params: {id: profile.to_param}, session: valid_session
expect(assigns(:profile)).to eq(profile)
end
end
describe "GET #new" do
it "assigns a new profile as @profile" do
get :new, params: {}, session: valid_session
expect(assigns(:profile)).to be_a_new(Profile)
describe 'GET #show' do
let(:profile) { build(:profile, id: 1) }
context 'profile found' do
before do
expect(Profile).to receive(:find).with(profile.id.to_s).and_return(profile)
end
it 'responds with ok' do
get :show, params: { id: profile.id }
expect(response.status).to eq 200
end
end
end
describe "GET #edit" do
it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
get :edit, params: {id: profile.to_param}, session: valid_session
expect(assigns(:profile)).to eq(profile)
context 'profile not found' do
before do
expect(Profile).to receive(:find).with(profile.id.to_s).and_raise ActiveRecord::RecordNotFound
end
it 'responds with not found' do
pending 'Handle not found errors'
get :show, params: { id: profile.id }
expect(response.status).to eq 404
end
end
end
......@@ -89,29 +82,11 @@ RSpec.describe ProfilesController, type: :controller do
}.to change(Profile, :count).by(1)
end
it "assigns a newly created profile as @profile" do
post :create, params: { profile: valid_request_parameters }, session: valid_session
expect(assigns(:profile)).to be_a(Profile)
expect(assigns(:profile)).to be_persisted
end
it "redirects to the created profile" do
post :create, params: { profile: valid_request_parameters }, session: valid_session
expect(response).to redirect_to(root_path)
end
end
context "with invalid params" do
it "assigns a newly created but unsaved profile as @profile" do
post :create, params: {profile: invalid_attributes}, session: valid_session
expect(assigns(:profile)).to be_a_new(Profile)
end
it "re-renders the 'new' template" do
post :create, params: {profile: invalid_attributes}, session: valid_session
expect(response).to render_template("new")
end
end
end
describe "PUT #update" do
......@@ -127,32 +102,12 @@ RSpec.describe ProfilesController, type: :controller do
skip("Add assertions for updated state")
end
it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
put :update, params: { id: profile.to_param, profile: valid_request_parameters }, session: valid_session
expect(assigns(:profile)).to eq(profile)
end
it "redirects to the profile" do
profile = Profile.create! valid_attributes
put :update, params: {id: profile.to_param, profile: valid_request_parameters }, session: valid_session
expect(response).to redirect_to(profile)
end
end
context "with invalid params" do
it "assigns the profile as @profile" do
profile = Profile.create! valid_attributes
put :update, params: {id: profile.to_param, profile: invalid_attributes}, session: valid_session
expect(assigns(:profile)).to eq(profile)
end
it "re-renders the 'edit' template" do
profile = Profile.create! valid_attributes
put :update, params: {id: profile.to_param, profile: invalid_attributes}, session: valid_session
expect(response).to render_template("edit")
end
end
end
describe "DELETE #destroy" do
......@@ -181,8 +136,6 @@ RSpec.describe ProfilesController, type: :controller do
get :states, params: params
end
it { is_expected.to render_template(partial: 'profiles/_states') }
it 'renders the list of subregions' do
country.subregions.each do |subregion|
expect(response.body).to include CGI.escapeHTML subregion.name
......
......@@ -4,7 +4,7 @@ RSpec.describe ProfilesController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/profiles").to route_to("profiles#index")
expect(:get => "/profiles").to_not route_to("profiles#index")
end
it "routes to #new" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment