access request tests (#772)

* access request tests

* map mailer spec update
This commit is contained in:
Devin Howard 2016-10-17 22:53:53 +08:00 committed by Connor Turland
parent 6c9d464a9f
commit 6e75274737
3 changed files with 49 additions and 4 deletions

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
FactoryGirl.define do
factory :access_request do
map
user
end
end

View file

@ -1,10 +1,24 @@
require 'rails_helper'
RSpec.describe MapMailer, type: :mailer do
let(:map) { create(:map) }
let(:inviter) { create(:user) }
let(:invitee) { create(:user) }
describe 'access_request_email' do
let(:request) { create(:access_request) }
let(:map) { create(:map) }
let(:mail) { described_class.access_request_email(request, map) }
it { expect(mail.from).to eq ['team@metamaps.cc'] }
it { expect(mail.to).to eq [map.user.email] }
it { expect(mail.subject).to match map.name }
it { expect(mail.body.encoded).to match map.name }
it { expect(mail.body.encoded).to match request.user.name }
it { expect(mail.body.encoded).to match 'Approve Request' }
it { expect(mail.body.encoded).to match 'Deny Request' }
end
describe 'invite_to_edit_email' do
let(:map) { create(:map) }
let(:inviter) { create(:user) }
let(:invitee) { create(:user) }
let(:mail) { described_class.invite_to_edit_email(map, inviter, invitee) }
it { expect(mail.from).to eq ['team@metamaps.cc'] }

View file

@ -1,5 +1,29 @@
require 'rails_helper'
RSpec.describe AccessRequest, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
include ActiveJob::TestHelper # enqueued_jobs
let(:access_request) { create(:access_request) }
describe 'approve' do
before :each do
access_request.approve
end
it { expect(access_request.approved).to be true }
it { expect(access_request.answered).to be true }
it { expect(UserMap.count).to eq 1 }
it { expect(enqueued_jobs.count).to eq 1 }
end
describe 'deny' do
before :each do
access_request.deny
end
it { expect(access_request.approved).to be false }
it { expect(access_request.answered).to be true }
it { expect(UserMap.count).to eq 0 }
it { expect(enqueued_jobs.count).to eq 0 }
end
end