Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #115 from arttu/admin-edit-idea-state

Ability for administrator to change idea's state.
  • Loading branch information...
commit 4a62fa1c87b5ba341ca2472bc181bd1082ae50e8 2 parents a31edba + d5fe174
@arttu arttu authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.