summaryrefslogtreecommitdiff
path: root/help/test
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-16 08:42:36 +0200
committerAzul <azul@leap.se>2014-05-16 08:42:36 +0200
commit8fbbb8717f0578536b97c2dc0883c632f120e976 (patch)
tree17aeb2b48ada703ac916a9a65fbf3c75a5dadb86 /help/test
parent81555ec6244ed76f92e3629880f68104b8705817 (diff)
parenta4f7a410c536d88c91c834cab6ee950c71005ddd (diff)
Merge remote-tracking branch 'origin/develop'
Conflicts: app/assets/javascripts/srp test/nagios/soledad_sync.py test/nagios/webapp_login.py
Diffstat (limited to 'help/test')
-rw-r--r--help/test/factories.rb18
-rw-r--r--help/test/functional/tickets_controller_test.rb283
-rw-r--r--help/test/integration/navigation_test.rb9
-rw-r--r--help/test/leap_web_help_test.rb7
-rw-r--r--help/test/test_helper.rb15
-rw-r--r--help/test/unit/account_extension_test.rb12
-rw-r--r--help/test/unit/ticket_comment_test.rb59
-rw-r--r--help/test/unit/ticket_test.rb88
8 files changed, 0 insertions, 491 deletions
diff --git a/help/test/factories.rb b/help/test/factories.rb
deleted file mode 100644
index be04f15..0000000
--- a/help/test/factories.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-FactoryGirl.define do
-
- factory :ticket do
- subject { Faker::Lorem.sentence }
- email { Faker::Internet.email }
-
- factory :ticket_with_comment do
- comments_attributes do
- { "0" => { "body" => Faker::Lorem.sentences.join(" ") } }
- end
- end
-
- factory :ticket_with_creator do
- created_by { FactoryGirl.create(:user).id }
- end
- end
-
-end
diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb
deleted file mode 100644
index 2530ba1..0000000
--- a/help/test/functional/tickets_controller_test.rb
+++ /dev/null
@@ -1,283 +0,0 @@
-require 'test_helper'
-
-class TicketsControllerTest < ActionController::TestCase
-
- test "should get index if logged in" do
- login
- get :index
- assert_response :success
- assert_not_nil assigns(:tickets)
- end
-
- test "no index if not logged in" do
- get :index
- assert_response :redirect
- assert_nil assigns(:tickets)
- end
-
- test "should get new" do
- get :new
- assert_equal Ticket, assigns(:ticket).class
- assert_response :success
- end
-
- test "unauthenticated tickets are visible" do
- ticket = find_record :ticket, :created_by => nil
- get :show, :id => ticket.id
- assert_response :success
- end
-
- test "user tickets are not visible without login" do
- user = find_record :user
- ticket = find_record :ticket, :created_by => user.id
- get :show, :id => ticket.id
- assert_response :redirect
- assert_redirected_to login_url
- end
-
- test "user tickets are visible to creator" do
- user = find_record :user
- ticket = find_record :ticket, :created_by => user.id
- login user
- get :show, :id => ticket.id
- assert_response :success
- end
-
- test "other users tickets are not visible" do
- other_user = find_record :user
- ticket = find_record :ticket, :created_by => other_user.id
- login
- get :show, :id => ticket.id
- assert_response :redirect
- assert_redirected_to home_url
- end
-
- test "should create unauthenticated ticket" do
- params = {:subject => "unauth ticket test subject", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}}
-
- assert_difference('Ticket.count') do
- post :create, :ticket => params
- end
-
- assert_response :redirect
- assert_nil assigns(:ticket).created_by
-
- assert_equal 1, assigns(:ticket).comments.count
- assert_nil assigns(:ticket).comments.first.posted_by
- assigns(:ticket).destroy # destroys without checking permission. is that okay?
-
- end
-
- test "should create authenticated ticket" do
-
- params = {:subject => "auth ticket test subject", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}}
-
- login
-
- assert_difference('Ticket.count') do
- post :create, :ticket => params
- end
-
- assert_response :redirect
-
- assert_not_nil assigns(:ticket).created_by
- assert_equal assigns(:ticket).created_by, @current_user.id
- assert_equal assigns(:ticket).email, @current_user.email_address
-
- assert_equal 1, assigns(:ticket).comments.count
- assert_not_nil assigns(:ticket).comments.first.posted_by
- assert_equal assigns(:ticket).comments.first.posted_by, @current_user.id
- assigns(:ticket).destroy
- end
-
- test "add comment to unauthenticated ticket" do
- ticket = FactoryGirl.create :ticket, :created_by => nil
-
- assert_difference('Ticket.find(ticket.id).comments.count') do
- put :update, :id => ticket.id,
- :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} }
- end
-
- assert_equal ticket, assigns(:ticket) # still same ticket, with different comments
- assert_not_equal ticket.comments, assigns(:ticket).comments # ticket == assigns(:ticket), but they have different comments (which we want)
-
- assigns(:ticket).destroy
- end
-
-
- test "add comment to own authenticated ticket" do
-
- login
- ticket = FactoryGirl.create :ticket, :created_by => @current_user.id
-
- #they should be able to comment if it is their ticket:
- assert_difference('Ticket.find(ticket.id).comments.count') do
- put :update, :id => ticket.id,
- :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} }
- end
- assert_not_equal ticket.comments, assigns(:ticket).comments
- assert_not_nil assigns(:ticket).comments.last.posted_by
- assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id
- assigns(:ticket).destroy
-
- end
-
-
- test "cannot comment if it is not your ticket" do
-
- other_user = find_record :user
- login :is_admin? => false, :email => nil
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
- # they should *not* be able to comment if it is not their ticket
- put :update, :id => ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"not allowed comment"}} }
- assert_response :redirect
- assert_access_denied
-
- assert_equal ticket.comments.map(&:body), assigns(:ticket).comments.map(&:body)
-
- end
-
-
- test "admin add comment to authenticated ticket" do
-
- other_user = find_record :user
- login :is_admin? => true
-
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
-
- #admin should be able to comment:
- assert_difference('Ticket.find(ticket.id).comments.count') do
- put :update, :id => ticket.id,
- :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} }
- end
- assert_not_equal ticket.comments, assigns(:ticket).comments
- assert_not_nil assigns(:ticket).comments.last.posted_by
- assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id
-
- assigns(:ticket).destroy
- end
-
- test "tickets by admin" do
- begin
- other_user = find_record :user
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
-
- login :is_admin? => true
-
- get :index, {:admin_status => "all", :open_status => "open"}
- assert assigns(:all_tickets).count > 0
-
- # if we close one ticket, the admin should have 1 less open ticket
- assert_difference('assigns[:all_tickets].count', -1) do
- assigns(:tickets).first.close
- assigns(:tickets).first.save
- get :index, {:admin_status => "all", :open_status => "open"}
- end
- ensure
- ticket.reload.destroy if ticket
- end
- end
-
-
- test "admin_status mine vs all" do
- testticket = FactoryGirl.create :ticket
- user = find_record :user
- login :is_admin? => true, :email => nil
-
- get :index, {:open_status => "open"}
- assert assigns(:all_tickets).include?(testticket)
- get :index, {:user_id => user.id, :open_status => "open"}
- assert !assigns(:all_tickets).include?(testticket)
- testticket.destroy
- end
-
- test "commenting on a ticket adds to tickets that are mine" do
- testticket = FactoryGirl.create :ticket
- user = find_record :admin_user
- login user
- get :index, {:user_id => user.id, :open_status => "open"}
- assert_difference('assigns[:all_tickets].count') do
- put :update, :id => testticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}}
- get :index, {:user_id => user.id, :open_status => "open"}
- end
-
- assert assigns(:all_tickets).include?(assigns(:ticket))
- assert_not_nil assigns(:ticket).comments.last.posted_by
- assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id
-
- assigns(:ticket).destroy
- end
-
- test "admin ticket ordering" do
- tickets = FactoryGirl.create_list :ticket, 2
-
- login :is_admin? => true, :email => nil
- get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_desc'}
-
- # this will consider all tickets, not just those on first page
- first_tick = assigns(:all_tickets).all.first
- last_tick = assigns(:all_tickets).all.last
- assert first_tick.created_at > last_tick.created_at
-
- # and now reverse order:
- get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_asc'}
-
- assert_equal first_tick, assigns(:all_tickets).last
- assert_equal last_tick, assigns(:all_tickets).first
-
- assert_not_equal first_tick, assigns(:all_tickets).first
- assert_not_equal last_tick, assigns(:all_tickets).last
-
- tickets.each {|ticket| ticket.destroy}
- end
-
- test "tickets for regular user" do
- login
- ticket = FactoryGirl.create :ticket
- other_ticket = FactoryGirl.create :ticket
-
- put :update, :id => ticket.id,
- :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} }
- assert_not_nil assigns(:ticket).comments.last.posted_by
- assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id
-
- get :index, {:open_status => "open"}
- assert assigns(:all_tickets).count > 0
- assert assigns(:all_tickets).include?(ticket)
- assert !assigns(:all_tickets).include?(other_ticket)
-
- # user should have one more ticket if a new tick gets a comment by this user
- assert_difference('assigns[:all_tickets].count') do
- put :update, :id => other_ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}}
- get :index, {:open_status => "open"}
- end
- assert assigns(:all_tickets).include?(other_ticket)
-
- # if we close one ticket, the user should have 1 less open ticket
- assert_difference('assigns[:all_tickets].count', -1) do
- other_ticket.reload
- other_ticket.close
- other_ticket.save
- get :index, {:open_status => "open"}
- end
-
- number_open_tickets = assigns(:all_tickets).count
-
- # look at closed tickets:
- get :index, {:open_status => "closed"}
- assert !assigns(:all_tickets).include?(ticket)
- assert assigns(:all_tickets).include?(other_ticket)
- number_closed_tickets = assigns(:all_tickets).count
-
- # all tickets should equal closed + open
- get :index, {:open_status => "all"}
- assert assigns(:all_tickets).include?(ticket)
- assert assigns(:all_tickets).include?(other_ticket)
- assert_equal assigns(:all_tickets).count, number_closed_tickets + number_open_tickets
-
- assigns(:all_tickets).each {|t| t.destroy}
-
- end
-
-end
-
diff --git a/help/test/integration/navigation_test.rb b/help/test/integration/navigation_test.rb
deleted file mode 100644
index eec8c0e..0000000
--- a/help/test/integration/navigation_test.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'test_helper'
-
-class NavigationTest < ActionDispatch::IntegrationTest
-
- # test "the truth" do
- # assert true
- # end
-end
-
diff --git a/help/test/leap_web_help_test.rb b/help/test/leap_web_help_test.rb
deleted file mode 100644
index d74c087..0000000
--- a/help/test/leap_web_help_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class LeapWebHelpTest < ActiveSupport::TestCase
- test "truth" do
- assert_kind_of Module, LeapWebHelp
- end
-end
diff --git a/help/test/test_helper.rb b/help/test/test_helper.rb
deleted file mode 100644
index 3381f44..0000000
--- a/help/test/test_helper.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# Configure Rails Environment
-ENV["RAILS_ENV"] = "test"
-
-require File.expand_path('../../../test/dummy/config/environment', __FILE__)
-require "rails/test_help"
-
-Rails.backtrace_cleaner.remove_silencers!
-
-# Load support files
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
-
-# Load fixtures from the engine
-if ActiveSupport::TestCase.method_defined?(:fixture_path=)
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
-end
diff --git a/help/test/unit/account_extension_test.rb b/help/test/unit/account_extension_test.rb
deleted file mode 100644
index aba162c..0000000
--- a/help/test/unit/account_extension_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'test_helper'
-
-class AccountExtensionTest < ActiveSupport::TestCase
-
- test "destroying an account triggers ticket destruction" do
- t = FactoryGirl.create :ticket_with_creator
- u = t.created_by_user
- Account.new(u).destroy
- assert_equal nil, Ticket.find(t.id)
- end
-
-end
diff --git a/help/test/unit/ticket_comment_test.rb b/help/test/unit/ticket_comment_test.rb
deleted file mode 100644
index fe8cc95..0000000
--- a/help/test/unit/ticket_comment_test.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require 'test_helper'
-
-class TicketCommentTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-
-=begin
- setup do
- @sample_ticket = Ticket.create :title => 'test ticket'
- @sample_ticket.save
- end
-=end
-
- test "create" do
-
- comment2 = TicketComment.new :body => "help my email is broken!"
- assert comment2.valid?
- #assert_not_nil comment2.posted_at #?
- #assert_nil comment2.posted_by #if not logged in #TODO
-
- #comment.ticket = testticket #Ticket.find_by_title("testing")
- #assert_equal testticket.title, comment.ticket.title
-
- #tc.ticket = Ticket.find_by_title("test title")
- #tc.ticket.title
- end
-
-=begin
- test "create authenticated comment" do
- User.current = 4
- comment2 = TicketComment.new :body => "help my email is broken!"
- comment2.valid? #save # should not save comment
- assert_not_nil comment2.posted_by
- end
-=end
-
- test "add comments" do
- testticket = Ticket.create :subject => "testing"
- assert_equal testticket.comments.count, 0
- comment = TicketComment.new :body => "my email broke"
- #assert comment.valid? #validating or saving necessary for setting posted_at
- #assert_not_nil comment.posted_at
-
- testticket.comments << comment
- assert_equal testticket.comments.count, 1
- sleep(1) # so first comment has earlier posted_at time
- comment2 = TicketComment.new :body => "my email broke"
- testticket.comments << comment2 #this should validate comment2
- testticket.valid?
- assert_equal testticket.comments.count, 2
- testticket.reload.destroy
- # where should posted_at be set?
- #assert_not_nil comment.posted_at
- #assert_not_nil testticket.comments.last.posted_at
- #assert testticket.comments.first.posted_at < testticket.comments.last.posted_at
- end
-
-end
diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb
deleted file mode 100644
index f5e6ea7..0000000
--- a/help/test/unit/ticket_test.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'test_helper'
-
-class TicketTest < ActiveSupport::TestCase
-
- test "ticket with default attribs is valid" do
- t = FactoryGirl.build :ticket
- assert t.valid?
- end
-
- test "ticket without email is valid" do
- t = FactoryGirl.build :ticket, email: ""
- assert t.valid?
- end
-
- test "ticket validates email format" do
- t = FactoryGirl.build :ticket, email: "aswerssfd"
- assert !t.valid?
- end
-
- test "ticket open states" do
- t = FactoryGirl.build :ticket
- assert t.is_open
- t.close
- assert !t.is_open
- t.reopen
- assert t.is_open
- end
-
- test "creation validated" do
- @sample = Ticket.new
- assert !@sample.is_creator_validated?
- #p current_user
- @sample.created_by = 22 #current_user
- assert @sample.is_creator_validated?
- end
-
- test "destroy all tickets from a user" do
- t = FactoryGirl.create :ticket_with_creator
- u = t.created_by_user
- Ticket.destroy_all_from(u)
- assert_equal nil, Ticket.find(t.id)
- end
-=begin
-# TODO: do once have current_user stuff in order
- test "code if & only if not creator-validated" do
- User.current_test = nil
- t1 = Ticket.create :subject => 'test title'
- assert_not_nil t1.code
- assert_nil t1.created_by
-
- User.current_test = 4
- t2 = Ticket.create :subject => 'test title'
- assert_nil t2.code
- assert_not_nil t2.created_by
- end
-=end
-
-
- test "find tickets user commented on" do
-
- # clear old tickets just in case
- # this will cause RestClient::ResourceNotFound errors if there are multiple copies of the same ticket returned
- Ticket.by_includes_post_by.key('123').each {|t| t.destroy}
- # TODO: the by_includes_post_by view is only used for tests. Maybe we should get rid of it and change the test to including ordering?
-
-
- testticket = Ticket.create :subject => "test retrieving commented tickets"
- comment = TicketComment.new :body => "my email broke", :posted_by => "123"
- assert_equal 0, testticket.comments.count
- assert_equal [], Ticket.by_includes_post_by.key('123').all
-
- testticket.comments << comment
- testticket.save
- assert_equal 1, testticket.reload.comments.count
- assert_equal [testticket], Ticket.by_includes_post_by.key('123').all
-
- comment = TicketComment.new :body => "another comment", :posted_by => "123"
- testticket.comments << comment
- testticket.save
-
- # this will ensure that the ticket is only included once, even though the user has commented on the ticket twice:
- assert_equal [testticket], Ticket.by_includes_post_by.key('123').all
-
- testticket.destroy
- assert_equal [], Ticket.by_includes_post_by.key('123').all;
- end
-
-end