Skip to content
Browse files

Ability for administrator to change idea's state.

  • Loading branch information...
1 parent a31edba commit d5fe174d4f0d99fc5fb3d66974720754e33de491 @arttu arttu committed Apr 4, 2012
Showing with 16 additions and 2 deletions.
  1. +4 −1 app/models/idea.rb
  2. +2 −1 app/views/admin/ideas/_form.html.haml
  3. +4 −0 config/locales/fi.yml
  4. +6 −0 spec/models/idea_spec.rb
View
5 app/models/idea.rb
@@ -3,12 +3,14 @@ class Idea < ActiveRecord::Base
include Changelogger
extend FriendlyId
+ VALID_STATES = %w(idea draft proposal law)
+
MAX_FB_TITLE_LENGTH = 100
MAX_FB_DESCRIPTION_LENGTH = 500
friendly_id :title, use: :slugged
- attr_accessible :title, :body, :summary
+ attr_accessible :title, :body, :summary, :state
has_many :comments, as: :commentable
has_many :votes
@@ -20,6 +22,7 @@ class Idea < ActiveRecord::Base
validates :author_id, presence: true
validates :title, length: { minimum: 5, message: "Otsikko on liian lyhyt." }
validates :body, length: { minimum: 5, message: "Kuvaa ideasi hieman tarkemmin." }
+ validates :state, inclusion: { in: VALID_STATES }
default_scope order("created_at DESC")
View
3 app/views/admin/ideas/_form.html.haml
@@ -20,7 +20,8 @@
Anna halutessasi idealle tarkempi kuvaus. Se voi sisältää linkkejä muihin lähteisiin,
listauksia puolesta ja vastaan argumenteista ja kysymyksiä joihin toivot kommentoijilta ja
asiantuntijoilta palautetta. Aluksi sinun ei tarvite täyttää tätä kohtaa, pääset muokkaamaan tietoja myöhemmin.
-
+ .grid_16
+ = f.input :state, collection: Idea::VALID_STATES
.grid_16
= f.submit @idea.new_record? ? I18n.t("buttons.create") : I18n.t("buttons.update")
View
4 config/locales/fi.yml
@@ -35,6 +35,10 @@ fi:
recommendation: "Suositus"
errors:
models:
+ idea:
+ attributes:
+ state:
+ inclusion: "%{value} ei ole sallittu"
article:
attributes:
article_type:
View
6 spec/models/idea_spec.rb
@@ -26,6 +26,12 @@
idea.should_not be_valid
end
end
+
+ it "should not be valid with a 'random' state" do
+ idea.state = 'random'
+ idea.should_not be_valid
+ idea.errors[:state].should include("random ei ole sallittu")
+ end
end
describe "#vote" do

0 comments on commit d5fe174

Please sign in to comment.
Something went wrong with that request. Please try again.