From 36d93d8764c28fa02da3c4ccb622fbe19af229d9 Mon Sep 17 00:00:00 2001
From: James deBoer <james@huronbox.com>
Date: Sat, 10 May 2014 09:07:31 -0700
Subject: [PATCH] fix(ViewCache): Use an unbounded cache in the ViewCache.

ViewCache was broken by the LruCache change in 3e60863.  Between
that change and this one, it was not caching any views.

Also, add a test.
---
 lib/core_dom/view_factory.dart     |  2 +-
 test/core_dom/view_cache_spec.dart | 36 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 test/core_dom/view_cache_spec.dart

diff --git a/lib/core_dom/view_factory.dart b/lib/core_dom/view_factory.dart
index 203258feb..ad242330f 100644
--- a/lib/core_dom/view_factory.dart
+++ b/lib/core_dom/view_factory.dart
@@ -118,7 +118,7 @@ class WalkingViewFactory implements ViewFactory {
 @Injectable()
 class ViewCache {
   // _viewFactoryCache is unbounded
-  final _viewFactoryCache = new LruCache<String, ViewFactory>(capacity: 0);
+  final _viewFactoryCache = new LruCache<String, ViewFactory>();
   final Http http;
   final TemplateCache templateCache;
   final Compiler compiler;
diff --git a/test/core_dom/view_cache_spec.dart b/test/core_dom/view_cache_spec.dart
new file mode 100644
index 000000000..2ecfaaa43
--- /dev/null
+++ b/test/core_dom/view_cache_spec.dart
@@ -0,0 +1,36 @@
+library angular.dom.view_cache_spec;
+
+import '../_specs.dart';
+
+main() {
+  describe('ViewCache', () {
+    var HTML = '<div>html</div>';
+    var mockCompiler;
+    beforeEachModule((Module module) {
+      var httpBackend = new MockHttpBackend();
+
+      module
+        ..bind(HttpBackend, toValue: httpBackend)
+        ..bind(MockHttpBackend, toValue: httpBackend);
+    });
+
+    it('should cache the ViewFactory', async((
+          ViewCache cache, MockHttpBackend backend, DirectiveMap directives) {
+      var firstFactory = cache.fromHtml(HTML, directives);
+
+      expect(cache.fromHtml(HTML, directives)).toBe(firstFactory);
+
+      // Also for fromUrl
+      backend.whenGET('template.url').respond(200, HTML);
+
+      var httpFactory;
+      cache.fromUrl('template.url', directives).then((f) => httpFactory = f);
+
+      microLeap();
+      backend.flush();
+      microLeap();
+
+      expect(httpFactory).toBe(firstFactory);
+    }));
+  });
+}