Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated some specs, preparing for action naming

  • Loading branch information...
commit 95de88310b5d89c2dc3b3048bf82434e5fb7ca2a 1 parent ba12a59
@casualjim casualjim authored
View
4 IronRubyMvc.Tests/Controllers/RubyControllerFactorySpec.cs
@@ -28,10 +28,10 @@ protected override void EstablishContext()
_controllerFactory
.WhenToldTo(factory => factory.CreateController(_requestContext, _controllerName))
- .Throw(new ArgumentNullException());
+ .Throw(new InvalidOperationException());
- _rubyEngine.WhenToldTo(eng => eng.LoadController(_requestContext, _controllerName)).Return(Dependency<RubyController>());
+ _rubyEngine.WhenToldTo(eng => eng.LoadController(_requestContext, _controllerName)).Return(new RubyController());
}
View
3  IronRubyMvc.Tests/Core/RouteCollectionSpec.cs
@@ -1,6 +1,7 @@
#region Usings
using System.Collections;
+using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.IronRuby.Core;
using System.Web.Routing;
@@ -69,7 +70,7 @@ protected override RubyRoutes CreateSut()
protected override void Because()
{
- Sut.MapRoute("my_controller", "my_controller");
+ Sut.MapRoute("my_controller", "my_controller", new Hash(new Dictionary<object, object>()));
Sut.MapRoute("my_controller2", "my_controller3");
Sut.MapRoute("my_controller3", "my_controller2");
}
View
2  IronRubyMvc.Tests/Core/RubyEngineSpec.cs
@@ -57,7 +57,7 @@ protected override void EstablishContext()
protected override void Because()
{
- _engine = RubyEngine.InitializeIronRubyMvc(_pathProvider, "~/routes.rb");
+ _engine = RubyEngine.InitializeIronRubyMvc(_pathProvider, "~/routes.rb", path => new TestStreamContentProvider(path));
}
View
20 IronRubyMvc.Tests/UnitTestHelpers.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Web.Hosting;
+using Microsoft.Scripting;
#endregion
@@ -80,4 +81,23 @@ public override Stream Open()
return stream;
}
}
+
+ internal class TestStreamContentProvider : StreamContentProvider
+ {
+ private readonly string _path;
+
+ public TestStreamContentProvider(string path)
+ {
+ _path = path;
+ }
+
+ #region Overrides of StreamContentProvider
+
+ public override Stream GetStream()
+ {
+ return new FileStream(_path, FileMode.Open);
+ }
+
+ #endregion
+ }
}
View
20 IronRubyMvc.sln
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.Mvc.IronRuby", "IronRubyMvc\System.Web.Mvc.IronRuby.csproj", "{46333EBB-C1FF-4E28-B48E-CB3D5BB70CDB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pictures", "Pictures\Pictures.csproj", "{3C0B630F-5168-41D4-91E6-C57BBC84B7C6}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRubyMvcWeb", "IronRubyMvcWeb\IronRubyMvcWeb.csproj", "{2E516619-7937-42EC-9427-AA554B36B1B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRubyMvcLibrary.Tests", "IronRubyMvc.Tests\IronRubyMvcLibrary.Tests.csproj", "{13CD326E-5C1A-4404-A1AB-8D0BA6D9FDF9}"
@@ -16,8 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README = README
EndProjectSection
EndProject
-Project("{325B8569-0C7C-4A6A-8AF8-89C3B6BC9E74}") = "IronRubyMvcLibrarySpecs", "IronRubyMvcLibrarySpecs\IronRubyMvcLibrarySpecs.stproj", "{70018A7B-9100-428A-AAFB-06E6B2C23710}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Signed|Any CPU = Debug_Signed|Any CPU
@@ -34,14 +30,6 @@ Global
{46333EBB-C1FF-4E28-B48E-CB3D5BB70CDB}.Release_Signed|Any CPU.Build.0 = Release_Signed|Any CPU
{46333EBB-C1FF-4E28-B48E-CB3D5BB70CDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46333EBB-C1FF-4E28-B48E-CB3D5BB70CDB}.Release|Any CPU.Build.0 = Release|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Debug_Signed|Any CPU.ActiveCfg = Debug_Signed|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Debug_Signed|Any CPU.Build.0 = Debug_Signed|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Release_Signed|Any CPU.ActiveCfg = Release_Signed|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Release_Signed|Any CPU.Build.0 = Release_Signed|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3C0B630F-5168-41D4-91E6-C57BBC84B7C6}.Release|Any CPU.Build.0 = Release|Any CPU
{2E516619-7937-42EC-9427-AA554B36B1B7}.Debug_Signed|Any CPU.ActiveCfg = Debug_Signed|Any CPU
{2E516619-7937-42EC-9427-AA554B36B1B7}.Debug_Signed|Any CPU.Build.0 = Debug_Signed|Any CPU
{2E516619-7937-42EC-9427-AA554B36B1B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -58,14 +46,6 @@ Global
{13CD326E-5C1A-4404-A1AB-8D0BA6D9FDF9}.Release_Signed|Any CPU.Build.0 = Release_Signed|Any CPU
{13CD326E-5C1A-4404-A1AB-8D0BA6D9FDF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13CD326E-5C1A-4404-A1AB-8D0BA6D9FDF9}.Release|Any CPU.Build.0 = Release|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Debug_Signed|Any CPU.ActiveCfg = Debug_Signed|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Debug_Signed|Any CPU.Build.0 = Debug_Signed|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Release_Signed|Any CPU.ActiveCfg = Release_Signed|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Release_Signed|Any CPU.Build.0 = Release_Signed|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {70018A7B-9100-428A-AAFB-06E6B2C23710}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
7 IronRubyMvc/Controllers/RubyActionSelector.cs
@@ -0,0 +1,7 @@
+namespace System.Web.Mvc.IronRuby.Controllers
+{
+ public abstract class RubyActionSelector
+ {
+ public abstract bool IsValidForRequest(ControllerContext controllerContext);
+ }
+}
View
41 IronRubyMvc/Controllers/controller.rb
@@ -75,12 +75,12 @@ def before_action(name, method_name=nil, &b)
impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String)
filter(name, RubyProcActionFilter.new(impl || b, nil))
end
-
+
def after_action(name, method_name=nil, &b)
impl = create_from_name(method_name) if method_name.is_a?(Symbol) or method_name.is_a?(String)
filter(name, RubyProcActionFilter.new(nil, impl || b))
end
-
+
def around_action(name, options={}, &b)
options[:before] ||= b if block_given?
options[:after] ||= b if block_given?
@@ -116,7 +116,7 @@ def around_result(name, method_name=nil, options={}, &b)
options[:after] ||= create_from_name(options[:after]) if options[:after].is_a?(Symbol) or options[:after].is_a?(String)
filter(name, RubyProcResultFilter.new(options[:before], options[:after]))
end
-
+
def filter(name, options=nil)
@action_filters ||= {}
klass = nil
@@ -128,16 +128,16 @@ def filter(name, options=nil)
@action_filters[name.to_sym] ||= []
@action_filters[name.to_sym] << klass
end
-
+
def action_filters
@action_filters ||= {}
@action_filters
end
private
- def create_from_name(name)
- lambda {|context| context.controller.send(name.to_sym, context) }
- end
+ def create_from_name(name)
+ lambda {|context| context.controller.send(name.to_sym, context) }
+ end
end
@@ -147,12 +147,35 @@ def self.included(base)
end
+ module ActionNaming
+
+ module ClassMethods
+
+ def action_name(name, act_name)
+ key = name.to_s.to_sym
+ action_names[key] ||= []
+ action_names[key] << act_name.to_s.to_clr_string
+ action_names[key].uniq!
+ action_names[key]
+ end
+
+ def action_names
+ @action_names ||= {}
+ @action_names
+ end
+ end
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+ end
+
module Selectors
module ClassMethods
- def action_selector(name, options={}, &b)
- @action_selectors ||= []
+ def action_method(name, options={}, &b)
+ @action_methods ||= []
options[:action] = b if block_given?
options[:action] ||= name.to_sym #class.instance_method(name.to_sym)
@action_selectors << { :name => name.to_sym, :options => options }
View
59 IronRubyMvc/Core/RubyEngine.cs
@@ -24,6 +24,8 @@ namespace System.Web.Mvc.IronRuby.Core
/// </summary>
public class RubyEngine : IRubyEngine
{
+ private readonly Func<string, StreamContentProvider> _contentProviderFactory;
+
/// <summary>
/// Initializes a new instance of the <see cref="RubyEngine"/> class.
/// </summary>
@@ -33,6 +35,15 @@ public RubyEngine(ScriptRuntime runtime, IPathProvider pathProvider)
{
Runtime = runtime;
PathProvider = pathProvider;
+ _contentProviderFactory = path => new VirtualPathStreamContentProvider(path);
+ Initialize();
+ }
+
+ internal RubyEngine(ScriptRuntime runtime, IPathProvider pathProvider, Func<string, StreamContentProvider> contentProviderFactory)
+ {
+ Runtime = runtime;
+ PathProvider = pathProvider;
+ _contentProviderFactory = contentProviderFactory;
Initialize();
}
@@ -91,13 +102,13 @@ public RubyController LoadController(RequestContext requestContext, string contr
if (controllerFilePath.IsNullOrBlank())
return null;
-
- Engine.CreateScriptSource(new VirtualPathStreamContentProvider(controllerFilePath), null, Encoding.UTF8).Execute(CurrentScope);
- var controllerClass = GetRubyClass(controllerClassName);
- var controller = ConfigureController(controllerClass, requestContext);
+ Engine.CreateScriptSource( _contentProviderFactory(controllerFilePath), null, Encoding.UTF8).Execute(CurrentScope);
+
+ var controllerClass = GetRubyClass(controllerClassName);
+ var controller = ConfigureController(controllerClass, requestContext);
- return controller;
+ return controller;
}
@@ -114,16 +125,6 @@ public RubyController ConfigureController(RubyClass rubyClass, RequestContext re
return controller;
}
- public string GetMethodName(object receiver, string message)
- {
- var methodNames = Operations.GetMemberNames(receiver);
-
- if (methodNames.Contains(message.Pascalize())) return message.Pascalize();
- if (methodNames.Contains(message.Underscore())) return message.Underscore();
-
- return message;
- }
-
/// <summary>
/// Calls the method.
/// </summary>
@@ -136,7 +137,6 @@ public object CallMethod(object receiver, string message, params object[] args)
return Operations.InvokeMember(receiver, GetMethodName(receiver, message), args);
}
-
/// <summary>
/// Determines whether the specified controller as the action.
@@ -217,6 +217,17 @@ public void LoadAssemblies(params Type[] assemblies)
#endregion
+ private string GetMethodName(object receiver, string message)
+ {
+ var methodNames = Operations.GetMemberNames(receiver);
+
+ if (methodNames.Contains(message.Pascalize())) return message.Pascalize();
+ if (methodNames.Contains(message.Underscore())) return message.Underscore();
+
+ // really? we got here.. that must be some pretty funky naming.
+ return message;
+ }
+
private void Initialize()
{
Engine = Ruby.GetEngine(Runtime);
@@ -265,9 +276,8 @@ internal string GetControllerFilePath(string controllerName)
internal void RequireRubyFile(string path, ReaderType readerType)
{
Engine.CreateScriptSource(readerType == ReaderType.File
- ? (StreamContentProvider) new VirtualPathStreamContentProvider(path)
+ ? _contentProviderFactory(path)
: new AssemblyStreamContentProvider(path, typeof (IRubyEngine).Assembly), null, Encoding.ASCII).Execute();
-
}
/// <summary>
@@ -278,7 +288,6 @@ public void AddLoadPaths()
var controllersDir = Path.Combine(PathProvider.ApplicationPhysicalPath, Constants.CONTROLLERS);
var modelsDir = Path.Combine(PathProvider.ApplicationPhysicalPath, Constants.MODELS);
var filtersDir = Path.Combine(PathProvider.ApplicationPhysicalPath, Constants.FILTERS);
-
Context.Loader.SetLoadPaths(new[] {controllersDir, modelsDir, filtersDir});
}
@@ -290,7 +299,12 @@ public void AddLoadPaths()
/// <param name="routesPath">The routes path.</param>
public static RubyEngine InitializeIronRubyMvc(IPathProvider pathProvider, string routesPath)
{
- var engine = InitializeIronRuby(pathProvider);
+ return InitializeIronRubyMvc(pathProvider, routesPath, path => new VirtualPathStreamContentProvider(path));
+ }
+
+ public static RubyEngine InitializeIronRubyMvc(IPathProvider pathProvider, string routesPath, Func<string, StreamContentProvider> contentProviderFactory)
+ {
+ var engine = InitializeIronRuby(pathProvider, contentProviderFactory);
ProcessRubyRoutes(engine, pathProvider, routesPath);
IntializeMvc(engine);
return engine;
@@ -303,17 +317,16 @@ private static void IntializeMvc(IRubyEngine engine)
ViewEngines.Engines.Add(new RubyViewEngine());
}
- private static RubyEngine InitializeIronRuby(IPathProvider vpp)
+ private static RubyEngine InitializeIronRuby(IPathProvider vpp, Func<string, StreamContentProvider> contentProviderFactory)
{
var rubySetup = Ruby.CreateRubySetup();
-// rubySetup.Options["InterpretedMode"] = true;
var runtimeSetup = new ScriptRuntimeSetup();
runtimeSetup.LanguageSetups.Add(rubySetup);
runtimeSetup.DebugMode = true;
var runtime = Ruby.CreateRuntime(runtimeSetup);
- return new RubyEngine(runtime, vpp);
+ return new RubyEngine(runtime, vpp, contentProviderFactory);
}
private static void ProcessRubyRoutes(RubyEngine engine, IPathProvider vpp, string routesPath)
View
5 IronRubyMvc/Core/RubyMvcApplication.cs
@@ -8,8 +8,6 @@ namespace System.Web.Mvc.IronRuby.Core
{
public class RubyMvcApplication : HttpApplication
{
-// private bool _isFirstRequest;
-// private bool _hasBeenReset;
protected void Application_Start(object sender, EventArgs e)
{
@@ -17,6 +15,9 @@ protected void Application_Start(object sender, EventArgs e)
OnStart();
}
+ /// <summary>
+ /// Called when the application is starting and the engine has been initialized.
+ /// </summary>
protected virtual void OnStart()
{
// override this to provide start behavior
View
39 IronRubyMvc/Core/RubyMvcModule.cs
@@ -0,0 +1,39 @@
+using System.Web.Mvc.IronRuby.Extensions;
+
+namespace System.Web.Mvc.IronRuby.Core
+{
+ public class RubyMvcModule : IHttpModule
+ {
+ #region Implementation of IHttpModule
+
+ /// <summary>
+ /// nitializes a module and prepares it to handle requests.
+ /// </summary>
+ /// <param name="context">
+ /// An <see cref="T:System.Web.HttpApplication" /> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application
+ /// </param>
+ public void Init(HttpApplication context)
+ {
+ context.Error += context_Error;
+ }
+
+ void context_Error(object sender, EventArgs e)
+ {
+ var application = sender as RubyMvcApplication;
+ if(sender.IsNotNull())
+ {
+ application.Context.Error
+ }
+ }
+
+ /// <summary>
+ /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule" />.
+ /// </summary>
+ public void Dispose()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ #endregion
+ }
+}
View
1  IronRubyMvc/System.Web.Mvc.IronRuby.csproj
@@ -94,6 +94,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\ControllerConfiguration.cs" />
+ <Compile Include="Controllers\RubyActionSelector.cs" />
<Compile Include="Core\AssemblyStreamContentProvider.cs" />
<Compile Include="Core\IPathProvider.cs" />
<Compile Include="Core\IRubyEngine.cs" />
View
7 IronRubyMvcWeb/Filters/RubyAuthorizationFilter.rb
@@ -0,0 +1,7 @@
+class RubyAuthorizationFilter < AuthorizationFilter
+
+ def on_authorization(context)
+ # put authorization logic here
+ end
+
+end
View
7 IronRubyMvcWeb/Filters/RubyExceptionFilter.rb
@@ -0,0 +1,7 @@
+class RubyExceptionFilter < ExceptionFilter
+
+ def on_exception(context)
+ # put exception handling here
+ end
+
+end
View
10 IronRubyMvcWeb/Filters/RubyResultFilter.rb
@@ -0,0 +1,10 @@
+class RubyResultFilter < ResultFilter
+
+ def on_result_executing(context)
+ # put before result filtering code here
+ end
+
+ def on_result_executed(context)
+ # put after result filtering code here
+ end
+end
View
7 IronRubyMvcWeb/Models/Person.cs
@@ -0,0 +1,7 @@
+namespace IronRubyMvcWeb.Models
+{
+ public class Person
+ {
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.