require 'rails_helper' module Logistics module Core RSpec.describe TransportRatePeriodsController, type: :controller do let(:valid_attributes) { skip("Add a hash of attributes valid for your model") } let(:invalid_attributes) { skip("Add a hash of attributes invalid for your model") } # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # TransportRatePeriodsController. Be sure to keep this updated too. let(:valid_session) { {} } describe "GET #index" do it "assigns all rate_periods as @rate_periods" do rate_period = TransportRatePeriod.create! valid_attributes get :index, {}, valid_session expect(assigns(:rate_periods)).to eq([rate_period]) end end describe "GET #show" do it "assigns the requested rate_period as @rate_period" do rate_period = TransportRatePeriod.create! valid_attributes get :show, {:id => rate_period.to_param}, valid_session expect(assigns(:rate_period)).to eq(rate_period) end end describe "GET #edit" do it "assigns the requested rate_period as @rate_period" do rate_period = TransportRatePeriod.create! valid_attributes get :edit, {:id => rate_period.to_param}, valid_session expect(assigns(:rate_period)).to eq(rate_period) end end describe "POST #create" do context "with valid params" do it "creates a new TransportRatePeriod" do expect { post :create, {:rate_period => valid_attributes}, valid_session }.to change(TransportRatePeriod, :count).by(1) end it "assigns a newly created rate_period as @rate_period" do post :create, {:rate_period => valid_attributes}, valid_session expect(assigns(:rate_period)).to be_a(TransportRatePeriod) expect(assigns(:rate_period)).to be_persisted end it "redirects to the created rate_period" do post :create, {:rate_period => valid_attributes}, valid_session expect(response).to redirect_to(TransportRatePeriod.last) end end context "with invalid params" do it "assigns a newly created but unsaved rate_period as @rate_period" do post :create, {:rate_period => invalid_attributes}, valid_session expect(assigns(:rate_period)).to be_a_new(TransportRatePeriod) end it "re-renders the 'new' template" do post :create, {:rate_period => invalid_attributes}, valid_session expect(response).to render_template("new") end end end describe "PUT #update" do context "with valid params" do let(:new_attributes) { skip("Add a hash of attributes valid for your model") } it "updates the requested rate_period" do rate_period = TransportRatePeriod.create! valid_attributes put :update, {:id => rate_period.to_param, :rate_period => new_attributes}, valid_session rate_period.reload skip("Add assertions for updated state") end it "assigns the requested rate_period as @rate_period" do rate_period = TransportRatePeriod.create! valid_attributes put :update, {:id => rate_period.to_param, :rate_period => valid_attributes}, valid_session expect(assigns(:rate_period)).to eq(rate_period) end it "redirects to the rate_period" do rate_period = TransportRatePeriod.create! valid_attributes put :update, {:id => rate_period.to_param, :rate_period => valid_attributes}, valid_session expect(response).to redirect_to(rate_period) end end context "with invalid params" do it "assigns the rate_period as @rate_period" do rate_period = TransportRatePeriod.create! valid_attributes put :update, {:id => rate_period.to_param, :rate_period => invalid_attributes}, valid_session expect(assigns(:rate_period)).to eq(rate_period) end it "re-renders the 'edit' template" do rate_period = TransportRatePeriod.create! valid_attributes put :update, {:id => rate_period.to_param, :rate_period => invalid_attributes}, valid_session expect(response).to render_template("edit") end end end describe "DELETE #destroy" do it "destroys the requested rate_period" do rate_period = TransportRatePeriod.create! valid_attributes expect { delete :destroy, {:id => rate_period.to_param}, valid_session }.to change(TransportRatePeriod, :count).by(-1) end it "redirects to the rate_periods list" do rate_period = TransportRatePeriod.create! valid_attributes delete :destroy, {:id => rate_period.to_param}, valid_session expect(response).to redirect_to(rate_periods_url) end end end end end