Skip to content

Commit

Permalink
Include name of missing profile fields when checking reimbursements
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Aug 25, 2014
1 parent 8caf144 commit 5c4bb0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions app/models/reimbursement.rb
Expand Up @@ -184,8 +184,9 @@ def ensure_bank_account

# Validates the existance of a complete profile
def user_profile_is_complete
unless user.profile.complete?
errors.add(:user, :incomplete)
fields = user.profile.missing_fields
unless fields.empty?
errors.add(:user, :incomplete, :fields => fields.values.to_sentence )
end
end

Expand Down
18 changes: 8 additions & 10 deletions app/models/user_profile.rb
Expand Up @@ -70,18 +70,16 @@ def have_editable?(attrib)
not UserProfile::FROM_OPENSUSE_CONNECT.keys.include?(attrib.to_sym)
end

# Checks whether all the fields that are required for processing
# reimbursements are present. The list of fields is set as a configuration
# parameter for the application.
# List of fields that are required for processing reimbursements but are
# not present. The list of fields is set as a configuration parameter for
# the application.
#
# @return [Boolean] true unless some of the required attributes is missing
def complete?
# @return [Hash] hash with the name of the fields as keys and its
# human-readable names as values
def missing_fields
fields = TravelSupport::Config.setting(:relevant_profile_fields)
return true if fields.blank?
fields.each do |f|
return false if send(f.to_sym).blank?
end
true
fields = fields.select {|f| send(f.to_sym).blank? }
Hash[fields.map {|f| [f, self.class.human_attribute_name(f)] }]
end

protected
Expand Down
2 changes: 1 addition & 1 deletion config/locales/models.en.yml
Expand Up @@ -27,7 +27,7 @@ en:
reimbursement:
attributes:
user:
incomplete: "important information is missing in the user's profile"
incomplete: "the following fields are missing in the user's profile: %{fields}"
expenses:
invalid: "are missing or invalid (some required field is probably blank in some of the expenses)"
state_adjustment:
Expand Down

0 comments on commit 5c4bb0a

Please sign in to comment.