Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: playerconnect/WSDSL
base: 2f2c9b4f60
...
head fork: playerconnect/WSDSL
compare: c89534d59b
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 76 additions and 3 deletions.
  1. +6 −3 lib/wsdsl.rb
  2. +70 −0 spec/wsdsl_spec.rb
View
9 lib/wsdsl.rb
@@ -169,9 +169,12 @@ def self.use_pluralized_controllers=(val)
# @api private
def controller_dispatch(app)
unless @controller
- if Object.const_defined?(@controller_name)
- @controller = Object.const_get(@controller_name)
- else
+ begin
+ @controller = Object
+ @controller_name.split("::").each do |const|
+ @controller = @controller.const_get(const)
+ end
+ rescue NameError => e
raise "The #{@controller_name} class was not found"
end
end
View
70 spec/wsdsl_spec.rb
@@ -97,6 +97,76 @@
service.action.should be == :foo
end
+ describe "#controller_dispatch" do
+
+ class ProjectsController
+ def initialize(app, service)
+ @app = app
+ @service = service.name
+ end
+
+ def send(action)
+ [@app, @service, action]
+ end
+ end
+
+ module Projects
+ class TasksController < ProjectsController
+ end
+ end
+
+ module Projects
+ module Tasks
+ class ItemsController < ProjectsController
+ end
+ end
+ end
+
+ before :all do
+ @original_services = WSList.all.dup
+ WSList.all.clear
+ end
+
+ after :all do
+ WSList.all.replace @original_services
+ end
+
+ it "should be able to dispatch controller" do
+ describe_service("projects.xml") { |s| }
+ service = WSList.all.find{|s| s.url == "projects.xml"}
+ service.controller_dispatch("application").
+ should == ["application", "projects", "list"]
+ end
+
+ it "should be able to dispatch namespaced controller" do
+ describe_service("project/:project_id/tasks.xml") do |service|
+ service.controller_name = "Projects::TasksController"
+ service.action = "list"
+ end
+
+ describe_service("project/:project_id/task/:task_id/items.xml") do |service|
+ service.controller_name = "Projects::Tasks::ItemsController"
+ service.action = "list"
+ end
+
+ service = WSList.all.find{|s| s.url == "project/:project_id/tasks.xml"}
+ service.controller_dispatch("application").should == ["application", "project", "list"]
+
+ service = WSList.all.find{|s| s.url == "project/:project_id/task/:task_id/items.xml"}
+ service.controller_dispatch("application").should == ["application", "project", "list"]
+ end
+
+ it "should raise exception when controller class is not found" do
+ describe_service("unknown.xml") do |service|
+ service.controller_name = "UnknownController"
+ service.action = "list"
+ end
+ service = WSList.all.find{|s| s.url == "unknown.xml"}
+ lambda { service.controller_dispatch("application") }.
+ should raise_error("The UnknownController class was not found")
+ end
+ end
+
describe WSDSL::Params do
before(:all) do

No commit comments for this range

Something went wrong with that request. Please try again.