Permalink
Browse files

starting to clean up the test unit stuff

  • Loading branch information...
1 parent 90eaab8 commit 202ca9dbd6c08f9299b9ff7a6271a34cbf679e1a @drapergeek drapergeek committed May 7, 2012
Showing with 45 additions and 825 deletions.
  1. +2 −0 Rakefile
  2. +2 −2 app/models/user.rb
  3. +0 −16 spec/requests/ticket_updates_spec.rb
  4. +0 −5 test/fixtures/areas.yml
  5. +0 −7 test/fixtures/buildings.yml
  6. +0 −11 test/fixtures/comments.yml
  7. +0 −5 test/fixtures/dns_names.yml
  8. +0 −7 test/fixtures/installations.yml
  9. +0 −9 test/fixtures/ips.yml
  10. +0 −63 test/fixtures/items.yml
  11. +0 −9 test/fixtures/locations.yml
  12. +0 −7 test/fixtures/operating_systems.yml
  13. +0 −5 test/fixtures/projects.yml
  14. +0 −15 test/fixtures/softwares.yml
  15. +0 −23 test/fixtures/tickets.yml
  16. +0 −14 test/fixtures/users.yml
  17. +0 −8 test/functional/admin_controller_test.rb
  18. +0 −54 test/functional/areas_controller_test.rb
  19. +0 −32 test/functional/buildings_controller_test.rb
  20. +0 −74 test/functional/comments_controller_test.rb
  21. +0 −31 test/functional/dns_names_controller_test.rb
  22. +0 −8 test/functional/incoming_email_controller_test.rb
  23. +0 −11 test/functional/installations_controller_test.rb
  24. +0 −32 test/functional/ips_controller_test.rb
  25. +0 −40 test/functional/items_controller_test.rb
  26. +0 −33 test/functional/locations_controller_test.rb
  27. +0 −33 test/functional/operating_systems_controller_test.rb
  28. +0 −54 test/functional/projects_controller_test.rb
  29. +0 −8 test/functional/sessions_controller_test.rb
  30. +0 −30 test/functional/softwares_controller_test.rb
  31. +0 −8 test/functional/ticket_mailer_test.rb
  32. +0 −54 test/functional/tickets_controller_test.rb
  33. +0 −46 test/functional/users_controller_test.rb
  34. +0 −9 test/performance/browsing_test.rb
  35. +1 −22 test/test_helper.rb
  36. +4 −4 test/unit/area_test.rb
  37. +36 −36 test/unit/comment_test.rb
View
2 Rakefile
@@ -5,3 +5,5 @@ require File.expand_path('../config/application', __FILE__)
require 'rake'
Findit::Application.load_tasks
+task(:default).clear
+task :default => [:spec, :cucumber, "app:dev:prime"]
View
4 app/models/user.rb
@@ -47,11 +47,11 @@ def full_info
def self.find_or_create_by_email(email)
user = User.find_by_email(email)
if user
- return user
+ return user
else
user = User.create(:email=>email, :first_name=>"No", :last_name=>"Name")
user.login = email.split("@")[0]
- user.save!
+ user.save_with_random_password
end
user
end
View
16 spec/requests/ticket_updates_spec.rb
@@ -1,16 +0,0 @@
-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
5 test/fixtures/areas.yml
@@ -1,5 +0,0 @@
-one:
- name: MyString
-
-two:
- name: MyString
View
7 test/fixtures/buildings.yml
@@ -1,7 +0,0 @@
-mccomas:
- name: McComas Hall
- info: MyText
-
-war:
- name: War Memorial Hall
- info: MyText
View
11 test/fixtures/comments.yml
@@ -1,11 +0,0 @@
-one:
- user:
- subject: MyString
- body: MyText
- ticket:
-
-two:
- user:
- subject: MyString
- body: MyText
- ticket:
View
5 test/fixtures/dns_names.yml
@@ -1,5 +0,0 @@
-one:
- name: MyString
-
-two:
- name: MyString
View
7 test/fixtures/installations.yml
@@ -1,7 +0,0 @@
-one:
- software_id: 1
- item_id: 1
-
-two:
- software_id: 1
- item_id: 1
View
9 test/fixtures/ips.yml
@@ -1,9 +0,0 @@
-mccomas_ip:
- number: 128.173.129.2
- info: None
- building: mccomas
-
-war_ip:
- number: 128.173.108.50
- info: MyText
- building: war
View
63 test/fixtures/items.yml
@@ -1,63 +0,0 @@
-desktop:
- name: rs-immodt-desktop
- make: Dell
- model: Optiplex GX260
- processor: Intel Core 2 Duo 2.4 Ghz
- processor_rating: 5
- ram: 1024
- hard_drive: 60
- serial: GSDB131
- vt_tag: VT000121457
- purchased_at: 2010-08-05 14:25:02
- warranty_expires_at: 2010-08-05 14:25:02
- recieved_at: 2010-08-05 14:25:02
- os: Windows XP
- type_of_item: Desktop
-
-laptop:
- name: rs-immolt-laptop
- make: Dell
- model: Latitude D620
- processor:
- processor_rating:
- ram: 4096
- hard_drive: 1231
- serial: FHG13F1
- vt_tag: VT0001244512
- purchased_at: 2010-08-05 14:25:02
- warranty_expires_at: 2010-08-05 14:25:02
- recieved_at: 2010-08-05 14:25:02
- os: Windows 7
- type_of_item: Laptop
-
-server:
- name: batman
- make: Dell
- model: Poweredge 2130
- processor: Intel Xeon 24 Core
- processor_rating: 18
- ram: 49152
- hard_drive: 10000
- serial: ASDB131
- vt_tag: VT0002131457
- purchased_at: 2010-08-05 14:25:02
- warranty_expires_at: 2010-08-05 14:25:02
- recieved_at: 2010-08-05 14:25:02
- os: VMWare ESXi
- type_of_item: Server
-
-printer:
- name: rs-immopt-hpbw
- make: HP
- model: Laserjet P2035
- processor:
- processor_rating:
- ram:
- hard_drive:
- serial: GSDFJKL1231fS
- vt_tag: VT0001214512
- purchased_at: 2010-08-05 14:25:02
- warranty_expires_at: 2010-08-05 14:25:02
- recieved_at: 2010-08-05 14:25:02
- os:
- type_of_item: Printer
View
9 test/fixtures/locations.yml
@@ -1,9 +0,0 @@
-one:
- name: MyString
- info: MyText
- building_id: 1
-
-two:
- name: MyString
- info: MyText
- building_id: 1
View
7 test/fixtures/operating_systems.yml
@@ -1,7 +0,0 @@
-one:
- name: MyString
- info: MyText
-
-two:
- name: MyString
- info: MyText
View
5 test/fixtures/projects.yml
@@ -1,5 +0,0 @@
-one:
- name: MyString
-
-two:
- name: MyString
View
15 test/fixtures/softwares.yml
@@ -1,15 +0,0 @@
-ms_office:
- name: Microsoft Office 2010
- license_key: 1233-1313-1313-13131
- os: Windows
- number_of_licenses: 5
- storage_location: MyString
- info: MyText
-
-parallels_desktop:
- name: Parallels Desktop 5
- license_key: GSDF-GSD1-FGJR-2134
- os: Mac OS
- number_of_licenses: 1
- storage_location: MyString
- info: MyText
View
23 test/fixtures/tickets.yml
@@ -1,23 +0,0 @@
-one:
- title: MyString
- description: MyText
- status: MyString
- priority: 1
- start_date: 2011-11-04
- due_date: 2011-11-04
- submitter_id:
- worker_id:
- project_id:
- area_id:
-
-two:
- title: MyString
- description: MyText
- status: MyString
- priority: 1
- start_date: 2011-11-04
- due_date: 2011-11-04
- submitter_id:
- worker_id:
- project_id:
- area_id:
View
14 test/fixtures/users.yml
@@ -1,14 +0,0 @@
-one:
- login: gdraper
- first_name: Jason
- last_name: Draper
- last_login: 2010-05-13 12:32:05
- last_login_ip: 2010-05-13 12:32:05
- can_login: true
-
-two:
- login: spiderman
- first_name: Peter
- last_name: Parker
- last_login: 2010-05-13 12:32:05
- last_login_ip: 2010-05-13 12:32:05
View
8 test/functional/admin_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class AdminControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
54 test/functional/areas_controller_test.rb
@@ -1,54 +0,0 @@
-require 'test_helper'
-
-class AreasControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Area.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_create_invalid
- Area.any_instance.stubs(:valid?).returns(false)
- post :create
- assert_template 'new'
- end
-
- def test_create_valid
- Area.any_instance.stubs(:valid?).returns(true)
- post :create
- assert_redirected_to area_url(assigns(:area))
- end
-
- def test_edit
- get :edit, :id => Area.first
- assert_template 'edit'
- end
-
- def test_update_invalid
- Area.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Area.first
- assert_template 'edit'
- end
-
- def test_update_valid
- Area.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Area.first
- assert_redirected_to area_url(assigns(:area))
- end
-
- def test_destroy
- area = Area.first
- delete :destroy, :id => area
- assert_redirected_to areas_url
- assert !Area.exists?(area.id)
- end
-end
View
32 test/functional/buildings_controller_test.rb
@@ -1,32 +0,0 @@
-require 'test_helper'
-
-class BuildingsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Building.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
- def test_edit
- get :edit, :id => Building.first
- assert_template 'edit'
- end
-
-
- def test_destroy
- building = Building.first
- delete :destroy, :id => building
- assert_redirected_to buildings_url
- assert !Building.exists?(building.id)
- end
-end
View
74 test/functional/comments_controller_test.rb
@@ -1,74 +0,0 @@
-require 'test_helper'
-
-class CommentsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Comment.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_create_invalid_with_no_ticket
- comment = Factory.build(:comment, :ticket=>nil, :user=>nil).attributes.symbolize_keys
- post :create, comment
- assert_template 'new'
- end
-
- def test_create_invalid_with_no_ticket
- ticket = Factory.create(:ticket)
- comment = Factory.build(:comment,:user=>nil, :ticket_id=>ticket.id,:body=>nil).attributes.symbolize_keys
- post :create, :comment=>comment
- assert_template 'tickets/show'
- end
-
- def test_create_valid
- ticket = Factory(:ticket)
- user = Factory(:user)
- comment = Factory.build(:comment, :ticket=>ticket, :user => user)
- assert comment.valid?
- comment = comment.attributes.symbolize_keys
- post :create, :comment=>comment
- assert_redirected_to ticket_url(comment[:ticket_id])
- end
-
- def test_edit
- get :edit, :id => Comment.first
- assert_template 'edit'
- end
-
- def test_update_invalid
- Comment.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Comment.first
- assert_template 'edit'
- end
-
- def test_update_status_in_comment
- ticket = Factory(:ticket)
- comment = Factory.build(:comment, :ticket=>ticket, :ticket_status => "Resolved")
- assert comment.valid?, "Should be a valid comment"
- comment = comment.attributes.symbolize_keys
- post :create, :comment=>comment
- assert_redirected_to ticket_url(comment[:ticket_id]), "should go to the ticket url"
- end
-
- def test_update_valid
- Comment.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Comment.first
- assert_redirected_to comment_url(assigns(:comment))
- end
-
- def test_destroy
- comment = Comment.first
- delete :destroy, :id => comment
- assert_redirected_to comments_url
- assert !Comment.exists?(comment.id)
- end
-end
View
31 test/functional/dns_names_controller_test.rb
@@ -1,31 +0,0 @@
-require 'test_helper'
-
-class DnsNamesControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => DnsName.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
- def test_edit
- get :edit, :id => DnsName.first
- assert_template 'edit'
- end
-
- def test_destroy
- dns_name = DnsName.first
- delete :destroy, :id => dns_name
- assert_redirected_to dns_names_url
- assert !DnsName.exists?(dns_name.id)
- end
-end
View
8 test/functional/incoming_email_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class IncomingEmailControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
11 test/functional/installations_controller_test.rb
@@ -1,11 +0,0 @@
-require 'test_helper'
-
-class InstallationsControllerTest < ActionController::TestCase
- test "uninstall software" do
- item = Factory(:item)
- software = Factory(:software)
- installation = Installation.create(:item => item, :software => software)
- get :uninstall_software, :software => software, :item => item
- assert_redirected_to item_url(item)
- end
-end
View
32 test/functional/ips_controller_test.rb
@@ -1,32 +0,0 @@
-require 'test_helper'
-
-class IpsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Ip.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
-
- def test_edit
- get :edit, :id => Ip.first
- assert_template 'edit'
- end
-
- def test_destroy
- ip = Ip.first
- delete :destroy, :id => ip
- assert_redirected_to ips_url
- assert !Ip.exists?(ip.id)
- end
-end
View
40 test/functional/items_controller_test.rb
@@ -1,40 +0,0 @@
-require 'test_helper'
-
-class ItemsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Item.first.name
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_edit
- item = Factory.create(:item)
- get :edit, :id => item.name
- assert_template 'edit'
- end
-
- test "removing an ip" do
- item = Factory(:item)
- ip = Factory(:ip, :item => item)
- get :remove_ip, :ip => ip.id
- assert_redirected_to item_url(item)
- end
-
-
- def test_destroy
- Factory.create(:item)
- item = Item.first
- delete :destroy, :id => item.name
- assert_redirected_to items_url
- assert !Item.exists?(item.id)
- end
-end
View
33 test/functional/locations_controller_test.rb
@@ -1,33 +0,0 @@
-require 'test_helper'
-
-class LocationsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Location.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
-
- def test_edit
- get :edit, :id => Location.first
- assert_template 'edit'
- end
-
-
- def test_destroy
- location = Location.first
- delete :destroy, :id => location
- assert_redirected_to locations_url
- assert !Location.exists?(location.id)
- end
-end
View
33 test/functional/operating_systems_controller_test.rb
@@ -1,33 +0,0 @@
-require 'test_helper'
-
-class OperatingSystemsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => OperatingSystem.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
- def test_edit
- get :edit, :id => OperatingSystem.first
- assert_template 'edit'
- end
-
-
-
- def test_destroy
- operating_system = OperatingSystem.first
- delete :destroy, :id => operating_system
- assert_redirected_to operating_systems_url
- assert !OperatingSystem.exists?(operating_system.id)
- end
-end
View
54 test/functional/projects_controller_test.rb
@@ -1,54 +0,0 @@
-require 'test_helper'
-
-class ProjectsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Project.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_create_invalid
- Project.any_instance.stubs(:valid?).returns(false)
- post :create
- assert_template 'new'
- end
-
- def test_create_valid
- Project.any_instance.stubs(:valid?).returns(true)
- post :create
- assert_redirected_to project_url(assigns(:project))
- end
-
- def test_edit
- get :edit, :id => Project.first
- assert_template 'edit'
- end
-
- def test_update_invalid
- Project.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Project.first
- assert_template 'edit'
- end
-
- def test_update_valid
- Project.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Project.first
- assert_redirected_to project_url(assigns(:project))
- end
-
- def test_destroy
- project = Project.first
- delete :destroy, :id => project
- assert_redirected_to projects_url
- assert !Project.exists?(project.id)
- end
-end
View
8 test/functional/sessions_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class SessionsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
30 test/functional/softwares_controller_test.rb
@@ -1,30 +0,0 @@
-require 'test_helper'
-
-class SoftwaresControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Software.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_edit
- get :edit, :id => Software.first
- assert_template 'edit'
- end
-
- def test_destroy
- software = Software.first
- delete :destroy, :id => software
- assert_redirected_to softwares_url
- assert !Software.exists?(software.id)
- end
-end
View
8 test/functional/ticket_mailer_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class TicketMailerTest < ActionMailer::TestCase
- # replace this with your real tests
- test "the truth" do
- assert true
- end
-end
View
54 test/functional/tickets_controller_test.rb
@@ -1,54 +0,0 @@
-require 'test_helper'
-
-class TicketsControllerTest < ActionController::TestCase
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_show
- get :show, :id => Ticket.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
- def test_create_invalid
- Ticket.any_instance.stubs(:valid?).returns(false)
- post :create
- assert_template 'new'
- end
-
- def test_create_valid
- Ticket.any_instance.stubs(:valid?).returns(true)
- post :create
- assert_redirected_to ticket_url(assigns(:ticket))
- end
-
- def test_edit
- get :edit, :id => Ticket.first
- assert_template 'edit'
- end
-
- def test_update_invalid
- Ticket.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Ticket.first
- assert_template 'edit'
- end
-
- def test_update_valid
- Ticket.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Ticket.first
- assert_redirected_to ticket_url(assigns(:ticket))
- end
-
- def test_destroy
- ticket = Ticket.first
- delete :destroy, :id => ticket
- assert_redirected_to tickets_url
- assert !Ticket.exists?(ticket.id)
- end
-end
View
46 test/functional/users_controller_test.rb
@@ -1,46 +0,0 @@
-require 'test_helper'
-
-class UsersControllerTest < ActionController::TestCase
-
- def setup
- login
- end
- def test_index
- get :index
- assert_template 'index'
- end
-
- def test_index_shows_name
- User.create(:login=>"stupid", :first_name=>"Stu", :last_name=>"Pid")
- get :index
- assert_template 'index'
- assert_select "td","Pid, Stu"
- assert_select "td", "stupid"
- assert_select "th", "Name"
- assert_select "th", "Login"
- end
-
- def test_show
- get :show, :id => User.first
- assert_template 'show'
- end
-
- def test_new
- get :new
- assert_template 'new'
- end
-
-
- def test_edit
- get :edit, :id => User.first
- assert_template 'edit'
- end
-
-
- def test_destroy
- user = User.first
- delete :destroy, :id => user
- assert_redirected_to users_url
- assert !User.exists?(user.id)
- end
-end
View
9 test/performance/browsing_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-# Profiling results for each test method are written to tmp/performance.
-class BrowsingTest < ActionDispatch::PerformanceTest
- def test_homepage
- get '/'
- end
-end
View
23 test/test_helper.rb
@@ -2,28 +2,7 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
- #
- #
- def login
- #this method will login as a user who has been defined in the system
- session[:user_id] = 1
- end
-
- def login_not_authorized
- session[:user_id] = 2
- end
-
- def logout
- current_user = nil
- end
-
+ include FactoryGirl::Syntax::Methods
def last_email
ActionMailer::Base.deliveries.last
View
8 test/unit/area_test.rb
@@ -2,26 +2,26 @@
class AreaTest < ActiveSupport::TestCase
def test_should_be_valid
- assert Factory.build(:area).valid?
+ assert build(:area).valid?
end
test "Test to make sure an area has a name" do
- area = Factory.build(:area, :name => '')
+ area = build(:area, :name => '')
assert !area.valid?, 'The area should be valid because it doesnt have a name'
area.name = 'Demo'
assert area.valid?, 'the area should be valid now that it has a name'
end
test "Test to make sure keywords are not required" do
- area = Factory.build(:area)
+ area = build(:area)
assert area.valid?, 'should be true because it is the default area and keywords is not required'
area.keywords = 'hello world, o no, hey'
assert area.valid?, 'should be true even after keywords are valid'
end
test "Make sure the keywords are stored properly" do
keywords = 'hello world, list2, number 3'
- area = Factory.build(:area, :keywords => keywords)
+ area = build(:area, :keywords => keywords)
assert area.valid?, 'This should be true as it is a standard area'
assert_equal area.keywords, keywords, 'This should be equal or the keywords are not stored properly'
end
View
72 test/unit/comment_test.rb
@@ -2,64 +2,64 @@
class CommentTest < ActiveSupport::TestCase
def test_should_be_valid
- assert Factory.build(:comment).valid?
+ assert build(:comment).valid?
end
-
+
test "Test that the user association is correct" do
- comment = Factory.build(:comment, :user => nil)
+ comment = build(:comment, :user => nil)
assert !comment.valid?, 'The comment should not be valid because it doesnt have a user'
- comment.user = Factory.build(:user)
+ comment.user = build(:user)
assert comment.valid?, 'the ticket should be valid now that it has a user'
end
-
+
test "test that the user is stored properly" do
- user = Factory.build(:user, :first_name => 'Brent', :last_name => 'Montague')
- comment = Factory.build(:comment, :user => user)
+ user = build(:user, :first_name => 'Brent', :last_name => 'Montague')
+ comment = build(:comment, :user => user)
assert_equal comment.user.first_name, 'Brent'
assert_equal comment.user.last_name, 'Montague'
end
-
+
test "Test that the body is validated correctly" do
- comment = Factory.build(:comment, :body => nil)
+ comment = build(:comment, :body => nil)
assert !comment.valid?, 'The comment should not be valid because it doesnt have a body'
comment.body = 'some latin saying here please'
assert comment.valid?, 'the ticket should be valid now that it has a body'
end
-
+
test "Test that the body is stored correctly" do
body = 'Some lating saying here'
- comment = Factory.build(:comment, :body => body)
+ comment = build(:comment, :body => body)
assert comment.valid?, 'This should be correct because it is simply the default factory'
assert_equal comment.body, body, 'The body was not stored properly'
end
-
+
test "Test that the subject is stored properly" do
subject = 'demo subject'
- comment = Factory.build(:comment, :subject => subject)
+ comment = build(:comment, :subject => subject)
assert comment.valid?, 'This should be correct because it is the default factory'
assert_equal comment.subject, subject, 'The subject was not stored properly'
end
-
+
test "test that the subject is not required" do
- comment = Factory.build(:comment, :subject => nil)
+ comment = build(:comment, :subject => nil)
assert comment.valid?, 'This should be valid because the subject is not needed'
assert_equal comment.subject, nil, 'This should match up or the subject was not saved right'
end
-
+
test "Test that a ticket is required and can be linked to a comment" do
- ticket = Factory.build(:ticket)
+ ticket = build(:ticket)
assert ticket.valid?, 'This should be true as the ticket is a default factory'
- comment = Factory.build(:comment, :ticket => nil)
+ comment = build(:comment, :ticket => nil)
assert !comment.valid?, 'This should be in-valid as the ticket has no ticket'
comment.ticket = ticket
assert comment.valid?, 'This should be valid as the ticket has a ticket'
end
-
+
test "Test that a tickets field link properly and can be seen by a comment" do
- user = Factory.build(:user, :first_name => 'Brent')
- ticket = Factory.build(:ticket, :submitter => user, :title => 'title', :description => 'desc', :status => 'status')
+ user = build(:user, :first_name => 'Brent')
+ ticket = build(:ticket, :submitter => user, :title => 'title', :description => 'desc', :status => 'status')
assert ticket.valid?, 'This should be true as the ticket is a default factory'
- comment = Factory.build(:comment, :ticket => ticket)
+ comment = build(:comment, :ticket => ticket)
assert comment.valid?, 'This should be valid as we have already tested this'
assert_equal comment.ticket.submitter.first_name, 'Brent', 'This simply gets the users first name'
assert_equal comment.ticket.title, 'title', 'This should return the title'
@@ -68,7 +68,7 @@ def test_should_be_valid
end
test "can create comments from an email" do
- ticket = Factory.create(:ticket)
+ ticket = create(:ticket)
from = "person@vt.edu"
subject = "Re: Rec Sports IT Ticket-ID##{ticket.id}"
body = "This thing is still broken!"
@@ -84,7 +84,7 @@ def test_should_be_valid
end
test "a closed ticket is reopened if an email comes in it" do
- ticket = Factory.create(:ticket, :status=>"Resolved")
+ ticket = create(:ticket, :status=>"Resolved")
from = "person@vt.edu"
subject = "Re: Rec Sports IT Ticket-ID##{ticket.id}"
body = "Uh, you can't close this, its still broken!"
@@ -96,8 +96,8 @@ def test_should_be_valid
test "an email is dispatched to only the ticket owner when a reply is submitted" do
reset_email
- worker = Factory.create(:user)
- ticket = Factory.create(:ticket, :worker=>worker)
+ worker = create(:user)
+ ticket = create(:ticket, :worker=>worker)
ticket.comments.create!(:user=>worker, :body=>"I have looked at this", :reply=>true)
assert last_email.to.include?(ticket.submitter.email)
assert !last_email.to.include?(ticket.worker.email)
@@ -106,9 +106,9 @@ def test_should_be_valid
test "email to worker and submitter new outside comments" do
reset_email
- worker = Factory.create(:user)
- commenter = Factory.create(:user)
- ticket = Factory.create(:ticket, :worker=>worker)
+ worker = create(:user)
+ commenter = create(:user)
+ ticket = create(:ticket, :worker=>worker)
ticket.comments.create!(:user=>commenter, :body=>"I have looked at this", :reply=>true)
assert last_email.to.include?(ticket.submitter.email)
assert last_email.to.include?(ticket.worker.email)
@@ -117,23 +117,23 @@ def test_should_be_valid
test "email to just worker when reply from submitter" do
reset_email
- worker = Factory.create(:user)
- ticket = Factory.create(:ticket, :worker=>worker)
+ worker = create(:user)
+ ticket = create(:ticket, :worker=>worker)
ticket.comments.create!(:user=>ticket.submitter, :body=>"I have looked at this", :reply=>true)
assert !last_email.to.include?(ticket.submitter.email)
assert last_email.to.include?(ticket.worker.email)
assert last_email.subject.include?("Reply from Ticket")
end
-
+
test "Can update ticket status from comment" do
- ticket = Factory.create(:ticket)
+ ticket = create(:ticket)
assert ticket.status == "Open"
- comment = Factory.build(:comment, :ticket=>ticket)
+ comment = build(:comment, :ticket=>ticket)
comment.ticket_status = "Resolved"
assert comment.save
assert ticket.status = "Resolved"
assert_equal comment.ticket_status, ticket.status
-
+
end
-
+
end

0 comments on commit 202ca9d

Please sign in to comment.