Skip to content

Commit

Permalink
[codeforamerica#18] Style, format fixes for models
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Hale committed Sep 1, 2013
1 parent c6f74a5 commit ec71b42
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
8 changes: 4 additions & 4 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Ability

def initialize(user)

@articles = [QuickAnswer, WebService, Guide]
articles = [QuickAnswer, WebService, Guide]

can :read, :all

Expand All @@ -12,12 +12,12 @@ def initialize(user)
end

if user.is_editor
can :manage, @articles + [Category, Contact, GuideStep]
can :manage, articles + [Category, Contact, GuideStep]
end

if user.is_writer
can :create, @articles + [Category, Contact, GuideStep]
can [:update, :destroy], @articles, status: "Draft", user_id: user.id
can :create, articles + [Category, Contact, GuideStep]
can [:update, :destroy], articles, status: "Draft", user_id: user.id
can [:update, :destroy], GuideStep, guide: { user_id: user.id, status: "Draft" }
end

Expand Down
9 changes: 2 additions & 7 deletions app/models/administrator.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
class Administrator < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, and :omniauthable
devise :database_authenticatable, :lockable, :timeoutable, :recoverable, :trackable #, :registerable, :validatable, :rememberable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation#, :remember_me
# attr_accessible :title, :body
devise :database_authenticatable, :lockable, :timeoutable, :recoverable, :trackable
attr_accessible :email, :password, :password_confirmation
end
27 changes: 13 additions & 14 deletions app/models/guide.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
class Guide < Article
include TankerArticleDefaults
include TankerArticleDefaults

has_many :guide_steps
has_many :guide_steps

tankit do
indexes :guide_steps_content do
guide_steps.map { |gs| gs.content }
end
indexes :guide_steps_title do
guide_steps.map { |gs| gs.title }
end
tankit do
indexes :guide_steps_content do
guide_steps.map { |gs| gs.content }
end
indexes :guide_steps_title do
guide_steps.map { |gs| gs.title }
end
end


def guide_steps
GuideStep.where("article_id = #{self.id}").order("step")
end
end
def guide_steps
GuideStep.where("article_id = #{self.id}").order("step")
end
end
6 changes: 3 additions & 3 deletions app/models/guide_step.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class GuideStep < ActiveRecord::Base
include TankerArticleDefaults
belongs_to :guide, :class_name => 'Guide', :foreign_key => 'article_id'
attr_accessible :article_id, :title, :content, :preview, :step
include TankerArticleDefaults
belongs_to :guide, :class_name => 'Guide', :foreign_key => 'article_id'
attr_accessible :article_id, :title, :content, :preview, :step
end
4 changes: 2 additions & 2 deletions app/models/keyword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Keyword < ActiveRecord::Base

after_create :analyse

after_save do
after_save do
Rails.cache.clear
end

# returns the total number of ocurrences of this keyword across all articles
# returns the total number of occurrences of this keyword across all articles
def count
self.wordcounts.map(&:count).inject(0, :+)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/quick_answer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class QuickAnswer < Article
include TankerArticleDefaults
end
include TankerArticleDefaults
end
8 changes: 3 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable, :registerable,
belongs_to :department
has_many :articles
devise :database_authenticatable,
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :is_admin, :is_editor, :is_writer, :department_id #:admin
attr_accessible :email, :password, :password_confirmation, :remember_me,
:is_admin, :is_editor, :is_writer, :department_id

after_validation :make_roles_exclusive

Expand Down
6 changes: 3 additions & 3 deletions app/models/web_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class WebService < Article
include TankerArticleDefaults
include TankerArticleDefaults

attr_accessible :service_url
attr_accessible :service_url

end
end

0 comments on commit ec71b42

Please sign in to comment.