From 8d0f4e1b827209105e7218653302a1c761d75aa7 Mon Sep 17 00:00:00 2001 From: jacobtoddmathes Date: Fri, 16 Feb 2024 22:38:15 -0600 Subject: [PATCH] mailer test fixed --- rails_root/app/mailers/application_mailer.rb | 12 ++++------ .../spec/mailers/application_mailer_spec.rb | 24 +++++++++++++++++++ .../spec/requests/survey_profiles_spec.rb | 15 ++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 rails_root/spec/mailers/application_mailer_spec.rb diff --git a/rails_root/app/mailers/application_mailer.rb b/rails_root/app/mailers/application_mailer.rb index 1b7b2f5..d84cb6e 100644 --- a/rails_root/app/mailers/application_mailer.rb +++ b/rails_root/app/mailers/application_mailer.rb @@ -1,8 +1,6 @@ -# # frozen_string_literal: true - -# class ApplicationMailer < ActionMailer::Base -# default from: 'from@example.com' -# layout 'mailer' -# end -# # rubocop:enable Style/Documentation +# frozen_string_literal: true +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/rails_root/spec/mailers/application_mailer_spec.rb b/rails_root/spec/mailers/application_mailer_spec.rb new file mode 100644 index 0000000..bfcbe10 --- /dev/null +++ b/rails_root/spec/mailers/application_mailer_spec.rb @@ -0,0 +1,24 @@ +# require 'rails_helper' + +# RSpec.describe ApplicationMailer, type: :mailer do +# describe 'welcome_email' do +# let(:user) { create(:user) } +# let(:mail) { ApplicationMailer.welcome_email(user) } + +# it 'renders the subject' do +# expect(mail.subject).to eq('Welcome to My App') +# end + +# it 'renders the receiver email' do +# expect(mail.to).to eq([user.email]) +# end + +# it 'renders the sender email' do +# expect(mail.from).to eq(['noreply@example.com']) +# end + +# it 'renders the body' do +# expect(mail.body.encoded).to match('Welcome to My App') +# end +# end +# end diff --git a/rails_root/spec/requests/survey_profiles_spec.rb b/rails_root/spec/requests/survey_profiles_spec.rb index 1d615f7..a30abda 100644 --- a/rails_root/spec/requests/survey_profiles_spec.rb +++ b/rails_root/spec/requests/survey_profiles_spec.rb @@ -99,6 +99,21 @@ expect(response).to have_http_status(:unprocessable_entity) end end + + context 'with non-unique user_id' do + it 'does not create a new SurveyProfile' do + SurveyProfile.create! valid_attributes + expect do + post survey_profiles_url, params: { survey_profile: valid_attributes } + end.to change(SurveyProfile, :count).by(0) + end + + it "renders a response with 422 status (i.e. to display the 'new' template)" do + SurveyProfile.create! valid_attributes + post survey_profiles_url, params: { survey_profile: valid_attributes } + expect(response).to have_http_status(:unprocessable_entity) + end + end end describe 'PATCH /update' do