-
-
Save anonymous/ca3b854467399d66bf2876631b0a8a99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe TestimonyService, type: :service do | |
subject { described_class.new } | |
let!(:user) { create(:user, status: 'active') } | |
let!(:course) { create :course } | |
context '.create' do | |
context 'when valid' do | |
let(:attributes) { attributes_for(:testimony, course_id: course.id) } | |
it 'create a new' do | |
expect do | |
subject.create(attributes) | |
end.to change(Testimony, :count).by(1) | |
end | |
it 'correct attributes' do | |
testimony = subject.create(attributes) | |
expect(testimony.body).to eql(attributes[:body]) | |
expect(testimony.score).to eql(attributes[:score]) | |
expect(testimony.email).to eql(attributes[:email]) | |
expect(testimony.full_name).to eql(attributes[:full_name]) | |
expect(testimony.course).to eql(course) | |
expect(testimony).to be_queue | |
end | |
it 'send a e-mail' do | |
expect do | |
subject.create(attributes) | |
end.to change(ActionMailer::Base.deliveries, :count).by(1) | |
end | |
end | |
context 'when invalid' do | |
let(:attributes) { attributes_for(:invalid_testimony) } | |
it 'not create' do | |
expect do | |
subject.create(attributes) | |
end.to change(Testimony, :count).by(0) | |
end | |
it 'not send a e-mail' do | |
expect do | |
subject.create(attributes) | |
end.to change(ActionMailer::Base.deliveries, :count).by(0) | |
end | |
end | |
end | |
context 'approve!' do | |
let(:testimony) { create(:testimony, status: 'approved') } | |
before { subject.approve!(testimony) } | |
it { expect(testimony).to be_approved } | |
it 'send a e-mail' do | |
expect do | |
subject.approve!(testimony) | |
end.to change(ActionMailer::Base.deliveries, :count).by(1) | |
end | |
end | |
context 'disapprove!' do | |
let(:testimony) { create(:testimony, status: 'queue') } | |
before { subject.disapprove!(testimony) } | |
it { expect(testimony).to be_disapproved } | |
it 'send a e-mail' do | |
expect do | |
subject.approve!(testimony) | |
end.to change(ActionMailer::Base.deliveries, :count).by(1) | |
end | |
end |
AndreiMotinga
commented
Dec 8, 2017
- https://robots.thoughtbot.com/mystery-guest
- https://robots.thoughtbot.com/four-phase-test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment