From 4747f387d0ca0a71badaee46f5059183b1917546 Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Wed, 25 Jul 2012 22:46:56 -0400 Subject: [PATCH 1/8] Issue #21: Change configuration to be tolerant of route reloading --- lib/versionist/configuration.rb | 1 + lib/versionist/routing.rb | 13 +---- lib/versionist/versioning_strategy/base.rb | 15 ++++-- lib/versionist/versioning_strategy/header.rb | 8 ++- .../versioning_strategy/parameter.rb | 8 ++- lib/versionist/versioning_strategy/path.rb | 6 +++ spec/api_routing_spec.rb | 4 +- spec/versioning_strategy/base_spec.rb | 53 +++++++++++++++++++ spec/versioning_strategy/header_spec.rb | 27 ++++++++++ spec/versioning_strategy/parameter_spec.rb | 27 ++++++++++ spec/versioning_strategy/path_spec.rb | 27 ++++++++++ 11 files changed, 170 insertions(+), 19 deletions(-) diff --git a/lib/versionist/configuration.rb b/lib/versionist/configuration.rb index 374bb9e..7e27504 100644 --- a/lib/versionist/configuration.rb +++ b/lib/versionist/configuration.rb @@ -16,6 +16,7 @@ def clear! @versioning_strategies.clear @default_version = nil @header_versions.clear + @parameter_versions.clear end end end diff --git a/lib/versionist/routing.rb b/lib/versionist/routing.rb index 68f595a..ef4f005 100644 --- a/lib/versionist/routing.rb +++ b/lib/versionist/routing.rb @@ -33,10 +33,10 @@ def configure_header(config, &block) end def configure_path(config, &block) + config[:path].slice!(0) if config[:path] =~ /^\// path = Versionist::VersioningStrategy::Path.new(config) # Use the :as option and strip out non-word characters from the path to avoid this: # https://github.com/rails/rails/issues/3224 - config[:path].slice!(0) if config[:path] =~ /^\// route_hash = {:module => config[:module], :as => config[:path].gsub(/\W/, '_')} route_hash.merge!({:defaults => config[:defaults]}) if config.has_key?(:defaults) namespace(config[:path], route_hash, &block) @@ -53,14 +53,3 @@ def configure_parameter(config, &block) end end end - -# Hook to clear versionist cached data when routes are reloaded -module Rails - class Application #:nodoc: - def reload_routes_with_versionist! - Versionist.configuration.clear! - reload_routes_without_versionist! - end - alias_method_chain :reload_routes!, :versionist - end -end diff --git a/lib/versionist/versioning_strategy/base.rb b/lib/versionist/versioning_strategy/base.rb index 8651e57..c0443ac 100644 --- a/lib/versionist/versioning_strategy/base.rb +++ b/lib/versionist/versioning_strategy/base.rb @@ -10,17 +10,26 @@ def initialize(config={}) raise ArgumentError, "you must pass a configuration Hash" if config.nil? || !config.is_a?(Hash) @config = config @config.symbolize_keys! - Versionist.configuration.versioning_strategies << self - raise ArgumentError, "[VERSIONIST] attempt to set more than one default api version" if !Versionist.configuration.default_version.nil? && @config.has_key?(:default) if @config.has_key?(:default) - Versionist.configuration.default_version = self @default = true + else + @default = false + end + if !Versionist.configuration.versioning_strategies.include?(self) + raise ArgumentError, "[VERSIONIST] attempt to set more than one default api version" if !Versionist.configuration.default_version.nil? && self.default? && Versionist.configuration.default_version != self + Versionist.configuration.versioning_strategies << self + Versionist.configuration.default_version = self if self.default? end end def default? @default end + + def ==(other) + return false if other.nil? || !other.is_a?(Versionist::VersioningStrategy::Base) + return self.config == other.config && self.default? == other.default? + end end end end diff --git a/lib/versionist/versioning_strategy/header.rb b/lib/versionist/versioning_strategy/header.rb index 977d05c..a29e161 100644 --- a/lib/versionist/versioning_strategy/header.rb +++ b/lib/versionist/versioning_strategy/header.rb @@ -7,9 +7,9 @@ class Header < Base # - :header the header to inspect # - :value the value of the header specifying the version def initialize(config) + super raise ArgumentError, "you must specify :header in the configuration Hash" if !config.has_key?(:header) raise ArgumentError, "you must specify :value in the configuration Hash" if !config.has_key?(:value) - super Versionist.configuration.header_versions << config[:value] end @@ -18,6 +18,12 @@ def matches?(request) return ((!header_string.blank? && header_string.include?(config[:value])) || (self.default? && (Versionist.configuration.header_versions.none? {|v| header_string.include?(v)}))) end + + def ==(other) + super + return false if !other.is_a?(Versionist::VersioningStrategy::Header) + return config[:header] == other.config[:header] && self.config[:value] == other.config[:value] + end end end end diff --git a/lib/versionist/versioning_strategy/parameter.rb b/lib/versionist/versioning_strategy/parameter.rb index 90b7a5a..3aec590 100644 --- a/lib/versionist/versioning_strategy/parameter.rb +++ b/lib/versionist/versioning_strategy/parameter.rb @@ -7,9 +7,9 @@ class Parameter < Base # - :parameter the parameter to inspect # - :value the value of the parameter specifying the version def initialize(config) + super raise ArgumentError, "you must specify :parameter in the configuration Hash" if !config.has_key?(:parameter) raise ArgumentError, "you must specify :value in the configuration Hash" if !config.has_key?(:value) - super Versionist.configuration.parameter_versions << config[:value] end @@ -18,6 +18,12 @@ def matches?(request) return ((!parameter_string.blank? && parameter_string == config[:value]) || (self.default? && (Versionist.configuration.parameter_versions.none? {|v| parameter_string.include?(v)}))) end + + def ==(other) + super + return false if !other.is_a?(Versionist::VersioningStrategy::Parameter) + return config[:parameter] == other.config[:parameter] && self.config[:value] == other.config[:value] + end end end end diff --git a/lib/versionist/versioning_strategy/path.rb b/lib/versionist/versioning_strategy/path.rb index 154f8bd..8cefe3f 100644 --- a/lib/versionist/versioning_strategy/path.rb +++ b/lib/versionist/versioning_strategy/path.rb @@ -7,8 +7,14 @@ class Path < Base # Creates a new Path VersioningStrategy object. config must contain the following keys: # - :path the path prefix containing the version def initialize(config) + super raise ArgumentError, "you must specify :path in the configuration Hash" if !config.has_key?(:path) + end + + def ==(other) super + return false if !other.is_a?(Versionist::VersioningStrategy::Path) + return config[:path] == other.config[:path] end end end diff --git a/spec/api_routing_spec.rb b/spec/api_routing_spec.rb index 77702dc..0152673 100644 --- a/spec/api_routing_spec.rb +++ b/spec/api_routing_spec.rb @@ -637,9 +637,9 @@ end context "route reloading" do - it "should clear cached data when calling Rails.application.reload_routes!" do + it "should handle Rails.application.reload_routes!" do lambda { - Versionist.configuration.should_receive(:clear!) + Rails.application.reload_routes! Rails.application.reload_routes! }.should_not raise_error end diff --git a/spec/versioning_strategy/base_spec.rb b/spec/versioning_strategy/base_spec.rb index 1826a5d..c59b5d3 100644 --- a/spec/versioning_strategy/base_spec.rb +++ b/spec/versioning_strategy/base_spec.rb @@ -17,6 +17,18 @@ }.should raise_error(ArgumentError, /you must pass a configuration Hash/) end + it "should set attributes" do + @base = Versionist::VersioningStrategy::Base.new({}) + @base.config.should == {} + @base.default?.should == false + + @base2 = Versionist::VersioningStrategy::Base.new({"default" => true}) + @base2.default?.should == true + # symbolize_keys! should be called + @base2.config.should_not == {"default" => true} + @base2.config.should == {:default => true} + end + it "should add self to Versionist::Configuration.versioning_strategies" do Versionist.configuration.versioning_strategies.should be_empty Versionist::VersioningStrategy::Base.new({}) @@ -24,6 +36,16 @@ Versionist.configuration.versioning_strategies.size.should == 1 end + it "should not add self to Versionist::Configuration.versioning_strategies more than once" do + Versionist.configuration.versioning_strategies.should be_empty + Versionist::VersioningStrategy::Base.new({}) + Versionist.configuration.versioning_strategies.should_not be_empty + Versionist.configuration.versioning_strategies.size.should == 1 + Versionist::VersioningStrategy::Base.new({}) + Versionist.configuration.versioning_strategies.should_not be_empty + Versionist.configuration.versioning_strategies.size.should == 1 + end + it "should set self as Versionist::Configuration.default_version if config contains :default" do Versionist.configuration.default_version.should be_nil Versionist::VersioningStrategy::Base.new({:default => true, :path => "foo"}) @@ -38,4 +60,35 @@ Versionist::VersioningStrategy::Base.new({:default => true, :path => "bar"}) }.should raise_error(ArgumentError, /attempt to set more than one default api version/) end + + context "==" do + before :each do + @base = Versionist::VersioningStrategy::Base.new({:default => false}) + @equal_base = Versionist::VersioningStrategy::Base.new({:default => false}) + end + + it "should return true if passed an equal object" do + (@base == @equal_base).should == true + end + + it "should return false if passed nil" do + (@base == nil).should == false + end + + it "should return false if passed an object that's not a Versionist::VersioningStrategy::Base" do + (@base == Array.new).should == false + end + + it "should return false if passed an object that's not equal" do + @unequal_base = Versionist::VersioningStrategy::Base.new({}) + (@base == @unequal_base).should == false + end + + it "should find equal versioning strategies via Array.include?" do + @array = Array.new + @array << @base + @array.include?(@base).should == true + @array.include?(@equal_base).should == true + end + end end diff --git a/spec/versioning_strategy/header_spec.rb b/spec/versioning_strategy/header_spec.rb index 360c521..992a74a 100644 --- a/spec/versioning_strategy/header_spec.rb +++ b/spec/versioning_strategy/header_spec.rb @@ -26,4 +26,31 @@ Versionist::VersioningStrategy::Header.new({:header => "foo", :value => "v3"}) Versionist.configuration.header_versions.include?("v3").should be_true end + + context "==" do + before :each do + @header = Versionist::VersioningStrategy::Header.new({:header => "Accept", :value => "application/vnd.mycompany.com; version=1"}) + @equal_header = Versionist::VersioningStrategy::Header.new({:header => "Accept", :value => "application/vnd.mycompany.com; version=1"}) + end + + it "should return true if passed an equal object" do + (@header == @equal_header).should == true + end + + it "should return false if passed an object that's not a Versionist::VersioningStrategy::Header" do + (@header == Array.new).should == false + end + + it "should return false if passed an object that's not equal" do + @unequal_header = Versionist::VersioningStrategy::Header.new({:header => "Accept", :value => "application/vnd.mycompany.com; version=2"}) + (@header == @unequal_header).should == false + end + + it "should find equal versioning strategies via Array.include?" do + @array = Array.new + @array << @header + @array.include?(@header).should == true + @array.include?(@equal_header).should == true + end + end end diff --git a/spec/versioning_strategy/parameter_spec.rb b/spec/versioning_strategy/parameter_spec.rb index 143f1e9..689372e 100644 --- a/spec/versioning_strategy/parameter_spec.rb +++ b/spec/versioning_strategy/parameter_spec.rb @@ -12,4 +12,31 @@ Versionist::VersioningStrategy::Parameter.new({:parameter => "version"}) }.should raise_error(ArgumentError, /you must specify :value in the configuration Hash/) end + + context "==" do + before :each do + @parameter = Versionist::VersioningStrategy::Parameter.new({:parameter => "version", :value => "1"}) + @equal_parameter = Versionist::VersioningStrategy::Parameter.new({:parameter => "version", :value => "1"}) + end + + it "should return true if passed an equal object" do + (@parameter == @equal_parameter).should == true + end + + it "should return false if passed an object that's not a Versionist::VersioningStrategy::Parameter" do + (@parameter == Array.new).should == false + end + + it "should return false if passed an object that's not equal" do + @unequal_parameter = Versionist::VersioningStrategy::Parameter.new({:parameter => "ver", :value => "1"}) + (@parameter == @unequal_parameter).should == false + end + + it "should find equal versioning strategies via Array.include?" do + @array = Array.new + @array << @parameter + @array.include?(@parameter).should == true + @array.include?(@equal_parameter).should == true + end + end end diff --git a/spec/versioning_strategy/path_spec.rb b/spec/versioning_strategy/path_spec.rb index ad7a33a..50c7998 100644 --- a/spec/versioning_strategy/path_spec.rb +++ b/spec/versioning_strategy/path_spec.rb @@ -6,4 +6,31 @@ Versionist::VersioningStrategy::Path.new({}) }.should raise_error(ArgumentError, /you must specify :path in the configuration Hash/) end + + context "==" do + before :each do + @path = Versionist::VersioningStrategy::Path.new({:path => "/v1"}) + @equal_path = Versionist::VersioningStrategy::Path.new({:path => "/v1"}) + end + + it "should return true if passed an equal object" do + (@path == @equal_path).should == true + end + + it "should return false if passed an object that's not a Versionist::VersioningStrategy::Path" do + (@path == Array.new).should == false + end + + it "should return false if passed an object that's not equal" do + @unequal_path = Versionist::VersioningStrategy::Path.new({:path => "v2"}) + (@path == @unequal_path).should == false + end + + it "should find equal versioning strategies via Array.include?" do + @array = Array.new + @array << @path + @array.include?(@path).should == true + @array.include?(@equal_path).should == true + end + end end From 3d893a915de10ebb83224e58a8ba5f61161e0a90 Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Wed, 25 Jul 2012 22:57:31 -0400 Subject: [PATCH 2/8] Version bump to 0.2.4 --- gemfiles/Rails-3.0.lock | 2 +- gemfiles/Rails-3.1.lock | 2 +- gemfiles/Rails-3.2.lock | 2 +- lib/versionist/version.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gemfiles/Rails-3.0.lock b/gemfiles/Rails-3.0.lock index bca62f9..15a80a1 100644 --- a/gemfiles/Rails-3.0.lock +++ b/gemfiles/Rails-3.0.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.3) + versionist (0.2.4) rails (~> 3.0) yard (~> 0.7) diff --git a/gemfiles/Rails-3.1.lock b/gemfiles/Rails-3.1.lock index 140f788..873f183 100644 --- a/gemfiles/Rails-3.1.lock +++ b/gemfiles/Rails-3.1.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.3) + versionist (0.2.4) rails (~> 3.0) yard (~> 0.7) diff --git a/gemfiles/Rails-3.2.lock b/gemfiles/Rails-3.2.lock index 1404efd..017d994 100644 --- a/gemfiles/Rails-3.2.lock +++ b/gemfiles/Rails-3.2.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.3) + versionist (0.2.4) rails (~> 3.0) yard (~> 0.7) diff --git a/lib/versionist/version.rb b/lib/versionist/version.rb index af271a5..01d6cd1 100644 --- a/lib/versionist/version.rb +++ b/lib/versionist/version.rb @@ -1,3 +1,3 @@ module Versionist - VERSION = '0.2.3' + VERSION = '0.2.4' end From 7bcb2f66bd86256f3e266fb2bd3296383e8f31af Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 11:20:00 -0400 Subject: [PATCH 3/8] Issue #27: Eliminate validation in copy_api_generator --- .../copy_api_version_generator.rb | 125 ++++++++++-------- .../copy_api_version_generator_spec.rb | 54 +++----- 2 files changed, 84 insertions(+), 95 deletions(-) diff --git a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb index 9210f3b..9d81f42 100644 --- a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb +++ b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb @@ -14,25 +14,6 @@ class CopyApiVersionGenerator < Rails::Generators::Base argument :new_version, :type => :string argument :new_module_name, :type => :string - def validate_old_version - in_root do - api_version_block = /api_version.*:module\s*(=>|:)\s*("|')#{module_name_for_route(old_module_name)}("|').*do/ - matching_version_blocks = File.readlines("config/routes.rb").grep(api_version_block) - raise "old API version #{old_module_name} not found in config/routes.rb" if matching_version_blocks.empty? - raise "old API version module namespace #{old_module_name} not found in app/controllers" if !File.exists?("app/controllers/#{module_name_for_path(old_module_name)}") - raise "old API version module namespace #{old_module_name} not found in app/presenters" if !File.exists?("app/presenters/#{module_name_for_path(old_module_name)}") - case Versionist.configuration.configured_test_framework - when :test_unit - raise "old API version module namespace #{old_module_name} not found in test/functional/#{module_name_for_path(old_module_name)}" if !File.exists?("test/functional/#{module_name_for_path(old_module_name)}") - raise "old API version module namespace #{old_module_name} not found in test/presenters/#{module_name_for_path(old_module_name)}" if !File.exists?("test/presenters/#{module_name_for_path(old_module_name)}") - when :rspec - raise "old API version module namespace #{old_module_name} not found in spec/controllers/#{module_name_for_path(old_module_name)}" if !File.exists?("spec/controllers/#{module_name_for_path(old_module_name)}") - raise "old API version module namespace #{old_module_name} not found in spec/presenters/#{module_name_for_path(old_module_name)}" if !File.exists?("spec/presenters/#{module_name_for_path(old_module_name)}") - end - raise "old API version #{old_version} not found in public/docs" if !File.exists?("public/docs/#{old_version}") - end - end - def copy_routes in_root do if RUBY_VERSION =~ /1.8/ || !defined?(RUBY_ENGINE) || RUBY_ENGINE != "ruby" @@ -44,20 +25,28 @@ def copy_routes 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)}("|')/ end - copied_routes = String.new(existing_routes) - copied_routes.gsub!(/"#{module_name_for_route(old_module_name)}"/, "\"#{module_name_for_route(new_module_name)}\"") - copied_routes.gsub!(/#{old_version}/, new_version) - route copied_routes + if !existing_routes.nil? + copied_routes = String.new(existing_routes) + copied_routes.gsub!(/"#{module_name_for_route(old_module_name)}"/, "\"#{module_name_for_route(new_module_name)}\"") + copied_routes.gsub!(/#{old_version}/, new_version) + route copied_routes + else + say "No routes found in config/routes.rb for #{old_version}" + end end end def copy_controllers in_root do - log "Copying all files from app/controllers/#{module_name_for_path(old_module_name)} to app/controllers/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "app/controllers/#{module_name_for_path(old_module_name)}", "app/controllers/#{module_name_for_path(new_module_name)}" - Dir.glob("app/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "app/controllers/#{module_name_for_path(old_module_name)}" + log "Copying all files from app/controllers/#{module_name_for_path(old_module_name)} to app/controllers/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "app/controllers/#{module_name_for_path(old_module_name)}", "app/controllers/#{module_name_for_path(new_module_name)}" + Dir.glob("app/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No controllers found in app/controllers for #{old_version}" end end end @@ -67,18 +56,26 @@ def copy_controller_tests in_root do case Versionist.configuration.configured_test_framework when :test_unit - log "Copying all files from test/functional/#{module_name_for_path(old_module_name)} to test/functional/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "test/functional/#{module_name_for_path(old_module_name)}", "test/functional/#{module_name_for_path(new_module_name)}" - Dir.glob("test/functional/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "test/functional/#{module_name_for_path(old_module_name)}" + log "Copying all files from test/functional/#{module_name_for_path(old_module_name)} to test/functional/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "test/functional/#{module_name_for_path(old_module_name)}", "test/functional/#{module_name_for_path(new_module_name)}" + Dir.glob("test/functional/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No controller tests found in test/functional for #{old_version}" end when :rspec - log "Copying all files from spec/controllers/#{module_name_for_path(old_module_name)} to spec/controllers/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "spec/controllers/#{module_name_for_path(old_module_name)}", "spec/controllers/#{module_name_for_path(new_module_name)}" - Dir.glob("spec/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "spec/controllers/#{module_name_for_path(old_module_name)}" + log "Copying all files from spec/controllers/#{module_name_for_path(old_module_name)} to spec/controllers/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "spec/controllers/#{module_name_for_path(old_module_name)}", "spec/controllers/#{module_name_for_path(new_module_name)}" + Dir.glob("spec/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No controller specs found in spec/controllers for #{old_version}" end else say "Unsupported test_framework: #{Versionist.configuration.configured_test_framework}" @@ -88,11 +85,15 @@ def copy_controller_tests def copy_presenters in_root do - log "Copying all files from app/presenters/#{module_name_for_path(old_module_name)} to app/presenters/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "app/presenters/#{module_name_for_path(old_module_name)}", "app/presenters/#{module_name_for_path(new_module_name)}" - Dir.glob("app/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "app/presenters/#{module_name_for_path(old_module_name)}" + log "Copying all files from app/presenters/#{module_name_for_path(old_module_name)} to app/presenters/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "app/presenters/#{module_name_for_path(old_module_name)}", "app/presenters/#{module_name_for_path(new_module_name)}" + Dir.glob("app/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No presenters found in app/presenters for #{old_version}" end end end @@ -101,18 +102,26 @@ def copy_presenter_tests in_root do case Versionist.configuration.configured_test_framework when :test_unit - log "Copying all files from test/presenters/#{module_name_for_path(old_module_name)} to test/presenters/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "test/presenters/#{module_name_for_path(old_module_name)}", "test/presenters/#{module_name_for_path(new_module_name)}" - Dir.glob("test/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "test/presenters/#{module_name_for_path(old_module_name)}" + log "Copying all files from test/presenters/#{module_name_for_path(old_module_name)} to test/presenters/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "test/presenters/#{module_name_for_path(old_module_name)}", "test/presenters/#{module_name_for_path(new_module_name)}" + Dir.glob("test/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No presenter tests found in test/presenters for #{old_version}" end when :rspec - log "Copying all files from spec/presenters/#{module_name_for_path(old_module_name)} to spec/presenters/#{module_name_for_path(new_module_name)}" - FileUtils.cp_r "spec/presenters/#{module_name_for_path(old_module_name)}", "spec/presenters/#{module_name_for_path(new_module_name)}" - Dir.glob("spec/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + if Dir.exists? "spec/presenters/#{module_name_for_path(old_module_name)}" + log "Copying all files from spec/presenters/#{module_name_for_path(old_module_name)} to spec/presenters/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "spec/presenters/#{module_name_for_path(old_module_name)}", "spec/presenters/#{module_name_for_path(new_module_name)}" + Dir.glob("spec/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No presenter specs found in spec/presenters for #{old_version}" end else say "Unsupported test_framework: #{Versionist.configuration.configured_test_framework}" @@ -122,11 +131,11 @@ def copy_presenter_tests def copy_documentation in_root do - log "Copying all files from public/docs/#{old_version} to public/docs/#{new_version}" - FileUtils.cp_r "public/docs/#{old_version}", "public/docs/#{new_version}" - Dir.glob("public/docs/#{new_version}/*.html").each do |f| - text = File.read(f) - File.open(f, 'w') {|f| f << text.gsub(/#{old_version}/, new_version)} + if Dir.exists? "public/docs/#{old_version}" + log "Copying all files from public/docs/#{old_version} to public/docs/#{new_version}" + FileUtils.cp_r "public/docs/#{old_version}/.", "public/docs/#{new_version}" + else + say "No documentation found in public/docs for #{old_version}" end end end diff --git a/spec/generators/copy_api_version_generator_spec.rb b/spec/generators/copy_api_version_generator_spec.rb index e100b2a..eccc144 100644 --- a/spec/generators/copy_api_version_generator_spec.rb +++ b/spec/generators/copy_api_version_generator_spec.rb @@ -32,50 +32,50 @@ Versionist.configuration.configured_test_framework = nil end - it "should raise an error if old version not found config/routes.rb" do + it "should not raise an error if old version not found config/routes.rb" do lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version #{mod} not found in config\/routes.rb/) + }.should_not raise_error end - it "should raise an error if old version module not found in app/controllers" do + it "should not raise an error if old version module not found in app/controllers" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in app\/controllers/) + }.should_not raise_error end - it "should raise an error if old version module not found in test/functional when Test::Unit is the test framework" do + it "should not raise an error if old version module not found in test/functional when Test::Unit is the test framework" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/presenters/#{module_name_for_path(mod)}", __FILE__)) Versionist.configuration.configured_test_framework = :test_unit lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in test\/functional/) + }.should_not raise_error end - it "should raise an error if old version module not found in spec/controllers when rspec is the test framework" do + it "should not raise an error if old version module not found in spec/controllers when rspec is the test framework" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/presenters/#{module_name_for_path(mod)}", __FILE__)) Versionist.configuration.configured_test_framework = :rspec lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in spec\/controllers/) + }.should_not raise_error end - it "should raise an error if old version module not found in app/presenters" do + it "should not raise an error if old version module not found in app/presenters" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}", __FILE__)) Versionist.configuration.configured_test_framework = :rspec lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in app\/presenters/) + }.should_not raise_error end - it "should raise an error if old version module not found in test/presenters when Test::Unit is the test framework" do + it "should not raise an error if old version module not found in test/presenters when Test::Unit is the test framework" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/test/functional/#{module_name_for_path(mod)}", __FILE__)) @@ -83,10 +83,10 @@ Versionist.configuration.configured_test_framework = :test_unit lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in test\/presenters/) + }.should_not raise_error end - it "should raise an error if old version module not found in spec/presenters when rspec is the test framework" do + it "should not raise an error if old version module not found in spec/presenters when rspec is the test framework" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}", __FILE__)) @@ -94,10 +94,10 @@ Versionist.configuration.configured_test_framework = :rspec lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version module namespace #{mod} not found in spec\/presenters/) + }.should_not raise_error end - it "should raise an error if old version not found in public/docs" do + it "should not raise an error if old version not found in public/docs" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}", __FILE__)) @@ -106,7 +106,7 @@ Versionist.configuration.configured_test_framework = :rspec lambda { run_generator [ver, mod, "x", "X", {}] - }.should raise_error(RuntimeError, /old API version #{ver} not found in public\/docs/) + }.should_not raise_error end end @@ -201,28 +201,8 @@ def to_xml(options={}, &block) end it "should copy documentation" do - expected_index_html = <<-HTML - - - - Documentation for x - - - -
-
-

API Operations

-
-
-

Documentation for x

-
-
- - - HTML - assert_file "public/docs/x/style.css" - assert_file "public/docs/x/index.html", expected_index_html.chop + assert_file "public/docs/x/index.html" end context "test_framework: test_unit" do From 6a26eef29e2b53518fdb7125506de0fb3f6aed15 Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 11:28:41 -0400 Subject: [PATCH 4/8] Issue #27: Changing Dir.exists? to File.exists? so it works with Ruby 1.8 --- .../copy_api_version/copy_api_version_generator.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb index 9d81f42..3fd5aca 100644 --- a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb +++ b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb @@ -38,7 +38,7 @@ def copy_routes def copy_controllers in_root do - if Dir.exists? "app/controllers/#{module_name_for_path(old_module_name)}" + if File.exists? "app/controllers/#{module_name_for_path(old_module_name)}" log "Copying all files from app/controllers/#{module_name_for_path(old_module_name)} to app/controllers/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "app/controllers/#{module_name_for_path(old_module_name)}", "app/controllers/#{module_name_for_path(new_module_name)}" Dir.glob("app/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -56,7 +56,7 @@ def copy_controller_tests in_root do case Versionist.configuration.configured_test_framework when :test_unit - if Dir.exists? "test/functional/#{module_name_for_path(old_module_name)}" + if File.exists? "test/functional/#{module_name_for_path(old_module_name)}" log "Copying all files from test/functional/#{module_name_for_path(old_module_name)} to test/functional/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "test/functional/#{module_name_for_path(old_module_name)}", "test/functional/#{module_name_for_path(new_module_name)}" Dir.glob("test/functional/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -67,7 +67,7 @@ def copy_controller_tests say "No controller tests found in test/functional for #{old_version}" end when :rspec - if Dir.exists? "spec/controllers/#{module_name_for_path(old_module_name)}" + if File.exists? "spec/controllers/#{module_name_for_path(old_module_name)}" log "Copying all files from spec/controllers/#{module_name_for_path(old_module_name)} to spec/controllers/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "spec/controllers/#{module_name_for_path(old_module_name)}", "spec/controllers/#{module_name_for_path(new_module_name)}" Dir.glob("spec/controllers/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -85,7 +85,7 @@ def copy_controller_tests def copy_presenters in_root do - if Dir.exists? "app/presenters/#{module_name_for_path(old_module_name)}" + if File.exists? "app/presenters/#{module_name_for_path(old_module_name)}" log "Copying all files from app/presenters/#{module_name_for_path(old_module_name)} to app/presenters/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "app/presenters/#{module_name_for_path(old_module_name)}", "app/presenters/#{module_name_for_path(new_module_name)}" Dir.glob("app/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -102,7 +102,7 @@ def copy_presenter_tests in_root do case Versionist.configuration.configured_test_framework when :test_unit - if Dir.exists? "test/presenters/#{module_name_for_path(old_module_name)}" + if File.exists? "test/presenters/#{module_name_for_path(old_module_name)}" log "Copying all files from test/presenters/#{module_name_for_path(old_module_name)} to test/presenters/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "test/presenters/#{module_name_for_path(old_module_name)}", "test/presenters/#{module_name_for_path(new_module_name)}" Dir.glob("test/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -113,7 +113,7 @@ def copy_presenter_tests say "No presenter tests found in test/presenters for #{old_version}" end when :rspec - if Dir.exists? "spec/presenters/#{module_name_for_path(old_module_name)}" + if File.exists? "spec/presenters/#{module_name_for_path(old_module_name)}" log "Copying all files from spec/presenters/#{module_name_for_path(old_module_name)} to spec/presenters/#{module_name_for_path(new_module_name)}" FileUtils.cp_r "spec/presenters/#{module_name_for_path(old_module_name)}", "spec/presenters/#{module_name_for_path(new_module_name)}" Dir.glob("spec/presenters/#{module_name_for_path(new_module_name)}/*.rb").each do |f| @@ -131,7 +131,7 @@ def copy_presenter_tests def copy_documentation in_root do - if Dir.exists? "public/docs/#{old_version}" + if File.exists? "public/docs/#{old_version}" log "Copying all files from public/docs/#{old_version} to public/docs/#{new_version}" FileUtils.cp_r "public/docs/#{old_version}/.", "public/docs/#{new_version}" else From 46dff57b43bc9bfd998f12d26bcd2fa9dfd9b17f Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 11:38:27 -0400 Subject: [PATCH 5/8] Version bump to 0.3.0 --- lib/versionist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/versionist/version.rb b/lib/versionist/version.rb index 01d6cd1..fe9329a 100644 --- a/lib/versionist/version.rb +++ b/lib/versionist/version.rb @@ -1,3 +1,3 @@ module Versionist - VERSION = '0.2.4' + VERSION = '0.3.0' end From 36ccef71e647c8ef817c7e6f03cde24fd0256822 Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 12:00:54 -0400 Subject: [PATCH 6/8] Switching to Oracle JDK, as OpenJDK keeps seg faulting and causing builds to fail --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index c2448c9..7b3d9c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,18 @@ rvm: - jruby-18mode - jruby-19mode - ree +jdk: + - oraclejdk7 +matrix: + exclude: + - rvm 1.8.7 + jdk: oraclejdk7 + - rvm 1.9.2 + jdk: oraclejdk7 + - rvm 1.9.3 + jdk: oraclejdk7 + - rvm ree + jdk: oraclejdk7 gemfile: - gemfiles/Rails-3.0 - gemfiles/Rails-3.1 From ded238eaaf726d293b081bef473421630ab87e52 Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 13:45:35 -0400 Subject: [PATCH 7/8] Issue #28: Adding support for integration tests/request specs in copy_api_generator --- gemfiles/Rails-3.0.lock | 2 +- gemfiles/Rails-3.1.lock | 2 +- gemfiles/Rails-3.2.lock | 2 +- .../copy_api_version_generator.rb | 22 +++++++ .../copy_api_version_generator_spec.rb | 63 +++++++++++++++++-- 5 files changed, 84 insertions(+), 7 deletions(-) diff --git a/gemfiles/Rails-3.0.lock b/gemfiles/Rails-3.0.lock index 15a80a1..8d4cc55 100644 --- a/gemfiles/Rails-3.0.lock +++ b/gemfiles/Rails-3.0.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.4) + versionist (0.3.0) rails (~> 3.0) yard (~> 0.7) diff --git a/gemfiles/Rails-3.1.lock b/gemfiles/Rails-3.1.lock index 873f183..b6f9bb7 100644 --- a/gemfiles/Rails-3.1.lock +++ b/gemfiles/Rails-3.1.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.4) + versionist (0.3.0) rails (~> 3.0) yard (~> 0.7) diff --git a/gemfiles/Rails-3.2.lock b/gemfiles/Rails-3.2.lock index 017d994..107ac87 100644 --- a/gemfiles/Rails-3.2.lock +++ b/gemfiles/Rails-3.2.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.2.4) + versionist (0.3.0) rails (~> 3.0) yard (~> 0.7) diff --git a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb index 3fd5aca..64a25a7 100644 --- a/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb +++ b/lib/generators/versionist/copy_api_version/copy_api_version_generator.rb @@ -66,6 +66,17 @@ def copy_controller_tests else say "No controller tests found in test/functional for #{old_version}" end + + if File.exists? "test/integration/#{module_name_for_path(old_module_name)}" + log "Copying all files from test/integration/#{module_name_for_path(old_module_name)} to test/integration/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "test/integration/#{module_name_for_path(old_module_name)}", "test/integration/#{module_name_for_path(new_module_name)}" + Dir.glob("test/integration/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No integration tests found in test/integration for #{old_version}" + end when :rspec if File.exists? "spec/controllers/#{module_name_for_path(old_module_name)}" log "Copying all files from spec/controllers/#{module_name_for_path(old_module_name)} to spec/controllers/#{module_name_for_path(new_module_name)}" @@ -77,6 +88,17 @@ def copy_controller_tests else say "No controller specs found in spec/controllers for #{old_version}" end + + if File.exists? "spec/requests/#{module_name_for_path(old_module_name)}" + log "Copying all files from spec/requests/#{module_name_for_path(old_module_name)} to spec/requests/#{module_name_for_path(new_module_name)}" + FileUtils.cp_r "spec/requests/#{module_name_for_path(old_module_name)}", "spec/requests/#{module_name_for_path(new_module_name)}" + Dir.glob("spec/requests/#{module_name_for_path(new_module_name)}/*.rb").each do |f| + text = File.read(f) + File.open(f, 'w') {|f| f << text.gsub(/#{old_module_name}/, new_module_name)} + end + else + say "No request specs found in spec/requests for #{old_version}" + end else say "Unsupported test_framework: #{Versionist.configuration.configured_test_framework}" end diff --git a/spec/generators/copy_api_version_generator_spec.rb b/spec/generators/copy_api_version_generator_spec.rb index eccc144..f02b201 100644 --- a/spec/generators/copy_api_version_generator_spec.rb +++ b/spec/generators/copy_api_version_generator_spec.rb @@ -28,7 +28,9 @@ ::FileUtils.rm_rf(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.rm_rf(::File.expand_path("../../tmp/app/presenters/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.rm_rf(::File.expand_path("../../tmp/test/functional/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.rm_rf(::File.expand_path("../../tmp/test/integration/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.rm_rf(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.rm_rf(::File.expand_path("../../tmp/spec/requests/#{module_name_for_path(mod)}", __FILE__)) Versionist.configuration.configured_test_framework = nil end @@ -55,6 +57,16 @@ }.should_not raise_error end + it "should not raise an error if old version module not found in test/integration when Test::Unit is the test framework" do + ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/presenters/#{module_name_for_path(mod)}", __FILE__)) + Versionist.configuration.configured_test_framework = :test_unit + lambda { + run_generator [ver, mod, "x", "X", {}] + }.should_not raise_error + end + it "should not raise an error if old version module not found in spec/controllers when rspec is the test framework" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) @@ -65,6 +77,16 @@ }.should_not raise_error end + it "should not raise an error if old version module not found in spec/requests when rspec is the test framework" do + ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/presenters/#{module_name_for_path(mod)}", __FILE__)) + Versionist.configuration.configured_test_framework = :rspec + lambda { + run_generator [ver, mod, "x", "X", {}] + }.should_not raise_error + end + it "should not raise an error if old version module not found in app/presenters" do ::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(mod)}\", :header => \"Accept\", :value => \"application/vnd.mycompany.com-#{ver}\") do\n end\nend"} ::FileUtils.mkdir_p(::File.expand_path("../../tmp/app/controllers/#{module_name_for_path(mod)}", __FILE__)) @@ -208,9 +230,12 @@ def to_xml(options={}, &block) context "test_framework: test_unit" do before :each do ::FileUtils.mkdir_p(::File.expand_path("../../tmp/test/functional/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/test/integration/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/test/presenters/#{module_name_for_path(mod)}", __FILE__)) ::File.open(::File.expand_path("../../tmp/test/functional/#{module_name_for_path(mod)}/base_controller_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::BaseControllerTest < ActionController::TestCase\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} ::File.open(::File.expand_path("../../tmp/test/functional/#{module_name_for_path(mod)}/foos_controller_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::FoosControllerTest < ActionController::TestCase\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} + ::File.open(::File.expand_path("../../tmp/test/integration/#{module_name_for_path(mod)}/base_controller_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::BaseControllerTest < ActionDispatch::IntegrationTest\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} + ::File.open(::File.expand_path("../../tmp/test/integration/#{module_name_for_path(mod)}/foos_controller_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::FoosControllerTest < ActionDispatch::IntegrationTest\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} ::File.open(::File.expand_path("../../tmp/test/presenters/#{module_name_for_path(mod)}/base_presenter_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::BasePresenterTest < Test::Unit::TestCase\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} ::File.open(::File.expand_path("../../tmp/test/presenters/#{module_name_for_path(mod)}/foo_presenter_test.rb", __FILE__), "w") {|f| f.write "require 'test_helper'\n\nclass #{mod}::FooPresenterTest < Test::Unit::TestCase\n # Replace this with your real tests.\n test \"the truth\" do\n assert true\n end\nend"} Versionist.configuration.configured_test_framework = :test_unit @@ -218,7 +243,7 @@ def to_xml(options={}, &block) end it "should copy old controller tests to new controller tests" do - expected_base_controller_test = <<-BASE + expected_base_controller_functional_test = <<-BASE require 'test_helper' class X::BaseControllerTest < ActionController::TestCase @@ -229,7 +254,18 @@ class X::BaseControllerTest < ActionController::TestCase end BASE - expected_foos_controller_test = <<-FOOS + expected_base_controller_integration_test = <<-BASE +require 'test_helper' + +class X::BaseControllerTest < ActionDispatch::IntegrationTest + # Replace this with your real tests. + test "the truth" do + assert true + end +end + BASE + + expected_foos_controller_functional_test = <<-FOOS require 'test_helper' class X::FoosControllerTest < ActionController::TestCase @@ -240,8 +276,22 @@ class X::FoosControllerTest < ActionController::TestCase end FOOS - assert_file "test/functional/#{module_name_for_path("X")}/base_controller_test.rb", expected_base_controller_test.chop - assert_file "test/functional/#{module_name_for_path("X")}/foos_controller_test.rb", expected_foos_controller_test.chop + expected_foos_controller_integration_test = <<-FOOS +require 'test_helper' + +class X::FoosControllerTest < ActionDispatch::IntegrationTest + # Replace this with your real tests. + test "the truth" do + assert true + end +end + FOOS + + + assert_file "test/functional/#{module_name_for_path("X")}/base_controller_test.rb", expected_base_controller_functional_test.chop + assert_file "test/integration/#{module_name_for_path("X")}/base_controller_test.rb", expected_base_controller_integration_test.chop + assert_file "test/functional/#{module_name_for_path("X")}/foos_controller_test.rb", expected_foos_controller_functional_test.chop + assert_file "test/integration/#{module_name_for_path("X")}/foos_controller_test.rb", expected_foos_controller_integration_test.chop end it "should copy old presenter tests to new presenter tests" do @@ -275,9 +325,12 @@ class X::FooPresenterTest < Test::Unit::TestCase context "test_framework: rspec" do before :each do ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}", __FILE__)) + ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/requests/#{module_name_for_path(mod)}", __FILE__)) ::FileUtils.mkdir_p(::File.expand_path("../../tmp/spec/presenters/#{module_name_for_path(mod)}", __FILE__)) ::File.open(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}/base_controller_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::BaseController do\n\nend"} ::File.open(::File.expand_path("../../tmp/spec/controllers/#{module_name_for_path(mod)}/foos_controller_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::FoosController do\n\nend"} + ::File.open(::File.expand_path("../../tmp/spec/requests/#{module_name_for_path(mod)}/base_controller_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::BaseController do\n\nend"} + ::File.open(::File.expand_path("../../tmp/spec/requests/#{module_name_for_path(mod)}/foos_controller_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::FoosController do\n\nend"} ::File.open(::File.expand_path("../../tmp/spec/presenters/#{module_name_for_path(mod)}/base_presenter_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::BasePresenter do\n\nend"} ::File.open(::File.expand_path("../../tmp/spec/presenters/#{module_name_for_path(mod)}/foo_presenter_spec.rb", __FILE__), "w") {|f| f.write "require 'spec_helper'\n\ndescribe #{mod}::FooPresenter do\n\nend"} Versionist.configuration.configured_test_framework = :rspec @@ -303,6 +356,8 @@ class X::FooPresenterTest < Test::Unit::TestCase assert_file "spec/controllers/#{module_name_for_path("X")}/base_controller_spec.rb", expected_base_controller_spec.chop assert_file "spec/controllers/#{module_name_for_path("X")}/foos_controller_spec.rb", expected_foos_controller_spec.chop + assert_file "spec/requests/#{module_name_for_path("X")}/base_controller_spec.rb", expected_base_controller_spec.chop + assert_file "spec/requests/#{module_name_for_path("X")}/foos_controller_spec.rb", expected_foos_controller_spec.chop end it "should copy old presenter specs to new presenter specs" do From c3187cbeef73b61b0c7afc2c36a5ffad0dab44fe Mon Sep 17 00:00:00 2001 From: Brian Ploetz Date: Fri, 27 Jul 2012 13:49:17 -0400 Subject: [PATCH 8/8] Version bump to 0.3.1 --- gemfiles/Rails-3.0.lock | 52 ++++++++++++++++++------------------- gemfiles/Rails-3.1.lock | 52 ++++++++++++++++++------------------- gemfiles/Rails-3.2.lock | 54 +++++++++++++++++++-------------------- lib/versionist/version.rb | 2 +- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/gemfiles/Rails-3.0.lock b/gemfiles/Rails-3.0.lock index 8d4cc55..45d2abd 100644 --- a/gemfiles/Rails-3.0.lock +++ b/gemfiles/Rails-3.0.lock @@ -1,7 +1,7 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.3.0) + versionist (0.3.1) rails (~> 3.0) yard (~> 0.7) @@ -9,12 +9,12 @@ GEM remote: http://rubygems.org/ specs: abstract (1.0.0) - actionmailer (3.0.15) - actionpack (= 3.0.15) + actionmailer (3.0.16) + actionpack (= 3.0.16) mail (~> 2.2.19) - actionpack (3.0.15) - activemodel (= 3.0.15) - activesupport (= 3.0.15) + actionpack (3.0.16) + activemodel (= 3.0.16) + activesupport (= 3.0.16) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.5.0) @@ -22,19 +22,19 @@ GEM rack-mount (~> 0.6.14) rack-test (~> 0.5.7) tzinfo (~> 0.3.23) - activemodel (3.0.15) - activesupport (= 3.0.15) + activemodel (3.0.16) + activesupport (= 3.0.16) builder (~> 2.1.2) i18n (~> 0.5.0) - activerecord (3.0.15) - activemodel (= 3.0.15) - activesupport (= 3.0.15) + activerecord (3.0.16) + activemodel (= 3.0.16) + activesupport (= 3.0.16) arel (~> 2.0.10) tzinfo (~> 0.3.23) - activeresource (3.0.15) - activemodel (= 3.0.15) - activesupport (= 3.0.15) - activesupport (3.0.15) + activeresource (3.0.16) + activemodel (= 3.0.16) + activesupport (= 3.0.16) + activesupport (3.0.16) arel (2.0.10) awesome_print (1.0.2) builder (2.1.2) @@ -45,7 +45,7 @@ GEM rails (>= 3.0, < 4.0) rspec-rails i18n (0.5.0) - json (1.7.3) + json (1.7.4) mail (2.2.19) activesupport (>= 2.3.6) i18n (>= 0.4.0) @@ -59,17 +59,17 @@ GEM rack (>= 1.0.0) rack-test (0.5.7) rack (>= 1.0) - rails (3.0.15) - actionmailer (= 3.0.15) - actionpack (= 3.0.15) - activerecord (= 3.0.15) - activeresource (= 3.0.15) - activesupport (= 3.0.15) + rails (3.0.16) + actionmailer (= 3.0.16) + actionpack (= 3.0.16) + activerecord (= 3.0.16) + activeresource (= 3.0.16) + activesupport (= 3.0.16) bundler (~> 1.0) - railties (= 3.0.15) - railties (3.0.15) - actionpack (= 3.0.15) - activesupport (= 3.0.15) + railties (= 3.0.16) + railties (3.0.16) + actionpack (= 3.0.16) + activesupport (= 3.0.16) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) diff --git a/gemfiles/Rails-3.1.lock b/gemfiles/Rails-3.1.lock index b6f9bb7..d687218 100644 --- a/gemfiles/Rails-3.1.lock +++ b/gemfiles/Rails-3.1.lock @@ -1,19 +1,19 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.3.0) + versionist (0.3.1) rails (~> 3.0) yard (~> 0.7) GEM remote: http://rubygems.org/ specs: - actionmailer (3.1.6) - actionpack (= 3.1.6) + actionmailer (3.1.7) + actionpack (= 3.1.7) mail (~> 2.3.3) - actionpack (3.1.6) - activemodel (= 3.1.6) - activesupport (= 3.1.6) + actionpack (3.1.7) + activemodel (= 3.1.7) + activesupport (= 3.1.7) builder (~> 3.0.0) erubis (~> 2.7.0) i18n (~> 0.6) @@ -22,19 +22,19 @@ GEM rack-mount (~> 0.8.2) rack-test (~> 0.6.1) sprockets (~> 2.0.4) - activemodel (3.1.6) - activesupport (= 3.1.6) + activemodel (3.1.7) + activesupport (= 3.1.7) builder (~> 3.0.0) i18n (~> 0.6) - activerecord (3.1.6) - activemodel (= 3.1.6) - activesupport (= 3.1.6) + activerecord (3.1.7) + activemodel (= 3.1.7) + activesupport (= 3.1.7) arel (~> 2.2.3) tzinfo (~> 0.3.29) - activeresource (3.1.6) - activemodel (= 3.1.6) - activesupport (= 3.1.6) - activesupport (3.1.6) + activeresource (3.1.7) + activemodel (= 3.1.7) + activesupport (= 3.1.7) + activesupport (3.1.7) multi_json (>= 1.0, < 1.3) arel (2.2.3) awesome_print (1.0.2) @@ -46,7 +46,7 @@ GEM rspec-rails hike (1.2.1) i18n (0.6.0) - json (1.7.3) + json (1.7.4) mail (2.3.3) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -63,17 +63,17 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) - rails (3.1.6) - actionmailer (= 3.1.6) - actionpack (= 3.1.6) - activerecord (= 3.1.6) - activeresource (= 3.1.6) - activesupport (= 3.1.6) + rails (3.1.7) + actionmailer (= 3.1.7) + actionpack (= 3.1.7) + activerecord (= 3.1.7) + activeresource (= 3.1.7) + activesupport (= 3.1.7) bundler (~> 1.0) - railties (= 3.1.6) - railties (3.1.6) - actionpack (= 3.1.6) - activesupport (= 3.1.6) + railties (= 3.1.7) + railties (3.1.7) + actionpack (= 3.1.7) + activesupport (= 3.1.7) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) diff --git a/gemfiles/Rails-3.2.lock b/gemfiles/Rails-3.2.lock index 107ac87..27a7ebc 100644 --- a/gemfiles/Rails-3.2.lock +++ b/gemfiles/Rails-3.2.lock @@ -1,38 +1,38 @@ PATH remote: /Users/bploetz/workspace/versionist specs: - versionist (0.3.0) + versionist (0.3.1) rails (~> 3.0) yard (~> 0.7) GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.6) - actionpack (= 3.2.6) + actionmailer (3.2.7) + actionpack (= 3.2.7) mail (~> 2.4.4) - actionpack (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + actionpack (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) erubis (~> 2.7.0) - journey (~> 1.0.1) + journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.1.3) - activemodel (3.2.6) - activesupport (= 3.2.6) + activemodel (3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) - activerecord (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + activerecord (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) - activesupport (3.2.6) + activeresource (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) + activesupport (3.2.7) i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) @@ -46,7 +46,7 @@ GEM hike (1.2.1) i18n (0.6.0) journey (1.0.4) - json (1.7.3) + json (1.7.4) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -61,17 +61,17 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) - rails (3.2.6) - actionmailer (= 3.2.6) - actionpack (= 3.2.6) - activerecord (= 3.2.6) - activeresource (= 3.2.6) - activesupport (= 3.2.6) + rails (3.2.7) + actionmailer (= 3.2.7) + actionpack (= 3.2.7) + activerecord (= 3.2.7) + activeresource (= 3.2.7) + activesupport (= 3.2.7) bundler (~> 1.0) - railties (= 3.2.6) - railties (3.2.6) - actionpack (= 3.2.6) - activesupport (= 3.2.6) + railties (= 3.2.7) + railties (3.2.7) + actionpack (= 3.2.7) + activesupport (= 3.2.7) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) diff --git a/lib/versionist/version.rb b/lib/versionist/version.rb index fe9329a..896714e 100644 --- a/lib/versionist/version.rb +++ b/lib/versionist/version.rb @@ -1,3 +1,3 @@ module Versionist - VERSION = '0.3.0' + VERSION = '0.3.1' end