Skip to content

Commit

Permalink
Adding missing module namespace on base controller superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ploetz committed Feb 22, 2012
1 parent 35b852d commit 53bf432
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Versionist
class NewControllerGenerator < Rails::Generators::NamedBase
desc "creates a new controller for an existing API version"
source_root File.expand_path('../templates', __FILE__)

argument :module_name, :type => :string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class <%= module_name %>::<%= class_name%>Controller < BaseController
class <%= module_name %>::<%= class_name%>Controller < <%= module_name %>::BaseController
end
10 changes: 5 additions & 5 deletions spec/generators/new_controller_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
context "#{name} => #{mod}" do
before :each do
::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{mod.underscore}", __FILE__))
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version({:module => \"#{mod}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\"}) do\n end\nend"}
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version(:module => \"#{mod}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\") do\n end\nend"}
run_generator [name, mod]
end

it "should create a namespaced controller" do
assert_directory "app/controllers/#{mod.underscore}"
assert_file "app/controllers/#{mod.underscore}/#{name.underscore}_controller.rb", "class #{mod}::#{name.camelize}Controller < BaseController\nend\n"
assert_file "app/controllers/#{mod.underscore}/#{name.underscore}_controller.rb", "class #{mod}::#{name.camelize}Controller < #{mod}::BaseController\nend\n"
end
end
end
Expand All @@ -58,7 +58,7 @@
context "api version duplicated in config/routes.rb" do
before :each do
::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/v1", __FILE__))
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version({:module => \"V1\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\"}) do\n end\n\n api_version({:module => \"V1\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\"}) do\n end\nend"}
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version(:module => \"V1\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\") do\n end\n\n api_version(:module => \"V1\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\") do\n end\nend"}
end

it "should raise an error" do
Expand All @@ -73,15 +73,15 @@
context "#{name} => #{mod}" do
before :each do
::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{mod.underscore}", __FILE__))
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version({:module => \"#{mod}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\"}) do\n end\nend"}
::File.open(::File.expand_path("../../tmp/config/routes.rb", __FILE__), "w") {|f| f.write "Test::Application.routes.draw do\n api_version(:module => \"#{mod}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\") do\n end\nend"}
run_generator [name, mod]
end

it "should add the new resource to the existing scope in routes.rb" do
assert_file "config/routes.rb"
expected = <<-CONTENTS
Test::Application.routes.draw do
api_version({:module => "#{mod}", :header => "Accept", :value => "application/vnd.mycompany.com-v1"}) do
api_version(:module => "#{mod}", :header => "Accept", :value => "application/vnd.mycompany.com-v1") do
resources :#{name}
end
end
Expand Down

0 comments on commit 53bf432

Please sign in to comment.