adds code to proposals

This commit is contained in:
Juanjo Bazán
2015-09-12 13:14:59 +02:00
parent 3889184432
commit e407173e4b
2 changed files with 10 additions and 0 deletions

View File

@@ -74,6 +74,10 @@ class Proposal < ActiveRecord::Base
user.level_two_verified? || !user.voted_for?(self)
end
def code
"#{Setting.value_for("proposal_code_prefix")}-#{created_at.strftime('%Y-%M')}-#{id}"
end
protected
def sanitize_description

View File

@@ -46,6 +46,12 @@ describe Proposal do
expect(proposal).to_not be_valid
end
it "should have a code" do
Setting.find_by(key: "proposal_code_prefix").update(value: "TEST")
proposal = create(:proposal)
expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime('%Y-%M')}-#{proposal.id}"
end
describe "#editable?" do
let(:proposal) { create(:proposal) }
before(:each) {Setting.find_by(key: "max_votes_for_proposal_edit").update(value: 100)}