# frozen_string_literal: true 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. RSpec.describe IssueCommentsController, type: :controller do let(:user) { FactoryBot.create(:user) } let(:project) { FactoryBot.create(:project, owner: user) } let(:issue) { FactoryBot.create(:issue, project: project, creator: user) } let(:issue_comment) { FactoryBot.create(:issue_comment, issue: issue, user: user) } before { devise_user_login(user) } # This should return the minimal set of attributes required to create a valid # IssueComment. As you add validations to IssueComment, be sure to # adjust the attributes here as well. let(:valid_parameters) do FactoryBot.attributes_for(:issue_comment).merge(issue_id: issue.id, user_id: user.id) end let(:invalid_parameters) do skip('Add a hash of attributes invalid for your model') end # 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 # IssueCommentsController. Be sure to keep this updated too. let(:valid_session) { {} } describe 'GET #index' do it 'assigns all issue_comments as @issue_comments' do get :index, session: valid_session, params: {} expect(assigns(:issue_comments)).to eq([issue_comment]) end end describe 'GET #show' do it 'assigns the requested issue_comment as @issue_comment' do issue_comment # To create issue_comment get :show, session: valid_session, params: { id: issue_comment.to_param } expect(assigns(:issue_comment)).to eq(issue_comment) end end describe 'GET #new' do it 'assigns a new issue_comment as @issue_comment' do get :new, session: valid_session, params: {} expect(assigns(:issue_comment)).to be_a_new(IssueComment) end end describe 'GET #edit' do it 'assigns the requested issue_comment as @issue_comment' do issue_comment # To create issue_comment get :edit, session: valid_session, params: { id: issue_comment.to_param } expect(assigns(:issue_comment)).to eq(issue_comment) end end describe 'POST #create' do context 'with valid params' do it 'creates a new IssueComment' do expect { post :create, session: valid_session, params: { issue_comment: valid_parameters } }.to change(IssueComment, :count).by(1) end it 'assigns a newly created issue_comment as @issue_comment' do post :create, session: valid_session, params: { issue_comment: valid_parameters } expect(assigns(:issue_comment)).to be_a(IssueComment) expect(assigns(:issue_comment)).to be_persisted end it 'redirects to the created issue_comment' do post :create, session: valid_session, params: { issue_comment: valid_parameters } expect(response).to redirect_to(IssueComment.last) end end context 'with invalid params' do it 'assigns a newly created but unsaved issue_comment as @issue_comment' do post :create, session: valid_session, params: { issue_comment: invalid_parameters } expect(assigns(:issue_comment)).to be_a_new(IssueComment) end it "re-renders the 'new' template" do post :create, session: valid_session, params: { issue_comment: invalid_parameters } expect(response).to render_template('new') end end end describe 'PUT #update' do context 'with valid params' do let(:new_parameters) do skip('Add a hash of attributes valid for your model') end it 'updates the requested issue_comment' do issue_comment # To create issue_comment put :update, session: valid_session, params: { id: issue_comment.to_param, issue_comment: new_parameters } issue_comment.reload skip('Add assertions for updated state') end it 'assigns the requested issue_comment as @issue_comment' do issue_comment # To create issue_comment put :update, session: valid_session, params: { id: issue_comment.to_param, issue_comment: new_parameters } expect(assigns(:issue_comment)).to eq(issue_comment) end it 'redirects to the issue_comment' do issue_comment # To create issue_comment put :update, session: valid_session, params: { id: issue_comment.to_param, issue_comment: new_parameters } expect(response).to redirect_to(issue_comment) end end context 'with invalid params' do it 'assigns the issue_comment as @issue_comment' do issue_comment # To create issue_comment put :update, session: valid_session, params: { id: issue_comment.to_param, issue_comment: invalid_parameters } expect(assigns(:issue_comment)).to eq(issue_comment) end it "re-renders the 'edit' template" do issue_comment # To create issue_comment put :update, session: valid_session, params: { id: issue_comment.to_param, issue_comment: invalid_parameters } expect(response).to render_template('edit') end end end describe 'DELETE #destroy' do it 'destroys the requested issue_comment' do issue_comment # To create issue_comment expect { delete :destroy, session: valid_session, params: { id: issue_comment.to_param } }.to change(IssueComment, :count).by(-1) end it 'redirects to the issue_comments list' do issue_comment # To create issue_comment delete :destroy, session: valid_session, params: { id: issue_comment.to_param } expect(response).to redirect_to(issue_comments_url) end end end