Skip to content

Commit

Permalink
/add_applicant & /remove_applicant -> /add_user & /remove_user
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed Jan 27, 2018
1 parent 4a86987 commit 1946d7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions api/app/controllers/v1/new_club_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update
end
end

def add_applicant
def add_user
app = NewClubApplication.find_by(id: params[:new_club_application_id])

return render_not_found unless app
Expand Down Expand Up @@ -72,7 +72,7 @@ def add_applicant
render_success
end

def remove_applicant
def remove_user
app = NewClubApplication.find_by(id: params[:new_club_application_id])
to_remove = User.find_by(id: params[:user_id])

Expand Down
4 changes: 2 additions & 2 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

resources :club_applications, only: [:create]
resources :new_club_applications, only: %i[show update] do
post 'add_applicant'
delete 'remove_applicant'
post 'add_user'
delete 'remove_user'
post 'submit'
end

Expand Down
40 changes: 20 additions & 20 deletions api/spec/requests/v1/new_club_applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@
end
end

describe 'POST /v1/new_club_applications/:id/add_applicant' do
describe 'POST /v1/new_club_applications/:id/add_user' do
let(:club_application) { create(:new_club_application) }

before { user.new_club_applications << club_application }

it 'requires authentication' do
post "/v1/new_club_applications/#{club_application.id}/add_applicant",
post "/v1/new_club_applications/#{club_application.id}/add_user",
params: { email: '[email protected]' }

expect(response.status).to eq(401)
Expand All @@ -258,7 +258,7 @@
it "fails when trying to add to someone else's application" do
other_application = create(:new_club_application)

post "/v1/new_club_applications/#{other_application.id}/add_applicant",
post "/v1/new_club_applications/#{other_application.id}/add_user",
headers: auth_headers,
params: { email: '[email protected]' }

Expand All @@ -267,7 +267,7 @@
end

it '404s when given application id does not exist' do
post "/v1/new_club_applications/#{club_application.id + 1}/add_applicant",
post "/v1/new_club_applications/#{club_application.id + 1}/add_user",
headers: auth_headers,
params: { email: '[email protected]' }

Expand All @@ -278,7 +278,7 @@
it 'creates new user and sends email when given email is new' do
starting_profile_count = User.count

post "/v1/new_club_applications/#{club_application.id}/add_applicant",
post "/v1/new_club_applications/#{club_application.id}/add_user",
headers: auth_headers,
params: { email: '[email protected]' }

Expand All @@ -299,7 +299,7 @@
new_user = create(:user)
starting_profile_count = User.count

post "/v1/new_club_applications/#{club_application.id}/add_applicant",
post "/v1/new_club_applications/#{club_application.id}/add_user",
headers: auth_headers,
params: { email: new_user.email }

Expand All @@ -324,7 +324,7 @@
to_rehydrate.update_attributes(leader_name: 'Jerry')
to_rehydrate.destroy

post "/v1/new_club_applications/#{club_application.id}/add_applicant",
post "/v1/new_club_applications/#{club_application.id}/add_user",
headers: auth_headers,
params: { email: to_readd.email }

Expand All @@ -342,7 +342,7 @@
new_user = create(:user)
club_application.users << new_user

post "/v1/new_club_applications/#{club_application.id}/add_applicant",
post "/v1/new_club_applications/#{club_application.id}/add_user",
headers: auth_headers,
params: { email: new_user.email }

Expand All @@ -359,7 +359,7 @@
post "/v1/new_club_applications/#{application.id}/submit",
headers: auth_headers

post "/v1/new_club_applications/#{application.id}/add_applicant",
post "/v1/new_club_applications/#{application.id}/add_user",
headers: auth_headers,
params: { email: '[email protected]' }

Expand All @@ -370,7 +370,7 @@
end
end

describe 'DELETE /v1/new_club_applications/:id/remove_applicant' do
describe 'DELETE /v1/new_club_applications/:id/remove_user' do
let(:application) { create(:completed_new_club_application) }

before do
Expand All @@ -380,14 +380,14 @@
end

it 'requires authentication' do
delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
params: { user_id: user.id }

expect(response.status).to eq(401)
end

it '404s when application does not exist' do
delete "/v1/new_club_applications/#{application.id + 1}/remove_applicant",
delete "/v1/new_club_applications/#{application.id + 1}/remove_user",
headers: auth_headers,
params: { user_id: user.id }

Expand All @@ -401,7 +401,7 @@

other_app.users << other_user

delete "/v1/new_club_applications/#{other_app.id}/remove_applicant",
delete "/v1/new_club_applications/#{other_app.id}/remove_user",
headers: auth_headers,
params: { user_id: other_user.id }

Expand All @@ -413,7 +413,7 @@
application.update_attributes(point_of_contact: nil)
other_user = create(:user, new_club_applications: [application])

delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: other_user.id }

Expand All @@ -422,7 +422,7 @@
end

it 'fails to delete self' do
delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: user.id }

Expand All @@ -431,7 +431,7 @@
end

it '404s when user does not exist' do
delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: user.id + 100 }

Expand All @@ -443,7 +443,7 @@
other_user = create(:user, new_club_applications: [application])

2.times do
delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: other_user.id }
end
Expand All @@ -457,7 +457,7 @@
it 'fails to delete user when application is submitted' do
application.submit!

delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: application.users.last.id }

Expand All @@ -468,7 +468,7 @@
end

it 'successfully deletes if point of contact' do
delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: application.users.last.id }

Expand All @@ -479,7 +479,7 @@
it 'preserves profile data on deletion' do
to_delete = application.users.last

delete "/v1/new_club_applications/#{application.id}/remove_applicant",
delete "/v1/new_club_applications/#{application.id}/remove_user",
headers: auth_headers,
params: { user_id: to_delete.id }

Expand Down

0 comments on commit 1946d7d

Please sign in to comment.