test/yao/resources/test_restfully_accessible.rb in yao-0.3.8 vs test/yao/resources/test_restfully_accessible.rb in yao-0.4.0

- old
+ new

@@ -1,26 +1,69 @@ class TestRestfullyAccesible < Test::Unit::TestCase - include Yao::Resources::RestfullyAccessible + include RestfullAccessibleStub + class Test + class << self + attr_accessor :client + end + extend Yao::Resources::RestfullyAccessible + end - def test_get - mock(self).find_by_name("dummy", {}) { Struct.new(:body).new("dummy") } - mock(self).resource_from_json("dummy") { "dummy" } - mock(self).return_resource("dummy") { "dummy" } + def setup + @url = "https://example.com:12345" + @resource_name = "dummy_resource" + @resources_name = "dummy_resources" - get("dummy") - RR.verify + Test.resource_name = @resource_name + Test.resources_name = @resources_name + Test.client = Yao::Client.gen_client(@url) end + sub_test_case 'get' do + test 'permalink' do + stub_get_request("https://example.com/dummy_resource", @resource_name) + mock(Test).new("dummy_resource") { "OK" } + assert_equal(Test.get("https://example.com/dummy_resource"), "OK") + end + + test 'uuid' do + uuid = "00112233-4455-6677-8899-aabbccddeeff" + stub_get_request([@url, @resources_name, uuid].join('/'), @resource_name) + mock(Test).new("dummy_resource") { "OK" } + assert_equal(Test.get(uuid), "OK") + end + + test 'id (not uuid)' do + id = "1" + stub_get_request([@url, @resources_name, id].join('/'), @resource_name) + mock(Test).new("dummy_resource") { "OK" } + assert_equal(Test.get(id), "OK") + end + + test 'name' do + Test.return_single_on_querying = true + name = "dummy" + uuid = "00112233-4455-6677-8899-aabbccddeeff" + + stub_get_request_not_found([@url, @resources_name, name].join('/')) + stub_get_request([@url, "#{@resources_name}?name=dummy"].join('/'), @resources_name) + mock(Test).new("dummy_resource") { [Struct.new(:id).new(uuid)] } + stub_get_request([@url, @resources_name, uuid].join('/'), @resources_name) + mock(Test).new("dummy_resource") { "OK" } + + assert_equal(Test.get(name), "OK") + end + end + def test_find_by_name - mock(self).list({"name" => "dummy"}) { "dummy" } + mock(Test).list({"name" => "dummy"}) { "dummy" } - assert_equal(find_by_name("dummy"), "dummy") + assert_equal(Test.find_by_name("dummy"), "dummy") end def test_uuid? - assert_equal(uuid?("00112233-4455-6677-8899-aabbccddeeff"), true) + assert_equal(Test.send(:uuid?, "00112233-4455-6677-8899-aabbccddeeff"), true) # not uuid - assert_equal(uuid?("dummy resource"), false) - assert_equal(uuid?("00112233445566778899aabbccddeeff"), false) + assert_equal(Test.send(:uuid?, "dummy resource"), false) + assert_equal(Test.send(:uuid?, "00112233445566778899aabbccddeeff"), false) end end