require 'rails_helper' # This spec was generated by rspec-rails when you ran the scaffold generator. # It demonstrates how one might use RSpec to specify the controller code that # was generated by Rails when you ran the scaffold generator. # # It assumes that the implementation code is generated by the rails scaffold # generator. If you are using any extension libraries to generate different # controller code, this generated spec may or may not pass. # # It only uses APIs available in rails and/or rspec-rails. There are a number # of tools you can use to make these specs even more expressive, but we're # sticking to rails and rspec-rails APIs to keep things simple and stable. # # Compared to earlier versions of this generator, there is very limited use of # stubs and message expectations in this spec. Stubs are only used when there # is no simpler way to get a handle on the object needed for the example. # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. module Tang RSpec.describe Admin::SubscriptionsController, type: :controller do before { StripeMock.start } after { StripeMock.stop } routes { Tang::Engine.routes } login_admin # This should return the minimal set of attributes required to create a valid # Subscription. As you add validations to Subscription, be sure to # adjust the attributes here as well. let(:valid_attributes) { # skip("Add a hash of attributes valid for your model") FactoryBot.attributes_for(:subscription) } let(:invalid_attributes) { # skip("Add a hash of attributes invalid for your model") FactoryBot.attributes_for(:subscription, plan_id: nil) } # 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 # SubscriptionsController. Be sure to keep this updated too. let(:valid_session) { {} } describe "GET #index" do it "assigns all subscriptions as @subscriptions" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) get :index, params: {}, session: valid_session expect(assigns(:subscriptions)).to eq([subscription]) end end describe "GET #show" do it "assigns the requested subscription as @subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) get :show, params: {id: subscription.to_param}, session: valid_session expect(assigns(:subscription)).to eq(subscription) end end describe "GET #edit" do it "assigns the requested subscription as @subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) get :edit, params: {id: subscription.to_param}, session: valid_session expect(assigns(:subscription)).to eq(subscription) end end describe "PUT #update" do context "with valid params" do let(:new_attributes) { # skip("Add a hash of attributes valid for your model") FactoryBot.attributes_for(:subscription, quantity: 2) } it "updates the requested subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) put :update, params: {id: subscription.to_param, subscription: new_attributes}, session: valid_session subscription.reload # skip("Add assertions for updated state") expect(subscription.quantity).to eq(2) end it "assigns the requested subscription as @subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) put :update, params: {id: subscription.to_param, subscription: valid_attributes}, session: valid_session expect(assigns(:subscription)).to eq(subscription) end it "redirects to the subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) put :update, params: {id: subscription.to_param, subscription: valid_attributes}, session: valid_session expect(response).to redirect_to(admin_subscription_url(subscription)) end end context "with invalid params" do it "assigns the subscription as @subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) put :update, params: {id: subscription.to_param, subscription: invalid_attributes}, session: valid_session expect(assigns(:subscription)).to eq(subscription) end it "re-renders the 'edit' template" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) put :update, params: {id: subscription.to_param, subscription: invalid_attributes}, session: valid_session expect(response).to render_template("edit") end end end describe "DELETE #destroy" do it "destroys the requested subscription" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) expect { delete :destroy, params: {id: subscription.to_param}, session: valid_session }.to change(Subscription.where.not(status: :canceled), :count).by(-1) end it "redirects to the subscriptions list" do # subscription = Subscription.create! valid_attributes subscription = FactoryBot.create(:subscription) delete :destroy, params: {id: subscription.to_param}, session: valid_session expect(response).to redirect_to(admin_subscriptions_url) end end end end