batch_api 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/changelog.md +14 -0
  3. data/lib/batch_api/configuration.rb +1 -1
  4. data/lib/batch_api/internal_middleware/decode_json_body.rb +7 -3
  5. data/lib/batch_api/operation/rack.rb +4 -1
  6. data/lib/batch_api/version.rb +1 -1
  7. data/readme.md +2 -2
  8. data/spec/dummy/Gemfile +1 -0
  9. data/spec/dummy/Gemfile.lock +8 -0
  10. data/spec/dummy/bin/bundle +3 -0
  11. data/spec/dummy/bin/rails +4 -0
  12. data/spec/dummy/bin/rake +4 -0
  13. data/spec/dummy/bin/setup +29 -0
  14. data/spec/dummy/config/application.rb +6 -37
  15. data/spec/dummy/config/boot.rb +2 -9
  16. data/spec/dummy/config/environment.rb +3 -3
  17. data/spec/dummy/config/environments/development.rb +22 -18
  18. data/spec/dummy/config/environments/production.rb +46 -34
  19. data/spec/dummy/config/environments/test.rb +19 -14
  20. data/spec/dummy/config/initializers/assets.rb +11 -0
  21. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  23. data/spec/dummy/config/initializers/inflections.rb +6 -5
  24. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  25. data/spec/dummy/config/initializers/session_store.rb +1 -6
  26. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  27. data/spec/dummy/config/locales/en.yml +20 -2
  28. data/spec/dummy/config/secrets.yml +22 -0
  29. data/spec/dummy/log/test.log +7369 -46081
  30. data/spec/lib/batch_api_spec.rb +3 -3
  31. data/spec/lib/batch_error_spec.rb +3 -3
  32. data/spec/lib/configuration_spec.rb +3 -3
  33. data/spec/lib/error_wrapper_spec.rb +20 -20
  34. data/spec/lib/internal_middleware/decode_json_body_spec.rb +13 -6
  35. data/spec/lib/internal_middleware/response_filter_spec.rb +3 -3
  36. data/spec/lib/internal_middleware_spec.rb +15 -13
  37. data/spec/lib/operation/rack_spec.rb +58 -50
  38. data/spec/lib/operation/rails_spec.rb +10 -10
  39. data/spec/lib/processor/executor_spec.rb +5 -5
  40. data/spec/lib/processor/sequential_spec.rb +10 -10
  41. data/spec/lib/processor_spec.rb +23 -21
  42. data/spec/lib/rack_middleware_spec.rb +17 -17
  43. data/spec/lib/response_spec.rb +9 -9
  44. data/spec/{integration → rack-integration}/rails_spec.rb +3 -3
  45. data/spec/{integration → rack-integration}/shared_examples.rb +24 -18
  46. data/spec/{integration → rack-integration}/sinatra_integration_spec.rb +5 -0
  47. data/spec/spec_helper.rb +15 -1
  48. data/spec/support/sinatra_xhr.rb +13 -0
  49. metadata +47 -135
  50. data/spec/dummy/db/development.sqlite3 +0 -0
  51. data/spec/dummy/log/development.log +0 -1742
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9ab45d250596f0c71250892b09df8f5a64ec4bb
4
+ data.tar.gz: d9bb33bda25321512da207c5c9586dd5a07a654f
5
+ SHA512:
6
+ metadata.gz: ce733215e37bb8ba34652a845ac6787fe2c75998d8abfcf998f91bb6a9f78c08da6e767dfbf5404053fb380a1d2cb00444257f9873e0a17803c653a54850db2d
7
+ data.tar.gz: 7e335ed992bccb7260eec0304c1533f9f2d62d9ba89aaf5fb2c578dc64055f9f5576f082d8265e8645167952ea7b8a800b4a67fce0a93e945ae92d4b5d56cc40
@@ -1,3 +1,17 @@
1
+ v0.3.0
2
+
3
+ New features:
4
+
5
+ * guard against nil REQUEST_URI (thanks, pbendersky and dlackty!)
6
+ * don't parse empty bodies as JSON (thanks, trungpham and dlackty!)
7
+
8
+ Testing improvements:
9
+
10
+ * modernize test infrastructure and test against newer Ruby versions (thanks, dwaller, pmq20 and dlackty!)
11
+ * update test Rails app version to 4.2
12
+ * modernize RSpec syntax using transpec
13
+
14
+
1
15
  v0.2.2
2
16
  * Update documentation to remove old options and add installation section
3
17
  * Update gems
@@ -8,7 +8,7 @@ module BatchApi
8
8
  # - verb: through which it's accessed (default "POST")
9
9
  # - limit: how many requests can be processed in a single request
10
10
  # (default 50)
11
- #
11
+ #
12
12
  # There are also two middleware-related options -- check out middleware.rb
13
13
  # for more information.
14
14
  # - global_middleware: any middlewares to use round the entire batch request
@@ -1,7 +1,7 @@
1
1
  module BatchApi
2
2
  module InternalMiddleware
3
3
  # Public: a middleware that decodes the body of any individual batch
4
- # operation if the it's JSON.
4
+ # operation if it's JSON.
5
5
  class DecodeJsonBody
6
6
  # Public: initialize the middleware.
7
7
  def initialize(app)
@@ -10,14 +10,18 @@ module BatchApi
10
10
 
11
11
  def call(env)
12
12
  @app.call(env).tap do |result|
13
- result.body = MultiJson.load(result.body) if should_decode?(result)
13
+ if should_decode?(result)
14
+ result.body = MultiJson.load(result.body)
15
+ end
14
16
  end
15
17
  end
16
18
 
17
19
  private
18
20
 
19
21
  def should_decode?(result)
20
- result.headers["Content-Type"] =~ /^application\/json/
22
+ result.headers["Content-Type"] =~ /^application\/json/ &&
23
+ # don't try to decode an empty response
24
+ result.body.present?
21
25
  end
22
26
  end
23
27
  end
@@ -57,7 +57,10 @@ module BatchApi
57
57
  @env["REQUEST_METHOD"] = @method.upcase
58
58
 
59
59
  # path and query string
60
- @env["REQUEST_URI"] = @env["REQUEST_URI"].gsub(/\/batch.*/, @url)
60
+ if @env["REQUEST_URI"]
61
+ # not all servers provide REQUEST_URI -- Pow, for instance, doesn't
62
+ @env["REQUEST_URI"] = @env["REQUEST_URI"].gsub(/#{BatchApi.config.endpoint}.*/, @url)
63
+ end
61
64
  @env["REQUEST_PATH"] = path
62
65
  @env["ORIGINAL_FULLPATH"] = @env["PATH_INFO"] = @url
63
66
 
@@ -1,3 +1,3 @@
1
1
  module BatchApi
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://secure.travis-ci.org/arsduo/batch_api.png?branch=master)](http://travis-ci.org/arsduo/batch_api)
1
+ [![Build Status](https://travis-ci.org/arsduo/batch_api.svg?branch=master)](http://travis-ci.org/arsduo/batch_api)
2
2
 
3
3
  ## What's this?
4
4
 
@@ -6,7 +6,7 @@ A gem that provides a RESTful Batch API for Rails and other Rack applications.
6
6
  In this system, batch requests are simply collections of regular REST calls,
7
7
  whose results are returned as an equivalent collection of regular REST results.
8
8
 
9
- This is heavily inspired by [Facebook's Batch API](http://developers.facebook.com/docs/reference/api/batch/).
9
+ This is heavily inspired by [Facebook's Batch API](https://developers.facebook.com/docs/graph-api/making-multiple-requests).
10
10
 
11
11
  ## A Quick Example
12
12
 
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,8 @@
1
+ GEM
2
+ specs:
3
+
4
+ PLATFORMS
5
+ java
6
+ ruby
7
+
8
+ DEPENDENCIES
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -2,7 +2,10 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- Bundler.require
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups)
8
+
6
9
  require "batch_api"
7
10
 
8
11
  module Dummy
@@ -11,16 +14,6 @@ module Dummy
11
14
  # Application configuration should go into files in config/initializers
12
15
  # -- all .rb files in that directory are automatically loaded.
13
16
 
14
- # Custom directories with classes and modules you want to be autoloadable.
15
- # config.autoload_paths += %W(#{config.root}/extras)
16
-
17
- # Only load the plugins named here, in the order given (default is alphabetical).
18
- # :all can be used as a placeholder for all plugins not explicitly named.
19
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
-
21
- # Activate observers that should always be running.
22
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
-
24
17
  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
18
  # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
19
  # config.time_zone = 'Central Time (US & Canada)'
@@ -29,35 +22,11 @@ module Dummy
29
22
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
23
  # config.i18n.default_locale = :de
31
24
 
32
- # Configure the default encoding used in templates for Ruby 1.9.
33
- config.encoding = "utf-8"
34
-
35
- # Configure sensitive parameters which will be filtered from the log file.
36
- config.filter_parameters += [:password]
37
-
38
- # Enable escaping HTML in JSON.
39
- config.active_support.escape_html_entities_in_json = true
40
-
41
- # Use SQL instead of Active Record's schema dumper when creating the database.
42
- # This is necessary if your schema can't be completely dumped by the schema dumper,
43
- # like if you have constraints or database-specific column types
44
- # config.active_record.schema_format = :sql
45
-
46
- # Enforce whitelist mode for mass assignment.
47
- # This will create an empty whitelist of attributes available for mass-assignment for all models
48
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
- # parameters by using an attr_accessible or attr_protected declaration.
50
- config.active_record.whitelist_attributes = true
51
-
52
- # Enable the asset pipeline
53
- config.assets.enabled = true
54
-
55
- # Version of your assets, change this if you want to expire all your assets
56
- config.assets.version = '1.0'
25
+ # Do not swallow errors in after_commit/after_rollback callbacks.
26
+ config.active_record.raise_in_transactional_callbacks = true
57
27
 
58
28
  config.middleware.use BatchApi::RackMiddleware do |batch|
59
29
  batch.limit = 25
60
30
  end
61
31
  end
62
32
  end
63
-
@@ -1,10 +1,3 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
2
 
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -1,5 +1,5 @@
1
- # Load the rails application
1
+ # Load the Rails application.
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -1,37 +1,41 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
5
5
  # every request. This slows down response time but is perfect for development
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
11
 
12
- # Show full error reports and disable caching
12
+ # Show full error reports and disable caching.
13
13
  config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
- # Don't care if the mailer can't send
16
+ # Don't care if the mailer can't send.
17
17
  config.action_mailer.raise_delivery_errors = false
18
18
 
19
- # Print deprecation notices to the Rails logger
19
+ # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
24
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
27
29
 
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
31
33
 
32
- # Do not compress assets
33
- config.assets.compress = false
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
34
38
 
35
- # Expands the lines which load the assets
36
- config.assets.debug = true
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
37
41
  end
@@ -1,67 +1,79 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
- # Code is not reloaded between requests
4
+ # Code is not reloaded between requests.
5
5
  config.cache_classes = true
6
6
 
7
- # Full error reports are disabled and caching is turned on
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
8
14
  config.consider_all_requests_local = false
9
15
  config.action_controller.perform_caching = true
10
16
 
11
- # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
21
+ # config.action_dispatch.rack_cache = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
13
26
 
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
27
+ # Compress JavaScripts and CSS.
28
+ config.assets.js_compressor = :uglifier
29
+ # config.assets.css_compressor = :sass
16
30
 
17
- # Don't fallback to assets pipeline if a precompiled asset is missed
31
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
18
32
  config.assets.compile = false
19
33
 
20
- # Generate digests for assets URLs
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
21
36
  config.assets.digest = true
22
37
 
23
- # Defaults to nil and saved in location specified by config.assets.prefix
24
- # config.assets.manifest = YOUR_PATH
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
25
39
 
26
- # Specifies the header that your server uses for sending files
27
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
40
+ # Specifies the header that your server uses for sending files.
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
29
43
 
30
44
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
45
  # config.force_ssl = true
32
46
 
33
- # See everything in the log (default is :info)
34
- # config.log_level = :debug
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
35
50
 
36
- # Prepend all log lines with the following tags
51
+ # Prepend all log lines with the following tags.
37
52
  # config.log_tags = [ :subdomain, :uuid ]
38
53
 
39
- # Use a different logger for distributed setups
54
+ # Use a different logger for distributed setups.
40
55
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
56
 
42
- # Use a different cache store in production
57
+ # Use a different cache store in production.
43
58
  # config.cache_store = :mem_cache_store
44
59
 
45
- # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
- # config.action_controller.asset_host = "http://assets.example.com"
47
-
48
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
- # config.assets.precompile += %w( search.js )
60
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
50
62
 
51
- # Disable delivery errors, bad email addresses will be ignored
63
+ # Ignore bad email addresses and do not raise email delivery errors.
64
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
52
65
  # config.action_mailer.raise_delivery_errors = false
53
66
 
54
- # Enable threaded mode
55
- # config.threadsafe!
56
-
57
67
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
- # the I18n.default_locale when a translation can not be found)
68
+ # the I18n.default_locale when a translation cannot be found).
59
69
  config.i18n.fallbacks = true
60
70
 
61
- # Send deprecation notices to registered listeners
71
+ # Send deprecation notices to registered listeners.
62
72
  config.active_support.deprecation = :notify
63
73
 
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
74
+ # Use default logging formatter so that PID and timestamp are not suppressed.
75
+ config.log_formatter = ::Logger::Formatter.new
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
67
79
  end
@@ -1,5 +1,5 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
5
  # test suite. You never need to work with it otherwise. Remember that
@@ -7,31 +7,36 @@ Dummy::Application.configure do
7
7
  # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
13
14
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
15
+ # Configure static file server for tests with Cache-Control for performance.
16
+ config.serve_static_files = true
17
+ config.static_cache_control = 'public, max-age=3600'
16
18
 
17
- # Show full error reports and disable caching
19
+ # Show full error reports and disable caching.
18
20
  config.consider_all_requests_local = true
19
21
  config.action_controller.perform_caching = false
20
22
 
21
- # Raise exceptions instead of rendering exception templates
23
+ # Raise exceptions instead of rendering exception templates.
22
24
  config.action_dispatch.show_exceptions = false
23
25
 
24
- # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
26
28
 
27
29
  # Tell Action Mailer not to deliver emails to the real world.
28
30
  # The :test delivery method accumulates sent emails in the
29
31
  # ActionMailer::Base.deliveries array.
30
32
  config.action_mailer.delivery_method = :test
31
33
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
+ # Randomize the order test cases are executed.
35
+ config.active_support.test_order = :random
34
36
 
35
- # Print deprecation notices to the stderr
37
+ # Print deprecation notices to the stderr.
36
38
  config.active_support.deprecation = :stderr
39
+
40
+ # Raises error for missing translations
41
+ # config.action_view.raise_on_missing_translations = true
37
42
  end