Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:JumpstartLab/jsblogger_advanced
- Loading branch information
Showing
13 changed files
with
239 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,11 @@ | |||
class DashboardController < ApplicationController | class DashboardController < ApplicationController | ||
def show | def show | ||
@articles = Article.for_dashboard | |||
@article_count = Article.count | |||
@article_word_count = Article.total_word_count | |||
|
|
||
@comments = Comment.for_dashboard | |||
@comment_count = Comment.count | |||
@comment_word_count = Comment.total_word_count | |||
end | end | ||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,19 @@ | |||
<h1>Dashboard</h1> | <h1>Dashboard</h1> | ||
|
|||
<h2>Articles:</h2> | |||
<p>Total articles: <%= @article_count %></p> | |||
<p>Total words: <%= @article_word_count %></p> | |||
<ul> | |||
<% @articles.each do |article| %> | |||
<li class="article"><%= article.title %></li> | |||
<% end %> | |||
</ul> | |||
|
|||
<h2>Comments:</h2> | |||
<p>Total comments: <%= @comment_count %></p> | |||
<p>Total words: <%= @comment_word_count %></p> | |||
<ul> | |||
<% @comments.each do |comment| %> | |||
<li class="comment"><%= comment.body %></li> | |||
<% end %> | |||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,43 @@ | |||
require 'spec_helper' | require 'spec_helper' | ||
|
|
||
describe DashboardController do | describe DashboardController do | ||
describe "show" do | |||
it "assigns @articles" do | |||
articles = stub | |||
Article.should_receive(:for_dashboard).and_return(articles) | |||
get :show | |||
assigns(:articles).should eq(articles) | |||
end | |||
|
|
||
it "assigns @comments" do | |||
comments = stub | |||
Comment.should_receive(:for_dashboard).and_return(comments) | |||
get :show | |||
assigns(:comments).should eq(comments) | |||
end | |||
|
|||
it "assigns @article_count" do | |||
Article.should_receive(:count).and_return(4) | |||
get :show | |||
assigns(:article_count).should eq(4) | |||
end | |||
|
|||
it "assigns @comment_count" do | |||
Comment.should_receive(:count).and_return(4) | |||
get :show | |||
assigns(:comment_count).should eq(4) | |||
end | |||
|
|||
it "assigns @article_word_count" do | |||
Article.should_receive(:total_word_count).and_return(150) | |||
get :show | |||
assigns(:article_word_count).should eq(150) | |||
end | |||
|
|||
it "assigns @comment_word_count" do | |||
Comment.should_receive(:total_word_count).and_return(150) | |||
get :show | |||
assigns(:comment_word_count).should eq(150) | |||
end | |||
end | |||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,5 @@ | |||
Fabricator(:comment) do | Fabricator(:comment) do | ||
author_name { Faker::Name.name } | author_name { Faker::Name.name } | ||
body { Faker::Lorem.paragraph } | body { Faker::Lorem.paragraph } | ||
end | article! | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,25 +1,46 @@ | |||
require 'spec_helper' | require 'spec_helper' | ||
|
|
||
describe Comment do | describe Comment do | ||
before(:each) do | let(:comment) { Fabricate(:comment) } | ||
@article = Article.create(:title => "Hello, World", | |||
:body => "Sample Body.") | |||
@comment = @article.comments.create(:author_name => "Daffy Duck", | |||
:body => "My comment goes here.") | |||
end | |||
|
|
||
it "should be valid with valid attributes" do | it "should be valid with valid attributes" do | ||
@article.should be_valid | comment.should be_valid | ||
@comment.should be_valid | |||
end | end | ||
|
|
||
it "should respond to article" do | it "should respond to article" do | ||
@comment.should respond_to(:article) | comment.should respond_to(:article) | ||
end | end | ||
|
|
||
it "must have a value in article_id" do | it "must have a value in article_id" do | ||
@comment.article_id = nil | comment.article_id = nil | ||
@comment.should_not be_valid | comment.should_not be_valid | ||
end | |||
|
|||
context ".for_dashboard" do | |||
it "gives the most recent 5 comments" do | |||
6.times do | |||
Fabricate(:comment) | |||
end | |||
expected = Comment.order('created_at DESC').limit(5).all | |||
|
|||
comments = Comment.for_dashboard | |||
comments.count.should eq(5) | |||
comments.should eq(expected) | |||
end | |||
end | end | ||
|
|
||
context ".total_word_count" do | |||
it "gives the word count for all comments" do | |||
2.times { Fabricate(:comment, :body => "I think that...") } | |||
|
|||
Comment.total_word_count.should eq(6) | |||
end | |||
end | |||
|
|||
context "#word_count" do | |||
it "gives the total number of words" do | |||
comment = Fabricate(:article, :body => "Four score and seven years ago...") | |||
comment.word_count.should eq(6) | |||
end | |||
end | |||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,87 @@ | |||
require 'spec_helper' | |||
|
|||
describe "front dashboard" do | |||
|
|||
it "loads from the root path" do | |||
visit "/" | |||
page.should have_content("Dashboard") | |||
end | |||
|
|||
context "recent articles" do | |||
before :each do | |||
6.times do |i| | |||
Fabricate(:article, :title => "Title #{i}") | |||
end | |||
|
|||
visit "/" | |||
end | |||
|
|||
it "lists the five most recent articles" do | |||
page.should have_content("Articles:") | |||
all(".article").count.should eq(5) | |||
end | |||
|
|||
it "lists them in reverse chronological order" do | |||
titles = page.all('li.article').map(&:text) | |||
titles.should eq(["Title 5", "Title 4", "Title 3", "Title 2", "Title 1"]) | |||
end | |||
end | |||
|
|||
context "recent comments" do | |||
before :each do | |||
6.times do |i| | |||
Fabricate(:comment, :body => "Body #{i}") | |||
end | |||
|
|||
visit "/" | |||
end | |||
|
|||
it "lists the five most recent comments" do | |||
page.should have_content("Comments:") | |||
all(".comment").count.should eq(5) | |||
end | |||
|
|||
it "lists them in reverse order" do | |||
bodies = page.all('li.comment').map(&:text) | |||
bodies.should eq(["Body 5", "Body 4", "Body 3", "Body 2", "Body 1"]) | |||
end | |||
end | |||
|
|||
context "statistics" do | |||
it "lists the total number of articles" do | |||
number_of_articles = rand(10) | |||
number_of_articles.times { Fabricate(:article) } | |||
|
|||
visit "/" | |||
page.should have_content("Total articles: #{number_of_articles}") | |||
end | |||
|
|||
it "lists the total number of comments" do | |||
number_of_comments = rand(10) | |||
number_of_comments.times { Fabricate(:comment) } | |||
|
|||
visit "/" | |||
page.should have_content("Total comments: #{number_of_comments}") | |||
end | |||
|
|||
|
|||
it "displays the total words of all articles" do | |||
Fabricate(:article, :body => "Four score and seven years...") | |||
|
|||
visit "/" | |||
|
|||
page.should have_content("Total words: 5") | |||
end | |||
|
|||
it "displays the total words of all comments" do | |||
Fabricate(:comment, :body => "I think that...") | |||
|
|||
visit "/" | |||
|
|||
page.should have_content("Total words: 3") | |||
end | |||
it "displays the time since the most recent article" | |||
it "displays the time since the most recent comment" | |||
it "displays the most active (most comments) article" | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters