-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Achievement condition validations #425
Achievement condition validations #425
Conversation
click_link I18n.t('course.condition.achievements.new.header') | ||
expect(page).not_to have_selector("#condition_achievement_achievement_id >" \ | ||
"option[value='#{other_achievement.id}']") | ||
expect(page).not_to have_selector("#condition_achievement_achievement_id >" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
b6ff773
to
e237ff3
Compare
_, achievement, other_achievement = create_achievement_condition | ||
visit edit_course_achievement_path(course, achievement) | ||
click_link I18n.t('course.condition.achievements.new.header') | ||
expect(page).not_to have_selector("#condition_achievement_achievement_id >" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
5618100
to
3be3d55
Compare
|
||
let!(:instance) { create(:instance) } | ||
with_tenant(:instance) do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at block body beginning.
156181d
to
fd618c5
Compare
# A human-readable name for each condition; usually just wraps a title | ||
# or name field. Meant to be used in a polymorphic manner for views. | ||
def name | ||
fail 'To be implemented by each condition.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we test this line? All models which declare acts_as_condition
and override this method are covered. Do we include this module in a dummy object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I told @minhtule to remove that line because it's no different from not defining the method. but there needs to be a place to put this info.
Yes, the most straightforward way is to include this in a class and not override the method.
By the way -- should this raise a NotImplementedError?
I'll review this again after #416 is merged. |
2779f6a
to
92ed2de
Compare
# @param [Course::Achievement] conditional The conditional for which to return conditions. | ||
# @return [Array<Course::Achievement>] | ||
def valid_achievement_conditions(conditional) | ||
Course::Achievement.all - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
course.achievements
92ed2de
to
0e3ebe8
Compare
@@ -69,33 +69,60 @@ | |||
end | |||
|
|||
scenario 'I can create an achievement condition' do | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at block body beginning.
29078b1
to
cf09820
Compare
# where { condition.conditional.id == achievement.id }. | ||
# map(&:achievement) | ||
|
||
# Workaround, pending the squeel bugfix (activerecord-hackery/squeel#390) that will allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome work!
Sorry, another batch... now that I've sat down and tried out the i18n framework myself. |
Added missing table headers Published status was shown regardless of ability to manage achievements
For use in polymorphic contexts where all require is the human-readable anme of the condition
cf09820
to
ec95034
Compare
@@ -3,4 +3,46 @@ class Course::Condition::Achievement < ActiveRecord::Base | |||
belongs_to :achievement, class_name: Course::Achievement.name, inverse_of: false | |||
|
|||
default_scope { includes(:achievement) } | |||
|
|||
validate :validate_achievement_condition, if: :achievement_id_changed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so did you check whether achievement_changed? is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Wrote a reply but it seems to have disappeared...)
In general it's better because it checks the validity of the association and not just the presence of the key, but in this case it's equivalent, because the id will always point to an existing achievement with a valid id; no achievement is being created.
Also, _changed?
methods are only provided for actual attributes, so there is no achievement_changed?
by default (in contrast, you can do stuff like validates :achievement, presence: true
on the association).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, great.
This ensures that there cannot be duplicate or self-referential achievement conditions
Conditions must be associated with a conditional. Achievement conditions must be associated with an achievement.
It fails FactoryGirl linting because it doesn't declare the now non-null `conditional` association. Since it cannot be directly instantiated, and the factories for things which act_as conditions do declare `conditional`, it isn't needed.
ec95034
to
61e751d
Compare
…finements Achievement condition validations
Depends on #416.