diff --git a/.travis.yml b/.travis.yml index 3fd192d..027f8fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,6 @@ gemfile: - gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile - gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile - gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile - - gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile \ No newline at end of file + - gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile + - gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile + - gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile diff --git a/Appraisals b/Appraisals index 0d2e38d..f84c6bb 100644 --- a/Appraisals +++ b/Appraisals @@ -1,12 +1,14 @@ rails_versions = ["~> 3.0.0", "~> 3.1.0", "~> 3.2.0", "~> 4.0.0", "~> 4.1.0", "~> 5.0.0"] jbuilder_versions = ["~> 1.5.0", "~> 2.0.0"] -rails_versions.each do |r| +rails_versions.each_with_index do |r,ri| jbuilder_versions.each do |j| appraise "rails_#{r.match(/\d.*/)} jbuilder_#{j.match(/\d.*/)}" do gem "railties", r gem "actionpack", r gem "jbuilder", j + gem "activerecord", r + gem "sqlite3", '~> 1.3.11' end end end diff --git a/Gemfile b/Gemfile index 9884ade..60be7c3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,4 @@ gemspec gem "rake" gem "mocha", require: false gem "appraisal" -gem "test-unit" \ No newline at end of file +gem "test-unit" diff --git a/Gemfile.lock b/Gemfile.lock index 3054c23..6432c4b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,32 +7,29 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (5.1.1) + activesupport (5.2.4.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) - concurrent-ruby (1.0.5) - i18n (0.8.4) - jbuilder (2.7.0) - activesupport (>= 4.2.0) - multi_json (>= 1.2) - metaclass (0.0.4) - minitest (5.10.2) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.12.1) - power_assert (0.2.2) - rake (10.4.2) - test-unit (3.0.8) + concurrent-ruby (1.1.7) + i18n (1.5.1) + concurrent-ruby (~> 1.0) + jbuilder (2.10.1) + activesupport (>= 5.0.0) + minitest (5.14.2) + mocha (1.11.2) + power_assert (1.2.0) + rake (13.0.1) + test-unit (3.3.6) power_assert - thor (0.19.1) + thor (1.0.1) thread_safe (0.3.6) - tzinfo (1.2.3) + tzinfo (1.2.7) thread_safe (~> 0.1) PLATFORMS @@ -46,4 +43,4 @@ DEPENDENCIES test-unit BUNDLED WITH - 1.15.1 + 1.17.3 diff --git a/README.md b/README.md index 6385323..8590da9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/quorak/jbuilder_cache_multi.svg?branch=master)](https://travis-ci.org/quorak/jbuilder_cache_multi) + # JbuilderCacheMulti Useful when you need to retrieve fragments for a collection of objects from the cache. This plugin gives you method called 'cache_collection!' which uses fetch_multi (new in Rails 4.1) to retrieve multiple keys in a single go. @@ -68,6 +70,28 @@ You can also conditionally cache a block by using `cache_collection_if!` like th json.partial! 'person', :person => person end +### Usage with ActiveRecord::Relation + +Sometimes queries can be very complex and populating models from queries with many includes take +up the majority of time. After checking the cache, it is than obvious populating all these models was not +necessary as we have a hit. Why not checking the cache after just using a simple query to build the cache-key +and only fire the complex query for those models, that do not exist in the cache? Well this is possible. + +For these cases you can paste the ActiveRecord::Relation and `cache_collection!` will: +1. unscope all `includes` for the initial query to build all cache_key's (make sure you use `joins` for + statements that are use in `where`) +2. gets the result from cache with `Rails.cache.read_multi` for existing cache_key hits +3. gets all missed hits from the database with complex includes and all fields +4. builds the block with all data +5. uses `Rails.cache.write_multi` if available to populate the cache with the missed values + + + + json.cache_collection! Post.includes(:author) do |post| + json.partial! 'post', :post => post + end + + ## Todo - Add support for passing a partial name as an argument (e.g. json.cache_collection! @people, partial: 'person') or maybe even just "json.cache_collection! @people" and infer the partial name from the collection... diff --git a/Rakefile b/Rakefile index ba82337..c1ba92a 100644 --- a/Rakefile +++ b/Rakefile @@ -10,9 +10,14 @@ else require "rails/version" test.libs << "test" + test.verbose = false + test.warning = false if Rails::VERSION::MAJOR == 3 - test.test_files = %w[test/jbuilder_template_test.rb] + test.test_files = %w[ + test/jbuilder_template_test.rb + test/jbuilder_template_active_record_relation_test.rb + ] else test.test_files = FileList["test/*_test.rb"] end diff --git a/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile index aa80362..016b6be 100644 --- a/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.0.0" gem "actionpack", "~> 3.0.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 3.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile.lock index 22735e4..78ff1b1 100644 --- a/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_3.0.0_jbuilder_1.5.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -22,11 +22,17 @@ GEM activesupport (= 3.0.20) builder (~> 2.1.2) i18n (~> 0.5.0) + activerecord (3.0.20) + activemodel (= 3.0.20) + activesupport (= 3.0.20) + arel (~> 2.0.10) + tzinfo (~> 0.3.23) activesupport (3.0.20) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (2.0.10) builder (2.1.2) erubis (2.6.6) abstract (>= 1.0.0) @@ -34,12 +40,10 @@ GEM jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.2.8) rack-mount (0.6.14) rack (>= 1.0.0) @@ -51,26 +55,29 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert thor (0.14.6) - tzinfo (0.3.44) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.0.0) + activerecord (~> 3.0.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 3.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile index 4ef4ffa..c8928b5 100644 --- a/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.0.0" gem "actionpack", "~> 3.0.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 3.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile.lock index a2cef12..3da4305 100644 --- a/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_3.0.0_jbuilder_2.0.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -22,11 +22,17 @@ GEM activesupport (= 3.0.20) builder (~> 2.1.2) i18n (~> 0.5.0) + activerecord (3.0.20) + activemodel (= 3.0.20) + activesupport (= 3.0.20) + arel (~> 2.0.10) + tzinfo (~> 0.3.23) activesupport (3.0.20) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (2.0.10) builder (2.1.2) erubis (2.6.6) abstract (>= 1.0.0) @@ -34,12 +40,10 @@ GEM jbuilder (2.0.8) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.2.8) rack-mount (0.6.14) rack (>= 1.0.0) @@ -51,26 +55,29 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert thor (0.14.6) - tzinfo (0.3.44) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.0.0) + activerecord (~> 3.0.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 3.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile index 26ae6a1..3bfe538 100644 --- a/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.1.0" gem "actionpack", "~> 3.1.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 3.1.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile.lock index 56972ea..fb3e6e5 100644 --- a/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_3.1.0_jbuilder_1.5.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -22,27 +22,33 @@ GEM activesupport (= 3.1.12) builder (~> 3.0.0) i18n (~> 0.6) + activerecord (3.1.12) + activemodel (= 3.1.12) + activesupport (= 3.1.12) + arel (~> 2.2.3) + tzinfo (~> 0.3.29) activesupport (3.1.12) multi_json (~> 1.0) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (2.2.3) builder (3.0.4) + concurrent-ruby (1.1.7) erubis (2.7.0) hike (1.2.3) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.3.10) - rack-cache (1.2) + rack-cache (1.9.0) rack (>= 0.4) rack-mount (0.8.3) rack (>= 1.0.0) @@ -57,30 +63,34 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) sprockets (2.0.5) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert thor (0.14.6) tilt (1.4.1) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.1.0) + activerecord (~> 3.1.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 3.1.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile index ff4d52e..df1beb7 100644 --- a/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.1.0" gem "actionpack", "~> 3.1.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 3.1.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile.lock index bf77b2d..4693527 100644 --- a/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_3.1.0_jbuilder_2.0.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -22,27 +22,33 @@ GEM activesupport (= 3.1.12) builder (~> 3.0.0) i18n (~> 0.6) + activerecord (3.1.12) + activemodel (= 3.1.12) + activesupport (= 3.1.12) + arel (~> 2.2.3) + tzinfo (~> 0.3.29) activesupport (3.1.12) multi_json (~> 1.0) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (2.2.3) builder (3.0.4) + concurrent-ruby (1.1.7) erubis (2.7.0) hike (1.2.3) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (2.0.8) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.3.10) - rack-cache (1.2) + rack-cache (1.9.0) rack (>= 0.4) rack-mount (0.8.3) rack (>= 1.0.0) @@ -57,30 +63,34 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) sprockets (2.0.5) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert thor (0.14.6) tilt (1.4.1) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.1.0) + activerecord (~> 3.1.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 3.1.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile index a2aba7d..c2cdfb5 100644 --- a/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.2.0" gem "actionpack", "~> 3.2.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 3.2.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile.lock index 274f4c2..615fcba 100644 --- a/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_3.2.0_jbuilder_1.5.0.gemfile.lock @@ -1,15 +1,15 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (3.2.22) - activemodel (= 3.2.22) - activesupport (= 3.2.22) + actionpack (3.2.22.5) + activemodel (= 3.2.22.5) + activesupport (= 3.2.22.5) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -17,45 +17,51 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.22) - activesupport (= 3.2.22) + activemodel (3.2.22.5) + activesupport (= 3.2.22.5) builder (~> 3.0.0) - activesupport (3.2.22) + activerecord (3.2.22.5) + activemodel (= 3.2.22.5) + activesupport (= 3.2.22.5) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activesupport (3.2.22.5) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (3.0.3) builder (3.0.4) + concurrent-ruby (1.1.7) erubis (2.7.0) hike (1.2.3) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) journey (1.0.4) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.4.7) - rack-cache (1.2) + rack-cache (1.9.0) rack (>= 0.4) rack-ssl (1.3.4) rack rack-test (0.6.3) rack (>= 1.0) - railties (3.2.22) - actionpack (= 3.2.22) - activesupport (= 3.2.22) + railties (3.2.22.5) + actionpack (= 3.2.22.5) + activesupport (= 3.2.22.5) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) sprockets (2.2.3) @@ -63,23 +69,27 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) + thor (1.0.1) tilt (1.4.1) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.2.0) + activerecord (~> 3.2.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 3.2.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile index 2b6f6e5..ce5c2bf 100644 --- a/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 3.2.0" gem "actionpack", "~> 3.2.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 3.2.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile.lock index cf2c2b2..ff36200 100644 --- a/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_3.2.0_jbuilder_2.0.0.gemfile.lock @@ -1,15 +1,15 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (3.2.22) - activemodel (= 3.2.22) - activesupport (= 3.2.22) + actionpack (3.2.22.5) + activemodel (= 3.2.22.5) + activesupport (= 3.2.22.5) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -17,45 +17,51 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.22) - activesupport (= 3.2.22) + activemodel (3.2.22.5) + activesupport (= 3.2.22.5) builder (~> 3.0.0) - activesupport (3.2.22) + activerecord (3.2.22.5) + activemodel (= 3.2.22.5) + activesupport (= 3.2.22.5) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activesupport (3.2.22.5) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (3.0.3) builder (3.0.4) + concurrent-ruby (1.1.7) erubis (2.7.0) hike (1.2.3) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (2.0.8) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) journey (1.0.4) - json (1.8.3) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.4.7) - rack-cache (1.2) + rack-cache (1.9.0) rack (>= 0.4) rack-ssl (1.3.4) rack rack-test (0.6.3) rack (>= 1.0) - railties (3.2.22) - actionpack (= 3.2.22) - activesupport (= 3.2.22) + railties (3.2.22.5) + actionpack (= 3.2.22.5) + activesupport (= 3.2.22.5) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.4.2) + rake (13.0.1) rdoc (3.12.2) json (~> 1.4) sprockets (2.2.3) @@ -63,23 +69,27 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - test-unit (3.0.8) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) + thor (1.0.1) tilt (1.4.1) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 3.2.0) + activerecord (~> 3.2.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 3.2.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile index 154a662..ec7b94b 100644 --- a/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 4.0.0" gem "actionpack", "~> 4.0.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 4.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile.lock index d6a2b12..4286695 100644 --- a/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_4.0.0_jbuilder_1.5.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -13,28 +13,38 @@ GEM erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) activesupport (4.0.13) i18n (~> 0.6, >= 0.6.9) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (4.0.2) builder (3.1.4) + concurrent-ruby (1.1.7) erubis (2.7.0) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - metaclass (0.0.4) minitest (4.7.5) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) @@ -43,25 +53,28 @@ GEM activesupport (= 4.0.13) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - test-unit (3.0.8) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (0.3.44) + thor (1.0.1) + thread_safe (0.3.6) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 4.0.0) + activerecord (~> 4.0.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 4.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile index 66a68f1..f988dbb 100644 --- a/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 4.0.0" gem "actionpack", "~> 4.0.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 4.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile.lock index 316c706..3dd5ed6 100644 --- a/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_4.0.0_jbuilder_2.0.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM @@ -13,28 +13,38 @@ GEM erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) activesupport (4.0.13) i18n (~> 0.6, >= 0.6.9) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) + arel (4.0.2) builder (3.1.4) + concurrent-ruby (1.1.7) erubis (2.7.0) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (2.0.8) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - metaclass (0.0.4) minitest (4.7.5) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) @@ -43,25 +53,28 @@ GEM activesupport (= 4.0.13) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - test-unit (3.0.8) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (0.3.44) + thor (1.0.1) + thread_safe (0.3.6) + tzinfo (0.3.57) PLATFORMS ruby DEPENDENCIES actionpack (~> 4.0.0) + activerecord (~> 4.0.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 4.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile index 656d3e4..445652c 100644 --- a/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 4.1.0" gem "actionpack", "~> 4.1.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 4.1.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile.lock index 0a9c34e..d56fb7e 100644 --- a/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_4.1.0_jbuilder_1.5.0.gemfile.lock @@ -1,58 +1,67 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (4.1.13) - actionview (= 4.1.13) - activesupport (= 4.1.13) + actionpack (4.1.16) + actionview (= 4.1.16) + activesupport (= 4.1.16) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.13) - activesupport (= 4.1.13) + actionview (4.1.16) + activesupport (= 4.1.16) builder (~> 3.1) erubis (~> 2.7.0) - activesupport (4.1.13) + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) + activesupport (4.1.16) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) - builder (3.2.2) + arel (5.0.1.20140414130214) + builder (3.2.4) + concurrent-ruby (1.1.7) erubis (2.7.0) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - json (1.8.3) - metaclass (0.0.4) - minitest (5.8.0) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + minitest (5.14.2) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) - railties (4.1.13) - actionpack (= 4.1.13) - activesupport (= 4.1.13) + railties (4.1.16) + actionpack (= 4.1.16) + activesupport (= 4.1.16) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - test-unit (3.0.8) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) + thor (1.0.1) + thread_safe (0.3.6) + tzinfo (1.2.7) thread_safe (~> 0.1) PLATFORMS @@ -60,13 +69,15 @@ PLATFORMS DEPENDENCIES actionpack (~> 4.1.0) + activerecord (~> 4.1.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 4.1.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile index 4fedfe8..d1c8625 100644 --- a/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 4.1.0" gem "actionpack", "~> 4.1.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 4.1.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile.lock index e1dfb97..dd4e78f 100644 --- a/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_4.1.0_jbuilder_2.0.0.gemfile.lock @@ -1,58 +1,67 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (4.1.13) - actionview (= 4.1.13) - activesupport (= 4.1.13) + actionpack (4.1.16) + actionview (= 4.1.16) + activesupport (= 4.1.16) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.13) - activesupport (= 4.1.13) + actionview (4.1.16) + activesupport (= 4.1.16) builder (~> 3.1) erubis (~> 2.7.0) - activesupport (4.1.13) + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) + activesupport (4.1.16) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) - appraisal (2.1.0) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) - builder (3.2.2) + arel (5.0.1.20140414130214) + builder (3.2.4) + concurrent-ruby (1.1.7) erubis (2.7.0) - i18n (0.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (2.0.8) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - json (1.8.3) - metaclass (0.0.4) - minitest (5.8.0) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.2) - power_assert (0.2.2) + json (1.8.6) + minitest (5.14.2) + mocha (1.11.2) + multi_json (1.15.0) + power_assert (1.2.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) - railties (4.1.13) - actionpack (= 4.1.13) - activesupport (= 4.1.13) + railties (4.1.16) + actionpack (= 4.1.16) + activesupport (= 4.1.16) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - test-unit (3.0.8) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) + thor (1.0.1) + thread_safe (0.3.6) + tzinfo (1.2.7) thread_safe (~> 0.1) PLATFORMS @@ -60,13 +69,15 @@ PLATFORMS DEPENDENCIES actionpack (~> 4.1.0) + activerecord (~> 4.1.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 4.1.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile b/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile index 965e1ae..a5246b2 100644 --- a/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile +++ b/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 5.0.0" gem "actionpack", "~> 5.0.0" gem "jbuilder", "~> 1.5.0" +gem "activerecord", "~> 5.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile.lock b/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile.lock index f3ff5ec..fb59122 100644 --- a/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile.lock +++ b/gemfiles/rails_5.0.0_jbuilder_1.5.0.gemfile.lock @@ -1,73 +1,82 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (5.0.2) - actionview (= 5.0.2) - activesupport (= 5.0.2) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.2) - activesupport (= 5.0.2) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activesupport (5.0.2) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) appraisal (2.2.0) bundler rake thor (>= 0.14.0) - builder (3.2.3) - concurrent-ruby (1.0.5) + arel (7.1.4) + builder (3.2.4) + concurrent-ruby (1.1.7) + crass (1.0.6) erubis (2.7.0) - i18n (0.8.1) + i18n (1.5.1) + concurrent-ruby (~> 1.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - loofah (2.0.3) + loofah (2.7.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - metaclass (0.0.4) - method_source (0.8.2) - mini_portile2 (2.1.0) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - multi_json (1.12.1) - nokogiri (1.7.1) - mini_portile2 (~> 2.1.0) - power_assert (1.0.2) - rack (2.0.2) + method_source (1.0.0) + mini_portile2 (2.4.0) + minitest (5.14.2) + mocha (1.11.2) + multi_json (1.15.0) + nokogiri (1.9.1) + mini_portile2 (~> 2.4.0) + power_assert (1.2.0) + rack (2.1.4) rack-test (0.6.3) rack (>= 1.0) - rails-dom-testing (2.0.2) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.2) - actionpack (= 5.0.2) - activesupport (= 5.0.2) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) - test-unit (3.2.3) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.4) + thor (1.0.1) thread_safe (0.3.6) - tzinfo (1.2.3) + tzinfo (1.2.7) thread_safe (~> 0.1) PLATFORMS @@ -75,13 +84,15 @@ PLATFORMS DEPENDENCIES actionpack (~> 5.0.0) + activerecord (~> 5.0.0) appraisal jbuilder (~> 1.5.0) jbuilder_cache_multi! mocha railties (~> 5.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile b/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile index 9c24ceb..7198f6c 100644 --- a/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile +++ b/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile @@ -3,11 +3,13 @@ source "https://rubygems.org" gem "rake" -gem "mocha", :require => false +gem "mocha", require: false gem "appraisal" gem "test-unit" gem "railties", "~> 5.0.0" gem "actionpack", "~> 5.0.0" gem "jbuilder", "~> 2.0.0" +gem "activerecord", "~> 5.0.0" +gem "sqlite3", "~> 1.3.11" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile.lock b/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile.lock index 485f265..8f5e892 100644 --- a/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile.lock +++ b/gemfiles/rails_5.0.0_jbuilder_2.0.0.gemfile.lock @@ -1,73 +1,82 @@ PATH remote: .. specs: - jbuilder_cache_multi (0.0.3) + jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) GEM remote: https://rubygems.org/ specs: - actionpack (5.0.2) - actionview (= 5.0.2) - activesupport (= 5.0.2) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.2) - activesupport (= 5.0.2) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activesupport (5.0.2) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) appraisal (2.2.0) bundler rake thor (>= 0.14.0) - builder (3.2.3) - concurrent-ruby (1.0.5) + arel (7.1.4) + builder (3.2.4) + concurrent-ruby (1.1.7) + crass (1.0.6) erubis (2.7.0) - i18n (0.8.1) + i18n (1.5.1) + concurrent-ruby (~> 1.0) jbuilder (2.0.5) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - loofah (2.0.3) + loofah (2.7.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - metaclass (0.0.4) - method_source (0.8.2) - mini_portile2 (2.1.0) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - multi_json (1.12.1) - nokogiri (1.7.1) - mini_portile2 (~> 2.1.0) - power_assert (1.0.2) - rack (2.0.2) + method_source (1.0.0) + mini_portile2 (2.4.0) + minitest (5.14.2) + mocha (1.11.2) + multi_json (1.15.0) + nokogiri (1.9.1) + mini_portile2 (~> 2.4.0) + power_assert (1.2.0) + rack (2.1.4) rack-test (0.6.3) rack (>= 1.0) - rails-dom-testing (2.0.2) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.2) - actionpack (= 5.0.2) - activesupport (= 5.0.2) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) - test-unit (3.2.3) + rake (13.0.1) + sqlite3 (1.3.13) + test-unit (3.3.6) power_assert - thor (0.19.4) + thor (1.0.1) thread_safe (0.3.6) - tzinfo (1.2.3) + tzinfo (1.2.7) thread_safe (~> 0.1) PLATFORMS @@ -75,13 +84,15 @@ PLATFORMS DEPENDENCIES actionpack (~> 5.0.0) + activerecord (~> 5.0.0) appraisal jbuilder (~> 2.0.0) jbuilder_cache_multi! mocha railties (~> 5.0.0) rake + sqlite3 (~> 1.3.11) test-unit BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/lib/jbuilder_cache_multi/jbuilder_ext.rb b/lib/jbuilder_cache_multi/jbuilder_ext.rb index 09779a7..45d9b75 100644 --- a/lib/jbuilder_cache_multi/jbuilder_ext.rb +++ b/lib/jbuilder_cache_multi/jbuilder_ext.rb @@ -8,7 +8,21 @@ # json.partial! 'person', :person => person # end def cache_collection!(collection, options = {}, &block) - if @context.controller.perform_caching && !collection.to_a.empty? + if @context.controller.perform_caching + results = if collection.is_a?(ActiveRecord::Relation) && !collection.loaded? && collection.respond_to?(:unscope) + cache_collection_for_active_relation(collection, options, &block) + else + cache_collection_others(collection, options, &block) + end + + results + else + array! collection, options, &block + end + end + + def cache_collection_others(collection, options, &block) + if !collection.to_a.empty? keys_to_collection_map = _keys_to_collection_map(collection, options) if ::Rails.cache.respond_to?(:fetch_multi) @@ -27,6 +41,75 @@ def cache_collection!(collection, options = {}, &block) end end + def cache_collection_for_active_relation(active_record_relation, options, &block) + key = options[:key] + query = active_record_relation.unscope(:includes) + model = query.klass + + + cache_key_record_id_set = {} + cache_results = {} + new_cache_to_write = {} + new_records = [] + + model.transaction(isolation: supported_isolation_level(model.connection)) do + if key.is_a? Array + # don't try to pluck strings, these are to be included verbatim in the final key + key_for_pluck = key.select { |k| k.is_a? Symbol } + # use the symbol fields for pluck + # id should alwys be first + query = query.pluck(:id, *key_for_pluck) + id_extractor = Proc.new { |fields| fields[0] } + elsif key.respond_to?(:call) + # if a proc is passed as key, use normal select + id_extractor = Proc.new { |record| record.id } + else + # nothing is passed, the cache_key method of AcriveRecord::Model will be called + # We only need :id and :updated_at for this + query = query.select(:id, :updated_at) + id_extractor = Proc.new { |record| record.id } + end + + cache_key_record_id_set = _keys_to_collection_map(query, options) + + cache_key_record_id_set.each do |key, record_or_array| + # either of type ActiveRecord::Model or Array. Harmonize. + cache_key_record_id_set[key] = id_extractor.call(record_or_array) + end + + cache_results = ::Rails.cache.read_multi(*cache_key_record_id_set.keys, options) + + missing_entries = cache_key_record_id_set.reject do |cache_key| + cache_results[cache_key].present? + end + + unless missing_entries.empty? + new_records = active_record_relation.find(missing_entries.values).to_a + end + end + + unless new_records.empty? + new_records.each do |record| + cache_key = cache_key_record_id_set.key(record.id) + raise NotImplementedError unless cache_key + cache_results[cache_key] = _scope { yield record } + new_cache_to_write[cache_key] = cache_results[cache_key] + end + end + + unless new_cache_to_write.empty? + if Rails.cache.respond_to? :write_multi + ::Rails.cache.write_multi(new_cache_to_write, options) + else + new_cache_to_write.each do |cache_key, entry| + ::Rails.cache.write(cache_key, entry, options) + end + end + end + + _process_collection_results(cache_results) + end + # Conditionally caches a collection of objects depending in the condition given as first parameter. # # Example: @@ -36,12 +119,16 @@ def cache_collection!(collection, options = {}, &block) # end def cache_collection_if!(condition, collection, options = {}, &block) condition ? - cache_collection!(collection, options, &block) : - array!(collection, options, &block) + cache_collection!(collection, options, &block) : + array!(collection, options, &block) end protected + def supported_isolation_level(connection) + connection.supports_transaction_isolation? ? :repeatable_read : nil + end + ## Implementing our own version of _cache_key because jbuilder's is protected def _cache_key_fetch_multi(key, options) key = _fragment_name_with_digest_fetch_multi(key, options) @@ -67,13 +154,13 @@ def _keys_to_collection_map(collection, options) collection.inject({}) do |result, item| cache_key = - if key.respond_to?(:call) - key.call(item) - elsif key - [key, item] - else - item - end + if key.respond_to?(:call) + key.call(item) + elsif key + [key, item] + else + item + end result[_cache_key_fetch_multi(cache_key, options)] = item result end diff --git a/test/jbuilder_template_active_record_relation_test.rb b/test/jbuilder_template_active_record_relation_test.rb new file mode 100644 index 0000000..34df151 --- /dev/null +++ b/test/jbuilder_template_active_record_relation_test.rb @@ -0,0 +1,99 @@ +require 'test_helper' +require 'mocha/setup' +require 'action_view' +require 'action_view/testing/resolvers' +require 'active_support/cache' +require 'jbuilder' +require 'jbuilder/jbuilder_template' +require 'jbuilder_cache_multi' +require 'active_record' +require 'sqlite3' + +ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:" +load File.dirname(__FILE__) + '/schema.rb' + +POST_PARTIAL = <<-JBUILDER + json.extract! post, :id, :body + json.author do + name = post.author.name.split(nil, 2) + json.first_name name[0] + json.last_name name[1] + end +JBUILDER + +class Author < ActiveRecord::Base + has_many :post +end +class Post < ActiveRecord::Base + belongs_to :author +end + +blog_authors = ['David Heinemeier Hansson', 'Pavel Pravosud' ].cycle +POST_COLLECTION = 10.times.map do |i| + Post.create!( + body: "post body #{i + 1}", + author: Author.create!(name: blog_authors.next) + ) +end + +module Rails + def self.cache + @cache ||= ActiveSupport::Cache::MemoryStore.new + end +end + +class JbuilderTemplateActiveRecordRelationTest < ActionView::TestCase + + def partials + { + '_post.json.jbuilder' => POST_PARTIAL + } + end + + def assert_collection_rendered(json, context = nil) + result = MultiJson.load(json) + result = result.fetch(context) if context + + assert_equal 10, Post.count + assert_equal Array, result.class + assert_equal 'post body 5', result[4]['body'] + assert_equal 'Heinemeier Hansson', result[2]['author']['last_name'] + assert_equal 'Pavel', result[5]['author']['first_name'] + end + + setup do + @context = self + Rails.cache.clear + end + + test 'render ActiveRecord::Relation with default key' do + json = render_jbuilder <<-JBUILDER + json.cache_collection! Post.all do |post| + json.partial! 'post', :post => post + end + JBUILDER + + assert_collection_rendered json + end + + test 'render ActiveRecord::Relation with fields as key' do + json = render_jbuilder <<-JBUILDER + json.cache_collection! Post.joins(:author).includes(:author), key: %i[posts.updated_at authors.updated_at] do |post| + json.partial! 'post', :post => post + end + JBUILDER + + assert_collection_rendered json + end + + test 'render ActiveRecord::Relation with proc as key' do + json = render_jbuilder <<-JBUILDER + json.cache_collection! Post.all, key: Proc.new { |post| post.author } do |post| + json.partial! 'post', :post => post + end + JBUILDER + + assert_collection_rendered json + end + +end diff --git a/test/jbuilder_template_test.rb b/test/jbuilder_template_test.rb index bd8f5ee..5ec68b5 100644 --- a/test/jbuilder_template_test.rb +++ b/test/jbuilder_template_test.rb @@ -23,67 +23,33 @@ blog_authors = [ 'David Heinemeier Hansson', 'Pavel Pravosud' ].cycle BLOG_POST_COLLECTION = 10.times.map{ |i| BlogPost.new(i+1, "post body #{i+1}", blog_authors.next) } -module Rails - def self.cache - @cache ||= ActiveSupport::Cache::MemoryStore.new - end -end - class JbuilderTemplateTest < ActionView::TestCase - setup do - @context = self - Rails.cache.clear - end - def partials { - '_partial.json.jbuilder' => 'json.content "hello"', + '_partial.json.jbuilder' => 'json.content "hello"', '_blog_post.json.jbuilder' => BLOG_POST_PARTIAL } end - # Stub out a couple of methods that'll get called from cache_fragment_name - def view_cache_dependencies - [] - end - def formats - [:json] - end - - def render_jbuilder(source) - @rendered = [] - lookup_context.view_paths = [ActionView::FixtureResolver.new(partials.merge('test.json.jbuilder' => source))] - ActionView::Template.new(source, 'test', JbuilderHandler, :virtual_path => 'test').render(self, {}).strip - end - - def undef_context_methods(*names) - self.class_eval do - names.each do |name| - undef_method name.to_sym if self.method_defined?(name.to_sym) - end - end - end - def assert_collection_rendered(json, context = nil) result = MultiJson.load(json) result = result.fetch(context) if context - assert_equal 10, result.length assert_equal Array, result.class - assert_equal 'post body 5', result[4]['body'] + assert_equal 'post body 5', result[4]['body'] assert_equal 'Heinemeier Hansson', result[2]['author']['last_name'] - assert_equal 'Pavel', result[5]['author']['first_name'] + assert_equal 'Pavel', result[5]['author']['first_name'] end test 'renders cached array of block partials' do undef_context_methods :fragment_name_with_digest, :cache_fragment_name - + json = render_jbuilder <<-JBUILDER json.cache_collection! BLOG_POST_COLLECTION do |blog_post| json.partial! 'blog_post', :blog_post => blog_post end JBUILDER - + assert_collection_rendered json end @@ -112,25 +78,25 @@ def assert_collection_rendered(json, context = nil) test 'reverts to cache! if cache does not support fetch_multi' do undef_context_methods :fragment_name_with_digest, :cache_fragment_name ActiveSupport::Cache::Store.send(:undef_method, :fetch_multi) if ActiveSupport::Cache::Store.method_defined?(:fetch_multi) - + json = render_jbuilder <<-JBUILDER json.cache_collection! BLOG_POST_COLLECTION do |blog_post| json.partial! 'blog_post', :blog_post => blog_post end JBUILDER - + assert_collection_rendered json end test 'reverts to array! when controller.perform_caching is false' do controller.perform_caching = false - + json = render_jbuilder <<-JBUILDER json.cache_collection! BLOG_POST_COLLECTION do |blog_post| json.partial! 'blog_post', :blog_post => blog_post end JBUILDER - + assert_collection_rendered json end @@ -140,7 +106,7 @@ def assert_collection_rendered(json, context = nil) json.partial! 'blog_post', :blog_post => blog_post end JBUILDER - + assert_equal '[]', json end diff --git a/test/schema.rb b/test/schema.rb new file mode 100644 index 0000000..d9f9368 --- /dev/null +++ b/test/schema.rb @@ -0,0 +1,19 @@ +ActiveRecord::Schema.define do + self.verbose = false + + create_table :posts, :force => true do |t| + t.string :title + t.string :body + t.integer :author_id + + t.timestamps + end + + create_table :authors, :force => true do |t| + t.string :name + t.integer :age + + t.timestamps + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index e90cb99..ce57cdb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,3 +8,40 @@ end require "active_support/test_case" + +module Rails + def self.cache + @cache ||= ActiveSupport::Cache::MemoryStore.new + end + def self.env + ENV["RAILS_ENV"] || ENV["RACK_ENV"] || 'test' + end +end + +module ActiveSupport + class TestCase + + # Stub out a couple of methods that'll get called from cache_fragment_name + def view_cache_dependencies + [] + end + + def formats + [:json] + end + + def render_jbuilder(source) + @rendered = [] + lookup_context.view_paths = [ActionView::FixtureResolver.new(partials.merge('test.json.jbuilder' => source))] + ActionView::Template.new(source, 'test', JbuilderHandler, :virtual_path => 'test').render(self, {}).strip + end + + def undef_context_methods(*names) + self.class_eval do + names.each do |name| + undef_method name.to_sym if self.method_defined?(name.to_sym) + end + end + end + end +end