Merge Request #1
← To merge requests
From
limit_200_chars_abstract
into
master
Limit 200 chars abstract
Issue 5 limitar proposta para 200 caracteres
Commits (2)
Showing
2 changed files
Show diff stats
| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | +require_relative '../../../proposals_discussion/lib/proposals_discussion_plugin/proposal.rb' | |
| 2 | + | |
| 3 | +class ProposalsDiscussionPlugin::Proposal | |
| 4 | + | |
| 5 | + validates :abstract, length: {maximum: 200}, if: proc { |a| a.environment.plugin_enabled?(DialogaPlugin)} | |
| 6 | + | |
| 7 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,38 @@ |
| 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 | + @environment = Environment.default | |
| 12 | + environment.enable_plugin(DialogaPlugin) | |
| 13 | + end | |
| 14 | + | |
| 15 | + attr_reader :profile, :proposal, :person, :discussion, :environment | |
| 16 | + | |
| 17 | + should 'should not save a proposal with an abstract greater than 200 chars' do | |
| 18 | + proposal.abstract = 201.times.map{'B'}.join | |
| 19 | + refute proposal.valid? | |
| 20 | + refute proposal.save | |
| 21 | + assert proposal.errors[:abstract].present? | |
| 22 | + end | |
| 23 | + | |
| 24 | + should 'should save a proposal with an abstract greater than 200 chars and dialoga plugin is not enabled' do | |
| 25 | + environment.disable_plugin(DialogaPlugin) | |
| 26 | + proposal.abstract = 201.times.map{'B'}.join | |
| 27 | + assert proposal.valid? | |
| 28 | + assert proposal.save | |
| 29 | + end | |
| 30 | + | |
| 31 | + should 'should save a proposal with an abstract not greater than 200 chars' do | |
| 32 | + proposal.abstract = 200.times.map{'B'}.join | |
| 33 | + assert proposal.valid? | |
| 34 | + assert proposal.save | |
| 35 | + end | |
| 36 | + | |
| 37 | + | |
| 38 | +end | ... | ... |
-
mentioned in commit a068a1a80b97e5c47a48b1385d3917cbf855874d