Commit e9b19a7a773bbcd57b4ce2a6e2a0a5d8928ddfe5
1 parent
c5fe417b
Exists in
master
and in
29 other branches
Validates period range
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
plugins/custom_forms/lib/custom_forms_plugin/form.rb
... | ... | @@ -10,6 +10,7 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
10 | 10 | |
11 | 11 | validates_presence_of :profile, :name |
12 | 12 | validates_uniqueness_of :slug, :scope => :profile_id |
13 | + validate :period_range, :if => Proc.new { |f| f.begining.present? && f.ending.present? } | |
13 | 14 | validate :access_format |
14 | 15 | |
15 | 16 | before_validation do |form| |
... | ... | @@ -75,4 +76,8 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
75 | 76 | end |
76 | 77 | end |
77 | 78 | end |
79 | + | |
80 | + def period_range | |
81 | + errors.add(:base, _('The time range selected is invalid.')) if ending < begining | |
82 | + end | |
78 | 83 | end | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
... | ... | @@ -53,6 +53,20 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
53 | 53 | assert !form.errors.invalid?(:slug) |
54 | 54 | end |
55 | 55 | |
56 | + should 'validate the difference between ending and beginning is positive' do | |
57 | + profile = fast_create(Profile) | |
58 | + form = CustomFormsPlugin::Form.new(:profile => profile, :name => 'Free Software') | |
59 | + | |
60 | + form.begining = Time.now | |
61 | + form.ending = Time.now + 1.day | |
62 | + assert form.valid? | |
63 | + assert !form.errors.invalid?(:base) | |
64 | + | |
65 | + form.ending = Time.now - 2.day | |
66 | + assert !form.valid? | |
67 | + assert form.errors.invalid?(:base) | |
68 | + end | |
69 | + | |
56 | 70 | should 'define form expiration' do |
57 | 71 | form = CustomFormsPlugin::Form.new |
58 | 72 | assert !form.expired? | ... | ... |