Skip to content
Browse files

Add timeline tracking

  • Loading branch information...
1 parent 5dcc0ee commit 7ea9f7c7a4aac91cb55606b294fa0dfe45646e81 @sachac committed Jul 15, 2012
Showing with 744 additions and 2 deletions.
  1. +1 −0 Gemfile
  2. +7 −0 Gemfile.lock
  3. +3 −0 app/assets/javascripts/timeline_events.js.coffee
  4. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  5. +3 −0 app/assets/stylesheets/timeline_events.css.scss
  6. +19 −0 app/controllers/admin_controller.rb
  7. +3 −0 app/controllers/contexts_controller.rb
  8. +90 −0 app/controllers/timeline_events_controller.rb
  9. +8 −0 app/helpers/timeline_events_helper.rb
  10. +1 −0 app/models/clothing.rb
  11. +2 −0 app/models/clothing_log.rb
  12. +1 −0 app/models/location_history.rb
  13. +3 −0 app/models/record.rb
  14. +2 −0 app/models/stuff.rb
  15. +1 −1 app/models/stuff_observer.rb
  16. +5 −0 app/models/timeline_event.rb
  17. +15 −0 app/views/admin/activity.html.haml
  18. +10 −0 app/views/timeline_events/_form.html.haml
  19. +7 −0 app/views/timeline_events/edit.html.haml
  20. +24 −0 app/views/timeline_events/index.html.haml
  21. +5 −0 app/views/timeline_events/new.html.haml
  22. +6 −0 app/views/timeline_events/show.html.haml
  23. +2 −0 config/routes.rb
  24. +15 −0 db/migrate/20120715160943_create_timeline_events.rb
  25. +13 −1 db/schema.rb
  26. 0 public/stylesheets/admin.css.css
  27. +79 −0 public/stylesheets/scaffolds.css
  28. +79 −0 public/stylesheets/scaffolds.css.css
  29. 0 public/stylesheets/timeline_events.css.css
  30. +157 −0 spec/controllers/timeline_events_controller_spec.rb
  31. +6 −0 spec/factories/timeline_events.rb
  32. +15 −0 spec/helpers/timeline_events_helper_spec.rb
  33. +5 −0 spec/models/timeline_event_spec.rb
  34. +11 −0 spec/requests/timeline_events_spec.rb
  35. +35 −0 spec/routing/timeline_events_routing_spec.rb
  36. +15 −0 spec/views/timeline_events/edit.html.haml_spec.rb
  37. +14 −0 spec/views/timeline_events/index.html.haml_spec.rb
  38. +15 −0 spec/views/timeline_events/new.html.haml_spec.rb
  39. +11 −0 spec/views/timeline_events/show.html.haml_spec.rb
View
1 Gemfile
@@ -7,6 +7,7 @@ gem 'rails', '3.1.5'
#gem 'arel', :git => 'git://github.com/rails/arel.git'
#gem 'journey', :git => 'git://github.com/rails/journey.git'
gem 'comma'
+gem 'timeline_fu', :git => 'https://github.com/jamesgolick/timeline_fu.git'
gem 'newrelic_rpm'
gem 'rails-dev-tweaks'
gem 'jquery-rails'
View
7 Gemfile.lock
@@ -42,6 +42,12 @@ GIT
ruby-graphviz (1.0.9)
GIT
+ remote: https://github.com/jamesgolick/timeline_fu.git
+ revision: 45b695375045ff80e852dbe52ecbd600d64b14a5
+ specs:
+ timeline_fu (0.4.1)
+
+GIT
remote: https://github.com/makandra/cucumber_factory.git
revision: 358b6280507e040cb4bb471fa322a17a1268221f
specs:
@@ -432,6 +438,7 @@ DEPENDENCIES
statsample
subdomain-fu!
therubyracer
+ timeline_fu!
uglifier
will_paginate
workflow
View
3 app/assets/javascripts/timeline_events.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
View
3 app/assets/stylesheets/timeline_events.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the TimelineEvents controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
19 app/controllers/admin_controller.rb
@@ -10,4 +10,23 @@ def become
sign_in User.find(params[:id]), :bypass => true
redirect_to root_url
end
+
+ def activity
+ authorize! :manage, User
+ @totals = Hash.new
+ threshold = Date.today - 30.days
+ ['Clothing', 'ClothingLog', 'Record', 'Stuff'].each do |type_name|
+ @totals[type_name] = Hash.new
+ type = type_name.constantize
+ @totals[type_name][:total] = type.count
+ @totals[type_name][:not_me] = type.where('user_id != ?', 1).count
+ if type_name == 'ClothingLog'
+ @totals[type_name][:last_30] = type.where('date > ?', threshold).count
+ @totals[type_name][:last_30_not_me] = type.where('user_id != ?', 1).where('date > ?', threshold).count
+ else
+ @totals[type_name][:last_30] = type.where('created_at > ?', threshold).count
+ @totals[type_name][:last_30_not_me] = type.where('user_id != ?', 1).where('created_at > ?', threshold).count
+ end
+ end
+ end
end
View
3 app/controllers/contexts_controller.rb
@@ -15,6 +15,9 @@ def index
def show
@context = current_account.contexts.find(params[:id])
authorize! :start, @context
+ if request.format.html?
+ redirect_to start_context_path(params[:id]) and return
+ end
respond_with @context, :location => start_context_path(params[:id])
end
View
90 app/controllers/timeline_events_controller.rb
@@ -0,0 +1,90 @@
+class TimelineEventsController < ApplicationController
+ include TimelineEventsHelper
+ # GET /timeline_events
+ # GET /timeline_events.json
+ def index
+ authorize! :manage, User
+ @timeline_events = TimelineEvent.order('created_at DESC')
+ @timeline_events = @timeline_events.paginate :page => params[:page]
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @timeline_events }
+ end
+ end
+
+ # GET /timeline_events/1
+ # GET /timeline_events/1.json
+ def show
+ authorize! :manage, User
+ @timeline_event = TimelineEvent.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @timeline_event }
+ end
+ end
+
+ # GET /timeline_events/new
+ # GET /timeline_events/new.json
+ def new
+ authorize! :manage, User
+ @timeline_event = TimelineEvent.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render :json => @timeline_event }
+ end
+ end
+
+ # GET /timeline_events/1/edit
+ def edit
+ @timeline_event = TimelineEvent.find(params[:id])
+ end
+
+ # POST /timeline_events
+ # POST /timeline_events.json
+ def create
+ authorize! :manage, User
+ @timeline_event = TimelineEvent.new(params[:timeline_event])
+
+ respond_to do |format|
+ if @timeline_event.save
+ format.html { redirect_to @timeline_event, :notice => 'Timeline event was successfully created.' }
+ format.json { render :json => @timeline_event, :status => :created, :location => @timeline_event }
+ else
+ format.html { render :action => "new" }
+ format.json { render :json => @timeline_event.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /timeline_events/1
+ # PUT /timeline_events/1.json
+ def update
+ authorize! :manage, User
+ @timeline_event = TimelineEvent.find(params[:id])
+
+ respond_to do |format|
+ if @timeline_event.update_attributes(params[:timeline_event])
+ format.html { redirect_to @timeline_event, :notice => 'Timeline event was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.json { render :json => @timeline_event.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /timeline_events/1
+ # DELETE /timeline_events/1.json
+ def destroy
+ authorize! :manage, User
+ @timeline_event = TimelineEvent.find(params[:id])
+ @timeline_event.destroy
+
+ respond_to do |format|
+ format.html { redirect_to timeline_events_url }
+ format.json { head :ok }
+ end
+ end
+end
View
8 app/helpers/timeline_events_helper.rb
@@ -0,0 +1,8 @@
+module TimelineEventsHelper
+ def explain_event(e)
+ case e.subject_type
+ when 'ClothingLog'
+ "#{l e.actor.name, e.actor} wore #{l e.secondary_subject.name, e.secondary_subject} on #{l e.subject.date, e.subject}"
+ end
+ end
+end
View
1 app/models/clothing.rb
@@ -88,4 +88,5 @@ def to_xml(options = {})
notes
end
+ fires :new, :on => :create, :actor => :user
end
View
2 app/models/clothing_log.rb
@@ -61,4 +61,6 @@ def as_json(options = {})
outfit_id
clothing :name
end
+
+ fires :new, :on => :create, :actor => :user, :secondary_subject => :clothing
end
View
1 app/models/location_history.rb
@@ -21,5 +21,6 @@ def to_xml(options = {})
def to_json(options = {})
super(options.update(:methods => [:stuff_name, :location_name]))
end
+ fires :new, :on => :create, :actor => :user, :secondary_subject => :stuff
end
View
3 app/models/record.rb
@@ -401,4 +401,7 @@ def self.get_records(account, options = {})
source_id
data 'Data' do |data| data.to_json if data and data.size > 0 end
end
+
+ fires :new, :on => :create, :actor => :user, :secondary_subject => :record_category
+
end
View
2 app/models/stuff.rb
@@ -70,4 +70,6 @@ def to_json(options = {})
super(options.update(:methods => [:home_location_name, :location_name]))
end
+ fires :new, :on => :create, :actor => :user
+
end
View
2 app/models/stuff_observer.rb
@@ -1,7 +1,7 @@
class StuffObserver < ActiveRecord::Observer
def after_save(stuff)
if stuff.location_id_changed?
- LocationHistory.create(:stuff_id => stuff.id, :location => stuff.location, :datetime => Time.now)
+ LocationHistory.create(:stuff_id => stuff.id, :location => stuff.location, :datetime => Time.now, :user => stuff.user)
end
end
end
View
5 app/models/timeline_event.rb
@@ -0,0 +1,5 @@
+class TimelineEvent < ActiveRecord::Base
+ belongs_to :actor, :polymorphic => true
+ belongs_to :subject, :polymorphic => true
+ belongs_to :secondary_subject, :polymorphic => true
+end
View
15 app/views/admin/activity.html.haml
@@ -0,0 +1,15 @@
+%table
+ %tr
+ %th Type
+ %th Total
+ %th Not me
+ %th Last 30
+ %th Last 30 not me
+ - @totals.each do |k,v|
+ %tr
+ %td= k.to_s
+ %td= v[:total]
+ %td= v[:not_me]
+ %td= v[:last_30]
+ %td= v[:last_30_not_me]
+
View
10 app/views/timeline_events/_form.html.haml
@@ -0,0 +1,10 @@
+= form_for @timeline_event do |f|
+ -if @timeline_event.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@timeline_event.errors.count, "error")} prohibited this timeline_event from being saved:"
+ %ul
+ - @timeline_event.errors.full_messages.each do |msg|
+ %li= msg
+
+ .actions
+ = f.submit 'Save'
View
7 app/views/timeline_events/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing timeline_event
+
+= render 'form'
+
+= link_to 'Show', @timeline_event
+\|
+= link_to 'Back', timeline_events_path
View
24 app/views/timeline_events/index.html.haml
@@ -0,0 +1,24 @@
+%h1 Timeline events
+
+%ul
+ - @timeline_events.each do |e|
+ %li
+ = link_to e.actor.username, e.actor
+ - case e.subject_type
+ - when 'ClothingLog'
+ - if e.secondary_subject
+ = "wore #{link_to e.secondary_subject.name, e.secondary_subject} on #{link_to e.subject.date, e.subject}".html_safe
+ - when 'Record'
+ = "tracked #{link_to e.secondary_subject.full_name, e.secondary_subject} starting #{e.subject.timestamp}".html_safe
+ - when 'Clothing'
+ = "created a clothing item #{link_to e.subject.name, e.subject}".html_safe
+ - when 'Stuff'
+ = "created stuff #{link_to e.subject.name, e.subject}".html_safe
+ - when 'LocationHistory'
+ = "moved #{link_to e.secondary_subject.name, e.secondary_subject} to #{link_to e.subject.location.name, e.subject.location}".html_safe
+ = link_to e do
+ = surround '(', ')' do
+ %time.timeago{:datetime => e.created_at} e.created_at
+= will_paginate @timeline_events, :renderer => PaginationListLinkRenderer
+%br
+
View
5 app/views/timeline_events/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New timeline_event
+
+= render 'form'
+
+= link_to 'Back', timeline_events_path
View
6 app/views/timeline_events/show.html.haml
@@ -0,0 +1,6 @@
+%p#notice= notice
+
+
+= link_to 'Edit', edit_timeline_event_path(@timeline_event)
+\|
+= link_to 'Back', timeline_events_path
View
2 config/routes.rb
@@ -6,6 +6,7 @@
resources :services, :only => [:index, :create, :destroy]
match 'signups' => 'signups#index'
match 'admin' => 'admin#index'
+ match 'admin/activity' => 'admin#activity'
match 'admin/become/:id' => 'admin#become', :as => :become_user, :via => :post
match 'feedback' => 'home#send_feedback', :via => :post
match 'feedback' => 'home#feedback', :as => :feedback
@@ -22,6 +23,7 @@
match '/offline.manifest' => offline
match 'records/batch' => 'records#batch', :as => :batch_records, :via => [:post, :get]
+ resources :timeline_events
resources :records do
collection do
get :help
View
15 db/migrate/20120715160943_create_timeline_events.rb
@@ -0,0 +1,15 @@
+class CreateTimelineEvents < ActiveRecord::Migration
+ def self.up
+ create_table :timeline_events do |t|
+ t.string :event_type, :subject_type, :actor_type, :secondary_subject_type
+ t.integer :subject_id, :actor_id, :secondary_subject_id
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :timeline_events
+ end
+end
+
+
View
14 db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120127231840) do
+ActiveRecord::Schema.define(:version => 20120715160943) do
create_table "clothing", :force => true do |t|
t.string "name"
@@ -383,6 +383,18 @@
add_index "time_records", ["user_id"], :name => "index_time_records_on_user_id"
+ create_table "timeline_events", :force => true do |t|
+ t.string "event_type"
+ t.string "subject_type"
+ t.string "actor_type"
+ t.string "secondary_subject_type"
+ t.integer "subject_id"
+ t.integer "actor_id"
+ t.integer "secondary_subject_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "toronto_libraries", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
View
0 public/stylesheets/admin.css.css
No changes.
View
79 public/stylesheets/scaffolds.css
@@ -0,0 +1,79 @@
+/* line 1, ../../app/assets/stylesheets/scaffolds.scss */
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+/* line 8, ../../app/assets/stylesheets/scaffolds.scss */
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+/* line 13, ../../app/assets/stylesheets/scaffolds.scss */
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+/* line 18, ../../app/assets/stylesheets/scaffolds.scss */
+a {
+ color: #000;
+}
+/* line 20, ../../app/assets/stylesheets/scaffolds.scss */
+a:visited {
+ color: #666;
+}
+/* line 22, ../../app/assets/stylesheets/scaffolds.scss */
+a:hover {
+ color: #fff;
+ background-color: #000;
+}
+
+/* line 27, ../../app/assets/stylesheets/scaffolds.scss */
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+/* line 30, ../../app/assets/stylesheets/scaffolds.scss */
+#notice {
+ color: green;
+}
+
+/* line 33, ../../app/assets/stylesheets/scaffolds.scss */
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+/* line 38, ../../app/assets/stylesheets/scaffolds.scss */
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+/* line 45, ../../app/assets/stylesheets/scaffolds.scss */
+#error_explanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+}
+/* line 54, ../../app/assets/stylesheets/scaffolds.scss */
+#error_explanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
View
79 public/stylesheets/scaffolds.css.css
@@ -0,0 +1,79 @@
+/* line 1, ../../app/assets/stylesheets/scaffolds.css.scss */
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+/* line 8, ../../app/assets/stylesheets/scaffolds.css.scss */
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+/* line 13, ../../app/assets/stylesheets/scaffolds.css.scss */
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+/* line 18, ../../app/assets/stylesheets/scaffolds.css.scss */
+a {
+ color: #000;
+}
+/* line 20, ../../app/assets/stylesheets/scaffolds.css.scss */
+a:visited {
+ color: #666;
+}
+/* line 22, ../../app/assets/stylesheets/scaffolds.css.scss */
+a:hover {
+ color: #fff;
+ background-color: #000;
+}
+
+/* line 27, ../../app/assets/stylesheets/scaffolds.css.scss */
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+/* line 30, ../../app/assets/stylesheets/scaffolds.css.scss */
+#notice {
+ color: green;
+}
+
+/* line 33, ../../app/assets/stylesheets/scaffolds.css.scss */
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+/* line 38, ../../app/assets/stylesheets/scaffolds.css.scss */
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+/* line 45, ../../app/assets/stylesheets/scaffolds.css.scss */
+#error_explanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+}
+/* line 54, ../../app/assets/stylesheets/scaffolds.css.scss */
+#error_explanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
View
0 public/stylesheets/timeline_events.css.css
No changes.
View
157 spec/controllers/timeline_events_controller_spec.rb
@@ -0,0 +1,157 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe TimelineEventsController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # TimelineEvent. As you add validations to TimelineEvent, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all timeline_events as @timeline_events" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ get :index
+ assigns(:timeline_events).should eq([timeline_event])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested timeline_event as @timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ get :show, :id => timeline_event.id
+ assigns(:timeline_event).should eq(timeline_event)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new timeline_event as @timeline_event" do
+ get :new
+ assigns(:timeline_event).should be_a_new(TimelineEvent)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested timeline_event as @timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ get :edit, :id => timeline_event.id
+ assigns(:timeline_event).should eq(timeline_event)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new TimelineEvent" do
+ expect {
+ post :create, :timeline_event => valid_attributes
+ }.to change(TimelineEvent, :count).by(1)
+ end
+
+ it "assigns a newly created timeline_event as @timeline_event" do
+ post :create, :timeline_event => valid_attributes
+ assigns(:timeline_event).should be_a(TimelineEvent)
+ assigns(:timeline_event).should be_persisted
+ end
+
+ it "redirects to the created timeline_event" do
+ post :create, :timeline_event => valid_attributes
+ response.should redirect_to(TimelineEvent.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved timeline_event as @timeline_event" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ TimelineEvent.any_instance.stub(:save).and_return(false)
+ post :create, :timeline_event => {}
+ assigns(:timeline_event).should be_a_new(TimelineEvent)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ TimelineEvent.any_instance.stub(:save).and_return(false)
+ post :create, :timeline_event => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ # Assuming there are no other timeline_events in the database, this
+ # specifies that the TimelineEvent created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ TimelineEvent.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => timeline_event.id, :timeline_event => {'these' => 'params'}
+ end
+
+ it "assigns the requested timeline_event as @timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ put :update, :id => timeline_event.id, :timeline_event => valid_attributes
+ assigns(:timeline_event).should eq(timeline_event)
+ end
+
+ it "redirects to the timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ put :update, :id => timeline_event.id, :timeline_event => valid_attributes
+ response.should redirect_to(timeline_event)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the timeline_event as @timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ TimelineEvent.any_instance.stub(:save).and_return(false)
+ put :update, :id => timeline_event.id, :timeline_event => {}
+ assigns(:timeline_event).should eq(timeline_event)
+ end
+
+ it "re-renders the 'edit' template" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ TimelineEvent.any_instance.stub(:save).and_return(false)
+ put :update, :id => timeline_event.id, :timeline_event => {}
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested timeline_event" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ expect {
+ delete :destroy, :id => timeline_event.id
+ }.to change(TimelineEvent, :count).by(-1)
+ end
+
+ it "redirects to the timeline_events list" do
+ timeline_event = TimelineEvent.create! valid_attributes
+ delete :destroy, :id => timeline_event.id
+ response.should redirect_to(timeline_events_url)
+ end
+ end
+
+end
View
6 spec/factories/timeline_events.rb
@@ -0,0 +1,6 @@
+# Read about factories at http://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :timeline_event do
+ end
+end
View
15 spec/helpers/timeline_events_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the TimelineEventsHelper. For example:
+#
+# describe TimelineEventsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe TimelineEventsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/timeline_event_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe TimelineEvent do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
11 spec/requests/timeline_events_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "TimelineEvents" do
+ describe "GET /timeline_events" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get timeline_events_path
+ response.status.should be(200)
+ end
+ end
+end
View
35 spec/routing/timeline_events_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe TimelineEventsController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/timeline_events").should route_to("timeline_events#index")
+ end
+
+ it "routes to #new" do
+ get("/timeline_events/new").should route_to("timeline_events#new")
+ end
+
+ it "routes to #show" do
+ get("/timeline_events/1").should route_to("timeline_events#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/timeline_events/1/edit").should route_to("timeline_events#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/timeline_events").should route_to("timeline_events#create")
+ end
+
+ it "routes to #update" do
+ put("/timeline_events/1").should route_to("timeline_events#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/timeline_events/1").should route_to("timeline_events#destroy", :id => "1")
+ end
+
+ end
+end
View
15 spec/views/timeline_events/edit.html.haml_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "timeline_events/edit.html.haml" do
+ before(:each) do
+ @timeline_event = assign(:timeline_event, stub_model(TimelineEvent))
+ end
+
+ it "renders the edit timeline_event form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => timeline_events_path(@timeline_event), :method => "post" do
+ end
+ end
+end
View
14 spec/views/timeline_events/index.html.haml_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe "timeline_events/index.html.haml" do
+ before(:each) do
+ assign(:timeline_events, [
+ stub_model(TimelineEvent),
+ stub_model(TimelineEvent)
+ ])
+ end
+
+ it "renders a list of timeline_events" do
+ render
+ end
+end
View
15 spec/views/timeline_events/new.html.haml_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe "timeline_events/new.html.haml" do
+ before(:each) do
+ assign(:timeline_event, stub_model(TimelineEvent).as_new_record)
+ end
+
+ it "renders new timeline_event form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => timeline_events_path, :method => "post" do
+ end
+ end
+end
View
11 spec/views/timeline_events/show.html.haml_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "timeline_events/show.html.haml" do
+ before(:each) do
+ @timeline_event = assign(:timeline_event, stub_model(TimelineEvent))
+ end
+
+ it "renders attributes in <p>" do
+ render
+ end
+end

0 comments on commit 7ea9f7c

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