Commit 198c114b authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

a bunch of things to get tests working

- cleaned up nested divs in views
- cleaned repetition from locale yamls
- removed obsolete state_collection concern
- fixed factory and all tests to run green
parent 62935962
.row {
.row,
.simple_form {
margin-bottom: $padding-large-horizontal;
}
......@@ -9,7 +9,7 @@ module VolunteerAttributes
:profession, :education, :motivation, :experience, :expectations,
:strengths, :skills, :interests, :state, :duration, :man, :woman,
:family, :kid, :sport, :creative, :music, :culture, :training,
:german_course, :adults, :teenagers, :children, :region
:german_course, :adults, :teenagers, :children, :region, :state
]
end
end
......
......@@ -9,6 +9,7 @@ class VolunteerApplicationsController < ApplicationController
end
def create
volunteer_params[:state] = 'registered'
@volunteer = Volunteer.new(volunteer_params)
if @volunteer.save
redirect_to thanks_volunteer_applications_url
......
......@@ -2,7 +2,6 @@ class VolunteersController < ApplicationController
include NestedAttributes
include VolunteerAttributes
before_action :set_volunteer, only: [:show, :edit, :update, :destroy]
before_action :set_state, only: [:update]
def index
@q = Volunteer.ransack(params[:q])
......@@ -30,19 +29,10 @@ class VolunteersController < ApplicationController
end
def update
if @volunteer.update(volunteer_params)
if @state == Volunteer::INTERESTED && @volunteer.state == Volunteer::ACCEPTED
new_user = User.new(email: @volunteer.email,
password: Devise.friendly_token, role: 'volunteer')
new_user.save
new_user.invite!
redirect_to volunteers_path, notice: t('invite_sent', email: new_user.email)
else
redirect_to @volunteer, notice: t('volunteer_updated')
end
else
render :edit
end
state_was_registered = @volunteer.registered?
return render :edit unless @volunteer.update(volunteer_params)
return invite_volunteer_user if state_was_registered && @volunteer.accepted?
redirect_to @volunteer, notice: t('volunteer_updated')
end
def destroy
......@@ -52,8 +42,11 @@ class VolunteersController < ApplicationController
private
def set_state
@state = @volunteer.state
def invite_volunteer_user
new_user = User.new(email: @volunteer.email, password: Devise.friendly_token, role: 'volunteer')
new_user.save
new_user.invite!
redirect_to volunteers_path, notice: t('invite_sent', email: new_user.email)
end
def set_volunteer
......@@ -61,8 +54,6 @@ class VolunteersController < ApplicationController
authorize @volunteer
end
def volunteer_params
params.require(:volunteer).permit(
volunteer_attributes,
......
class Client < ApplicationRecord
include AssociatableFields
include FullName
include StateCollection
include StateCollection
include GenderCollection
REGISTERED = 'registered'.freeze
RESERVED = 'reserved'.freeze
ACTIVE = 'active'.freeze
FINISHED = 'finished'.freeze
REJECTED = 'rejected'.freeze
STATES = [REGISTERED, RESERVED, ACTIVE, FINISHED, REJECTED].freeze
belongs_to :user
validates :first_name, :last_name, presence: true
validates :state, inclusion: { in: STATES }
def self.state_collection
STATES.map(&:to_sym)
end
end
module StateCollection
extend ActiveSupport::Concern
included do
def self.state_collection
[:registered, :reserved, :active, :finished, :rejected]
end
end
end
......@@ -2,35 +2,47 @@ class Volunteer < ApplicationRecord
include AssociatableFields
include FullName
include GenderCollection
include StateCollection
acts_as_paranoid
belongs_to :user, optional: true
before_save :default_state
has_attached_file :avatar, styles: { thumb: '100x100#' }
REGISTERED = 'registered'.freeze
ACCEPTED = 'accepted'.freeze
REJECTED = 'rejected'.freeze
INACTIVE = 'inactive'.freeze
RESIGNED = 'resigned'.freeze
STATES_FOR_REVIEWED = [ACCEPTED, REJECTED, INACTIVE, RESIGNED].freeze
STATES = [REGISTERED] + STATES_FOR_REVIEWED
validates :first_name, :last_name, :email, presence: true
validates :email, uniqueness: true
belongs_to :user, optional: true
has_attached_file :avatar, styles: { thumb: '100x100#' }
validates :state, inclusion: { in: STATES }
validates_attachment :avatar, content_type: {
content_type: /\Aimage\/.*\z/
}
validates :first_name, :last_name, :email, presence: true
validates :email, uniqueness: true
# Volunteer state definition
INTERESTED = 'interested'.freeze
ACCEPTED = 'accepted'.freeze
REJECTED = 'rejected'.freeze
INACTIVE = 'inactive'.freeze
STATES_FOR_REVIEWED = [ACCEPTED, REJECTED, INACTIVE].freeze
STATES = STATES_FOR_REVIEWED + [INTERESTED]
def self.state_collection
STATES.map(&:to_sym)
end
def interested?
state == Volunteer::INTERESTED
def self.state_collection_for_reviewed
STATES_FOR_REVIEWED.map(&:to_sym)
end
def registered?
state == REGISTERED
end
def accepted?
state == ACCEPTED
end
def rejected?
state == Volunteer::REJECTED
state == REJECTED
end
def self.duration_collection
......@@ -53,14 +65,6 @@ class Volunteer < ApplicationRecord
boolean ? I18n.t('simple_form.yes') : I18n.t('simple_form.no')
end
def self.state_collection
STATES.map(&:to_sym)
end
def self.state_collection_for_reviewed
STATES_FOR_REVIEWED.map(&:to_sym)
end
def self.rejection_collection
[:us, :her, :other]
end
......@@ -68,4 +72,10 @@ class Volunteer < ApplicationRecord
def to_s
full_name
end
private
def default_state
self.state ||= REGISTERED
end
end
......@@ -59,15 +59,10 @@
= f.input :skills
= f.input :interests
- if policy(Volunteer).access_state?
.row
.col-xs-12
= f.input :state, collection: Volunteer.state_collection
- if policy(Volunteer).destroy?
.row
.col-xs-12
= f.input :state, collection: Volunteer.state_collection_for_reviewed
= f.input :state, collection: Volunteer.state_collection, default: :registered
.col-xs-12
= f.input :rejection_type, collection: Volunteer.rejection_collection, as: :radio_buttons
.col-xs-12
......
......@@ -4,7 +4,7 @@ tr
td = country(volunteer.nationality) if volunteer.nationality.present?
td = l(volunteer.created_at)
td = t("gender.#{volunteer.gender}") unless volunteer.gender.blank?
td = t("simple_form.options.volunteer.state.#{volunteer.state}")
td = t("state.#{volunteer.state}", scope: [:simple_form, :options, :volunteer])
td = link_to t_action(:show), volunteer
td = link_to t_action(:edit), edit_volunteer_path(volunteer)
td = link_to t_action(:destroy), volunteer, data: { confirm: t_confirm_delete(volunteer) }, method: :delete
.row
.col-xs-12
h1= t_title(:new)
h1= t_title(:new)
= simple_form_for(@volunteer, url: volunteers_path) do |f|
= render 'volunteers/form', f: f
......
......@@ -64,7 +64,7 @@ h1= @volunteer.full_name
- if policy(Volunteer).destroy?
tr
td= t_attr(:state)
td= t("simple_form.options.volunteer.state.#{@volunteer.state}")
td= t("state.#{@volunteer.state}", scope: [:simple_form, :options, :volunteer])
- if @volunteer.rejected?
tr
td= t_attr(:rejection_type)
......
......@@ -270,7 +270,7 @@ de:
send_instructions: Sie erhalten in wenigen Minuten eine Email mit der Anleitung, wie Sie Ihren Account entsperren können.
send_paranoid_instructions: Falls Ihre Mailadresse in unserer Datenbank existiert erhalten Sie in wenigen Minuten eine Email mit der Anleitung, wie Sie Ihren Account entsperren können.
unlocked: Ihr Account wurde entsperrt. Sie sind jetzt angemeldet.
duration:
duration: &id-durations
long: Längerfristig (min 6 Mt.)
short: Kurzfristig
edit_login: Login bearbeiten
......@@ -287,7 +287,7 @@ de:
one: 'Konnte %{resource} nicht speichern: ein Fehler.'
other: 'Konnte %{resource} nicht speichern: %{count} Fehler.'
forgot_password: Passwort vergessen?
gender:
gender: &id-genders
female: Weiblich
male: Männlich
get_back: Wir werden uns bald bei Ihnen melden.
......@@ -303,7 +303,7 @@ de:
create: Benutzer erstellen
update: Login aktualisieren
invite_sent: 'Einladung wurde an %{email} verschickt.'
language_level:
language_level: &id-lang-levels
basic: Grundlagen
fluent: Fliessend
good: Gut
......@@ -316,12 +316,12 @@ de:
personal_background: Persönlicher Hintergrund
profile_created: Profil wurde erfolgreich erstellt.
profile_updated: Profil wurde erfolgreich aktualisiert.
region:
region: &id-regions
canton: Kanton
city: Stadt
region: Region
registered_by: SozialberaterIn
rejection_type:
rejection_type: &id-rejection-types
her: von Freiwillige vor / nach Erstgespräch
other: Anderer Grund
us: durch uns vor / nach Gespräch
......@@ -329,7 +329,7 @@ de:
remember_me: Angemeldet bleiben
remove_language: Sprache entfernen
remove_relative: Verwandte entfernen
role:
role: &id-roles
department_manager: Standortverantwortliche/er
social_worker: SozialarbeiterIn
superadmin: Superadmin
......@@ -366,73 +366,43 @@ de:
"no": 'Nein'
options:
client:
gender:
female: Weiblich
male: Männlich
gender: *id-genders
language_skills:
level:
basic: Grundlagen
fluent: Fliessend
good: Gut
native_speaker: Muttersprachler
level: *id-lang-levels
point_of_contact:
label:
email: Mailadresse
fax: Faxnummer
phone: Telefonnummer
state:
state: &id-states
accepted: Akzeptiert
active: Aktiv
all: Alle
finished: Abgeschlossen
inactive: Inaktiv
interested: Interessiert
registered: Registriert
rejected: Abgelehnt
reserved: Reserviert
resigned: Abgemeldet
user:
role:
department_manager: Standort Verantwortliche/r
social_worker: SozialarbeiterIn
superadmin: Superadmin
role: *id-roles
volunteer:
duration:
long: Längerfristig (min 6 Mt.)
short: Kurzfristig
gender:
female: Weiblich
male: Mänlich
duration: *id-durations
gender: *id-genders
language_skills:
level:
basic: Grundlagen
fluent: Fliessend
good: Gut
native_speaker: Muttersprachler
region:
canton: Kanton
city: Stadt
region: Region
rejection_type:
her: von Freiwillige vor / nach Erstgespräch
other: Anderer Grund
us: durch uns vor / nach Gespräch
level: *id-lang-levels
region: *id-regions
rejection_type: *id-rejection-types
state:
active: aktiv / im Einsatz
all: Alle
finished: ausgetreten
registered: interessiert / angemeldet
rejected: Absage
reserved: kontaktiert / für Gespräch eingeladen
<<: *id-states
registered: Interessiert
placeholders:
required:
mark: '*'
text: notwendig
"yes": 'Ja'
state:
accepted: Akzeptiert
active: Aktiv
finished: Abgeschlossen
inactive: Inaktiv
interested: Interessiert
registered: Registriert
rejected: Abgelehnt
reserved: Reserviert
state: *id-states
submit_application: Bewerbung abschicken
target_groups: Zielgruppe
thank_you: "Vielen Dank \U0001F389"
......
......@@ -165,7 +165,7 @@ en:
one: '1 error prohibited this %{resource} from being saved:'
other: '%{count} errors prohibited this %{resource} from being saved:'
forgot_password: Forgot your password?
gender:
gender: &id-genders
female: female
male: male
get_back: We will soon get back to you.
......@@ -181,7 +181,7 @@ en:
create: Create User
update: Update login
invite_sent: 'Invitation sent to %{email}'
language_level:
language_level: &id-lang-levels
basic: Basic
fluent: Fluent
good: Good
......@@ -197,12 +197,12 @@ en:
personal_background: Personal background
profile_created: Profile was successfully created.
profile_updated: Profile was successfully updated.
region:
region: &id-regions
canton: Canton
city: City
region: Region
registered_by: Responsible Volunteer
rejection_type:
rejection_type: &id-rejection-types
her: by volunteer before / after the first call
other: Other
us: by us before / after conversation
......@@ -210,7 +210,7 @@ en:
remember_me: Remember me
remove_language: Remove language
remove_relative: Remove family member
role:
role: &id-roles
department_manager: Department manager
social_worker: Social worker
superadmin: Superadmin
......@@ -233,68 +233,40 @@ en:
"no": 'No'
options:
client:
gender:
female: Female
male: Male
gender: *id-genders
language_skills:
level:
basic: Basic
fluent: Fluent
good: Good
native_speaker: Native speaker
state:
level: *id-lang-levels
state: &id-states
accepted: Accepted
active: Active
all: All
finished: Finished
inactive: Inactive
interested: Interested
registered: Registered
rejected: Rejected
reserved: Reserved
resigned: Resigned
user:
role:
department_manager: Departement manager
social_worker: Social worker
superadmin: Superadmin
role: *id-roles
volunteer:
duration:
long: Long term (min 6 months)
short: Short term
gender:
female: Female
male: Male
gender: *id-genders
language_skills:
level:
basic: Basic
fluent: Fluent
good: Good
native_speaker: Native speaker
region:
canton: Canton
city: City
region: Region
rejection_type:
her: by volunteer before / after the first call
other: Other
us: by us before / after conversation
level: *id-lang-levels
region: *id-regions
rejection_type: *id-rejection-types
state:
active: active / participating
all: All
finished: resigned
registered: intrested / registered
rejected: rejected
reserved: contacted / invited to meeting
<<: *id-states
registered: Interested
placeholders:
required:
mark: '*'
text: 'required'
"yes": 'Yes'
state:
accepted: Accepted
active: Active
finished: Finished
inactive: Inactive
interested: Interested
registered: Registered
rejected: Rejected
reserved: Reserved
state: *id-states
submit_application: Submit application
target_groups: Target groups
thank_you: "Thank you \U0001F389"
......
......@@ -9,6 +9,18 @@ def random_relation
].sample
end
def make_person_data(subject)
subject.first_name = Faker::Name.first_name
subject.last_name = Faker::Name.last_name
subject.date_of_birth = Faker::Date.birthday(18, 75)
subject.zip = Faker::Address.zip_code
subject.city = Faker::Address.city
subject.street = Faker::Address.street_address
subject.email = Faker::Internet.email
subject.phone = Faker::PhoneNumber.phone_number
subject.gender = ['male', 'female'].sample
end
def make_relatives
Array.new(2).map do
Relative.new do |relative|
......@@ -58,10 +70,7 @@ User.where(role: ['superadmin', 'social_worker']).each do |user|
next if user.clients.count > 1
user.clients = Array.new(4).map do
Client.new do |client|
client.first_name = Faker::Name.first_name
client.last_name = Faker::Name.last_name
client.date_of_birth = Faker::Date.birthday(18, 65)
client.gender = ['male', 'female'].sample
make_person_data(client)
client.nationality = ISO3166::Country.codes.sample
client.email = Faker::Internet.unique.email
client.relatives = make_relatives
......@@ -97,18 +106,10 @@ if Department.count < 1
department.save!
end
Volunteer.state_collection_for_reviewed.each do |state|
Volunteer.state_collection.each do |state|
Volunteer.find_or_create_by!(email: "volunteer_#{state}@example.com", state: state) do |v|
v.first_name = Faker::Name.first_name
v.last_name = Faker::Name.last_name
v.date_of_birth = Faker::Date.birthday(18, 75)
v.zip = Faker::Address.zip_code
v.city = Faker::Address.city
v.street = Faker::Address.street_address
v.email = Faker::Internet.email
v.phone = Faker::PhoneNumber.phone_number
make_person_data(v)
v.profession = Faker::Company.profession
v.gender = ['male', 'female'].sample
[:experience, :man, :woman, :family, :kid, :sport, :creative, :music,
:culture, :training, :german_course, :adults, :teenagers, :children].each do |bool_attr|
v[bool_attr] = [true, false].sample
......
......@@ -3,7 +3,7 @@ FactoryGirl.define do
sequence :first_name { |n| "First#{n}" }
sequence :last_name { |n| "Volunteer#{n}" }
sequence :email { |n| "volunteer#{n}@example.com" }
state :state
state 'registered'
sequence :gender { [:male, :female].sample }
sequence :nationality { ISO3166::Country.codes.sample }
trait :with_relatives do
......
......@@ -85,10 +85,10 @@ class UsersTest < ApplicationSystemTestCase
select('Accepted', from: 'State')
assert_difference 'User.count', 1 do
click_button 'Update Volunteer'
assert page.has_text? 'Invitation sent to volunteer@example.com'
end
assert page.has_text? "Invitation sent to #{volunteer.email}"
assert_equal 1, ActionMailer::Base.deliveries.size
email = ActionMailer::Base.deliveries.last
assert_equal 'volunteer@example.com', email['to'].to_s
assert_equal volunteer.email, email['to'].to_s
end
end
......@@ -4,7 +4,7 @@ class VolunteersTest < ApplicationSystemTestCase
setup do
@user = create :user, :with_profile, email: 'superadmin@example.com'
login_as @user
[:registered, :reserved, :active, :finished, :rejected].each do |s|
Volunteer.state_collection.each do |s|
create :volunteer, state: s.to_s
end
end
......@@ -37,8 +37,8 @@ class VolunteersTest < ApplicationSystemTestCase
fill_in 'Education', with: 'CEID'
fill_in 'What is your motivation to volunteer with migrants?', with: 'asfd'
page.check('volunteer_experience')
fill_in 'What do you expect from a person who would accompany you / your volunteer work?', with: 'asdf'
fill_in 'Where do you see your strengths? (Social competencies that you could contribute to voluntary work)', with: 'asdf'
fill_in 'What do you expect from a person who would accompany you', with: 'asdf'
fill_in 'Where do you see your strengths?', with: 'asdf'
fill_in 'Professional skills that you could bring?', with: 'asdf'
fill_in 'What are your most important leisure interests?', with: 'asdf'
page.choose('volunteer_duration_short')
......@@ -91,34 +91,26 @@ class VolunteersTest < ApplicationSystemTestCase
assert page.has_content? 'Explanation for rejection'
end