diff --git a/lib/ext/proposal.rb b/lib/ext/proposal.rb new file mode 100644 index 0000000..8635c8b --- /dev/null +++ b/lib/ext/proposal.rb @@ -0,0 +1,11 @@ +require_relative '../../../proposals_discussion/lib/proposals_discussion_plugin/proposal.rb' + +class ProposalsDiscussionPlugin::Proposal < TinyMceArticle + validate :abstract_max_length + + def abstract_max_length + if abstract.size > 200 and environment.plugin_enabled? "Dialoga" + errors.add(:proposal, "Proposal must be no longer than 200 characters") + end + end +end diff --git a/test/unit/proposal_test.rb b/test/unit/proposal_test.rb new file mode 100644 index 0000000..a6b0555 --- /dev/null +++ b/test/unit/proposal_test.rb @@ -0,0 +1,28 @@ +require_relative '../test_helper' + +class ProposalTest < ActiveSupport::TestCase + + def setup + @profile = fast_create(Community) + @person = fast_create(Person) + @discussion = ProposalsDiscussionPlugin::Discussion.create!(:name => 'discussion', :profile => person, :allow_topics => false) + @proposal = ProposalsDiscussionPlugin::Proposal.new(:name => 'test', :abstract => 'abstract', :profile => @profile, :parent => @discussion) + @proposal.created_by = @person + end + + attr_reader :profile, :proposal, :person, :discussion + + should 'should not save a proposal with an abstract > 200 chars' do + proposal.abstract = 201.times.map{'B'}.join + refute proposal.valid? + refute proposal.save + end + + should 'should save a proposal with abstract <= 200 chars' do + proposal.abstract = 200.times.map{'B'}.join + assert proposal.valid? + assert proposal.save + end + + +end -- libgit2 0.21.2