Skip to content

Commit

Permalink
Improve namings for achievement condition's validation
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtule committed Dec 17, 2015
1 parent e955ff4 commit c277052
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/course/condition/achievement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def satisfied_by?(course_user)

private

# Given an achievement, returns all its achievement conditions.
# Given a conditional object, returns all achievements that it requires.
#
# @param [Course::Achievement] achievement The achievement to return achievement conditions for.
# @param [Object] conditional The conditional object for which returned achievements are required.
# @return [Array<Course::Achievement>]
def achievement_conditions(achievement)
def required_achievements_for(conditional)
# Course::Condition::Achievement.
# joins { condition.conditional(Course::Achievement) }.
# where { condition.conditional.id == achievement.id }.
Expand All @@ -37,7 +37,7 @@ def achievement_conditions(achievement)
(SELECT cca.achievement_id
FROM course_condition_achievements cca INNER JOIN course_conditions cc
ON cc.actable_type = 'Course::Condition::Achievement' AND cc.actable_id = cca.id
WHERE cc.conditional_id = #{achievement.id}) ids
WHERE cc.conditional_id = #{conditional.id}) ids
ON ids.achievement_id = course_achievements.id")
end

Expand All @@ -52,7 +52,7 @@ def validate_references_self
end

def validate_unique_dependency
return unless achievement_conditions(conditional).include?(achievement)
return unless required_achievements_for(conditional).include?(achievement)
errors.add(:achievement, :unique_dependency)
end
end

0 comments on commit c277052

Please sign in to comment.