adds resolution to spending proposals

This commit is contained in:
Juanjo Bazán
2016-01-07 14:56:02 +01:00
parent b3677fc044
commit facf6183d7
4 changed files with 31 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ class SpendingProposal < ActiveRecord::Base
apply_simple_captcha
RESOLUTIONS = ["accepted", "rejected"]
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :geozone
@@ -13,6 +15,14 @@ class SpendingProposal < ActiveRecord::Base
validates :title, length: { in: 4..SpendingProposal.title_max_length }
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :resolution, inclusion: { in: RESOLUTIONS, allow_nil: true }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
def accept
update_attribute(:resolution, "accepted")
end
def reject
update_attribute(:resolution, "rejected")
end
end

View File

@@ -0,0 +1,6 @@
class AddResolutionToSpendingProposals < ActiveRecord::Migration
def change
add_column :spending_proposals, :resolution, :string, default: nil
add_index :spending_proposals, :resolution
end
end

View File

@@ -289,10 +289,12 @@ ActiveRecord::Schema.define(version: 20160108133501) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "geozone_id"
t.string "resolution"
end
add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree
add_index "spending_proposals", ["geozone_id"], name: "index_spending_proposals_on_geozone_id", using: :btree
add_index "spending_proposals", ["resolution"], name: "index_spending_proposals_on_resolution", using: :btree
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"

View File

@@ -41,4 +41,16 @@ describe SpendingProposal do
expect(spending_proposal).to_not be_valid
end
end
describe "resolution status" do
it "can be accepted" do
spending_proposal.accept
expect(spending_proposal.reload.resolution).to eq("accepted")
end
it "can be rejected" do
spending_proposal.reject
expect(spending_proposal.reload.resolution).to eq("rejected")
end
end
end