Permalink
Browse files

Issue #51: Add fix to copy_api_version generator and add specs

  • Loading branch information...
1 parent e3171d2 commit 7905a163b0da40587058891b47ddfde27dc2bda3 Brian Ploetz committed Aug 29, 2013
@@ -23,7 +23,7 @@ def copy_routes
parser = YARD::Parser::SourceParser.parse_string(File.read("config/routes.rb"))
existing_routes = nil
parser.enumerator.first.traverse do |node|
- existing_routes = node.source if node.type == :fcall && node.source =~ /api_version.*:module\s*(=>|:)\s*("|')#{module_name_for_route(old_module_name)}("|')/
+ existing_routes = node.source if node.type == :fcall && node.source =~ /api_version.*:?module\s*(=>|:)\s*("|')#{module_name_for_route(old_module_name)}("|')/
end
if !existing_routes.nil?
copied_routes = String.new(existing_routes)
@@ -23,6 +23,30 @@
end
end
+ context "ruby hash syntaxes" do
+ context "< 1.9" do
+ it "should not raise an error if api version exists" do
+ ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path("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 => \"#{module_name_for_route("V1")}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-v1\") do\n end\nend"}
+ Versionist.configuration.configured_test_framework = nil
+ lambda {
+ run_generator ["foo", "V1"]
+ }.should_not raise_error(RuntimeError, /API version doesn't exist in config\/routes.rb. Please run \'rails generate versionist:new_api_version\' generator first/)
+ end
+ end
+
+ context ">= 1.9" do
+ it "should not raise an error if api version exists" do
+ ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path("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: \"#{module_name_for_route("V1")}\", header: \"Accept\", value: \"application/vnd.mycompany.com-v1\") do\n end\nend"}
+ Versionist.configuration.configured_test_framework = nil
+ lambda {
+ run_generator ["foo", "V1"]
+ }.should_not raise_error(RuntimeError, /API version doesn't exist in config\/routes.rb. Please run \'rails generate versionist:new_api_version\' generator first/)
+ end
+ end
+ end
+
context "api version exists" do
{"foo" => "V1", "bar" => "V2", "foos" => "V2_1", "bazs" => "Api::V3"}.each do |name, mod|
context "#{name} => #{mod}" do

0 comments on commit 7905a16

Please sign in to comment.