From 911c6198226709e996769b395cbae92b770415e3 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Thu, 12 Sep 2013 19:12:36 +0400 Subject: [PATCH 1/6] upgrade to rails4 --- api_taster.gemspec | 2 +- spec/dummy/config/environments/development.rb | 5 ++--- spec/dummy/config/environments/production.rb | 2 ++ spec/dummy/config/environments/test.rb | 5 ++--- spec/mapper_spec.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api_taster.gemspec b/api_taster.gemspec index 4114d80..6f5666b 100644 --- a/api_taster.gemspec +++ b/api_taster.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split($\) s.test_files = Dir["spec/**/*"] - s.add_dependency 'rails', '~> 3.2.0' + s.add_dependency 'rails', '~> 4.0.0' s.add_dependency 'jquery-rails' s.add_dependency 'sass-rails' s.add_dependency 'bootstrap-sass', '~> 2.1' diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 3b9e645..9121010 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -6,9 +6,6 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -34,4 +31,6 @@ # Expands the lines which load the assets config.assets.debug = true + + config.eager_load = false end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index 166953a..91c400f 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -64,4 +64,6 @@ # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + config.eager_load = true end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 5eeb1e4..87c5f75 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -11,9 +11,6 @@ config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -34,4 +31,6 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + config.eager_load = false end diff --git a/spec/mapper_spec.rb b/spec/mapper_spec.rb index 1127ef4..4b6f481 100644 --- a/spec/mapper_spec.rb +++ b/spec/mapper_spec.rb @@ -36,7 +36,7 @@ module ApiTaster before(:all) do Rails.application.routes.draw do resources :dummy_users do - member { map_method :patch, :update } + member { map_method :patch, [:update] } end end From 1071c8bf3804d58e1e2f9286e58915755a3bcefa Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Thu, 12 Sep 2013 19:41:22 +0400 Subject: [PATCH 2/6] fix spec deprecation warnings --- lib/api_taster/route.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index 1d12b97..0ec0a5e 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -129,13 +129,19 @@ def split_input(input, route) url_param_keys = route[:path].scan /:\w+/ url_params = input.reject { |k, v| ! ":#{k}".in?(url_param_keys) } - post_params = input.diff(url_params) + post_params = hash_diff(input, url_params) { :url_params => url_params, :post_params => post_params } end + + def hash_diff(h1, h2) + h1.dup.delete_if do |k, v| + h2[k] == v + end.merge!(h2.dup.delete_if { |k, v| h1.has_key?(k) }) + end end end end From a1561f51645abe90d64b867b5b9329cee89f19da Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Thu, 12 Sep 2013 19:46:37 +0400 Subject: [PATCH 3/6] exclude rails routes --- lib/api_taster/route.rb | 1 + spec/route_spec.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index 0ec0a5e..e36c0ab 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -37,6 +37,7 @@ def normalise_routes! route_set.routes.each do |route| next if route.app.is_a?(Sprockets::Environment) next if route.app == ApiTaster::Engine + next if route.defaults[:controller].to_s.starts_with?('rails/') rack_app = discover_rack_app(route.app) diff --git a/spec/route_spec.rb b/spec/route_spec.rb index 41747d2..d376568 100644 --- a/spec/route_spec.rb +++ b/spec/route_spec.rb @@ -32,6 +32,9 @@ module ApiTaster end mount Rails.application => '/app' mount proc {} => '/rack_app' + + get 'rails/info/properties' => 'rails/info#properties', :as => :rails_info_properties + get '/' => 'rails/welcome#index' end Rails.application.stub(:routes).and_return(routes) From 0ba64689386dfc7fd6b0d77223c8f55f2a556a01 Mon Sep 17 00:00:00 2001 From: Artem Biserov Date: Mon, 7 Oct 2013 17:57:08 +0400 Subject: [PATCH 4/6] do not render layout in xhr request --- .../api_taster/application_controller.rb | 2 +- .../api_taster/routes_controller_spec.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/api_taster/application_controller.rb b/app/controllers/api_taster/application_controller.rb index d5654d9..76f491c 100644 --- a/app/controllers/api_taster/application_controller.rb +++ b/app/controllers/api_taster/application_controller.rb @@ -1,6 +1,6 @@ module ApiTaster class ApplicationController < ActionController::Base - layout proc { |controller| controller.request.xhr? ? nil : 'api_taster/application' } + layout proc { |controller| controller.request.xhr? ? false : 'api_taster/application' } before_filter :reload_routes diff --git a/spec/controllers/api_taster/routes_controller_spec.rb b/spec/controllers/api_taster/routes_controller_spec.rb index 87c8bc2..7c09df9 100644 --- a/spec/controllers/api_taster/routes_controller_spec.rb +++ b/spec/controllers/api_taster/routes_controller_spec.rb @@ -41,5 +41,25 @@ module ApiTaster assigns(:obsolete_definitions).should be_kind_of(Array) end + + context 'layout' do + context 'when request is not XHR' do + it 'renders application layout' do + get :index, :use_route => :api_taster + + response.should render_template('api_taster/application') + end + end + + context 'when request is XHR' do + before { request.stub(:xhr?) { true } } + + it 'does not render layout' do + get :index, :use_route => :api_taster + + response.should_not render_template('api_taster/application') + end + end + end end end From 4551e5735fea710d4ff3e2d7eaf16bdc49436900 Mon Sep 17 00:00:00 2001 From: Dmitry Trager Date: Wed, 9 Oct 2013 13:03:49 +0400 Subject: [PATCH 5/6] remove the restriction for rails version --- api_taster.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_taster.gemspec b/api_taster.gemspec index 6f5666b..77e543e 100644 --- a/api_taster.gemspec +++ b/api_taster.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split($\) s.test_files = Dir["spec/**/*"] - s.add_dependency 'rails', '~> 4.0.0' + s.add_dependency 'rails', '>= 4.0' s.add_dependency 'jquery-rails' s.add_dependency 'sass-rails' s.add_dependency 'bootstrap-sass', '~> 2.1' From 7fa87023f6d9a87cbb279c81a8cae1e4ec706e8b Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Thu, 10 Oct 2013 20:16:01 +0400 Subject: [PATCH 6/6] play nice with Rails 3 and 4 --- .travis.yml | 3 +++ api_taster.gemspec | 2 +- gemfiles/Gemfile.rails-3.2.x | 5 +++++ spec/mapper_spec.rb | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 gemfiles/Gemfile.rails-3.2.x diff --git a/.travis.yml b/.travis.yml index 222078e..fd52367 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,6 @@ language: ruby rvm: - 1.9.3 - 2.0.0 +gemfile: + - gemfiles/Gemfile.rails-3.2.x + - Gemfile diff --git a/api_taster.gemspec b/api_taster.gemspec index 77e543e..38d3009 100644 --- a/api_taster.gemspec +++ b/api_taster.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split($\) s.test_files = Dir["spec/**/*"] - s.add_dependency 'rails', '>= 4.0' + s.add_dependency 'rails', '>= 3.2' s.add_dependency 'jquery-rails' s.add_dependency 'sass-rails' s.add_dependency 'bootstrap-sass', '~> 2.1' diff --git a/gemfiles/Gemfile.rails-3.2.x b/gemfiles/Gemfile.rails-3.2.x new file mode 100644 index 0000000..30583a5 --- /dev/null +++ b/gemfiles/Gemfile.rails-3.2.x @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gemspec :path => '..' + +gem "rails", "~> 3.2.6" diff --git a/spec/mapper_spec.rb b/spec/mapper_spec.rb index 4b6f481..245c423 100644 --- a/spec/mapper_spec.rb +++ b/spec/mapper_spec.rb @@ -36,7 +36,11 @@ module ApiTaster before(:all) do Rails.application.routes.draw do resources :dummy_users do - member { map_method :patch, [:update] } + if Rails.version.starts_with? '4' + member { map_method :patch, [:update] } + else + member { map_method :patch, :update } + end end end