Permalink
Browse files

Start of tests - gotta start somewhere

  • Loading branch information...
1 parent effd49e commit 3ff771afb8024e0344a451d1e216b716dd4c11ef @johnbeynon committed Apr 23, 2012
View
@@ -0,0 +1,5 @@
+language: ruby
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
View
@@ -107,6 +107,8 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ shoulda-matchers (1.1.0)
+ activesupport (>= 3.0.0)
simple_form (2.0.1)
actionpack (~> 3.0)
activemodel (~> 3.0)
@@ -133,4 +135,5 @@ DEPENDENCIES
helpdesk!
jquery-rails
rspec-rails
+ shoulda-matchers
sqlite3
@@ -14,12 +14,21 @@ def new
def show
@ticket = Ticket.find(params[:id])
+ 1.times{@ticket.comments.build}
end
def create
if Ticket.create(params[:ticket])
redirect_to admin_root_url
end
end
+
+ def update
+ @ticket = Ticket.find(params[:id])
+ if @ticket.update_attributes(params[:ticket])
+ redirect_to admin_root_url
+ end
+ end
+
end
end
@@ -0,0 +1,6 @@
+module Helpdesk
+ class Comment < ActiveRecord::Base
+ attr_accessible :author_id, :comment, :public, :ticket_id
+ belongs_to :author, :class_name => Helpdesk.user_class.to_s
+ end
+end
@@ -1,11 +1,16 @@
module Helpdesk
class Ticket < ActiveRecord::Base
- attr_accessible :description, :requester_id, :assignee_id, :subject, :status, :issue_type
+ attr_accessible :description, :requester_id, :assignee_id, :subject, :status, :issue_type, :comments_attributes
belongs_to :requester, :class_name => Helpdesk.user_class.to_s
belongs_to :assignee, :class_name => Helpdesk.user_class.to_s
-
+ has_many :comments, :order => "helpdesk_comments.created_at DESC"
+
scope :unassigned, where('assignee_id is null')
+ validates_presence_of :description
+
+ accepts_nested_attributes_for :comments
+
state_machine :status, :initial => :new do
end
@@ -20,6 +20,13 @@
<%= f.input :description %>
<% else %>
<%= @ticket.description %>
+ <%= f.simple_fields_for :comments do |tickets_form| %>
+ <% unless tickets_form.object.persisted? %>
+ <%= tickets_form.input :comment %>
+ <%= tickets_form.input :public, :hint => 'Requester can see this comment (public comment)' %>
+ <%= tickets_form.input :author_id, :as => :hidden, :input_html => { :value => helpdesk_user.id } %>
+ <% end %>
+ <% end %>
<% end %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
@@ -1,3 +1,11 @@
<h1>Ticket #<%= @ticket.id %></h1>
<%= render 'form' %>
<h2>Comments</h2>
+<% @ticket.comments.each do |comment| %>
+ <% if comment.persisted? %>
+ <%= comment.comment %>
+ <br />
+ <small><%= comment.created_at %> by <%= comment.author %></small>
+ <hr />
+ <% end %>
+<% end %>
@@ -0,0 +1,12 @@
+class CreateHelpdeskComments < ActiveRecord::Migration
+ def change
+ create_table :helpdesk_comments do |t|
+ t.integer :ticket_id
+ t.text :comment
+ t.integer :author_id
+ t.boolean :public
+
+ t.timestamps
+ end
+ end
+end
View
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'devise'
s.add_development_dependency "sqlite3"
+ s.add_development_dependency "shoulda-matchers"
end
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120420204444) do
+ActiveRecord::Schema.define(:version => 20120423113938) do
+
+ create_table "helpdesk_comments", :force => true do |t|
+ t.integer "ticket_id"
+ t.text "comment"
+ t.integer "author_id"
+ t.boolean "public"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "helpdesk_tickets", :force => true do |t|
t.string "subject"
@@ -0,0 +1,16 @@
+require 'spec_helper'
+describe Helpdesk::Ticket do
+
+ it { should accept_nested_attributes_for :comments }
+
+ describe "Validations" do
+ it { should validate_presence_of :description }
+ end
+
+ describe "States" do
+ describe "should be new for a new ticket" do
+
+ end
+ end
+end
+
View
@@ -3,6 +3,7 @@
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
+require 'shoulda-matchers'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ ticket_id: 1
+ comment: MyText
+ author_id: 1
+ public: false
+
+two:
+ ticket_id: 1
+ comment: MyText
+ author_id: 1
+ public: false
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+module Helpdesk
+ class CommentTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+ end
+end

0 comments on commit 3ff771a

Please sign in to comment.