Commit 3d090c903262f45010fd9fd33c3ba282e8f45385
Committed by
Victor Costa
1 parent
b963a3fc
Exists in
master
Limit max length of proposal's abstract
Showing
2 changed files
with
39 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +require_relative '../../../proposals_discussion/lib/proposals_discussion_plugin/proposal.rb' | |
| 2 | + | |
| 3 | +class ProposalsDiscussionPlugin::Proposal < TinyMceArticle | |
| 4 | + validate :abstract_max_length | |
| 5 | + | |
| 6 | + def abstract_max_length | |
| 7 | + if abstract.size > 200 and environment.plugin_enabled? "Dialoga" | |
| 8 | + errors.add(:proposal, "Proposal must be no longer than 200 characters") | |
| 9 | + end | |
| 10 | + end | |
| 11 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +require_relative '../test_helper' | |
| 2 | + | |
| 3 | +class ProposalTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @profile = fast_create(Community) | |
| 7 | + @person = fast_create(Person) | |
| 8 | + @discussion = ProposalsDiscussionPlugin::Discussion.create!(:name => 'discussion', :profile => person, :allow_topics => false) | |
| 9 | + @proposal = ProposalsDiscussionPlugin::Proposal.new(:name => 'test', :abstract => 'abstract', :profile => @profile, :parent => @discussion) | |
| 10 | + @proposal.created_by = @person | |
| 11 | + end | |
| 12 | + | |
| 13 | + attr_reader :profile, :proposal, :person, :discussion | |
| 14 | + | |
| 15 | + should 'should not save a proposal with an abstract > 200 chars' do | |
| 16 | + proposal.abstract = 201.times.map{'B'}.join | |
| 17 | + refute proposal.valid? | |
| 18 | + refute proposal.save | |
| 19 | + end | |
| 20 | + | |
| 21 | + should 'should save a proposal with abstract <= 200 chars' do | |
| 22 | + proposal.abstract = 200.times.map{'B'}.join | |
| 23 | + assert proposal.valid? | |
| 24 | + assert proposal.save | |
| 25 | + end | |
| 26 | + | |
| 27 | + | |
| 28 | +end | ... | ... |