suggested changes that includes:

moving actions for custom domain in its own controller
use separate service class for custom domains
updated help text for custom domains
increased test coverage for custom domains
This commit is contained in:
shlok007 2017-08-19 13:57:09 +05:30
parent d2b5ec1770
commit bc17f210a6
14 changed files with 208 additions and 73 deletions

View file

@ -0,0 +1,42 @@
require 'spec_helper'
describe Admin::ConferenceDomainsController do
let!(:admin) { create(:admin) }
let!(:conference) { create(:conference) }
context 'as signed in admin' do
before do
sign_in admin
end
describe 'GET #show' do
it 'redirects to edit if custom domain is not present' do
get :show, conference_id: conference.short_title
expect(response).to redirect_to(admin_conference_conference_domains_edit_path)
end
it 'renders correct template if custom domain is present' do
conference.update_attribute(:custom_domain, 'mydomain.conf')
get :show, conference_id: conference.short_title
expect(response).to render_template('show')
end
end
describe 'PATCH #update' do
before do
patch :update, conference_id: conference.short_title,
conference: { custom_domain: 'newdomain.conf' }
end
it 'successfully updates the custom domain' do
expect(conference.reload.custom_domain).to eq('newdomain.conf')
end
end
describe 'GET #edit' do
it 'renders correct template' do
get :edit, conference_id: conference.short_title
expect(response).to render_template('edit')
end
end
end
end

View file

@ -135,15 +135,6 @@ describe Admin::ConferencesController do
end
end
end
describe 'GET #custom_domain', blah: true do
it 'render custom domain' do
get :custom_domain, id: conference.short_title
expect(response).to render_template :custom_domain
expect(response).to be_success
end
end
end
shared_examples 'access as organization_admin' do

View file

@ -0,0 +1,87 @@
require 'spec_helper'
feature Conference do
let!(:organization) { create(:organization) }
let!(:conference) { create(:conference, custom_domain: 'mydomain.conf', organization: organization) }
let(:admin) { create(:admin) }
let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) }
let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) }
let(:role_organizer) { Role.find_by(name: 'organizer', resource: conference) }
let(:user_organizer) { create(:user, role_ids: [role_organizer.id]) }
let(:role_info_desk) { Role.find_by(name: 'info_desk', resource: conference) }
let(:user_info_desk) { create(:user, role_ids: [role_info_desk.id]) }
let(:role_cfp) { Role.find_by(name: 'cfp', resource: conference) }
let(:user_cfp) { create(:user, role_ids: [role_cfp.id]) }
shared_examples 'successfully adds, update or show custom domain' do
scenario 'adds or update custom domain of a conference', feature: true, js: true do
visit admin_conference_conference_domains_edit_path(conference.short_title)
fill_in 'conference_custom_domain', with: 'newdomain.conf'
click_button 'Attach this domain'
expect(flash).to eq 'Attached new domain name to conference. This does not mean that the new domain should work. Please make sure you follow step 3 to point your domain to this hosted version'
expect(page).to have_text('newdomain.conf')
end
scenario 'show custom domain of a conference', feature: true, js: true do
visit admin_conference_conference_domain_path(conference.short_title)
expect(page).to have_text('mydomain.conf')
end
end
shared_examples 'does not add, update or show custom domain' do
scenario 'does not add or update custom domain', feature: true, js: true do
visit admin_conference_conference_domains_edit_path(conference.short_title)
expect(flash).to eq 'You are not authorized to access this page.'
end
scenario 'does not show custom domain of a conference', feature: true, js: true do
visit admin_conference_conference_domain_path(conference.short_title)
expect(flash).to eq 'You are not authorized to access this page.'
end
end
context 'signed in as admin' do
before do
sign_in admin
end
it_behaves_like 'successfully adds, update or show custom domain'
end
context 'signed in as organization admin' do
before do
sign_in user_organization_admin
end
it_behaves_like 'successfully adds, update or show custom domain'
end
context 'signed in as organizer' do
before do
sign_in user_organizer
end
it_behaves_like 'successfully adds, update or show custom domain'
end
context 'signed in as info_desk' do
before do
sign_in user_info_desk
end
it_behaves_like 'does not add, update or show custom domain'
end
context 'signed in as cfp' do
before do
sign_in user_cfp
end
it_behaves_like 'does not add, update or show custom domain'
end
end

View file

@ -68,15 +68,6 @@ feature Conference do
expect(conference.short_title).to eq('NewCon')
expect(Conference.count).to eq(expected_count)
end
scenario 'show custom domain of a conference', feature: true, js: true do
conference = create(:conference, custom_domain: 'mydomain.conf')
sign_in user
visit custom_domain_admin_conference_path(conference.short_title)
expect(page).to have_text('mydomain.conf')
end
end
describe 'admin' do