Skip to content

Commit

Permalink
Rename applicant profiles to leader profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed Jan 27, 2018
1 parent 1946d7d commit 6af1470
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

module V1
class ApplicantProfilesController < ApiController
class LeaderProfilesController < ApiController
include UserAuth

def show
profile = ApplicantProfile.find_by(id: params[:id])
profile = LeaderProfile.find_by(id: params[:id])

return render_not_found unless profile
return render_access_denied if profile.user != @user
Expand All @@ -14,14 +14,15 @@ def show
end

def update
profile = ApplicantProfile.find_by(id: params[:id])
profile = LeaderProfile.find_by(id: params[:id])

return render_not_found unless profile
return render_access_denied if profile.user != @user

if profile.submitted_at.present?
return render_field_error(:base,
'cannot edit applicant profile after submit')
return render_field_error(
:base, 'cannot edit leader profile after submit'
)
end

# TODO: Check for errors and return them if needed
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/v1/new_club_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def add_user
return render_field_error(:email, 'already added')
end

profile = ApplicantProfile.with_deleted.find_or_create_by(
profile = LeaderProfile.with_deleted.find_or_create_by(
user: to_add,
new_club_application: app
)
Expand Down
Binary file modified api/app/mailers/applicant_mailer.rb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ApplicantProfile < ApplicationRecord
class LeaderProfile < ApplicationRecord
include Geocodeable

# preserve information from record deletions
Expand Down Expand Up @@ -80,7 +80,7 @@ def update_completion_status
end

def make_immutable
errors.add(:base, 'cannot edit applicant profile after submit') if changed?
errors.add(:base, 'cannot edit leader profile after submit') if changed?
end

def submitted_at
Expand Down
10 changes: 5 additions & 5 deletions api/app/models/new_club_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class NewClubApplication < ApplicationRecord

validate :point_of_contact_is_associated

has_many :applicant_profiles
has_many :users, through: :applicant_profiles
has_many :leader_profiles
has_many :users, through: :leader_profiles
belongs_to :point_of_contact, class_name: 'User'

geocode_attrs address: :high_school_address,
Expand Down Expand Up @@ -42,15 +42,15 @@ class NewClubApplication < ApplicationRecord
:point_of_contact,
presence: true

# ensure applicant profiles are complete
# ensure leader profiles are complete
application.validate do |app|
all_complete = true

app.applicant_profiles.each do |profile|
app.leader_profiles.each do |profile|
all_complete = false unless profile.completed_at
end

errors.add(:base, 'applicant profiles not complete') unless all_complete
errors.add(:base, 'leader profiles not complete') unless all_complete
end

# make model immutable
Expand Down
4 changes: 2 additions & 2 deletions api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class User < ApplicationRecord
validates :login_code, uniqueness: { if: -> { login_code.present? } }
validates :auth_token, uniqueness: { if: -> { auth_token.present? } }

has_many :applicant_profiles
has_many :new_club_applications, through: :applicant_profiles
has_many :leader_profiles
has_many :new_club_applications, through: :leader_profiles

def generate_login_code!
loop do
Expand Down
4 changes: 2 additions & 2 deletions api/app/serializers/new_club_application_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class NewClubApplicationSerializer < ActiveModel::Serializer
:point_of_contact_id,
:submitted_at

has_many :applicant_profiles
has_many :leader_profiles

class ApplicantProfileSerializer < ActiveModel::Serializer
class LeaderProfileSerializer < ActiveModel::Serializer
attributes :id, :completed_at
has_one :user

Expand Down
2 changes: 1 addition & 1 deletion api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
post 'submit'
end

resources :applicant_profiles, only: %i[show update]
resources :leader_profiles, only: %i[show update]

resources :users, only: [] do
collection do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RenameApplicantProfilesToLeaderProfiles < ActiveRecord::Migration[5.1]
def change
rename_table :applicant_profiles, :leader_profiles
end
end
76 changes: 38 additions & 38 deletions api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180127073628) do
ActiveRecord::Schema.define(version: 20180127084614) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -23,43 +23,6 @@
t.datetime "updated_at", null: false
end

create_table "applicant_profiles", id: :serial, force: :cascade do |t|
t.integer "user_id"
t.integer "new_club_application_id"
t.text "leader_name"
t.text "leader_email"
t.integer "leader_year_in_school"
t.integer "leader_gender"
t.integer "leader_ethnicity"
t.text "leader_phone_number"
t.text "leader_address"
t.decimal "leader_latitude"
t.decimal "leader_longitude"
t.text "leader_parsed_address"
t.text "leader_parsed_city"
t.text "leader_parsed_state"
t.text "leader_parsed_state_code"
t.text "leader_parsed_postal_code"
t.text "leader_parsed_country"
t.text "leader_parsed_country_code"
t.text "presence_personal_website"
t.text "presence_github_url"
t.text "presence_linkedin_url"
t.text "presence_facebook_url"
t.text "presence_twitter_url"
t.text "skills_system_hacked"
t.text "skills_impressive_achievement"
t.boolean "skills_is_technical"
t.datetime "completed_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "leader_birthday"
t.datetime "deleted_at"
t.index ["deleted_at"], name: "index_applicant_profiles_on_deleted_at"
t.index ["new_club_application_id"], name: "index_applicant_profiles_on_new_club_application_id"
t.index ["user_id"], name: "index_applicant_profiles_on_user_id"
end

create_table "athul_clubs", id: :serial, force: :cascade do |t|
t.integer "club_id"
t.integer "leader_id"
Expand Down Expand Up @@ -190,6 +153,43 @@
t.text "bot_username"
end

create_table "leader_profiles", id: :serial, force: :cascade do |t|
t.integer "user_id"
t.integer "new_club_application_id"
t.text "leader_name"
t.text "leader_email"
t.integer "leader_year_in_school"
t.integer "leader_gender"
t.integer "leader_ethnicity"
t.text "leader_phone_number"
t.text "leader_address"
t.decimal "leader_latitude"
t.decimal "leader_longitude"
t.text "leader_parsed_address"
t.text "leader_parsed_city"
t.text "leader_parsed_state"
t.text "leader_parsed_state_code"
t.text "leader_parsed_postal_code"
t.text "leader_parsed_country"
t.text "leader_parsed_country_code"
t.text "presence_personal_website"
t.text "presence_github_url"
t.text "presence_linkedin_url"
t.text "presence_facebook_url"
t.text "presence_twitter_url"
t.text "skills_system_hacked"
t.text "skills_impressive_achievement"
t.boolean "skills_is_technical"
t.datetime "completed_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "leader_birthday"
t.datetime "deleted_at"
t.index ["deleted_at"], name: "index_leader_profiles_on_deleted_at"
t.index ["new_club_application_id"], name: "index_leader_profiles_on_new_club_application_id"
t.index ["user_id"], name: "index_leader_profiles_on_user_id"
end

create_table "leaders", id: :serial, force: :cascade do |t|
t.text "name"
t.text "gender"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

FactoryBot.define do
factory :applicant_profile do
factory :leader_profile do
association :user
association :new_club_application

# applicant profile ready for submission. only includes required fields +
# leader profile ready for submission. only includes required fields +
# relationships.
factory :completed_applicant_profile do
factory :completed_leader_profile do
association :new_club_application,
factory: :completed_new_club_application

Expand Down
4 changes: 2 additions & 2 deletions api/spec/factories/new_club_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

# relationships
after(:create) do |application, evaluator|
# will also create applicants
create_list(:completed_applicant_profile, evaluator.profile_count,
# will also create leader profiles
create_list(:completed_leader_profile, evaluator.profile_count,
new_club_application: application)

application.point_of_contact = application.users.first
Expand Down
6 changes: 3 additions & 3 deletions api/spec/mailers/applicant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
expect(mail).to have_body_text(application.progress_general)
end

it "includes fields from the user's applicant profile" do
profile = ApplicantProfile.find_by(user: user,
new_club_application: application)
it "includes fields from the user's leader profile" do
profile = LeaderProfile.find_by(user: user,
new_club_application: application)
expect(mail).to have_body_text(profile.skills_system_hacked)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe ApplicantProfile, type: :model do
RSpec.describe LeaderProfile, type: :model do
## db columns ##

# metadata
Expand Down Expand Up @@ -69,16 +69,16 @@

it 'should prefill email with applicant info' do
# when email is not set, prefill
profile = create(:applicant_profile)
profile = create(:leader_profile)
expect(profile.leader_email).to eq(profile.user.email)

# when email is set, do not overwrite it
profile = create(:applicant_profile, leader_email: '[email protected]')
profile = create(:leader_profile, leader_email: '[email protected]')
expect(profile.leader_email).to eq('[email protected]')
end

describe 'completed_at autosetting / unsetting' do
let(:unsaved_profile) { build(:completed_applicant_profile) }
let(:unsaved_profile) { build(:completed_leader_profile) }
let(:profile) { unsaved_profile.save && unsaved_profile }

it 'should set completed_at when required fields are completed' do
Expand Down Expand Up @@ -115,20 +115,20 @@
end

it 'should become immutable after application is submitted' do
profile = create(:completed_applicant_profile)
profile = create(:completed_leader_profile)
profile.new_club_application.submit!

profile.update_attributes(leader_name: 'Jane Doe')
expect(profile.errors[:base]).to include(
'cannot edit applicant profile after submit'
'cannot edit leader profile after submit'
)
end

it 'should preserve information on deletion' do
profile = create(:completed_applicant_profile)
profile = create(:completed_leader_profile)
profile.destroy

deleted = ApplicantProfile.with_deleted.find_by(id: profile.id)
deleted = LeaderProfile.with_deleted.find_by(id: profile.id)
expect(deleted).to_not be_nil
expect(deleted.deleted_at).to be_within(1.minute).of(Time.current)
expect(deleted.leader_name).to eq(profile.leader_name)
Expand Down
14 changes: 7 additions & 7 deletions api/spec/models/new_club_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@

## relationships ##

it { should have_many(:applicant_profiles) }
it { should have_many(:users).through(:applicant_profiles) }
it { should have_many(:leader_profiles) }
it { should have_many(:users).through(:leader_profiles) }
it { should belong_to(:point_of_contact) }

it 'requires points of contact to be associated users' do
Expand All @@ -78,8 +78,8 @@
subject { create(:completed_new_club_application, profile_count: 3) }
let(:user) { subject.point_of_contact }
let(:profile) do
ApplicantProfile.find_by(user: user,
new_club_application: subject)
LeaderProfile.find_by(user: user,
new_club_application: subject)
end

it 'fails when missing required fields' do
Expand All @@ -94,18 +94,18 @@
expect(subject.errors[:progress_general]).to include "can't be blank"
end

it 'fails when applicant profiles are not complete' do
it 'fails when leader profiles are not complete' do
profile.update_attributes(leader_name: nil)
res = subject.submit!

expect(res).to eq(false)
expect(subject.submitted_at).to be_nil
expect(subject.errors[:base]).to include(
'applicant profiles not complete'
'leader profiles not complete'
)
end

it 'succeeds when required fields are set & applicant profiles complete' do
it 'succeeds when required fields are set & leader profiles complete' do
res = subject.submit!

expect(res).to eq(true)
Expand Down
4 changes: 2 additions & 2 deletions api/spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
it { should validate_uniqueness_of :login_code }
it { should validate_uniqueness_of :auth_token }

it { should have_many(:applicant_profiles) }
it { should have_many(:new_club_applications).through(:applicant_profiles) }
it { should have_many(:leader_profiles) }
it { should have_many(:new_club_applications).through(:leader_profiles) }

example ':generate_login_code!' do
subject.login_code = nil
Expand Down
Loading

0 comments on commit 6af1470

Please sign in to comment.