ref: refs/heads/master
commit 69875c4a403c30977d70f6f4c5e8f2c99f3905a0
Author: Josef Reidinger
Date: Thu Nov 26 15:13:23 2009 +0100
add initial test suite for status
---
.../test/functional/status_controller_test.rb | 55 ++++++++++++++++++++
plugins/status/test/status_test.rb | 8 ---
plugins/status/test/test_helper.rb | 54 +++++++++++++++++++-
3 files changed, 108 insertions(+), 9 deletions(-)
diff --git a/plugins/status/test/functional/status_controller_test.rb b/plugins/status/test/functional/status_controller_test.rb
new file mode 100644
index 0000000..5de00c1
--- /dev/null
+++ b/plugins/status/test/functional/status_controller_test.rb
@@ -0,0 +1,55 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require 'test/unit'
+require File.expand_path( File.join("test","validation_assert"), RailsParent.parent )
+require 'mocha'
+
+class StatusControllerTest < ActionController::TestCase
+
+class Log
+ attr_accessor :description,:id,:path
+ def initialize(d,i,p)
+ @description =d
+ @id = i
+ @path = p
+ end
+end
+
+DEFINED_LOGS = [
+ Log.new("test","test","/log/test"),
+ Log.new("test2","test2","/log/test2")
+]
+
+ class StatusProxy
+ attr_accessor :result, :permissions, :timeout
+ def find(arg=nil)
+ return {}
+ end
+ end
+
+ class LogsProxy
+ attr_accessor :result, :permissions, :timeout
+ def find(arg)
+ return @result
+ end
+ end
+
+ def setup
+ StatusController.any_instance.stubs(:login_required)
+ @controller = StatusController.new
+ @request = ActionController::TestRequest.new
+ # http://railsforum.com/viewtopic.php?id=1719
+ @request.session[:account_id] = 1 # defined in fixtures
+ @logs_proxy = LogsProxy.new
+ @logs_proxy.result = DEFINED_LOGS
+ end
+
+ def test_index
+ YaST::ServiceResource.stubs(:proxy_for).with('org.opensuse.yast.system.logs').returns(@logs_proxy)
+ YaST::ServiceResource.stubs(:proxy_for).with('org.opensuse.yast.system.status').returns(StatusProxy.new)
+ get :index
+
+ assert_response :success
+ assert_valid_markup
+ assert assigns(:logs)
+ end
+end
diff --git a/plugins/status/test/status_test.rb b/plugins/status/test/status_test.rb
deleted file mode 100644
index 8206f39..0000000
--- a/plugins/status/test/status_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class StatusTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
diff --git a/plugins/status/test/test_helper.rb b/plugins/status/test/test_helper.rb
index 61e0acc..dd80852 100644
--- a/plugins/status/test/test_helper.rb
+++ b/plugins/status/test/test_helper.rb
@@ -1,2 +1,54 @@
+# find the rails parent
+require File.join(File.dirname(__FILE__), '..', 'config', 'rails_parent')
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path( File.join("config","environment"), RailsParent.parent )
+require 'test_help'
+
require 'active_support'
-require 'active_support/test_case'
\ No newline at end of file
+require 'active_support/test_case'
+
+class ActiveSupport::TestCase
+ # Transactional fixtures accelerate your tests by wrapping each test method
+ # in a transaction that's rolled back on completion. This ensures that the
+ # test database remains unchanged so your fixtures don't have to be reloaded
+ # between every test method. Fewer database queries means faster tests.
+ #
+ # Read Mike Clark's excellent walkthrough at
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+ #
+ # Every Active Record database supports transactions except MyISAM tables
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
+ # is recommended.
+ #
+ # The only drawback to using transactional fixtures is when you actually
+ # need to test transactions. Since your test is bracketed by a transaction,
+ # any transactions started in your code will be automatically rolled back.
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where otherwise you
+ # would need people(:david). If you don't want to migrate your existing
+ # test cases which use the @david style and don't mind the speed hit (each
+ # instantiated fixtures translates to a database query per test method),
+ # then set this back to true.
+ self.use_instantiated_fixtures = false
+
+ # 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...
+
+ # See http://pennysmalls.com/2009/03/04/rails-23-breakage-and-fixage/
+ def clean_backtrace(&block)
+ yield
+ rescue ActiveSupport::TestCase::Assertion => error
+ framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
+ raise
+ end
+
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org