Skip to content
Browse files

added the rspec stuff for integration testing and fixed the comment u…

…pdating of the status
  • Loading branch information...
1 parent 22f8437 commit fcb318631f355c0acb2bc7cac74cc746ae72aed1 @drapergeek drapergeek committed Dec 8, 2011
Showing with 130 additions and 1 deletion.
  1. +1 −0 .rspec
  2. +5 −0 Gemfile
  3. +40 −0 Gemfile.lock
  4. +20 −0 Guardfile
  5. +13 −1 app/models/comment.rb
  6. +1 −0 app/views/comments/_add_comment.html.erb
  7. +16 −0 spec/requests/ticket_updates_spec.rb
  8. +34 −0 spec/spec_helper.rb
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
5 Gemfile
@@ -41,11 +41,16 @@ gem 'thor'
gem 'comma'
gem 'factory_girl_rails'
gem 'formtastic'
+
+gem "rspec-rails", :group => [:test, :development]
group :development, :test do
gem "guard-test"
gem "guard-livereload"
gem "growl"
gem 'web-app-theme', '>= 0.6.2'
+ gem "capybara"
+ gem "guard-rspec"
+ gem "launchy"
end
gem "nifty-generators", :group => :development
gem "mocha", :group => :test
View
40 Gemfile.lock
@@ -31,9 +31,19 @@ GEM
addressable (2.2.4)
arel (2.0.10)
builder (2.1.2)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.2.3)
+ ffi (~> 1.0.6)
comma (0.4.3)
activesupport (>= 2.2.2)
fastercsv
+ diff-lcs (1.1.3)
em-websocket (0.3.5)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
@@ -50,6 +60,7 @@ GEM
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
fastercsv (1.5.4)
+ ffi (1.0.11)
formtastic (2.0.2)
rails (~> 3.0)
growl (1.0.3)
@@ -59,6 +70,8 @@ GEM
em-websocket (>= 0.2.0)
guard (>= 0.4.0)
multi_json (~> 1.0.3)
+ guard-rspec (0.5.9)
+ guard (>= 0.8.4)
guard-test (0.4.1)
guard (>= 0.4)
test-unit (~> 2.2)
@@ -67,6 +80,8 @@ GEM
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
+ json_pure (1.6.3)
+ launchy (2.0.3)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -148,10 +163,29 @@ GEM
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rspec-rails (2.7.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.7.0)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
rubyntlm (0.1.1)
+ rubyzip (0.9.5)
+ selenium-webdriver (2.13.0)
+ childprocess (>= 0.2.1)
+ ffi (~> 1.0.9)
+ json_pure
+ rubyzip
simple_form (1.5.2)
actionpack (~> 3.0)
activemodel (~> 3.0)
@@ -166,24 +200,30 @@ GEM
tzinfo (0.3.31)
web-app-theme (0.7.0)
will_paginate (3.0.2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
comma
factory_girl_rails
fastercsv
formtastic
growl
guard-livereload
+ guard-rspec
guard-test
jquery-rails
+ launchy
mail
mocha
nifty-generators
omniauth (= 0.2.6)
rails (= 3.0.10)
+ rspec-rails
simple_form
sqlite3-ruby
thor
View
20 Guardfile
@@ -24,3 +24,23 @@ guard 'test' do
end
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
+
View
14 app/models/comment.rb
@@ -8,6 +8,8 @@ class Comment < ActiveRecord::Base
delegate :name, :to=>:user, :prefix=>true, :allow_nil=>true
after_create :send_emails
+ after_save :update_ticket_status
+
def send_emails
if self.reply
if self.user == self.ticket.worker
@@ -38,7 +40,17 @@ def ticket_status
end
def ticket_status=(status)
- self.ticket.status = status unless ticket.nil?
+ @status = status
end
+
+ private
+
+ def update_ticket_status
+ if self.ticket && @status && self.ticket.status != @status
+ self.ticket.update_attributes(:status=>@status)
+ end
+ end
+
+
end
View
1 app/views/comments/_add_comment.html.erb
@@ -1,6 +1,7 @@
<h2>Add Comment</h2>
<%= semantic_form_for @comment do |f| %>
<%= f.inputs :name => "" do %>
+ <%= f.input :ticket_status,:as => :select, :include_blank => false, :collection => ["New", "Open", "Stalled", "Resolved"] %>
<%= f.input :body %>
<%= f.input :reply %>
<%= f.input :user_id, :as => :hidden %>
View
16 spec/requests/ticket_updates_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe "TicketUpdates" do
+ describe "ticket change" do
+ it "allows the user to update the ticket status in a comment" do
+ ticket = Factory.create(:ticket)
+ visit ticket_path(ticket)
+ fill_in "comment_body", :with=>"This is my comment"
+ select "Resolved", :from=>"comment_ticket_status"
+ click_button "Create Comment"
+ current_path.should eq(ticket_path(ticket))
+ save_and_open_page
+ page.should have_content("Status: Resolved")
+ end
+ end
+end
View
34 spec/spec_helper.rb
@@ -0,0 +1,34 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+require 'capybara/rspec'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end

0 comments on commit fcb3186

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