Created
November 11, 2012 15:42
-
-
Save benjaminvialle/4055262 to your computer and use it in GitHub Desktop.
Diff from RB for issue 474
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/assignment.rb b/app/models/assignment.rb | |
--- a/app/models/assignment.rb | |
+++ b/app/models/assignment.rb | |
@@ -68,7 +68,11 @@ class Assignment < ActiveRecord::Base | |
validates_inclusion_of :assign_graders_to_criteria, :in => [true, false] | |
before_save :reset_collection_time | |
- validate :minimum_number_of_groups, :check_timezone | |
+ validate :minimum_number_of_groups | |
+ # Call custom validator in order to validate the :due_date attribute | |
+ # :date => true maps to DateValidator (:custom_name => true maps to CustomNameValidator) | |
+ # Look in lib/validators/* for more info | |
+ validates :due_date, :date => true | |
after_save :update_assigned_tokens | |
# Export a YAML formatted string created from the assignment rubric criteria. | |
@@ -111,13 +115,6 @@ class Assignment < ActiveRecord::Base | |
end | |
end | |
- def check_timezone | |
- if Time.zone.parse(due_date.to_s).nil? | |
- errors.add :due_date, 'is not a valid date' | |
- return false | |
- end | |
- end | |
- | |
# Are we past all the due dates for this assignment? | |
def past_due_date? | |
# If no section due dates | |
diff --git a/app/models/grade_entry_form.rb b/app/models/grade_entry_form.rb | |
--- a/app/models/grade_entry_form.rb | |
+++ b/app/models/grade_entry_form.rb | |
@@ -9,7 +9,11 @@ class GradeEntryForm < ActiveRecord::Base | |
has_many :grade_entry_items, :dependent => :destroy | |
has_many :grade_entry_students, :dependent => :destroy | |
has_many :grades, :through => :grade_entry_items | |
- validate :check_timezone | |
+ | |
+ # Call custom validator in order to validate the date attribute | |
+ # :date => true maps to DateValidator (:custom_name => true maps to CustomNameValidator) | |
+ # Look in lib/validators/* for more info | |
+ validates :date, :date => true | |
validates_presence_of :short_identifier | |
validates_uniqueness_of :short_identifier, :case_sensitive => true | |
@@ -18,14 +22,6 @@ class GradeEntryForm < ActiveRecord::Base | |
BLANK_MARK = "" | |
- def check_timezone | |
- # Check that the date is valid - the date is allowed to be in the past | |
- if Time.zone.parse(date.to_s).nil? | |
- errors.add :date, I18n.t('grade_entry_forms.invalid_date') | |
- return false | |
- end | |
- end | |
- | |
# The total number of marks for this grade entry form | |
def out_of_total | |
return grade_entry_items.sum('out_of').round(2) | |
diff --git a/config/application.rb b/config/application.rb | |
--- a/config/application.rb | |
+++ b/config/application.rb | |
@@ -44,6 +44,7 @@ module Markus | |
app/controllers/api | |
lib | |
lib/classes | |
+ lib/validators | |
) | |
# Load any local configuration that is kept out of source control | |
# (e.g. gems, patches). | |
diff --git a/config/locales/en.yml b/config/locales/en.yml | |
--- a/config/locales/en.yml | |
+++ b/config/locales/en.yml | |
@@ -1122,6 +1122,10 @@ en: | |
#app/views/main/_grade_distribution_graph.html.erb | |
grade_distribution: "Grade Distribution" | |
+ #lib/validators/ | |
+ date_validator: | |
+ invalid_date: "is not a valid date" | |
+ | |
#Test Framework | |
automated_tests: | |
automated_tests: "Test Framework" | |
diff --git a/config/locales/fr.yml b/config/locales/fr.yml | |
--- a/config/locales/fr.yml | |
+++ b/config/locales/fr.yml | |
@@ -1093,6 +1093,10 @@ fr: | |
#app/views/main/_grade_distribution_graph.html.erb | |
grade_distribution: "Répartition des notes" | |
+ #lib/validators/ | |
+ date_validator: | |
+ invalid_date: "n'est pas une date valide" | |
+ | |
#Test Framework | |
automated_tests: | |
automated_tests: "Tests" | |
diff --git a/lib/validators/date_validator.rb b/lib/validators/date_validator.rb | |
--- /dev/null | |
+++ b/lib/validators/date_validator.rb | |
@@ -0,0 +1,8 @@ | |
+class DateValidator < ActiveModel::EachValidator | |
+ def validate_each(record, attribute, value) | |
+ if Time.zone.parse(value.to_s).nil? | |
+ record.errors.add attribute, I18n.t('date_validator.invalid_date') | |
+ return false | |
+ end | |
+ end | |
+end | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment