Refactoring Admin menu #384

This commit is contained in:
Chrisbr 2014-07-30 12:03:16 +02:00
parent 518e1cc62b
commit d1f5b1e3cc
30 changed files with 865 additions and 190 deletions

View file

@ -0,0 +1,177 @@
require 'spec_helper'
describe Admin::ConferenceBasicsController do
# It is necessary to use bang version of let to build roles before user
let!(:organizer_role) { create(:organizer_role) }
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
let(:conference) { create(:conference) }
let(:admin) { create(:admin) }
let(:organizer) { create(:organizer) }
let(:participant) { create(:participant) }
shared_examples 'access as administration or organizer' do
before(:each) do
request.env['HTTP_REFERER'] = 'http://test.host'
end
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested conference' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
expect(assigns(:conference)).to eq(conference)
end
it 'changes conference attributes' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: 'ExCon')
conference.reload
expect(conference.title).to eq('Example Con')
expect(conference.short_title).to eq('ExCon')
end
it 'redirects to the updated conference' do
session[:return_to] = request.env['HTTP_REFERER'] +
edit_admin_conference_conference_contacts_path(conference.short_title)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
conference.reload
expect(response).to redirect_to edit_admin_conference_conference_contacts_path(
conference.short_title)
end
it 'redirects to conference show if no :return_to is specified' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
conference.reload
expect(response).to redirect_to admin_conference_path(
conference.short_title)
end
it 'sends email notification on conference date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, start_date: Date.today + 2.days, end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
it 'sends email notification on conference registration date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, registration_start_date: Date.today + 2.days, registration_end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
context 'invalid attributes' do
it 'does not change conference attributes' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
conference.reload
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(conference.title).to eq('The dog and pony show')
expect(conference.short_title).to eq("#{conference.short_title}")
end
it 're-renders the #show template' do
request.env['HTTP_REFERER'] = request.env['HTTP_REFERER'] +
edit_admin_conference_conference_contacts_path(conference.short_title)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(response).to redirect_to edit_admin_conference_conference_contacts_path(
conference.short_title)
end
end
end
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :edit, conference_id: conference.short_title
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :edit, conference_id: conference.short_title
expect(response).to render_template :edit
end
end
end
describe 'administrator access' do
before do
sign_in(admin)
end
it_behaves_like 'access as administration or organizer'
end
describe 'organizer access' do
before(:each) do
sign_in(organizer)
end
it_behaves_like 'access as administration or organizer'
end
shared_examples 'access as participant or guest' do |success_path|
describe 'GET #edit' do
it 'requires admin privileges' do
get :edit, conference_id: conference.short_title
expect(response).to redirect_to(send(success_path))
end
end
describe 'PATCH #update' do
it 'requires admin privileges' do
patch :update, conference_id: conference.short_title,
conference: attributes_for(:conference,
short_title: 'ExCon')
expect(response).to redirect_to(send(success_path))
end
end
end
describe 'participant access' do
before(:each) do
sign_in(participant)
end
it_behaves_like 'access as participant or guest', :root_path
end
describe 'guest access' do
it_behaves_like 'access as participant or guest', :new_user_session_path
end
end

View file

@ -0,0 +1,177 @@
require 'spec_helper'
describe Admin::ConferenceContactsController do
# It is necessary to use bang version of let to build roles before user
let!(:organizer_role) { create(:organizer_role) }
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
let(:conference) { create(:conference) }
let(:admin) { create(:admin) }
let(:organizer) { create(:organizer) }
let(:participant) { create(:participant) }
shared_examples 'access as administration or organizer' do
before(:each) do
request.env['HTTP_REFERER'] = 'http://test.host'
end
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested conference' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
expect(assigns(:conference)).to eq(conference)
end
it 'changes conference attributes' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: 'ExCon')
conference.reload
expect(conference.title).to eq('Example Con')
expect(conference.short_title).to eq('ExCon')
end
it 'redirects to the updated conference' do
session[:return_to] = request.env['HTTP_REFERER'] +
edit_admin_conference_conference_basics_path(conference.short_title)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
conference.reload
expect(response).to redirect_to edit_admin_conference_conference_basics_path(
conference.short_title)
end
it 'redirects to conference show if no :return_to is specified' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
conference.reload
expect(response).to redirect_to admin_conference_path(
conference.short_title)
end
it 'sends email notification on conference date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, start_date: Date.today + 2.days, end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
it 'sends email notification on conference registration date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, registration_start_date: Date.today + 2.days, registration_end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
context 'invalid attributes' do
it 'does not change conference attributes' do
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
conference.reload
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(conference.title).to eq('The dog and pony show')
expect(conference.short_title).to eq("#{conference.short_title}")
end
it 're-renders the #show template' do
request.env['HTTP_REFERER'] = request.env['HTTP_REFERER'] +
edit_admin_conference_conference_basics_path(conference.short_title)
patch :update, conference_id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(response).to redirect_to edit_admin_conference_conference_basics_path(
conference.short_title)
end
end
end
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :edit, conference_id: conference.short_title
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :edit, conference_id: conference.short_title
expect(response).to render_template :edit
end
end
end
describe 'administrator access' do
before do
sign_in(admin)
end
it_behaves_like 'access as administration or organizer'
end
describe 'organizer access' do
before(:each) do
sign_in(organizer)
end
it_behaves_like 'access as administration or organizer'
end
shared_examples 'access as participant or guest' do |success_path|
describe 'GET #edit' do
it 'requires admin privileges' do
get :edit, conference_id: conference.short_title
expect(response).to redirect_to(send(success_path))
end
end
describe 'PATCH #update' do
it 'requires admin privileges' do
patch :update, conference_id: conference.short_title,
conference: attributes_for(:conference,
short_title: 'ExCon')
expect(response).to redirect_to(send(success_path))
end
end
end
describe 'participant access' do
before(:each) do
sign_in(participant)
end
it_behaves_like 'access as participant or guest', :root_path
end
describe 'guest access' do
it_behaves_like 'access as participant or guest', :new_user_session_path
end
end

View file

@ -14,81 +14,6 @@ describe Admin::ConferenceController do
shared_examples 'access as administration or organizer' do
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested conference' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
expect(assigns(:conference)).to eq(conference)
end
it 'changes conference attributes' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: 'ExCon')
conference.reload
expect(conference.title).to eq('Example Con')
expect(conference.short_title).to eq('ExCon')
end
it 'redirects to the updated conference' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con')
conference.reload
expect(response).to redirect_to edit_admin_conference_path(
conference.short_title)
end
it 'sends email notification on conference date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, id: conference.short_title, conference:
attributes_for(:conference, start_date: Date.today + 2.days, end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
it 'sends email notification on conference registration date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, id: conference.short_title, conference:
attributes_for(:conference, registration_start_date: Date.today + 2.days, registration_end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
context 'invalid attributes' do
it 'does not change conference attributes' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
conference.reload
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(conference.title).to eq('The dog and pony show')
expect(conference.short_title).to eq("#{conference.short_title}")
end
it 're-renders the #show template' do
patch :update, id: conference.short_title, conference:
attributes_for(:conference, title: 'Example Con',
short_title: nil)
expect(flash[:alert]).
to eq("Updating conference failed. Short title can't be blank.")
expect(response).to redirect_to edit_admin_conference_path(
conference.short_title)
end
end
end
describe 'POST #create' do
context 'with valid attributes' do
it 'saves the conference to the database' do
@ -142,18 +67,6 @@ describe Admin::ConferenceController do
end
end
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :show, id: conference.short_title
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :show, id: conference.short_title
expect(response).to render_template :show
end
end
describe 'GET #show' do
it 'assigns the requested conference to conference' do
get :show, id: conference.short_title
@ -263,14 +176,6 @@ describe Admin::ConferenceController do
end
end
describe 'PATCH #update' do
it 'requires admin privileges' do
patch :update, id: conference.short_title,
conference: attributes_for(:conference,
short_title: 'ExCon')
expect(response).to redirect_to(send(success_path))
end
end
end
describe 'participant access' do

View file

@ -1,7 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :photo do
picture { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'suse.jpg'), 'image/jpg') }
picture_file_name 'rails.png'
picture_content_type 'image/png'
picture_file_size '1024'

View file

@ -19,13 +19,12 @@ feature Conference do
select('(GMT+01:00) Berlin', from: 'conference[timezone]')
today = Date.today - 1
page.
execute_script("$('#conference-start-datepicker').val('" +
"#{today.strftime('%d/%m/%Y')}')")
"#{1.weeks.from_now.strftime('%d/%m/%Y')}')")
page.
execute_script("$('#conference-end-datepicker').val('" +
"#{(today + 7).strftime('%d/%m/%Y')}')")
"#{2.weeks.from_now.strftime('%d/%m/%Y')}')")
click_button 'Create Conference'
@ -34,15 +33,26 @@ feature Conference do
expect(Conference.count).to eq(expected_count)
end
scenario 'update conference', feature: true, js: true do
scenario 'update basic conference settings', feature: true, js: true do
conference = create(:conference)
expected_count = Conference.count
sign_in create(user)
visit edit_admin_conference_path(conference.short_title)
visit edit_admin_conference_conference_basics_path(conference.short_title)
click_link 'Edit'
fill_in 'conference_title', with: 'New Con'
fill_in 'conference_short_title', with: 'NewCon'
fill_in 'conference_social_tag', with: 'NewCon'
fill_in 'conference_description', with: 'Lorem ipsum dolorem...'
select('YouTube', from: 'conference_media_type')
fill_in 'conference_media_id', with: '123456'
page.
execute_script("$('#conference-start-datepicker').val('" +
"#{2.weeks.from_now.strftime('%d/%m/%Y')}')")
page.
execute_script("$('#conference-end-datepicker').val('" +
"#{3.weeks.from_now.strftime('%d/%m/%Y')}')")
click_button 'Update Conference'
expect(flash).
@ -50,8 +60,43 @@ feature Conference do
conference.reload
expect(conference.title).to eq('New Con')
expect(conference.description).to eq('Lorem ipsum dolorem...')
expect(conference.media_type).to eq('YouTube')
expect(conference.media_id).to eq('123456')
expect(conference.start_date).to eq(2.weeks.from_now.to_date)
expect(conference.end_date).to eq(3.weeks.from_now.to_date)
expect(conference.short_title).to eq('NewCon')
expect(conference.social_tag).to eq('NewCon')
expect(Conference.count).to eq(expected_count)
end
scenario 'update contact conference settings', feature: true, js: true do
conference = create(:conference)
expected_count = Conference.count
sign_in create(user)
visit edit_admin_conference_conference_contacts_path(conference.short_title)
click_link 'Edit'
fill_in 'conference_contact_email', with: 'example@example.de'
fill_in 'conference_social_tag', with: '#social-tag'
fill_in 'conference_facebook_url', with: 'http://www.facebook.com'
fill_in 'conference_google_url', with: 'http://www.google.com'
fill_in 'conference_twitter_url', with: 'http://www.twitter.com'
fill_in 'conference_instagram_url', with: 'http://www.instagram.com'
click_button 'Update Conference'
expect(flash).
to eq('Conference was successfully updated.')
conference.reload
expect(conference.contact_email).to eq('example@example.de')
expect(conference.social_tag).to eq('#social-tag')
expect(conference.facebook_url).to eq('http://www.facebook.com')
expect(conference.google_url).to eq('http://www.google.com')
expect(conference.twitter_url).to eq('http://www.twitter.com')
expect(conference.instagram_url).to eq('http://www.instagram.com')
expect(Conference.count).to eq(expected_count)
end
end

View file

@ -0,0 +1,76 @@
require 'spec_helper'
feature Photo do
# It is necessary to use bang version of let to build roles before user
let!(:organizer_role) { create(:organizer_role) }
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
shared_examples 'add and update photo' do |user|
scenario 'adds a new photo', feature: true, js: true do
expected_count = Photo.count + 1
conference = create(:conference)
sign_in create(user)
visit new_admin_conference_photo_path(conference.short_title)
file_path = Rails.root + 'spec/fixtures/suse.jpg'
attach_file('photo_picture', file_path)
fill_in 'photo_description', with: 'Lorem ipsum dolorem...'
click_button 'Save Photo'
expect(flash).
to eq('Photo was successfully created.')
expect(Photo.count).to eq(expected_count)
end
scenario 'updates a photo', feature: true, js: true do
expected_count = Photo.count + 1
conference = create(:conference)
photo = create(:photo)
sign_in create(user)
visit edit_admin_conference_photo_path(conference.short_title, photo.id)
file_path = Rails.root + 'spec/fixtures/suse_pinguin.png'
attach_file('photo_picture', file_path)
fill_in 'photo_description', with: 'Lorem ipsum dolorem...'
click_button 'Save Photo'
expect(flash).
to eq('Photo was successfully updated.')
expect(Photo.count).to eq(expected_count)
end
scenario 'adds a text file', feature: true, js: true do
expected_count = Photo.count
conference = create(:conference)
sign_in create(user)
visit new_admin_conference_photo_path(conference.short_title)
file_path = Rails.root + 'spec/fixtures/test.txt'
attach_file('photo_picture', file_path)
fill_in 'photo_description', with: 'Lorem ipsum dolorem...'
click_button 'Save Photo'
expect(flash).
to eq("A error prohibited this Photo from being saved: Picture has an extension that does not match its contents. "\
"Picture is invalid. Picture content type is invalid.")
expect(Photo.count).to eq(expected_count)
end
end
describe 'admin' do
it_behaves_like 'add and update photo', :admin
end
describe 'organizer' do
it_behaves_like 'add and update photo', :organizer
end
end

BIN
spec/fixtures/suse.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

BIN
spec/fixtures/suse_pinguin.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

0
spec/fixtures/test.txt vendored Normal file
View file

View file

@ -1,12 +0,0 @@
require 'spec_helper'
describe 'admin/conference/edit' do
it 'renders conference details which are editable' do
@conference = create(:conference, title: 'OpenSUSE')
assign :conference, @conference
render template: 'admin/conference/edit.html.haml'
expect(rendered).to include('OpenSUSE')
expect(rendered).to include("#{@conference.contact_email}")
end
end