Sha256: 4ca8e28bf3144778064ec755c73c99d05cc0217cab43aaa6dae1360653357dd2
Contents?: true
Size: 1.68 KB
Versions: 7
Compression:
Stored size: 1.68 KB
Contents
require 'spec_helper' describe Maily::EmailsController, type: :controller do # Rails 4 <-> 5 compatibility def compatible_get(action, **params) if ::Rails::VERSION::STRING > '5' get action, params: params else get action, params end end routes { Maily::Engine.routes } before(:each) do Maily.init! end it 'responds ok if enabled' do expect { get :index }.not_to raise_error end it 'raises 404 if disabled' do Maily.enabled = false get :index expect(response.status).to eq(404) end it 'responds with 401 if http authorization fails' do Maily.http_authorization = { username: 'admin', password: 'admin' } get :index expect(response.status).to eq(401) end it 'responds ok with valid http authorization' do Maily.http_authorization = { username: 'admin', password: 'admin' } request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('admin', 'admin') get :index expect(response.status).to eq(200) end describe 'non-existent emails' do it 'email not in the system -> 302' do compatible_get :show, mailer: 'notifier', email: 'non_existent_email' expect(response.status).to eq(302) expect(flash.alert).to eq("Email not found!") end it 'hidden emails -> 302' do compatible_get :show, mailer: 'notifier', email: 'hidden' expect(response.status).to eq(302) expect(flash.alert).to eq("Email not found!") end end describe 'GET #raw' do it 'renders the template' do compatible_get :raw, mailer: 'notifier', email: 'invitation' expect(response.body).to match("<h1>Invitation</h1>") end end end
Version data entries
7 entries across 7 versions & 1 rubygems