Skip to content
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

Merged

Conversation

dariusf
Copy link
Contributor

@dariusf dariusf commented Jul 14, 2015

Depends on #416.

  • Achievements page now shows requirements
  • Front- and back-end validations for achievement conditions, and related specs

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 >" \

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.

@dariusf dariusf force-pushed the dariusf/condition-refinements branch from b6ff773 to e237ff3 Compare July 14, 2015 08:01
_, 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 >" \

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.

@dariusf dariusf force-pushed the dariusf/condition-refinements branch 3 times, most recently from 5618100 to 3be3d55 Compare July 14, 2015 10:07

let!(:instance) { create(:instance) }
with_tenant(:instance) do

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.

@dariusf dariusf force-pushed the dariusf/condition-refinements branch 3 times, most recently from 156181d to fd618c5 Compare July 14, 2015 10:18
# 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.'
Copy link
Contributor Author

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?

Copy link
Member

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?

@lowjoel
Copy link
Member

lowjoel commented Jul 15, 2015

I'll review this again after #416 is merged.

@dariusf dariusf force-pushed the dariusf/condition-refinements branch 2 times, most recently from 2779f6a to 92ed2de Compare July 15, 2015 07:23
# @param [Course::Achievement] conditional The conditional for which to return conditions.
# @return [Array<Course::Achievement>]
def valid_achievement_conditions(conditional)
Course::Achievement.all -
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

course.achievements

@dariusf dariusf force-pushed the dariusf/condition-refinements branch from 92ed2de to 0e3ebe8 Compare July 15, 2015 09:51
@@ -69,33 +69,60 @@
end

scenario 'I can create an achievement condition' do

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.

@dariusf dariusf force-pushed the dariusf/condition-refinements branch 2 times, most recently from 29078b1 to cf09820 Compare July 28, 2015 12:03
# where { condition.conditional.id == achievement.id }.
# map(&:achievement)

# Workaround, pending the squeel bugfix (activerecord-hackery/squeel#390) that will allow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work!

@lowjoel
Copy link
Member

lowjoel commented Jul 29, 2015

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
@dariusf dariusf force-pushed the dariusf/condition-refinements branch from cf09820 to ec95034 Compare July 29, 2015 08:11
@@ -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?
Copy link
Member

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?

Copy link
Contributor Author

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).

Copy link
Member

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.
@dariusf dariusf force-pushed the dariusf/condition-refinements branch from ec95034 to 61e751d Compare July 29, 2015 09:45
lowjoel added a commit that referenced this pull request Jul 29, 2015
…finements

Achievement condition validations
@lowjoel lowjoel merged commit 977cb77 into Coursemology:master Jul 29, 2015
@dariusf dariusf deleted the dariusf/condition-refinements branch October 20, 2015 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants