Permalink
Browse files

Updated IronRuby, fixed C# specs, fixed errors that came out of using…

… System.Linq for list operations when possible
  • Loading branch information...
1 parent 39143f0 commit 939319febe205a43d6837e50fe3fe4740708fd58 @casualjim casualjim committed May 2, 2009
@@ -131,7 +131,7 @@ protected override void EstablishContext()
_rubyEngine.ExecuteScript(script.ToString());
_controllerDescriptor =
- MockRepository.GenerateStub<RubyControllerDescriptor>(_rubyEngine.GetRubyClass("SamuraisController"));
+ MockRepository.GenerateStub<RubyControllerDescriptor>(_rubyEngine.GetRubyClass("SamuraisController"), _rubyEngine);
}
protected override RubyActionDescriptor CreateSut()
@@ -181,9 +181,11 @@ public void should_have_the_correct_ruby_controller_class()
}
[Observation]
- public void should_have_an_empty_actions_list()
+ public void should_have_at_least_one_action_in_the_canonical_actions_list()
{
- Sut.GetCanonicalActions().ShouldBeEmpty();
+ var actions = Sut.GetCanonicalActions();
+ actions.ShouldNotBeEmpty();
+
}
}
@@ -253,9 +253,21 @@ public class when_asked_to_execute_an_action : when_a_controller_is_initialized
{
private Action _action;
+ protected override void EstablishContext()
+ {
+ base.EstablishContext();
+
+ var form = new NameValueCollection();
+ var queryString = new NameValueCollection();
+ _httpContextMock.HttpRequest.Expect(r => r.Form).Returns(form);
+ _httpContextMock.HttpRequest.Expect(r => r.QueryString).Returns(queryString);
+ }
+
protected override void Because()
{
- _action = () => ((IController)Sut).Execute(new RequestContext(_httpContextMock.Object, new RouteData{Values = {{"action", "my_action"}}}));
+ var context = new RequestContext(_httpContextMock.Object, new RouteData {Values = {{"action", "my_action"}}});
+
+ _action = () => ((IController)Sut).Execute(context);
}
[Observation]
@@ -48,13 +48,14 @@ protected override void Because()
[Observation]
public void it_should_have_a_global_routes_variable()
{
- _engine.GetGlobalVariable<object>("routes").ShouldNotBeNull();
+ _engine.Context.GetGlobalVariable("routes").ShouldNotBeNull();
+// _engine.GetGlobalVariable<object>("routes").ShouldNotBeNull();
}
[Observation]
public void routes_should_be_a_ruby_route_collection()
{
- _engine.GetGlobalVariable<object>("routes").ShouldBeAnInstanceOf<RubyRoutes>();
+ _engine.Context.GetGlobalVariable("routes").ShouldBeAnInstanceOf<RubyRoutes>();
}
[Observation]
@@ -98,7 +99,7 @@ protected override void Because()
[Observation]
public void it_should_not_have_a_global_routes_variable()
{
- _engine.GetGlobalVariable<object>("routes").ShouldBeNull();
+ _engine.Context.GetGlobalVariable("routes").ShouldBeNull();
}
@@ -51,6 +51,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dependencies\IronRuby.dll</HintPath>
</Reference>
+ <Reference Include="IronRuby.Libraries, Version=0.4.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\dependencies\IronRuby.Libraries.dll</HintPath>
+ </Reference>
<Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dependencies\Microsoft.Scripting.dll</HintPath>
@@ -48,7 +48,7 @@ public RubyEngine(ScriptRuntime runtime, IPathProvider pathProvider)
/// Gets the context.
/// </summary>
/// <value>The context.</value>
- private RubyContext Context { get; set; }
+ internal RubyContext Context { get; set; }
/// <summary>
/// Gets the engine.
@@ -123,11 +123,14 @@ public IEnumerable<string> MethodNames(IController controller)
public IEnumerable<string> MethodNames(RubyClass controllerClass)
{
var names = new List<string>();
- controllerClass.EnumerateMethods((_, methodName, __) =>
- {
- names.Add(methodName);
- return false;
- });
+ using (Context.ClassHierarchyLocker())
+ {
+ controllerClass.EnumerateMethods((_, methodName, __) =>
+ {
+ names.Add(methodName);
+ return false;
+ });
+ }
return names;
}
@@ -265,7 +268,7 @@ public void RequireRubyFile(string path)
public void RequireRubyFile(string path, ReaderType readerType)
{
Engine.CreateScriptSource(readerType == ReaderType.File
- ? (StreamContentProvider)new VirtualPathStreamContentProvider(path)
+ ? (StreamContentProvider)new VirtualPathStreamContentProvider(path, PathProvider)
: new AssemblyStreamContentProvider(path, typeof (IRubyEngine).Assembly), null, Encoding.ASCII).Execute();
}
@@ -11,17 +11,19 @@ namespace System.Web.Mvc.IronRuby.Core
public class VirtualPathStreamContentProvider : StreamContentProvider
{
private readonly string _fileName;
+ private readonly IPathProvider _pathProvider;
- public VirtualPathStreamContentProvider(string fileName)
+ public VirtualPathStreamContentProvider(string fileName, IPathProvider pathProvider)
{
_fileName = fileName;
+ _pathProvider = pathProvider;
}
#region Overrides of StreamContentProvider
public override Stream GetStream()
{
- return HostingEnvironment.VirtualPathProvider.GetFile(_fileName).Open();
+ return _pathProvider.Open(_fileName);
}
#endregion
@@ -71,7 +71,7 @@ private static IEnumerable<TITarget> ToFilters<TITarget>(this IDictionary<object
var hasKey = filterDescriptions.ContainsKey(key);
if (hasKey)
{
- filters.AddRange((filterDescriptions[key] as RubyArray).Cast<TITarget>());
+ filters.AddRange((filterDescriptions[key] as RubyArray).CastTo<TITarget>());
}
return filters;
}
@@ -95,5 +95,16 @@ internal static IEnumerable<SelectListItem> ToSelectListItemList(this IEnumerabl
});
return result;
}
+
+ internal static IEnumerable<TTarget> CastTo<TTarget>(this IEnumerable collection) where TTarget : class
+ {
+ var result = new List<TTarget>();
+ collection.ForEach(item =>
+ {
+ var casted = (typeof(TTarget) == typeof(string)) ? item.ToString() as TTarget : item as TTarget;
+ if (casted.IsNotNull()) result.Add(casted);
+ });
+ return result;
+ }
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 939319f

Please sign in to comment.