forked from dzog/ffagc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from FireflyArtsCollective/cleanup-artists-con…
…troller Cleanup artists controller
- Loading branch information
Showing
10 changed files
with
108 additions
and
77 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,48 @@ | ||
class ArtistsController < ApplicationController | ||
load_and_authorize_resource only: [:index, :show] | ||
load_and_authorize_resource | ||
|
||
before_filter :initialize_user, except: [:show] | ||
def show | ||
end | ||
|
||
def signup | ||
@artist.artist_survey ||= ArtistSurvey.new | ||
def new | ||
@artist.artist_survey ||= @artist.build_artist_survey | ||
end | ||
|
||
def create | ||
if Artist.exists?(email: artist_params[:email].downcase) | ||
flash[:warning] = "The email address #{artist_params[:email.downcase]} already exists in our system" | ||
render "signup_failure" | ||
return | ||
end | ||
|
||
@artist = Artist.new(artist_params) | ||
@artist.email = @artist.email.downcase | ||
|
||
if @artist.save | ||
# save optional survey | ||
artist_survey = ArtistSurvey.new(artist_survey_params) | ||
artist_survey.artist_id = @artist.id | ||
artist_survey.save | ||
|
||
# Send email! | ||
begin | ||
UserMailer.account_activation("artists", @artist).deliver_now | ||
UserMailer.account_activation('artists', @artist).deliver_now | ||
logger.info "email: artist account activation sent to #{@artist.email}" | ||
rescue | ||
flash[:warning] = "Error sending email confirmation" | ||
render "signup_failure" | ||
return | ||
flash[:warning] = 'Error sending email confirmation' | ||
end | ||
|
||
render "signup_success" | ||
else | ||
@artist.artist_survey ||= ArtistSurvey.new(artist_survey_params) | ||
render "signup" | ||
end | ||
end | ||
|
||
def delete_grant | ||
if !artist_logged_in? | ||
return | ||
end | ||
|
||
begin | ||
@submission = GrantSubmission.find(params[:grant_id]) | ||
rescue | ||
redirect_to action: "index" | ||
return | ||
end | ||
|
||
# TODO: is this enough "security"? | ||
if @submission.artist_id != current_artist.id | ||
# Log more stuff | ||
logger.info "SECURITY WARNING: Attempted to delete grant while not logged in as that artist" | ||
redirect_to action: "index" | ||
return | ||
end | ||
# Also should delete pdf from filesystem | ||
@submission.destroy | ||
redirect_to action: "index" | ||
render 'new' | ||
end | ||
|
||
private | ||
|
||
def initialize_user | ||
@artist = Artist.new | ||
end | ||
|
||
def artist_params | ||
artist_survey_attribute_names = [ | ||
:has_attended_firefly, :has_attended_firefly_desc, | ||
:has_attended_regional, :has_attended_regional_desc, | ||
:has_attended_bm, :has_attended_bm_desc, | ||
:can_use_as_example | ||
] | ||
|
||
params.require(:artist).permit(:name, :password_digest, :password, | ||
:password_confirmation, :email, :contact_name, :contact_phone, | ||
:contact_street, :contact_city, :contact_state, :contact_zipcode, | ||
:contact_country) | ||
end | ||
|
||
def artist_survey_params | ||
params.require(:artist).require(:artist_survey).permit(:has_attended_firefly, | ||
:has_attended_firefly_desc, :has_attended_regional, | ||
:has_attended_regional_desc, :has_attended_bm, :has_attended_bm_desc, | ||
:can_use_as_example) | ||
:contact_country, artist_survey_attributes: [artist_survey_attribute_names]) | ||
end | ||
end |
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
describe ArtistsController do | ||
subject { response } | ||
|
||
describe '#index' do | ||
def go! | ||
get :index | ||
end | ||
|
||
it { go!; is_expected.to be_forbidden } | ||
|
||
context 'when admin signed in' do | ||
let!(:admin) { FactoryGirl.create(:admin) } | ||
|
||
before do | ||
sign_in admin | ||
end | ||
|
||
it 'is ok' do | ||
go! | ||
expect(response).to render_template('index') | ||
expect(response).to be_ok | ||
end | ||
end | ||
end | ||
|
||
describe '#new' do | ||
def go! | ||
get :new | ||
end | ||
|
||
before { go! } | ||
|
||
it { is_expected.to render_template('new') } | ||
it { is_expected.to be_ok } | ||
end | ||
|
||
describe '#create' do | ||
def go! | ||
post :create, artist_params | ||
end | ||
|
||
let(:artist_attributes) { FactoryGirl.attributes_for(:artist) } | ||
let(:artist_survey_attributes) { FactoryGirl.attributes_for(:artist_survey) } | ||
let(:artist_params) do | ||
{ | ||
artist: artist_attributes.merge(artist_survey_attributes: artist_survey_attributes) | ||
} | ||
end | ||
|
||
it 'creates Artist' do | ||
expect { go! }.to change { Artist.count }.by(1) | ||
end | ||
|
||
it 'creates ArtistSurvey' do | ||
expect { go! }.to change { ArtistSurvey.count }.by(1) | ||
end | ||
|
||
it 'sends email' do | ||
expect(UserMailer).to receive(:account_activation) | ||
go! | ||
end | ||
|
||
context 'with invalid params' do | ||
let(:artist_attributes) { FactoryGirl.attributes_for(:artist, email: '') } | ||
|
||
it 'displays form' do | ||
expect { go! }.not_to change { Admin.count } | ||
expect(response).to render_template('new') | ||
end | ||
end | ||
end | ||
end |
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