Skip to content
Browse files

Request specs

  • Loading branch information...
1 parent 854b3a2 commit 295cfa3a82e2ac731a9647f88e5f0b4daed50aca @dce dce committed Nov 27, 2012
View
2 app/views/stat_board/stats/_chart.html.erb
@@ -1,4 +1,4 @@
-<div class="span4">
+<div id="<%= title.downcase.gsub(" ", "-") %>" class="span4">
<table class="table table-striped">
<thead>
<tr>
View
3 spec/dummy/app/models/post.rb
@@ -0,0 +1,3 @@
+class Post < ActiveRecord::Base
+ attr_accessible :body, :title, :created_at
+end
View
1 spec/dummy/config/initializers/state_board.rb
@@ -0,0 +1 @@
+StatBoard.models = [Post]
View
3 spec/dummy/config/routes.rb
@@ -1,4 +1,3 @@
Rails.application.routes.draw do
-
- mount StatBoard::Engine => "/stat_board"
+ mount StatBoard::Engine => "/stats"
end
View
10 spec/dummy/db/migrate/20121127202112_create_posts.rb
@@ -0,0 +1,10 @@
+class CreatePosts < ActiveRecord::Migration
+ def change
+ create_table :posts do |t|
+ t.string :title
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
View
23 spec/dummy/db/schema.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20121127202112) do
+
+ create_table "posts", :force => true do |t|
+ t.string "title"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
76 spec/requests/stat_board_spec.rb
@@ -0,0 +1,76 @@
+require "spec_helper"
+
+describe "a user visiting the stat board" do
+ it "sees the dashboard" do
+ visit "/stats"
+ page.should have_content("StatBoard")
+ end
+
+ it "sees the specified models (post)" do
+ visit "/stats"
+ page.should have_content("Posts")
+ end
+
+ describe "with no records" do
+ before do
+ visit "/stats"
+ end
+
+ it "sees that no posts were created overall" do
+ within "div#overall" do
+ page.should have_content("0")
+ end
+ end
+
+ it "sees that no posts were created this month" do
+ within "div#this-month" do
+ page.should have_content("0")
+ end
+ end
+
+ it "sees that no posts were created this week" do
+ within "div#this-week" do
+ page.should have_content("0")
+ end
+ end
+ end
+
+ describe "with some records" do
+ before do
+ Post.create(:created_at => 1.year.ago)
+ Post.create(:created_at => 2.weeks.ago)
+ Post.create(:created_at => 2.days.ago)
+
+ visit "/stats"
+ end
+
+ it "sees that 3 posts were created overall" do
+ within "div#overall" do
+ page.should have_content("3")
+ end
+ end
+
+ it "sees that 2 posts were created this month" do
+ within "div#this-month" do
+ page.should have_content("2")
+ end
+ end
+
+ it "sees that 1 post was created this week" do
+ within "div#this-week" do
+ page.should have_content("1")
+ end
+ end
+ end
+
+ describe "with a custom title" do
+ before do
+ StatBoard.title = "App Stats"
+ end
+
+ it "sees it" do
+ visit "/stats"
+ page.should have_content("App Stats")
+ end
+ end
+end

0 comments on commit 295cfa3

Please sign in to comment.
Something went wrong with that request. Please try again.