./test/unit/service_response_test.rb in umlaut-3.3.1 vs ./test/unit/service_response_test.rb in umlaut-4.0.0.beta1
- old
+ new
@@ -1,9 +1,68 @@
require File.dirname(__FILE__) + '/../test_helper'
-class ServiceResponseTest < Test::Unit::TestCase
+class ServiceResponseTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
+ def test_view_data
+ sr = ServiceResponse.new
+ sr.take_key_values(
+ :service_id => "DummyService",
+ :display_text => "Display text",
+ :notes => "notes",
+ :my_own_key => "my_own_key",
+ :service_type_value => :fulltext
+ )
+
+ assert_equal "Display text", sr.view_data[:display_text]
+ assert_equal "Display text", sr.view_data['display_text']
+
+ assert_equal "notes", sr.view_data[:notes]
+ assert_equal "notes", sr.view_data["notes"]
+
+ assert_equal "my_own_key", sr.view_data[:my_own_key]
+ assert_equal "my_own_key", sr.view_data['my_own_key']
+
+ assert sr.view_data[:service_type_value].present?
+ assert_equal "fulltext", sr.view_data[:service_type_value]
end
+
+ # A service that does nothing!
+ class DummyService < Service
+ def handle(request)
+ return request.dispatched(self, true)
+ end
+
+ # Optional method for display-time transformations
+ # of view_datahash
+ def transform_view_data(hash)
+ hash[:added_by_transform_view_data] = "added by transform"
+ return hash
+ end
+ end
+
+ def test_view_data_i18n
+ I18n.backend.store_translations("en",
+ {"umlaut" =>
+ {"services" =>
+ { "service_response_test/dummy_service" =>
+ {"localized_text" => "localized text value"},
+ }
+ }
+ }
+ )
+
+ I18n.with_locale("en") do
+ sr = ServiceResponse.new
+ sr.instance_variable_set("@service", DummyService.new({'service_id' => "dummy", 'priority' => '3'}))
+ sr.take_key_values(:display_text => "raw text", :display_text_i18n => "localized_text")
+
+ assert_equal "localized text value", sr.view_data[:display_text]
+ end
+ end
+
+ def test_transform_view_data
+ sr = ServiceResponse.new
+ sr.instance_variable_set("@service", DummyService.new({'service_id' => "dummy", 'priority' => '3'}))
+ assert_equal "added by transform", sr.view_data[:added_by_transform_view_data]
+ end
+
end