Permalink
Browse files

Simplified variable names in PagesController#home.

  • Loading branch information...
1 parent 1ae99e5 commit 75cae20af73feb19fc848146ed4358ca2ddb9efc @arttu arttu committed with ljuti Mar 5, 2012
Showing with 21 additions and 21 deletions.
  1. +5 −5 app/controllers/pages_controller.rb
  2. +5 −5 app/views/pages/home.html.haml
  3. +11 −11 spec/controllers/pages_controller_spec.rb
@@ -1,8 +1,8 @@
class PagesController < ApplicationController
def home
- @recent_drafts = Idea.where(state: 'draft').order("updated_at DESC").limit(3).includes(:votes).all
+ @drafts = Idea.where(state: 'draft').order("updated_at DESC").limit(3).includes(:votes).all
@draft_counts = {}
- @recent_drafts.map do |idea|
+ @drafts.map do |idea|
for_count = idea.vote_counts[1] || 0
against_count = idea.vote_counts[0] || 0
comment_count = idea.comments.count()
@@ -14,9 +14,9 @@ def home
@draft_counts[idea.id] = [for_portion, for_, against_portion, against_]
end
- @recent_ideas = Idea.where(state: 'idea').order("updated_at DESC").limit(4).includes(:votes).all
+ @ideas = Idea.where(state: 'idea').order("updated_at DESC").limit(4).includes(:votes).all
@idea_counts = {}
- @recent_ideas.map do |idea|
+ @ideas.map do |idea|
for_count = idea.vote_counts[1] || 0
against_count = idea.vote_counts[0] || 0
comment_count = idea.comments.count()
@@ -34,6 +34,6 @@ def home
end
end
- @front_page_articles = Article.published.where(article_type: 'blog').limit(3).all
+ @blog_articles = Article.published.where(article_type: 'blog').limit(3).all
end
end
@@ -7,9 +7,9 @@
%a.button{href: "/artikkelit/miten-palvelu-toimii"} Lisätietoa
.container_24.top_drafts
%h2 Luonnokset
- - [["grid_8", "popular", "alpha"], ["grid_8", "popular"], ["grid_8", "popular", "omega"]][0, [3, @recent_drafts.size].min].each_with_index do |klasses, i|
+ - [["grid_8", "popular", "alpha"], ["grid_8", "popular"], ["grid_8", "popular", "omega"]][0, [3, @drafts.size].min].each_with_index do |klasses, i|
%div{:class => klasses}
- - if recent_draft = @recent_drafts[i]
+ - if recent_draft = @drafts[i]
%h3.title=link_to shorten(recent_draft.summary, 100, 20, "»"), idea_path(recent_draft)
%div{id: "draft_bar#{i}", class: "bar"}
- for_portion, for_, against_portion, against_ = @draft_counts[recent_draft.id]
@@ -23,7 +23,7 @@
.grid_16.top_ideas.alpha
%h2 Ajankohtaiset ideat
- - @recent_ideas.each do |idea|
+ - @ideas.each do |idea|
.idea
.grid_16.info
%span.type
@@ -44,8 +44,8 @@
.grid_8.news.omega
%h2 Ministeriössä tapahtuu
%iframe{width: "310", height: "192", src: "http://www.youtube.com/embed/R2wa2O0EBTg?rel=0", frameborder: "0", allowfullscreen: ""}
- - if @front_page_articles.any?
- - @front_page_articles.each do |article|
+ - if @blog_articles.any?
+ - @blog_articles.each do |article|
.news_item
- author_name = (article.author && article.author.profile.name) || "Tuntematon"
=link_to author_name, article_path(article)
@@ -8,16 +8,16 @@
response.should be_success
end
- describe "recent drafts section" do
+ describe "drafts section" do
before :each do
@recent_draft = Factory(:idea, state: 'draft')
@recent_idea = Factory(:idea, state: 'idea')
end
it "should include only drafts to drafts section" do
get :home
- assigns(:recent_drafts).should include(@recent_draft)
- assigns(:recent_drafts).should_not include(@recent_idea)
+ assigns(:drafts).should include(@recent_draft)
+ assigns(:drafts).should_not include(@recent_idea)
end
it "should calculate vote counts for a draft" do
@@ -35,16 +35,16 @@
end
end
- describe "recent ideas section" do
+ describe "ideas section" do
before :each do
@recent_idea = Factory(:idea, state: 'idea')
@recent_draft = Factory(:idea, state: 'draft')
end
it "should include only ideas in state 'idea' to ideas section" do
get :home
- assigns(:recent_ideas).should include(@recent_idea)
- assigns(:recent_ideas).should_not include(@recent_draft)
+ assigns(:ideas).should include(@recent_idea)
+ assigns(:ideas).should_not include(@recent_draft)
end
it "should calculate vote counts for an idea" do
@@ -80,7 +80,7 @@
@article = Factory(:article, article_type: 'blog')
end
- it "should show a temporary text on home page when no there are no blog posts" do
+ it "should show a temporary text on home page when no there are no blog articles" do
@article.update_attributes(article_type: 'statement')
get :home
@@ -93,8 +93,8 @@
get :home
- assigns(:front_page_articles).should include(@article)
- assigns(:front_page_articles).should_not include(not_blog)
+ assigns(:blog_articles).should include(@article)
+ assigns(:blog_articles).should_not include(not_blog)
end
it "should show only published blog articles" do
@@ -103,8 +103,8 @@
get :home
- assigns(:front_page_articles).should_not include(unpublished)
- assigns(:front_page_articles).should_not include(moderated)
+ assigns(:blog_articles).should_not include(unpublished)
+ assigns(:blog_articles).should_not include(moderated)
end
end
end

0 comments on commit 75cae20

Please sign in to comment.