Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reworked dashboard testing to better exercise statistics section

  • Loading branch information...
commit 952d201d63d91cf8fb5e89124787c40de1578868 1 parent a5b72c0
@jcasimir jcasimir authored
View
1  app/controllers/dashboard_controller.rb
@@ -3,6 +3,7 @@ def show
@articles = Article.for_dashboard
@article_count = Article.count
@article_word_count = Article.total_word_count
+ @most_popular_article = Article.most_popular
@comments = Comment.for_dashboard
@comment_count = Comment.count
View
57 app/views/dashboard/show.html.erb
@@ -1,19 +1,42 @@
-<h1>Dashboard</h1>
+<h1>JSBlogger 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>
+<p>
+ <%= link_to "See All Articles", articles_path %>
+</p>
+<div class='dashboard_block'>
+ <h2>Most Recent Articles</h2>
+ <ul>
+ <% @articles.each do |article| %>
+ <li class="article"><%= link_to article.title, article %> published <%= article.created_at %></li>
+ <% end %>
+ </ul>
+</div>
-<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>
+<div class='dashboard_block'>
+ <h2>Most Recent Comments</h2>
+ <ul>
+ <% @comments.each do |comment| %>
+ <li class="comment">
+ <%= comment.author_name %>
+ said
+ "<%= comment.body %>"
+ in response to
+ <%= link_to comment.article.title, comment.article %>
+ at
+ <%= comment.created_at %>
+ </li>
+ <% end %>
+ </ul>
+</div>
+
+<div class="dashboard_block" id='statistics'>
+ <h2>Site-Wide Statistics</h2>
+ <ul>
+ <li id='total_articles'>Total articles: <%= @article_count %></li>
+ <li id='total_comments'>Total comments: <%= @comment_count %></li>
+ <li id='total_article_words'>Words in all articles: <%= @article_word_count %></li>
+ <li id='total_comment_words'>Words in all comments: <%= @comment_word_count %></li>
+ <li id='total_words'>Total Words: <%= @article_word_count + @comment_word_count %></li>
+ <li id='most_popular'>Most Popular Article: <%= @most_popular_article %></li>
+ </ul>
+</div>
View
50 spec/requests/dashboard_spec.rb
@@ -17,13 +17,15 @@
end
it "lists the five most recent articles" do
- page.should have_content("Articles:")
+ page.should have_content("Most Recent 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"])
+ titles.each_with_index do |title, i|
+ title.should include("Title #{titles.size - i}")
+ end
end
end
@@ -37,51 +39,63 @@
end
it "lists the five most recent comments" do
- page.should have_content("Comments:")
+ page.should have_content("Most Recent 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"])
+ listings = page.all('li.comment').map(&:text)
+ listings.each_with_index do |listing, i|
+ listing.should include("Body #{listings.size - i}")
+ end
end
end
- context "statistics" do
+ 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}")
+ page.find("#total_articles").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}")
+ page.find("#total_comments").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")
+ page.find("#total_article_words").should have_content("5")
end
it "displays the total words of all comments" do
Fabricate(:comment, :body => "I think that...")
+ visit "/"
+ page.find("#total_comment_words").should have_content("3")
+ end
+ it "displays the total words of all articles and comments" do
+ article = Fabricate(:article, :body => "Four score and seven years...")
+ comment = Fabricate(:comment, :body => "I think that...", :article => article)
visit "/"
+ page.find("#total_words").should have_content(comment.word_count + article.word_count)
+ end
- page.should have_content("Total words: 3")
+ it "displays the most popular (most comments) article" do
+ articles = (0..3).collect{ Fabricate(:article) }
+ target = articles[rand(articles.size)]
+ Fabricate(:comment, :article => target)
+ visit "/"
+ page.find("#most_popular").should have_content(target.title)
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"
+
+
+ # it "displays the time since the most recent article"
+ # it "displays the time since the most recent comment"
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.