Rescue from duplicate key errors in AspectMembershipsController
This commit is contained in:
parent
7f5f696642
commit
69619f9ba2
2 changed files with 13 additions and 2 deletions
|
|
@ -17,7 +17,7 @@ class AspectMembershipsController < ApplicationController
|
|||
@contact = current_user.contact_for(Person.where(:id => @person_id).first)
|
||||
membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil
|
||||
|
||||
if membership && membership.destroy
|
||||
if membership && membership.destroy
|
||||
@aspect = membership.aspect
|
||||
flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success'
|
||||
|
||||
|
|
@ -76,4 +76,8 @@ class AspectMembershipsController < ApplicationController
|
|||
render :text => response_hash.to_json
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::RecordNotUnique do
|
||||
render :text => "Duplicate record rejected.", :status => 400
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ describe AspectMembershipsController do
|
|||
@contact = alice.contact_for(bob.person)
|
||||
alice.getting_started = false
|
||||
alice.save
|
||||
sign_in :user, alice
|
||||
sign_in :user, alice
|
||||
@controller.stub(:current_user).and_return(alice)
|
||||
request.env["HTTP_REFERER"] = 'http://' + request.host
|
||||
end
|
||||
|
|
@ -62,6 +62,13 @@ describe AspectMembershipsController do
|
|||
flash[:error].should_not be_empty
|
||||
end
|
||||
|
||||
it 'does not 500 on a duplicate key error' do
|
||||
params = {:format => 'js', :person_id => @person.id, :aspect_id => @aspect0.id}
|
||||
post :create, params
|
||||
post :create, params
|
||||
response.status.should == 400
|
||||
end
|
||||
|
||||
context 'json' do
|
||||
it 'returns a list of aspect ids for the person' do
|
||||
post :create,
|
||||
|
|
|
|||
Loading…
Reference in a new issue