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 4114d80..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', '~> 3.2.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/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/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/lib/api_taster/route.rb b/lib/api_taster/route.rb index 1d12b97..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) @@ -129,13 +130,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 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 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..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 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)