pax_global_header00006660000000000000000000000064143210757100014512gustar00rootroot0000000000000052 comment=ea230e04492ac4bf855962119c7908ef4f53cd4a rabl-0.16.1/000077500000000000000000000000001432107571000125175ustar00rootroot00000000000000rabl-0.16.1/.github/000077500000000000000000000000001432107571000140575ustar00rootroot00000000000000rabl-0.16.1/.github/workflows/000077500000000000000000000000001432107571000161145ustar00rootroot00000000000000rabl-0.16.1/.github/workflows/ci.yml000066400000000000000000000012631432107571000172340ustar00rootroot00000000000000name: Ruby tests on: push: branches: [ master ] pull_request: branches: [ master ] jobs: test: name: Ruby tests runs-on: ubuntu-latest strategy: matrix: ruby-version: ['1.9.3', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1'] experimental: [false] include: - ruby-version: 'head' experimental: true continue-on-error: ${{ matrix.experimental }} steps: - uses: actions/checkout@v2 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests run: bundle exec rake rabl-0.16.1/.gitignore000066400000000000000000000001271432107571000145070ustar00rootroot00000000000000*.gem .bundle .rvmrc Gemfile.lock pkg/* fixtures/rails2/log/*.log tags .idea yarn.lock rabl-0.16.1/CHANGELOG.md000066400000000000000000000272261432107571000143410ustar00rootroot00000000000000# CHANGELOG ## 0.16.1 (Oct 10, 2022) * Fix ArgumentError when there are no keyword arguments for Ruby < 2.7 (Thanks @sylvain-8422) ## 0.16.0 (August 21, 2022) * Add "except" option to `extends` (Thanks @perryqh) * Fix `ArgumentError` when block given with keyword arguments (Thanks @kyoshidajp) * Add Ruby 3.1 to the CI matrix (Thanks @petergoldstein) * Document Rabl setting `oj`'s mode (Thanks @ghiculescu) ## 0.15.0 (December 30, 2021) * Support for Rails 7 (@tagliala) * Improvements to unit testing * Miscellanious other bug fixes ## 0.14.5 (May 29th, 2021) * Restrict and validate the `to_***` methods available within engine (Brian McFadden) ## 0.14.4 (April 1st, 2021) * Test against latest Ruby versions * Exclude yarn lock * Remove non-required files from the .gem ## 0.14.3 (April 22nd, 2020) * Fix regression on Rails 4.2 (@tagliala) ## 0.14.2 (September 10th, 2019) * Made Rails 6 compatible (@jpawlyn) * Drop EOL'd property from gemspec (@olleolleolle) ## 0.14.1 (April 28th, 2019) * Many adjustments and various non-breaking fixes * Improvements to caching (@zenspider) * Fix tests for Rails 5 (@robertoz) ## 0.13.1 (October 21st, 2016) * Further compatibility with Rails 5 ## 0.13.0 (July 15th, 2016) * Compatibility with Rails 5 ## 0.12.0 (February 13th, 2016) * Compatibility with ruby 2.3.0 (@vmeyet) ## 0.11.8 (January 10th, 2016) * Check that the Rails module has the .version method before invocation (@caldwecr) * Adds nominal rails5 support (@lsylvester) ## 0.11.7 (December 6th, 2015) * Use empty hash as default cache options (@infertux) * Update ERB::Util link in README (@mortonfox) ## 0.11.6 (January 26th) * Fix resolve_condition and simplify call_condition_proc (@vmeyet) * Respect eagerly loaded collections by not always calling #to_ary (@DouweM) * Move creation of options and engine in tilt template to avoid threading issues (@jseriff) ## 0.11.5 (December 5th) * Check if context_scope includes ".settings.views" for Sinatra (@LTe) * Fix view path issue for partials (@LTe) ## 0.11.4 (November 7th) * FIX Get MultiBuilder to behave properly around nil engines (@DouweM) ## 0.11.3 (November 3rd) * FIX error when attempting to cache empty child collections (@DouweM) * FIX bug causing Rails 4 cache digests never to be appended (@DouweM) ## 0.11.2 (October 26th) * FIX Don't put nil into builder engines when glueing nil object (@DouweM) ## 0.11.1 (October 19th) * NEW #417 Major rewrite caching layer to be much faster using read_multi (@ahlatimer, @DouweM) * FIX #589 Use set to speed up is_collection method check (@ccocchi) * FIX #584 Fix issues with newer releases of oj gem (@DouweM) ## 0.11.0 (August 16th) * Restore ruby 1.8 compatibility (@s01ipsist, @patrickdavey) * Fix Rabl::Tracker to match paths with numbers (@szimek) * Fix caching of a recursive template (@bonobos) * Fix cache for non-rails apps (@t-k) * Escape output all at once to properly escape content (@bholzer) * Add hashie mash to known object list (@nguyenmighty) * Remove root object when set to false value (@mrThe) ## 0.10.1 (May 28th) * Fix nasty formatting bug that broke XML (@bhicks) ## 0.10.0 (May 24th) * Fix typo in readme about new options (@PikachuEXE) * Use the request format for source lookup (@omgitsads) * Simplify rendering methods with refactor (@bhicks) * Reset format and scope options for each request (@bhicks) * Convert keys to ensure uniqueness (@swalkinshaw) * Add fallback for child name if its nil (@swalkinshaw) * Apply replace_xxx_values recursively within nested values (@igas) ## 0.9.4.pre1 (March 30th) * NEW #527 Add configuration excluding empty values in collections (@addbrick) * FIX #516 Set default root_object lazily (@DouweM) * FIX #540 Fix cache digest in Rails 4.1 (@huoxito) * FIX #534 Bug with management of empty string values (@nickkov89) * FIX #519 JSON in README (@shirish4you) * NEW #514 Add configuration to exclude nil values (@oharsta) ## 0.9.3 (December 5th) * FIX Send engine options through from render call (Thanks @bhicks) * FIX Cleanup compile_hash method through refactoring complexity (Thanks @bhicks) * FIX #503 handling render case with no lookup_context in Rails 4 * FIX #502 fix regression in render when object is nil with explicit root name ## 0.9.2 (November 21 2013) * FIX #508 by avoiding new proc syntax breaking 1.8.7 ## 0.9.1 (November 17 2013) * NEW #507 Resolve conditionals for extends (Thanks @micahcraig) * NEW #453 Support for symbol conditionals (Thanks @leoc) ## 0.9.0 (October 14 2013) * FIX #497 Renderer should support partial caching and a digestor bug fixed (Thanks @siong1987) ## 0.9.0.pre3 (Sept 22 2013) * FIX #495 Digest cache when rendering from controller (Thanks @siong1987) ## 0.9.0.pre2 (Sept 02 2013) * FIX #142 Better resource resolution for AR Scopes * Adds Rails 4 test fixture (Thanks @siong1987) * Adds Rails 4 cache digestor (Thanks @siong1987) * Child now supports `object_root` and `root` arguments like 'collection' * FIX #486 Prioritize to_hash options to allow setting root ## 0.8.6 * FIX #142 #467 Do not use a collection as the default object. (Thanks @mrbrdo) * NEW Options hash for glue function added (Thanks @sassysolutions) * FIX #470 Better template lookups when Padrino is defined (Thanks @LTe) ## 0.8.5 * FIX #386 Support disabling root on child calls (Thanks @digger69) ## 0.8.4 * NEW #411 Add "replace nil values with empty strings" option (Thanks @manuelmeurer) ## 0.8.3 * Closes #421 bug with locals in engine ## 0.8.2 * Passing locals when rendering templates via partials or inheritance (Thanks @simsalabim) ## 0.8.1 * Fix to respect @collection :root for xml output (Thanks @chinshr) ## 0.8.0 * Remove multi_json dependency, simpler JSON handling ## 0.7.10 * Add early support for Rails 4 (Thanks @jopotts) * Add configuration option for raising on missing attributes (Thanks @ReneB) * Allow caching outside the Rails environment (Thanks @flyerhzm) * Fix template lookup on Rails (Thanks @vimutter) ## 0.7.9 * Replace yajl with oj in docs and tests * Fix handling of empty children arrays with tests (Thanks @sethvargo) ## 0.7.8 * Additional fix for attribute conditional support ## 0.7.7 * Fix #344 to avoid: "warning: default `to_a' will be obsolete" * Fix #356 by adding 'known object classes' like struct to be recognized as objects. * Fix #354 by adding 'if' and 'unless' to `attribute` (Thanks @andrewhubbs) ## 0.7.6 * Fix render behavior by separating data_object and data_name in engine * Fix regression with 'child' behavior with nil on extends (with tests) ## 0.7.5 * Avoid incorrectly setting implicit objects for 'object false' partials ## 0.7.4 * Fix issue #347 with extends failing for custom object templates ## 0.7.3 * Fix issue #342 with nil case for format checking in engine `request_params` ## 0.7.2 * Set instance variables for locals in engine instead of renderer (Thanks @geehsien) * Changes default JSON engine for Rails, move logic to separate class (Thanks @shmeltex) ## 0.7.1 * Improved renderer interface (Thanks @siong1987) * Pass current object into blocks (Thanks @braddunbar) ## 0.7.0 * Use source_format when looking up partials (Thanks @databyte) * Add README note about render_views (Thanks @databyte) * Add support for Rails 3.2+ sending custom mime types (Thanks @databyte) * Add option to define his own cache_engine (Thanks @shingara) ## 0.6.14 * Fix RSpec under Rails 3, use render_views to test output (Thanks @agibralter) * Fix extends allows passing in local object when root object is specified ## 0.6.13 * Small tweak to is_collection detection (look for each and map) * Adds `include_child_root` configuration option (Thanks @yoon) ## 0.6.12 * Fix view_path options for renderer (Thanks @ivanvanderbyl and @route) * Only escape if data exists * Fix default object recognition for Rails 2.3.2 * Adds `root_object` method on engine (Thanks @OliverLetterer) ## 0.6.11 * Changes send to __send__ (Thanks @alindeman) * Change object/collection checks to :map instead of :each * Adds support for auto-escaping attribute configuration (Thanks @databyte) * Adds support for configuration of view_paths (Thanks @ivanvanderbyl) * Fix issue with helpers caching check ## 0.6.10 * Fixes expected behavior with nil and collection keyword * Fixes multi_json to support newer form syntax (Thanks @rajatvig) ## 0.6.9 * Adds support for generic template rendering (Thanks @ivanvanderbyl) * Allow cache to be called with an explicit key (Thanks @databyte) ## 0.6.8 * Fix Rails 3 resolution on Ruby < 1.9.2 ## 0.6.7 * Fix format to default to json in the event that it is a 'hash' (Thanks @databyte) * Support using cache keys within extended templates (Thanks @databyte) ## 0.6.6 * Even more improvements to Rails template resolution (Thanks @databyte) * Added fixture integration tests for rendering rabl inline from html (Thanks @databyte) * Added useful note to README about Padrino (Thanks @simonc) ## 0.6.5 * Fixed issue with multi_json version use ~> 1.0 (Thanks @sferik) ## 0.6.4 * Further improvements to template path resolution for Rails (Thanks @radar) * Change multi_json to be > 1.1.0 to support 1.2.0 with Oj support (Thanks @jherdman) ## 0.6.3 * Adds Rails 3.2 Integration Test * Much improved Rails template path resolution ## 0.6.2 * Adds template caching support for Rails (Thanks @databyte) ## 0.6.1 * Upgrade dependency to multi_json 1.1.0 (Thanks @geronimo) ## 0.6.0 * Change engine to only instantiate one builder when rendering a collection * Alias to\_msgpack to to\_mpac * Cache template sources for faster partial lookups (thanks @cj) * Adds BSON format support (thanks @Antiarchitect) * Use template lookup mechanism to find templates in Rails 3 (thanks @blakewatters) * Adds a 'object_root' option to collection (thanks @blakewatters) * Adds a 'root_name' option to collection * Adds PList format support (thanks @alzeih) * Fixes infinite recursion in edge case calculating object root name * Fixes issue with nameless node that has an array result * Adds support for `object_root => false` (Thanks @Lytol) ## 0.5.4 * Ensure ActionView is defined before registering Rails template handler (thanks cj) ## 0.5.2-0.5.3 * Add better support for conditionals for child (thanks gregory) * Fix issue introduced with 'node' and properly clear options (thanks joshbuddy) ## 0.5.1 * Use respond\_to? instead of checking Enumerable for is\_object * Performance optimization (thanks Eric Allen) ## 0.5.0 * Adds comprehensive fixture suite (padrino,rails2,rails3,sinatra) * Travis CI Integration Testing * Cleanup json configuration and related tests (Thanks mschulkind) * Adds CHANGELOG to track changes * Adds optional MessagePack format support (thanks byu) * Explicit requires for ActiveSupport now in gemspec and lib * Adds template support for regular (non-ORM) ruby objects (thanks plukevdh) * Fixes bug with the child root not properly appearing in all cases * Better stack traces by tracking source location in instance_eval (thanks skade) * Fix issue with controller object detection failing in namespaces (thanks alunny) * Fix ruby -w warnings (thanks achiu) * Better partial implementation which passes options * Better fetch_source implementation for Padrino (thanks skade) * Better fetch_source implementation for Rails * Added fetch_source implementation for Sinatra * Lots of test refactorings / cleanup / improvement * Code block name is now optional [Thanks brentmurphy] ## 0.3.0 * Use multi_json to handle JSON encoding (Thanks kossnocorp) * Fixes unit tests with hash order on 1.8.7 ## 0.2.8 * Fixes Rails 3.1 Compatibility (Thanks skyeagle) * Fixes Ruby 1.8.6 Compatibility (Thanks Don) * Adds much better riot unit testing (Thanks Achiu) rabl-0.16.1/CONTRIBUTING.md000066400000000000000000000025331432107571000147530ustar00rootroot00000000000000We love pull requests. Here's a quick guide: 1. Fork the repo. 2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `bundle && bundle exec rake test` 3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test! 4. Make the test pass. 5. Push to your fork and submit a pull request. At this point you're waiting on us. We like to at least comment on, if not accept, pull requests within three business days (and, typically, one business day). We may suggest some changes or improvements or alternatives. Some things that will increase the chance that your pull request is accepted: * Use Rails idioms and helpers * Include tests that fail without your code, and pass with it * Update the documentation and README for anything affected by your contribution Syntax: * Two spaces, no tabs. * No trailing whitespace. Blank lines should not have any space. * Prefer &&/|| over and/or. * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg. * a = b and not a=b. * Follow the conventions you see used in the source already. And in case we didn't emphasize it enough: we love tests! NOTE: Adapted from https://raw.githubusercontent.com/thoughtbot/factory_bot_rails/main/CONTRIBUTING.md rabl-0.16.1/Gemfile000066400000000000000000000010321432107571000140060ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in rabl.gemspec gemspec gem 'i18n', '>= 0.6' platforms :mri_18 do gem 'SystemTimer' gem 'json' end group :test do # RABL TEST gem 'builder' rails_version = RUBY_VERSION =~ /\A(1|2.[01])/ ? '~> 4.0' : '>= 4.0' # FIXTURES gem 'rack-test', :require => 'rack/test' gem 'activerecord', rails_version, :require => 'active_record' gem 'sqlite3' gem 'sinatra', '>= 1.2.0' gem 'hashie' gem 'riot' end group :development, :test do # gem 'debugger' end rabl-0.16.1/MIT-LICENSE000066400000000000000000000020431432107571000141520ustar00rootroot00000000000000Copyright (c) 2010 Nathan Esquenazi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.rabl-0.16.1/README.md000066400000000000000000000642751432107571000140140ustar00rootroot00000000000000# RABL # [![Continuous Integration status](https://github.com/nesquena/rabl/actions/workflows/ci.yml/badge.svg)](https://github.com/nesquena/rabl/actions) [![Code Climate](https://codeclimate.com/github/nesquena/rabl.svg)](https://codeclimate.com/github/nesquena/rabl) RABL (Ruby API Builder Language) is a Rails and [Padrino](http://padrinorb.com) ruby templating system for generating JSON, XML, MessagePack, PList and BSON. When using the ActiveRecord 'to_json' method, I find myself wanting a more expressive and powerful solution for generating APIs. This is especially true when the JSON representation is complex or doesn't match the exact schema defined within the database. In particular, I want to easily: * Create arbitrary nodes named based on combining data in an object * Pass arguments to methods and store the result as a child node * Render partial templates and inherit to reduce code duplication * Rename or alias attributes to change the name from the model * Append attributes from a child into a parent node * Include nodes only if a certain condition has been met Anyone who has tried the 'to_json' method used in ActiveRecord for generating a JSON response has felt the pain of this restrictive approach. RABL is a general templating system created to solve these problems by approaching API response generation in an entirely new way. RABL at the core is all about adhering to MVC principles by deferring API data representations to the **view** layer of your application. For a breakdown of common misconceptions about RABL, please check out our guide to [understanding RABL](https://github.com/nesquena/rabl/wiki/Understanding-RABL) which can help clear up any confusion about this project. ## Breaking Changes ## * v0.9.0 (released Oct 14, 2013) changes the [default node name for certain associations](https://github.com/nesquena/rabl/issues/505) especially around STI models. You might want to verify for any breakages as a result and be more explicit by specifying an alias i.e `@users => :users` * v0.8.0 (released Feb 14, 2013) removes multi_json dependency and relies on Oj (or JSON) as the json parser. Simplifies code, removes a dependency but you might want to remove any references to MultiJson. * v0.6.14 (released June 28, 2012) requires the use of render_views with RSpec to test templates. Otherwise, the controller will simply pass through the render command as it does with ERB templates. ## Installation ## Install RABL as a gem: ``` gem install rabl ``` or add to your Gemfile: ```ruby # Gemfile gem 'rabl' # Also add either `oj` or `yajl-ruby` as the JSON parser # If using `oj`, Rabl will set the mode to :compat gem 'oj' ``` and run `bundle install` to install the dependency. If you are using **Rails 2.3.8 (and up), Rails 3.X or Padrino**, RABL works without configuration. **Important:** With Padrino, be sure that **the rabl gem is listed after the padrino gem in your Gemfile**, otherwise Rabl will not register properly as a template engine. With Sinatra, or any other tilt-based framework, simply register: ```ruby Rabl.register! ``` and RABL will be initialized and ready for use. For usage with Sinatra, check out the [Sinatra Usage](https://github.com/nesquena/rabl/wiki/Setup-for-Sinatra) guide. ## Overview ## You can use RABL to generate JSON and XML based APIs from any ruby object. With RABL, the data typically is derived primarily from models (ORM-agnostic) and the representation of the API output is described within a view template using a simple ruby DSL. This allows you to keep your data separated from the JSON or XML you wish to output. Once you have installed RABL (explained above), you can construct a RABL view template and then render the template from your Sinatra, Padrino or Rails applications from the controller (or route) very easily. Using [Padrino](http://padrinorb.com) as an example, assuming you have a `Post` model filled with blog posts, you can render an API representation (both JSON and XML) by creating a route: ```ruby # app/app.rb get "/posts", :provides => [:json, :xml] do @user = current_user @posts = Post.order("id DESC") render "posts/index" end ``` Then we can create the following RABL template to express the API output of `@posts`: ```ruby # app/views/posts/index.rabl collection @posts attributes :id, :title, :subject child(:user) { attributes :full_name } node(:read) { |post| post.read_by?(@user) } ``` Which would output the following JSON or XML when visiting `http://localhost:3000/posts.json` ```js [{ "post" : { "id" : 5, "title": "...", "subject": "...", "user" : { "full_name" : "..." }, "read" : true } }] ``` That's a basic overview but there is a lot more to see such as partials, inheritance, custom nodes, etc. Read the full details of RABL below. ## Configuration ## RABL is intended to require little to no configuration to get working. This is the case in most scenarios, but depending on your needs you may want to set the following global configurations in your application (this block is completely optional): ```ruby # config/initializers/rabl_init.rb require 'rabl' Rabl.configure do |config| # Commented as these are defaults # config.cache_all_output = false # config.cache_sources = Rails.env != 'development' # Defaults to false # config.cache_engine = Rabl::CacheEngine.new # Defaults to Rails cache # config.perform_caching = false # config.escape_all_output = false # config.json_engine = nil # Class with #dump class method (defaults JSON) # config.msgpack_engine = nil # Defaults to ::MessagePack # config.bson_engine = nil # Defaults to ::BSON # config.plist_engine = nil # Defaults to ::Plist::Emit # config.include_json_root = true # config.include_msgpack_root = true # config.include_bson_root = true # config.include_plist_root = true # config.include_xml_root = false # config.include_child_root = true # config.enable_json_callbacks = false # config.xml_options = { :dasherize => true, :skip_types => false } # config.view_paths = [] # config.raise_on_missing_attribute = true # Defaults to false # config.replace_nil_values_with_empty_strings = true # Defaults to false # config.replace_empty_string_values_with_nil_values = true # Defaults to false # config.exclude_nil_values = true # Defaults to false # config.exclude_empty_values_in_collections = true # Defaults to false # config.camelize_keys = :upper # Defaults to false end ``` Each option specifies behavior related to RABL's output. If `include_json_root` is disabled that removes the root node for each root object in the output, and `enable_json_callbacks` enables support for 'jsonp' style callback output if the incoming request has a 'callback' parameter. If `include_child_root` is set to false then child objects in the response will not include a root node by default. This allows you to further fine-tune your desired response structure. If `cache_engine` is set, you should assign it to a class with a `fetch` method. See the [default engine](https://github.com/nesquena/rabl/blob/master/lib/rabl/cache_engine.rb) for an example. If `perform_caching` is set to `true` then it will perform caching. You can ignore this option if you are using Rails, it's same to Rails `config.action_controller.perform_caching` If `cache_sources` is set to `true`, template lookups will be cached for improved performance. The cache can be reset manually by running `Rabl.reset_source_cache!` within your application. If `cache_all_output` is set to `true`, every template including each individual template used as part of a collection will be cached separately. Additionally, anything within child, glue and partial will also be cached separately. To cache just a single template, see the section titled 'Caching' below. If `escape_all_output` is set to `true` and ActiveSupport is available, attribute output will be escaped using [ERB::Util.html_escape](http://api.rubyonrails.org/classes/ERB/Util.html). If `view_paths` is set to a path, this view path will be checked for every rabl template within your application. Add to this path especially when including Rabl in an engine and using view paths within a another Rails app. If `raise_on_missing_attribute` is set to `true`, a RuntimeError will be raised whenever Rabl attempts to render an attribute that does not exist. Otherwise, the attribute will simply be omitted. Setting this to true during development may help increase the robustness of your code, but using `true` in production code is not recommended. If `replace_nil_values_with_empty_strings` is set to `true`, all values that are `nil` and would normally be displayed as `null` in the response are converted to empty strings. If `exclude_nil_values` is set to `true`, all values that are `nil` and would normally be displayed as `null` in the response are not included in the response. if `exclude_empty_values_in_collections` is set to `true`, all values in a collection that are `{}` and would normally be displayed as `{}` in the response are not included in the response. If `camelize_keys` is set to `true`, all object keys will be converted to camel case. By default the first character will be lower case. The value can be set to `:upper` to set the first character to upper case. If you wish to use [oj](https://github.com/ohler55/oj) as the primary JSON encoding engine simply add that to your Gemfile: ```ruby # Gemfile gem 'oj' ``` and RABL will use that engine automatically for encoding your JSON responses. Set your own custom json_engine which define a `dump` or `encode` method for converting to JSON from ruby data: ```ruby config.json_engine = ActiveSupport::JSON ``` ### Format Configuration ### RABL supports configuration for MessagePack, BSON, and Plist. Check the [Format Configuration](https://github.com/nesquena/rabl/wiki/Configuring-Formats) page for more details. ## Usage ## ### Object Assignment ### To declare the data object for use in the template: ```ruby # app/views/users/show.json.rabl object @user ``` or specify an alias for the object: ```ruby object @user => :person # => { "person" : { ... } } ``` or pass a collection of objects: ```ruby collection @users # => [ { "user" : { ... } } ] ``` or specify a root node label for the collection: ```ruby collection @users => :people # => { "people" : [ { "person" : { ... } } ] } ``` or even specify both the child and root labels for a collection: ```ruby collection @users, :root => "people", :object_root => "user" # => { "people" : [ { "user" : { ... } } ] } ``` and this will be used as the default data for the rendering, or disable the object root explicitly: ```ruby collection @users, :root => "people", :object_root => false # => { "people" : [ { ... }, { ... } ] } ``` There can also be odd cases where the root-level of the response doesn't map directly to any object: ```ruby object false node(:some_count) { |m| @user.posts.count } child(@user) { attribute :name } ``` In those cases, object can be assigned to 'false' and nodes can be constructed free-form. ### Attributes ### Basic usage of the templater to define a few simple attributes for the response: ```ruby # app/views/users/show.json.rabl attributes :id, :foo, :bar ``` or use with aliased attributes: ```ruby # Take the value of model attribute `foo` and name the node `bar` attribute :foo => :bar # => { bar : 5 } ``` or even multiple aliased attributes: ```ruby attributes :bar => :baz, :dog => :animal # => # { baz : , animal : } ``` or show attributes only if a condition is true: ```ruby # m is the object being rendered, also supports :unless attributes :foo, :bar, :if => lambda { |m| m.condition? } ``` Named and aliased attributes can not be combined on the same line. This currently does not work: ```ruby attributes :foo, :bar => :baz # throws exception ``` in such cases, you need to specify attributes twice. ```ruby attributes :foo attributes :bar => :baz ``` ### Child Nodes ### Often a response requires including nested information from data associated with the parent model: ```ruby child :address do attributes :street, :city, :zip, :state end ``` You can also disable object root for child node: ```ruby child :posts, :object_root => false do attributes :id, :title end ``` You can also add child nodes from an arbitrary data source: ```ruby child @posts => :foobar do attributes :id, :title end ``` or use model associations with an alias: ```ruby # Renders all the 'posts' association # from the model into a node called 'foobar' child :posts => :foobar do attributes :id, :title end ``` You can also pass in the current object: ```ruby object @user child :posts do |user| attribute :title unless user.suspended? end ``` ### Gluing Attributes ### You can also append child attributes back to the root node: ```ruby # Appends post_id and post_name to parent json object glue @post do attributes :id => :post_id, :name => :post_name end ``` Use glue to add additional attributes to the parent object. You can also pass in the current object: ```ruby object @user glue(@post) {|user| attribute :title if user.active? } ``` ### Custom Nodes ### This will generate a json response based on the result of the `node` block: ```ruby # app/views/users/show.json.rabl node :full_name do |u| u.first_name + " " + u.last_name end ``` or don't pass a name and have the node block merged into the response: ```ruby node do |u| { :full_name => u.first_name + " " + u.last_name } # => { full_name : "Bob Johnson" } end ``` You can use custom nodes like these to create flexible representations of a value utilizing all the data from the model. ### Partials ### Often you need to access other data objects in order to construct custom nodes in more complex associations. You can get access to the rabl representation of another data object by rendering a RABL partial: ```ruby node :location do { :city => @city, :address => partial("users/address", :object => @address) } end ``` or even access an object associated with the parent model: ```ruby node :location do |m| { :city => m.city, :address => partial("users/address", :object => m.address) } end ``` You can use this method to construct arbitrarily complex nodes for your APIs. Note that you need to have RABL templates defined for each of the objects you wish to construct representations for in this manner. ### Inheritance ### Another common issue of many template builders is unnecessary code redundancy. Typically many representations of an object across multiple endpoints share common attributes or nodes. The nodes for a 'post' object are probably the same or similar in most references throughout the various endpoints. RABL has the ability to extend other "base" rabl templates and additional attributes: ```ruby # app/views/users/advanced.json.rabl extends "users/base" # another RABL template in "app/views/users/base.json.rabl" node :can_drink do |m| m.age > 21 end ``` You can also extend other rabl templates while constructing child nodes to reduce duplication: ```ruby # app/views/users/show.json.rabl child @address do extends "address/item" end ``` Using partials and inheritance can significantly reduce code duplication in your templates. You can see more examples on the [Reusing Templates wiki page](https://github.com/nesquena/rabl/wiki/Reusing-templates). ### Passing Locals in Partials ### You can pass an arbitrary set of locals when rendering partials or extending templates. For example, if we want to show on `posts/:id.json` any information regarding particular post and associated comments but in other cases we want to hide those comments. We can use locals to do this: ```ruby # app/views/posts/index.json.rabl collection @posts extends('posts/show', :locals => { :hide_comments => true }) # or using partial instead of extends # node(false) { |post| partial('posts/show', :object => :post, :locals => { :hide_comments => true })} ``` and then access locals in the sub-template: ```ruby # app/views/posts/show.json.rabl object @post attributes :id, :title, :body, :created_at node(:comments) { |post| post.comments } unless locals[:hide_comments] ``` This can be useful as an advanced tool when extending or rendering partials. ### Conditions ### You can provide conditions to all kinds of nodes, attributes, extends, etc. which includes a given element only if the specified condition is true. ```ruby collection @posts # m is the object being rendered, also supports :unless node(:coolness, :if => lambda { |m| m.coolness > 5 }) do |m| m.coolness end ``` Because attributes take conditional options as well, we could simplify the example with: ```ruby collection @posts # m is the object being rendered, also supports :unless attribute(:coolness, :if => lambda { |m| m.coolness > 5 }) ``` The value for the `:if` and `:unless` options may be a simple `Boolean`, `Proc` or a `Symbol`. If it is a `Symbol` and the specific `@object` responds to its, the method will be called. Thus the example above can be rewritten as: ```ruby class Post def cool? coolness > 5 end end ``` and then: ```ruby collection @posts attribute :coolness, if: :cool? ``` Using conditions allows for easy control over when certain elements render. ### Template Scope ### In RABL, you have access to everything you need to build an API response. Each RABL template has full access to the controllers instance variables as well as all view helpers and routing urls. ```ruby # app/some/template.rabl object @post # Access instance variables child(@user => :user) { ... } # or Rails helpers node(:formatted_body) { |post| simple_format(post.body) } ``` There should be no problem fetching the appropriate data to construct a response. ### Deep Nesting ### In APIs, you can often need to construct 2nd or 3rd level nodes. Let's suppose we have a 'quiz' model that has many 'questions' and then each question has many 'answers'. We can display this hierarchy in RABL quite easily: ```ruby # app/views/quizzes/show.json.rabl object @quiz attribute :title child :questions do attribute :caption child :answers do # Use inheritance to reduce duplication extends "answers/item" end end ``` This will display the quiz object with nested questions and answers as you would expect with a quiz node, and embedded questions and answers. Note that RABL can be nested arbitrarily deep within child nodes to allow for these representations to be defined. ### Caching ### RABL has built-in caching support for templates leveraging fragment caching strategies. Note that caching is currently **only available** for Rails but support for other frameworks is planned in a future release. Simplest caching usage is: ```ruby # app/views/users/show.json.rabl object @quiz cache @quiz # key = rabl/quiz/[cache_key] attribute :title ``` Caching can significantly speed up the rendering of RABL templates in production and is strongly recommended when possible. For more a more detailed look at caching, check out the [Caching](https://github.com/nesquena/rabl/wiki/Caching-in-RABL) guide on the wiki. ### Rendering Templates Directly ### There are situations where an application requires RABL templates to be rendered outside a traditional view context. For instance, to render RABL within a Rake task or to create message queue payloads. For this case, `Rabl.render` can be used as show below: ```ruby Rabl.render(object, template, :view_path => 'app/views', :format => :json) #=> "{...json...}" ``` You can use convenience methods on `Rabl::Renderer` to render the objects as well: ```ruby Rabl::Renderer.json(@post, 'posts/show') Rabl::Renderer.xml(@post, 'posts/show') ``` These methods allow RABL to be used for arbitrary conversions of an object into a desired format. ```ruby Rabl::Renderer.new('posts/show', @post, :view_path => 'app/views', :format => 'hash').render ``` You can also pass in other instance variables to be used in your template as: ```ruby Rabl::Renderer.new('posts/show', @post, :locals => { :custom_title => "Hello world!" }) ```` Then, in your template, you can use `locals[:custom_title]` as: ```ruby attribute :content node(:title) { locals[:custom_title] } ``` ### Content Type Headers ### Currently in RABL, the content-type of your response is not set automatically. This is because RABL is intended to work for any Rack-based framework and as agnostic to format as possible. Check [this issue](https://github.com/nesquena/rabl/issues/185#issuecomment-4501232) for more details, and if you have any ideas or patches please let me know. In the meantime, be sure to set the proper content-types if needed. This is usually pretty simple in both Rails and Padrino. I recommend a before_filter on that controller or directly specified in an action. ## Resources ## There are many resources available relating to RABL including the [RABL Wiki](https://github.com/nesquena/rabl/wiki), and many tutorials and guides detailed below. You can check out the [RABL Site](http://nesquena.github.com/rabl) as well. ### Advanced Usage ### Links to resources for advanced usage: * [Managing Complexity](https://github.com/nesquena/rabl/wiki/Managing-complexity-with-presenters) * [Production Optimizations](https://github.com/nesquena/rabl/wiki/Rabl-In-Production) * [Grape Integration](https://github.com/nesquena/rabl/wiki/Using-Rabl-with-Grape) * [Rendering JSON for a tree structure using RABL](https://github.com/nesquena/rabl/issues/70) * [Layouts (erb, haml and rabl) in RABL](https://github.com/nesquena/rabl/wiki/Using-Layouts) * [Backbone or Ember.js Integration](https://github.com/nesquena/rabl/wiki/Backbone-Integration) * [RABL with Rails Engines](https://github.com/nesquena/rabl/wiki/Setup-rabl-with-rails-engines) Please add your own usages and let me know so we can add them here! Also be sure to check out the [RABL Wiki](https://github.com/nesquena/rabl/wiki) for other usages. ### Tutorials ### Tutorials can always be helpful when first getting started: * [Railscasts #322](http://railscasts.com/episodes/322-rabl) - Ryan Bates explains RABL * [BackboneRails](http://www.backbonerails.com/) - Great screencasts by Brian Mann * http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/ * http://tech.favoritemedium.com/2011/06/using-rabl-in-rails-json-web-api.html * http://seesparkbox.com/foundry/better_rails_apis_with_rabl * http://teohm.github.com/blog/2011/05/31/using-rabl-in-rails-json-web-api Let me know if there's any other useful resources not listed here. ### Related Libraries ### There are other libraries that can either complement or extend the functionality of RABL: * [versioncake](https://github.com/bwillis/versioncake) - Excellent library for easily versioning your RABL APIs * [gon](https://github.com/gazay/gon) - Exposes your Rails variables in JS with RABL support integrated. * [rabl-rails](https://github.com/ccocchi/rabl-rails) - Reimplementation for RABL and Rails [focused on speed](https://github.com/ccocchi/rabl-benchmark/blob/master/BENCHMARK). Let me know if there's any other related libraries not listed here. ### Troubleshooting ### * [Redundant calls for a collection](https://github.com/nesquena/rabl/issues/142#issuecomment-2969107) * [Testing RABL Views](https://github.com/nesquena/rabl/issues/130#issuecomment-4179285) ### Examples ### See the [examples](https://github.com/nesquena/rabl/tree/master/examples) directory. ## Issues ## Check out the [Issues](https://github.com/nesquena/rabl/issues) tab for a full list: * Rigorous benchmarking and performance optimizations ## Authors and Contributors ## Active Maintainers: * [Douwe Maan](https://github.com/DouweM) * [Nathan Esquenazi](https://github.com/nesquena) Thanks to [Miso](http://gomiso.com) for allowing me to create this for our applications and release this project! * [Nathan Esquenazi](https://github.com/nesquena) - Creator of the project * [Arthur Chiu](https://github.com/achiu) - Core Maintainer, Riot Testing Guru * [Tim Lee](https://github.com/timothy1ee) - RABL was a great name chosen by the Miso CTO. * [Douwe Maan](https://github.com/DouweM) - Multi support for caching, fixed test suite * [Andrew Latimer](https://github.com/ahlatimer) - Multi support for caching * [David Sommers](https://github.com/databyte) - Template resolution, caching support, and much more * [Rick Thomas](https://github.com/rickthomasjr) - Added options for extends and Sinatra testing * [Benjamin Yu](https://github.com/byu) - Added msgpack format support * [Chris Kimpton](https://github.com/kimptoc) - Helping with documentation and wiki * [Marjun](https://github.com/mpagalan) - Added xml option configurations * [Anton Orel](https://github.com/skyeagle) - Added Rails 3.1 compatibility * [Sasha Koss](https://github.com/kossnocorp) - Added multi_json support * [Matthew Schulkind](https://github.com/mschulkind) - Cleanup of configuration and tests * [Luke van der Hoeven](https://github.com/plukevdh) - Support non-ORM objects in templates * [Andrey Voronkov](https://github.com/Antiarchitect) - Added BSON format support * [Alli Witheford](https://github.com/alzeih) - Added Plist format support * [Ryan Bigg](https://github.com/radar) - Improved template resolution code * [Ivan Vanderbyl](https://github.com/ivanvanderbyl) - Added general purpose renderer * [Cyril Mougel](https://github.com/shingara) - Added cache_engine pluggable support and renderer tweaks * [Teng Siong Ong](https://github.com/siong1987) - Improved renderer interface * [Brad Dunbar](https://github.com/braddunbar) - Pass current object into blocks and many more contributors listed in the [CHANGELOG](https://github.com/nesquena/rabl/blob/master/CHANGELOG.md). Want to contribute support for another format? Check out the patches for [msgpack support](https://github.com/nesquena/rabl/pull/69), [plist support](https://github.com/nesquena/rabl/pull/153) and [BSON support](https://github.com/nesquena/rabl/pull/163) for reference. Please fork and contribute, any help in making this project better is appreciated! This project is a member of the [OSS Manifesto](http://ossmanifesto.org). ## Inspirations ## There are a few excellent libraries that helped inspire RABL and they are listed below: * [Tequila](https://github.com/inem/tequila) * [JSON Builder](https://github.com/dewski/json_builder) * [Argonaut](https://github.com/jbr/argonaut) Thanks again for all of these great projects. ## Copyright ## Copyright © 2011-2013 Nathan Esquenazi. See [MIT-LICENSE](https://github.com/nesquena/rabl/blob/master/MIT-LICENSE) for details. rabl-0.16.1/Rakefile000066400000000000000000000036361432107571000141740ustar00rootroot00000000000000include Rake::DSL require 'bundler' Bundler::GemHelper.install_tasks require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'lib' << 'test' test.pattern = 'test/*_test.rb' test.warning = true test.verbose = true if RUBY_VERSION < "1.9.0" # -rubygems isn't needed as of 1.9, and is gone as of 2.5 # https://github.com/ruby/ruby/blob/v2_5_0/NEWS#stdlib-compatibility-issues-excluding-feature-bug-fixes test.ruby_opts = ['-rubygems'] end end # Running integration tests # rake test:clean # rake test:setup # rake test:full fixture_list = "{padrino_test,sinatra_test,rails2,rails3,rails3_2,rails4,rails5,rails5_api}" desc "Clean up the fixtures being tested by cleaning and installing dependencies" task "test:clean" do Dir[File.dirname(__FILE__) + "/fixtures/#{fixture_list}"].each do |fixture| puts "\n*** Cleaning up for #{File.basename(fixture)} tests ***\n" Dir.chdir(fixture) { puts `rm Gemfile.lock` } end end desc "Prepares the fixtures being tested by installing dependencies" task "test:setup" do Dir[File.dirname(__FILE__) + "/fixtures/#{fixture_list}"].each do |fixture| puts "\n*** Setting up for #{File.basename(fixture)} tests ***\n" `export BUNDLE_GEMFILE="#{fixture}/Gemfile"` if ENV["CI"] Bundler.with_clean_env { Dir.chdir(fixture) { puts `mkdir -p tmp/cache; bundle install --gemfile="#{fixture}/Gemfile"` if fixture.include? 'rails' puts `bundle exec rake db:reset` end } } end end desc "Executes the fixture tests" task "test:fixtures" do Dir[File.dirname(__FILE__) + "/fixtures/#{fixture_list}"].each do |fixture| puts "\n*** Running tests for #{File.basename(fixture)}... ***\n" Bundler.with_clean_env { Dir.chdir(fixture) { puts `bundle check; bundle exec rake test:rabl` } } end end task "test:full" => [:test, "test:fixtures"] desc "Run tests for rabl" task :default => :test rabl-0.16.1/examples/000077500000000000000000000000001432107571000143355ustar00rootroot00000000000000rabl-0.16.1/examples/base.json.rabl000066400000000000000000000002711432107571000170610ustar00rootroot00000000000000# See 'inherited' for an example of how to extend this template # Include these three attributes attributes :title, :kind, :id child @users do attributes :full_name, :first_name endrabl-0.16.1/examples/demo.json.rabl000066400000000000000000000023031432107571000170710ustar00rootroot00000000000000# Use the @media object set in route object @media # Include these three attributes attributes :title, :kind, :id # Rename 'studio' to be the 'company' node attributes :studio => :company # Arbitrary code blocks can be defined # Creates a 'release_year' node code :release_year do |m| date = m.release_date || m.series_start date.try(:year) end # Creates a node 'users' with an array of the nested users for media # Block is the same rabl syntax for the sub object child @users do attributes :full_name, :first_name end # Uses the associations of the parent media object # Rename 'users' association to 'people' node child :users => :people do attributes :full_name, :first_name end # Creates the "actor" association as a 'user' node # Use the information from another rabl template to describe the representation child :actor => :user do extends "users/simple" end # Append attributes to the root node with prefixed names glue @users.first do attributes :full_name => :user_full_name, :first_name => :user_first_name end # Render an arbitrary hash with a partial rabl json as one of the keys code :topics do |m| { :fake => partial("media/user", :object => @users.first), :raw => @users.first } endrabl-0.16.1/examples/inherited.json.rabl000066400000000000000000000002701432107571000201210ustar00rootroot00000000000000# Extends base.json.rabl and adds additional nodes extends("base") code :release_year do |m| m.release_date.year end code :poster_image_url do |m| m.poster_image_url(:large) endrabl-0.16.1/fixtures/000077500000000000000000000000001432107571000143705ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/000077500000000000000000000000001432107571000157775ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/NOTES000066400000000000000000000101221432107571000166060ustar00rootroot00000000000000# Sinatra cd fixtures/sinatra_test ln -s "../ashared/models" models ln -s "../ashared/views/" views ln -s "../../ashared/migrate" db/migrate ln -s ../../../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb # Padrino cd fixtures/padrino_test ln -s "../ashared/models" models ln -s "../../ashared/views/" app/views ln -s "../../ashared/migrate" db/migrate ln -s ../../../../../test/integration/posts_controller_test.rb test/app/controllers/posts_controller_test.rb ln -s ../../../../../test/integration/users_controller_test.rb test/app/controllers/users_controller_test.rb # Rails 2 cd fixtures/rails2 ln -s "../../ashared/models" app/models ln -s "../../ashared/views/" app/views ln -s "../../ashared/migrate" db/migrate ln -s ../../../../test/integration/posts_controller_test.rb test/functionals/posts_controller_test.rb ln -s ../../../../test/integration/users_controller_test.rb test/functionals/users_controller_test.rb # Rails 3 cd fixtures/rails3 ln -s "../../ashared/models" app/models ln -s "../../ashared/views/" app/views ln -s "../../ashared/migrate" db/migrate ln -s ../../../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb # Rails 3.2 cd fixtures/rails3_2 ln -s "../../ashared/models" app/models ln -s "../../ashared/views_rails_3/" app/views ln -s "../../ashared/migrate" db/migrate ln -s ../../../../test/integration/rails3_2/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/rails3_2/users_controller_test.rb test/functional/users_controller_test.rb # Rails 5 cd fixtures/rails5 ln -s "../../ashared/models" app/models ln -s "../../ashared/views_rails_3/" app/views ln -s "../../ashared/migrate" db/migrate ln -s "../../ashared/helpers" app/helpers ln -s "../../../ashared/controllers_rails_5/posts_controller.rb" app/controllers/posts_controller.rb ln -s "../../../ashared/controllers_rails_5/users_controller.rb" app/controllers/users_controller.rb ln -s ../../../../test/integration/rails5/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/rails5/users_controller_test.rb test/functional/users_controller_test.rb echo "Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1" >> config/initializers/mime_types.rb # Do route file? # Rails 5 API mode # Basic setup cd fixtures rvm use 2.5.0 rails _5.0.2_ new rails5_api --api cd rails5_api # Server config echo "Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1" >> config/initializers/mime_types.rb cp ../rails5/config/routes.rb config/routes.rb # Application rm -r app/models app/views app/migrate ln -s "../../ashared/models" app/models ln -s "../../ashared/views_rails_3/" app/views ln -s "../../ashared/migrate" db/migrate ln -s "../../ashared/helpers" app/helpers ln -s "../../../ashared/controllers_rails_5/posts_controller.rb" app/controllers/posts_controller.rb ln -s "../../../ashared/controllers_rails_5/users_controller.rb" app/controllers/users_controller.rb # Test setup cp ../rails5/Rakefile ./ mkdir test/functional ln -s ../../../../test/integration/rails5/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/rails5/users_controller_test.rb test/functional/users_controller_test.rb cp ../rails5/test/test_helper.rb ./test/test_helper.rb # Do a bunch of junk with gemfiles and test helpers and such # end Rails 5 API mode # Rails 6 cd fixtures/rails6 ln -s "../../ashared/models" app/models ln -s "../../ashared/views_rails_6/" app/views ln -s "../../ashared/helpers" app/helpers ln -s ../../../../test/integration/rails6/posts_controller_test.rb test/functional/posts_controller_test.rb ln -s ../../../../test/integration/rails6/users_controller_test.rb test/functional/users_controller_test.rb echo "Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1" >> config/initializers/mime_types.rb rabl-0.16.1/fixtures/ashared/README000066400000000000000000000011631432107571000166600ustar00rootroot00000000000000Fixtures to test RABL: Gemfile: gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'riot', :group => "test" models: user t.string :username t.string :email t.string :location t.boolean :is_admin t.timestamps posts t.integer :user_id t.string :title t.text :body t.timestamps phone_number t.integer :user_id t.boolean :is_primary t.string :area_code t.string :prefix t.string :suffix t.string :name controllers: users posts layouts: application.html.haml views: posts (index, show, date) users (index, show)rabl-0.16.1/fixtures/ashared/controllers_rails_5/000077500000000000000000000000001432107571000217635ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/controllers_rails_5/posts_controller.rb000066400000000000000000000005721432107571000257270ustar00rootroot00000000000000class PostsController < ApplicationController respond_to :json, :xml, :html, :rabl_test_v1 def index @posts = Post.order('id ASC').load end def show @post = Post.find(params[:id]) end def renderer post = Post.find(params[:id]) render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context) end end rabl-0.16.1/fixtures/ashared/controllers_rails_5/users_controller.rb000066400000000000000000000002721432107571000257150ustar00rootroot00000000000000class UsersController < ApplicationController respond_to :json def index @users = User.order('username ASC').load end def show @user = User.find(params[:id]) end end rabl-0.16.1/fixtures/ashared/helpers/000077500000000000000000000000001432107571000174415ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/helpers/application_helper.rb000066400000000000000000000000771432107571000236340ustar00rootroot00000000000000module ApplicationHelper def helper_foo "BAR!" end end rabl-0.16.1/fixtures/ashared/migrate/000077500000000000000000000000001432107571000174275ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/migrate/20111002092016_create_users.rb000066400000000000000000000004201432107571000240640ustar00rootroot00000000000000class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :username t.string :email t.string :location t.boolean :is_admin t.timestamps end end def self.down drop_table :users end end rabl-0.16.1/fixtures/ashared/migrate/20111002092019_create_posts.rb000066400000000000000000000003611432107571000241020ustar00rootroot00000000000000class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.integer :user_id t.string :title t.text :body t.timestamps end end def self.down drop_table :posts end end rabl-0.16.1/fixtures/ashared/migrate/20111002092024_create_phone_numbers.rb000066400000000000000000000005011432107571000255660ustar00rootroot00000000000000class CreatePhoneNumbers < ActiveRecord::Migration def self.up create_table :phone_numbers do |t| t.integer :user_id t.boolean :is_primary t.string :area_code t.string :prefix t.string :suffix t.string :name end end def self.down drop_table :phone_numbers end end rabl-0.16.1/fixtures/ashared/models/000077500000000000000000000000001432107571000172625ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/models/phone_number.rb000066400000000000000000000002151432107571000222660ustar00rootroot00000000000000class PhoneNumber < ActiveRecord::Base belongs_to :user def formatted "(#{self.area_code}) #{self.prefix}-#{self.suffix}" end end rabl-0.16.1/fixtures/ashared/models/post.rb000066400000000000000000000000671432107571000205770ustar00rootroot00000000000000class Post < ActiveRecord::Base belongs_to :user end rabl-0.16.1/fixtures/ashared/models/user.rb000066400000000000000000000000761432107571000205700ustar00rootroot00000000000000class User < ActiveRecord::Base has_many :phone_numbers end rabl-0.16.1/fixtures/ashared/views/000077500000000000000000000000001432107571000171345ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views/layouts/000077500000000000000000000000001432107571000206345ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views/layouts/application.html.erb000066400000000000000000000001651432107571000245760ustar00rootroot00000000000000 RABL ROCKS! <%= yield %> rabl-0.16.1/fixtures/ashared/views/posts/000077500000000000000000000000001432107571000203045ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views/posts/_show_footer_script.js.erb000066400000000000000000000001121432107571000254640ustar00rootroot00000000000000var output = <%= render(file: 'posts/show', formats: :json).html_safe %>; rabl-0.16.1/fixtures/ashared/views/posts/date.rabl000066400000000000000000000001211432107571000220550ustar00rootroot00000000000000code(:day) { |d| d.day } code(:hour) { |d| d.hour } code(:full) { |d| d.iso8601 }rabl-0.16.1/fixtures/ashared/views/posts/index.rabl000066400000000000000000000004121432107571000222520ustar00rootroot00000000000000collection @posts => :articles cache ['kittens!', @posts] extends "posts/show" node(:created_by_admin, :if => lambda { |p| p.user.is_admin }) do |p| true end child({ :user => :admin }, { :if => lambda { |p| p.user.is_admin }}) do |p| extends "users/show" endrabl-0.16.1/fixtures/ashared/views/posts/show.rabl000066400000000000000000000004151432107571000221260ustar00rootroot00000000000000object @post cache @post attributes :title, :body attributes :created_at => :posted_at child :user do extends "users/show" end glue :user do attributes :username => :author_name end code(:created_date) do |p| partial("posts/date", :object => p.created_at) endrabl-0.16.1/fixtures/ashared/views/users/000077500000000000000000000000001432107571000202755ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views/users/index.json.rabl000066400000000000000000000000471432107571000232170ustar00rootroot00000000000000collection @users extends "users/show"rabl-0.16.1/fixtures/ashared/views/users/phone_number.json.rabl000066400000000000000000000001641432107571000245710ustar00rootroot00000000000000attributes :prefix, :suffix, :area_code attributes :is_primary => :primary node :formatted do |n| n.formatted endrabl-0.16.1/fixtures/ashared/views/users/show.json.rabl000066400000000000000000000005141432107571000230670ustar00rootroot00000000000000object @user => :person attributes :username, :email, :location attributes :created_at => :registered_at node :role do |user| user.is_admin ? 'admin' : 'normal' end child :phone_numbers => :pnumbers do extends "users/phone_number" end node :node_numbers do |u| partial("users/phone_number", :object => u.phone_numbers) endrabl-0.16.1/fixtures/ashared/views_rails_3/000077500000000000000000000000001432107571000205505ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_3/layouts/000077500000000000000000000000001432107571000222505ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_3/layouts/application.html.erb000066400000000000000000000003051432107571000262060ustar00rootroot00000000000000 RABL ROCKS! <%= yield %> <%= javascript_tag do %> <%= yield(:footer_scripts) %> <% end %> rabl-0.16.1/fixtures/ashared/views_rails_3/posts/000077500000000000000000000000001432107571000217205ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_3/posts/_show_footer_script.js.erb000066400000000000000000000001121432107571000271000ustar00rootroot00000000000000var output = <%= render(file: 'posts/show', formats: :json).html_safe %>; rabl-0.16.1/fixtures/ashared/views_rails_3/posts/date.rabl000066400000000000000000000001211432107571000234710ustar00rootroot00000000000000code(:day) { |d| d.day } code(:hour) { |d| d.hour } code(:full) { |d| d.iso8601 }rabl-0.16.1/fixtures/ashared/views_rails_3/posts/index.html.erb000066400000000000000000000001751432107571000244670ustar00rootroot00000000000000<%= content_for :footer_scripts do %> var output = <%= render(file: 'posts/index', formats: :json).html_safe %>; <% end %> rabl-0.16.1/fixtures/ashared/views_rails_3/posts/index.rabl000066400000000000000000000004121432107571000236660ustar00rootroot00000000000000collection @posts => :articles cache ['kittens!', @posts] extends "posts/show" node(:created_by_admin, :if => lambda { |p| p.user.is_admin }) do |p| true end child({ :user => :admin }, { :if => lambda { |p| p.user.is_admin }}) do |p| extends "users/show" endrabl-0.16.1/fixtures/ashared/views_rails_3/posts/renderer.rabl000066400000000000000000000001731432107571000243710ustar00rootroot00000000000000object @post cache @post attributes :title, :body node :partial do |p| partial('posts/renderer_partial', object: p) endrabl-0.16.1/fixtures/ashared/views_rails_3/posts/renderer_partial.rabl000066400000000000000000000000621432107571000261020ustar00rootroot00000000000000object @post cache @post attributes :title, :bodyrabl-0.16.1/fixtures/ashared/views_rails_3/posts/show.html.erb000066400000000000000000000001541432107571000243350ustar00rootroot00000000000000<%= content_for :footer_scripts do %> <%= render partial: "show_footer_script", formats: :js %> <% end %> rabl-0.16.1/fixtures/ashared/views_rails_3/posts/show.rabl000066400000000000000000000006411432107571000235430ustar00rootroot00000000000000object @post cache @post attributes :title, :body attributes :created_at => :posted_at child :user do extends "users/show" end glue :user do attributes :username => :author_name end code(:created_date) do |p| partial("posts/date", :object => p.created_at) end node(:post) do |post| [post.title, post.body] end node(:foo) { helper_foo } node(:created_at_in_words) {|p| time_ago_in_words(p.created_at) } rabl-0.16.1/fixtures/ashared/views_rails_3/posts/show.rabl_test_v1.rabl000066400000000000000000000001271432107571000261260ustar00rootroot00000000000000object @post attribute :title => :title_v1 child :user do extends "users/show" end rabl-0.16.1/fixtures/ashared/views_rails_3/users/000077500000000000000000000000001432107571000217115ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_3/users/index.json.rabl000066400000000000000000000001111432107571000246230ustar00rootroot00000000000000collection @users extends "users/show", :locals => { :reversed => true }rabl-0.16.1/fixtures/ashared/views_rails_3/users/phone_number.json.rabl000066400000000000000000000002761432107571000262110ustar00rootroot00000000000000attributes :prefix, :suffix, :area_code attributes :is_primary => :primary if locals[:reversed] node(:reversed) { |n| n.formatted.reverse } else node(:formatted) { |n| n.formatted } endrabl-0.16.1/fixtures/ashared/views_rails_3/users/phone_number.xml.rabl000077700000000000000000000000001432107571000323212phone_number.json.rablustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_3/users/show.json.rabl000066400000000000000000000006041432107571000245030ustar00rootroot00000000000000object @user => :person attributes :username, :email, :location attributes :created_at => :registered_at node :role do |user| user.is_admin ? 'admin' : 'normal' end child :phone_numbers => :pnumbers do extends "users/phone_number" end node :node_numbers do |u| partial("users/phone_number", :object => u.phone_numbers, :locals => { :reversed => locals[:reversed].presence }) endrabl-0.16.1/fixtures/ashared/views_rails_3/users/show.rabl_test_v1.rabl000066400000000000000000000000751432107571000261210ustar00rootroot00000000000000object @user => :person attribute :username => :username_v1 rabl-0.16.1/fixtures/ashared/views_rails_6/000077500000000000000000000000001432107571000205535ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_6/layouts/000077500000000000000000000000001432107571000222535ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_6/layouts/application.html.erb000066400000000000000000000003051432107571000262110ustar00rootroot00000000000000 RABL ROCKS! <%= yield %> <%= javascript_tag do %> <%= yield(:footer_scripts) %> <% end %> rabl-0.16.1/fixtures/ashared/views_rails_6/posts/000077500000000000000000000000001432107571000217235ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_6/posts/_show_footer_script.js.erb000066400000000000000000000001161432107571000271070ustar00rootroot00000000000000var output = <%= render(template: 'posts/show', formats: :json).html_safe %>; rabl-0.16.1/fixtures/ashared/views_rails_6/posts/date.rabl000066400000000000000000000001211432107571000234740ustar00rootroot00000000000000code(:day) { |d| d.day } code(:hour) { |d| d.hour } code(:full) { |d| d.iso8601 }rabl-0.16.1/fixtures/ashared/views_rails_6/posts/index.html.erb000066400000000000000000000002011432107571000244600ustar00rootroot00000000000000<%= content_for :footer_scripts do %> var output = <%= render(template: 'posts/index', formats: :json).html_safe %>; <% end %> rabl-0.16.1/fixtures/ashared/views_rails_6/posts/index.rabl000066400000000000000000000004121432107571000236710ustar00rootroot00000000000000collection @posts => :articles cache ['kittens!', @posts] extends "posts/show" node(:created_by_admin, :if => lambda { |p| p.user.is_admin }) do |p| true end child({ :user => :admin }, { :if => lambda { |p| p.user.is_admin }}) do |p| extends "users/show" endrabl-0.16.1/fixtures/ashared/views_rails_6/posts/renderer.rabl000066400000000000000000000001731432107571000243740ustar00rootroot00000000000000object @post cache @post attributes :title, :body node :partial do |p| partial('posts/renderer_partial', object: p) endrabl-0.16.1/fixtures/ashared/views_rails_6/posts/renderer_partial.rabl000066400000000000000000000000631432107571000261060ustar00rootroot00000000000000object @post cache @post attributes :title, :body rabl-0.16.1/fixtures/ashared/views_rails_6/posts/show.html.erb000066400000000000000000000001541432107571000243400ustar00rootroot00000000000000<%= content_for :footer_scripts do %> <%= render partial: "show_footer_script", formats: :js %> <% end %> rabl-0.16.1/fixtures/ashared/views_rails_6/posts/show.rabl000066400000000000000000000006411432107571000235460ustar00rootroot00000000000000object @post cache @post attributes :title, :body attributes :created_at => :posted_at child :user do extends "users/show" end glue :user do attributes :username => :author_name end code(:created_date) do |p| partial("posts/date", :object => p.created_at) end node(:post) do |post| [post.title, post.body] end node(:foo) { helper_foo } node(:created_at_in_words) {|p| time_ago_in_words(p.created_at) } rabl-0.16.1/fixtures/ashared/views_rails_6/posts/show.rabl_test_v1.rabl000066400000000000000000000001271432107571000261310ustar00rootroot00000000000000object @post attribute :title => :title_v1 child :user do extends "users/show" end rabl-0.16.1/fixtures/ashared/views_rails_6/users/000077500000000000000000000000001432107571000217145ustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_6/users/index.json.rabl000066400000000000000000000001111432107571000246260ustar00rootroot00000000000000collection @users extends "users/show", :locals => { :reversed => true }rabl-0.16.1/fixtures/ashared/views_rails_6/users/phone_number.json.rabl000066400000000000000000000002761432107571000262140ustar00rootroot00000000000000attributes :prefix, :suffix, :area_code attributes :is_primary => :primary if locals[:reversed] node(:reversed) { |n| n.formatted.reverse } else node(:formatted) { |n| n.formatted } endrabl-0.16.1/fixtures/ashared/views_rails_6/users/phone_number.xml.rabl000077700000000000000000000000001432107571000323242phone_number.json.rablustar00rootroot00000000000000rabl-0.16.1/fixtures/ashared/views_rails_6/users/show.json.rabl000066400000000000000000000006041432107571000245060ustar00rootroot00000000000000object @user => :person attributes :username, :email, :location attributes :created_at => :registered_at node :role do |user| user.is_admin ? 'admin' : 'normal' end child :phone_numbers => :pnumbers do extends "users/phone_number" end node :node_numbers do |u| partial("users/phone_number", :object => u.phone_numbers, :locals => { :reversed => locals[:reversed].presence }) endrabl-0.16.1/fixtures/ashared/views_rails_6/users/show.rabl_test_v1.rabl000066400000000000000000000000751432107571000261240ustar00rootroot00000000000000object @user => :person attribute :username => :username_v1 rabl-0.16.1/fixtures/padrino_test/000077500000000000000000000000001432107571000170635ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/.components000066400000000000000000000001401432107571000212440ustar00rootroot00000000000000--- :orm: activerecord :test: riot :mock: none :script: none :renderer: haml :stylesheet: none rabl-0.16.1/fixtures/padrino_test/.gitignore000066400000000000000000000001211432107571000210450ustar00rootroot00000000000000.DS_Store log/**/* tmp/**/* bin/* vendor/gems/* !vendor/gems/cache/ .sass-cache/*rabl-0.16.1/fixtures/padrino_test/Gemfile000066400000000000000000000006011432107571000203530ustar00rootroot00000000000000source 'https://rubygems.org' # Project requirements gem 'rake' # Component requirements gem 'activerecord', :require => "active_record" gem 'sqlite3' # Test requirements gem 'riot', :group => "test" gem 'rack-test', :require => "rack/test", :group => "test" # Padrino gem 'padrino', '~> 0.10.7' gem 'json' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") rabl-0.16.1/fixtures/padrino_test/Rakefile000066400000000000000000000001521432107571000205260ustar00rootroot00000000000000require File.expand_path('../config/boot.rb', __FILE__) require 'padrino-core/cli/rake' PadrinoTasks.init rabl-0.16.1/fixtures/padrino_test/app/000077500000000000000000000000001432107571000176435ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/app/app.rb000066400000000000000000000026161432107571000207550ustar00rootroot00000000000000class PadrinoTest < Padrino::Application register Padrino::Rendering register Padrino::Mailer register Padrino::Helpers enable :sessions ## # Application configuration options # # set :raise_errors, true # Raise exceptions (will stop application) (default for test) # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development) # set :show_exceptions, true # Shows a stack trace in browser (default for development) # set :logging, true # Logging in STDOUT for development and file for production (default only for development) # set :public, "foo/bar" # Location for static assets (default root/public) # set :reload, false # Reload application files (default in development) # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder') # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales) # disable :sessions # Disabled sessions by default (enable if needed) # disable :flash # Disables rack-flash (enabled by default if Rack::Flash is defined) # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application) # end # Patch times to return as iso8601 class Time alias_method :old_to_s, :to_s def to_s(format=nil) format ? old_to_s(format) : iso8601 end endrabl-0.16.1/fixtures/padrino_test/app/controllers/000077500000000000000000000000001432107571000222115ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/app/controllers/posts.rb000066400000000000000000000003501432107571000237040ustar00rootroot00000000000000PadrinoTest.controllers :posts do get :index do @posts = Post.order("id ASC") render "posts/index" end get :show, :map => "/posts", :with => :id do @post = Post.find(params[:id]) render "posts/show" end end rabl-0.16.1/fixtures/padrino_test/app/controllers/users.rb000066400000000000000000000003561432107571000237030ustar00rootroot00000000000000PadrinoTest.controllers :users do get :index do @users = User.order("username ASC") render "users/index" end get :show, :map => "/users", :with => :id do @user = User.find(params[:id]) render "users/show" end end rabl-0.16.1/fixtures/padrino_test/app/helpers/000077500000000000000000000000001432107571000213055ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/app/helpers/posts_helper.rb000066400000000000000000000002451432107571000243420ustar00rootroot00000000000000# Helper methods defined here can be accessed in any controller or view in the application PadrinoTest.helpers do # def simple_helper_method # ... # end end rabl-0.16.1/fixtures/padrino_test/app/helpers/users_helper.rb000066400000000000000000000002451432107571000243330ustar00rootroot00000000000000# Helper methods defined here can be accessed in any controller or view in the application PadrinoTest.helpers do # def simple_helper_method # ... # end end rabl-0.16.1/fixtures/padrino_test/app/views000077700000000000000000000000001432107571000241122../../ashared/views/ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/config.ru000066400000000000000000000003161432107571000207000ustar00rootroot00000000000000#!/usr/bin/env rackup # encoding: utf-8 # This file can be used to start Padrino, # just execute it from the command line. require File.expand_path("../config/boot.rb", __FILE__) run Padrino.application rabl-0.16.1/fixtures/padrino_test/config/000077500000000000000000000000001432107571000203305ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/config/apps.rb000066400000000000000000000025011432107571000216160ustar00rootroot00000000000000## # This file mounts each app in the Padrino project to a specified sub-uri. # You can mount additional applications using any of these commands below: # # Padrino.mount("blog").to('/blog') # Padrino.mount("blog", :app_class => "BlogApp").to('/blog') # Padrino.mount("blog", :app_file => "path/to/blog/app.rb").to('/blog') # # You can also map apps to a specified host: # # Padrino.mount("Admin").host("admin.example.org") # Padrino.mount("WebSite").host(/.*\.?example.org/) # Padrino.mount("Foo").to("/foo").host("bar.example.org") # # Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'. # Note 2: If you use the host matching remember to respect the order of the rules. # # By default, this file mounts the primary app which was generated with this project. # However, the mounted app can be modified as needed: # # Padrino.mount("AppName", :app_file => "path/to/file", :app_class => "BlogApp").to('/') # ## # Setup global project settings for your apps. These settings are inherited by every subapp. You can # override these settings in the subapps as needed. # Padrino.configure_apps do # enable :sessions set :session_secret, '1559bdc5e1f33a0d1c9a597580a189080b39ab7d06eed1a7db12e90f9d269e89' end # Mounts the core application for this project Padrino.mount("PadrinoTest").to('/') rabl-0.16.1/fixtures/padrino_test/config/boot.rb000066400000000000000000000011741432107571000216230ustar00rootroot00000000000000# Defines our constants PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV) PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT) # Load our dependencies require 'rubygems' unless defined?(Gem) require 'bundler/setup' Bundler.require(:default, PADRINO_ENV) ## # Enable devel logging # # Padrino::Logger::Config[:development] = { :log_level => :devel, :stream => :stdout } # Padrino::Logger.log_static = true # ## # Add your before load hooks here # Padrino.before_load do end ## # Add your after load hooks here # Padrino.after_load do end Padrino.load! rabl-0.16.1/fixtures/padrino_test/config/database.rb000066400000000000000000000024221432107571000224210ustar00rootroot00000000000000## # You can use other adapters like: # # ActiveRecord::Base.configurations[:development] = { # :adapter => 'mysql', # :encoding => 'utf8', # :reconnect => true, # :database => 'your_database', # :pool => 5, # :username => 'root', # :password => '', # :host => 'localhost', # :socket => '/tmp/mysql.sock' # } # ActiveRecord::Base.configurations[:development] = { :adapter => 'sqlite3', :database => ":memory:" } ActiveRecord::Base.configurations[:test] = { :adapter => 'sqlite3', :database => ":memory:" } # Setup our logger ActiveRecord::Base.logger = logger # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full class name (including module namespace) in STI type column. ActiveRecord::Base.store_full_sti_class = true # Use ISO 8601 format for JSON serialized times and dates. ActiveSupport.use_standard_json_time_format = true # Don't escape HTML entities in JSON, leave that for the #json_escape helper. # if you're including raw json in an HTML page. ActiveSupport.escape_html_entities_in_json = false # Now we can estabilish connection with our db ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env]) rabl-0.16.1/fixtures/padrino_test/db/000077500000000000000000000000001432107571000174505ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/db/migrate000077700000000000000000000000001432107571000244262../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/db/schema.rb000066400000000000000000000025441432107571000212420ustar00rootroot00000000000000# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 3) do create_table "phone_numbers", :force => true do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", :force => true do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/padrino_test/models000077700000000000000000000000001432107571000233142../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/public/000077500000000000000000000000001432107571000203415ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/public/favicon.ico000066400000000000000000000000001432107571000224500ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/000077500000000000000000000000001432107571000200425ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/app/000077500000000000000000000000001432107571000206225ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/app/controllers/000077500000000000000000000000001432107571000231705ustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/app/controllers/posts_controller_test.rb000077700000000000000000000000001432107571000417522../../../../../test/integration/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/app/controllers/users_controller_test.rb000077700000000000000000000000001432107571000417342../../../../../test/integration/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/padrino_test/test/test.rake000066400000000000000000000007011432107571000216630ustar00rootroot00000000000000require 'rake/testtask' test_tasks = Dir['test/*/'].map { |d| File.basename(d) } test_tasks.each do |folder| Rake::TestTask.new("test:#{folder}") do |test| test.pattern = "test/#{folder}/**/*_test.rb" test.verbose = true end end desc "Run application test suite" task 'test' => test_tasks.map { |f| "test:#{f}" } Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/app/controllers/**/*_test.rb" test.verbose = true endrabl-0.16.1/fixtures/padrino_test/test/test_config.rb000066400000000000000000000010461432107571000226740ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") silence_warnings do PADRINO_ENV = 'test' unless defined?(PADRINO_ENV) require File.expand_path(File.dirname(__FILE__) + "/../config/boot") silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } # Load up test migrations end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") class Riot::Situation def app @app || Padrino.application end end rabl-0.16.1/fixtures/rails2/000077500000000000000000000000001432107571000155645ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/.gitignore000066400000000000000000000000051432107571000175470ustar00rootroot00000000000000log/*rabl-0.16.1/fixtures/rails2/Gemfile000066400000000000000000000004441432107571000170610ustar00rootroot00000000000000source 'https://rubygems.org' gem "rails", "~> 2.3.18" gem "sqlite3", :require => "sqlite3" gem 'json' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'rake', "~> 0.9.2.2" gem 'riot', :group => "test" gem 'rack-test', :require => "rack/test", :group => "test" rabl-0.16.1/fixtures/rails2/Rakefile000066400000000000000000000006201432107571000172270ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'tasks/rails' Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functionals/**/*_test.rb" test.verbose = true endrabl-0.16.1/fixtures/rails2/app/000077500000000000000000000000001432107571000163445ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/app/controllers/000077500000000000000000000000001432107571000207125ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/app/controllers/application_controller.rb000066400000000000000000000006561432107571000260140ustar00rootroot00000000000000# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password end rabl-0.16.1/fixtures/rails2/app/controllers/posts_controller.rb000066400000000000000000000004761432107571000246610ustar00rootroot00000000000000class PostsController < ApplicationController def index @posts = Post.all(:order => "id ASC") respond_to do |format| format.json { render "posts/index" } end end def show @post = Post.find(params[:id]) respond_to do |format| format.json { render "posts/show" } end end end rabl-0.16.1/fixtures/rails2/app/controllers/users_controller.rb000066400000000000000000000005041432107571000246420ustar00rootroot00000000000000class UsersController < ApplicationController def index @users = User.all(:order => "username ASC") respond_to do |format| format.json { render "users/index" } end end def show @user = User.find(params[:id]) respond_to do |format| format.json { render "users/show" } end end end rabl-0.16.1/fixtures/rails2/app/helpers/000077500000000000000000000000001432107571000200065ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/app/helpers/application_helper.rb000066400000000000000000000000351432107571000241730ustar00rootroot00000000000000module ApplicationHelper end rabl-0.16.1/fixtures/rails2/app/helpers/posts_helper.rb000066400000000000000000000000271432107571000230410ustar00rootroot00000000000000module PostsHelper end rabl-0.16.1/fixtures/rails2/app/helpers/users_helper.rb000066400000000000000000000000271432107571000230320ustar00rootroot00000000000000module UsersHelper end rabl-0.16.1/fixtures/rails2/app/models000077700000000000000000000000001432107571000230102../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/app/views000077700000000000000000000000001432107571000226132../../ashared/views/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/config/000077500000000000000000000000001432107571000170315ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/config/boot.rb000066400000000000000000000061611432107571000203250ustar00rootroot00000000000000# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? defined? Rails::Initializer end def pick_boot (vendor_rails? ? VendorBoot : GemBoot).new end def vendor_rails? File.exist?("#{RAILS_ROOT}/vendor/rails") end def preinitialize load(preinitializer_path) if File.exist?(preinitializer_path) end def preinitializer_path "#{RAILS_ROOT}/config/preinitializer.rb" end end class Boot def run load_initializer Rails::Initializer.run(:set_load_path) end end class VendorBoot < Boot def load_initializer require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" Rails::Initializer.run(:install_gem_spec_stubs) Rails::GemDependency.add_frozen_gem_path end end class GemBoot < Boot def load_initializer self.class.load_rubygems load_rails_gem require 'initializer' end def load_rails_gem if version = self.class.gem_version gem 'rails', version else gem 'rails' end rescue Gem::LoadError => load_error if load_error.message =~ /Could not find RubyGem rails/ STDERR.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) exit 1 else raise end end class << self def rubygems_version Gem::RubyGemsVersion rescue nil end def gem_version if defined? RAILS_GEM_VERSION RAILS_GEM_VERSION elsif ENV.include?('RAILS_GEM_VERSION') ENV['RAILS_GEM_VERSION'] else parse_gem_version(read_environment_rb) end end def load_rubygems min_version = '1.3.2' require 'rubygems' unless rubygems_version >= min_version $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) exit 1 end rescue LoadError $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) exit 1 end def parse_gem_version(text) $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ end private def read_environment_rb File.read("#{RAILS_ROOT}/config/environment.rb") end end end end # Bundler: http://gembundler.com/rails23.html class Rails::Boot def run load_initializer Rails::Initializer.class_eval do def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end end Rails::Initializer.run(:set_load_path) end end # All that for this: Rails.boot! rabl-0.16.1/fixtures/rails2/config/database.yml000066400000000000000000000006551432107571000213260ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: ":memory:" pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: ":memory:" pool: 5 timeout: 5000 rabl-0.16.1/fixtures/rails2/config/environment.rb000066400000000000000000000046571432107571000217360ustar00rootroot00000000000000# Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.18' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') # Hot patch since Gem.source_index was deprecated in later rubygems unless Gem.method_defined?(:source_index) module Gem def self.source_index sources end def self.cache sources end SourceIndex = Specification class SourceList # If you want vendor gems, this is where to start writing code. def search( *args ); []; end def each( &block ); end include Enumerable end end end Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs # config.autoload_paths += %W( #{RAILS_ROOT}/extras ) # Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "sqlite3-ruby", :lib => "sqlite3" # config.gem "aws-s3", :lib => "aws/s3" config.gem "rack-test", :lib => "rack/test" # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. config.time_zone = 'UTC' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de endrabl-0.16.1/fixtures/rails2/config/environments/000077500000000000000000000000001432107571000215605ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/config/environments/development.rb000066400000000000000000000013531432107571000244310ustar00rootroot00000000000000# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver 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.action_controller.consider_all_requests_local = true config.action_view.debug_rjs = true config.action_controller.perform_caching = false # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = falserabl-0.16.1/fixtures/rails2/config/environments/production.rb000066400000000000000000000017631432107571000243020ustar00rootroot00000000000000# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching = true config.action_view.cache_template_loading = true # See everything in the log (default is :info) # config.log_level = :debug # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Use a different cache store in production # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe!rabl-0.16.1/fixtures/rails2/config/environments/test.rb000066400000000000000000000024371432107571000230720ustar00rootroot00000000000000# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false config.action_view.cache_template_loading = true # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Use SQL instead of Active Record's schema dumper when creating the test database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sqlrabl-0.16.1/fixtures/rails2/config/initializers/000077500000000000000000000000001432107571000215375ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000260540ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a problem that might steem from framework code. # Rails.backtrace_cleaner.remove_silencers!rabl-0.16.1/fixtures/rails2/config/initializers/cookie_verification_secret.rb000066400000000000000000000007711432107571000274510ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. ActionController::Base.cookie_verifier_secret = '07d74a7edfe4b5e0cf80f002948a3907a515a0dc6c8fdb2411dc73de8547012acde659641dba5cc31b5a40a09c4fd1298c2ea0080eda689181ed786502e70e00'; rabl-0.16.1/fixtures/rails2/config/initializers/inflections.rb000066400000000000000000000005711432107571000244040ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end rabl-0.16.1/fixtures/rails2/config/initializers/mime_types.rb000066400000000000000000000003151432107571000242360ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone rabl-0.16.1/fixtures/rails2/config/initializers/new_rails_defaults.rb000066400000000000000000000015011432107571000257330ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full class name (including module namespace) in STI type column. ActiveRecord::Base.store_full_sti_class = true end ActionController::Routing.generate_best_match = false # Use ISO 8601 format for JSON serialized times and dates. ActiveSupport.use_standard_json_time_format = true # Don't escape HTML entities in JSON, leave that for the #json_escape helper. # if you're including raw json in an HTML page. ActiveSupport.escape_html_entities_in_json = falserabl-0.16.1/fixtures/rails2/config/initializers/session_store.rb000066400000000000000000000014371432107571000247700ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. ActionController::Base.session = { :key => '_rails2_session', :secret => 'b2d31ab1f626a19684aee969cb099d7ab2824150dae712c1c69aaf421bbce2ceb9c2ae85ea9f213440e6baa8e6029f75cebe80fa3af2de8309f885e5f646e8a8' } # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rake db:sessions:create") # ActionController::Base.session_store = :active_record_store rabl-0.16.1/fixtures/rails2/config/locales/000077500000000000000000000000001432107571000204535ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/config/locales/en.yml000066400000000000000000000003241432107571000215770ustar00rootroot00000000000000# Sample localization file for English. Add more files in this directory for other locales. # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world"rabl-0.16.1/fixtures/rails2/config/preinitializer.rb000066400000000000000000000011301432107571000224030ustar00rootroot00000000000000begin require "rubygems" require "bundler" rescue LoadError raise "Could not load the bundler gem. Install it with `gem install bundler`." end if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") raise RuntimeError, "Your bundler version is too old for Rails 2.3." + "Run `gem install bundler` to upgrade." end begin # Set up load paths for all bundled gems ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) Bundler.setup rescue Bundler::GemNotFound raise RuntimeError, "Bundler couldn't find some gems." + "Did you run `bundle install`?" endrabl-0.16.1/fixtures/rails2/config/routes.rb000066400000000000000000000036471432107571000207110ustar00rootroot00000000000000ActionController::Routing::Routes.draw do |map| map.resources :posts map.resources :users # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # map.resources :products # Sample resource route with options: # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # Sample resource route with sub-resources: # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # Sample resource route with more complex sub-resources # map.resources :products do |products| # products.resources :comments # products.resources :sales, :collection => { :recent => :get } # end # Sample resource route within a namespace: # map.namespace :admin do |admin| # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # admin.resources :products # end # You can have the root of your site routed with map.root -- just remember to delete public/index.html. # map.root :controller => "welcome" # See how all your routes lay out with "rake routes" # Install the default routes as the lowest priority. # Note: These default routes make all actions in every controller accessible via GET requests. You should # consider removing or commenting them out if you're using named routes and resources. # map.connect ':controller/:action/:id' # map.connect ':controller/:action/:id.:format' end rabl-0.16.1/fixtures/rails2/db/000077500000000000000000000000001432107571000161515ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/db/migrate000077700000000000000000000000001432107571000231272../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/db/schema.rb000066400000000000000000000025361432107571000177440ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your database schema. If you need # to create the application database on another system, you should be using db:schema:load, not running # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 20111002092024) do create_table "phone_numbers", :force => true do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", :force => true do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/rails2/db/seeds.rb000066400000000000000000000005441432107571000176040ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Major.create(:name => 'Daley', :city => cities.first) rabl-0.16.1/fixtures/rails2/public/000077500000000000000000000000001432107571000170425ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/public/404.html000066400000000000000000000016631432107571000202450ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

rabl-0.16.1/fixtures/rails2/public/422.html000066400000000000000000000016421432107571000202420ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

rabl-0.16.1/fixtures/rails2/public/500.html000066400000000000000000000016641432107571000202430ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

rabl-0.16.1/fixtures/rails2/public/favicon.ico000066400000000000000000000000001432107571000211510ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/public/images/000077500000000000000000000000001432107571000203075ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/public/images/rails.png000066400000000000000000000147661432107571000221450ustar00rootroot00000000000000PNG  IHDR2@X${tEXtSoftwareAdobe ImageReadyqe<IDATxڬ[ \eR֮^;Iwga@`gGgDgtqDFqFDqF@NRU]˫|_-Qy^Ǹ.݋0W_6kbf̻ܸ6<4 w5~*r?9m&"M7@vm' {_S)Vi\WG?իjMd@ lDLX鸺W-TU+@EPo\&*Rnn, fDWrX|3M=\EJB[d6A'=tx^$a86̈{, ϱPepN*_W_3o;ޥ(0E:i6eXnhGf"L|S+(+.gФg=Ych=m#V_#}Ǫ|tR D8VՄM~xg!ni%Dy( B,{(Np$3iر$h.@e[a'eJԂyϠ4>H*MHQ(Jgt-֢QI ^d„@s-'- 51{'0 |n4ۉh{V@ܩw"BT =rzqPpBHȃ?ň ]-qpgsPiSӪg`jn)m 御B2L.x!jJP! K/\ ʮRB[09Trӈu. uH$ DDQ+:ݘٻ 3/nލ%Sjm2!&D/[EHwW A-RR!PeuHim"t6lFgЫ-O.1?ƞksX~VtmZJR11Nu&<⽩,Tb,`w WPx-G5 `մ/5pbAtIVJ_]0/DiH=ô#*77-3 VuQ0.pݔ%yw hљW0),2$b6&I/@bj$I(fx' JnO"`<-/LѮ%^ȫͶn2wҗ2}}XսL'Q-,m/ꤋ4#0Q&00NKrsA,Aײ)aIEC(ERK{8Ȭ[y?iI5$%f{}u F 1~;v1l'@F 'IF'm!K7"&]w 15#4Vižn[v 8Ě)>C=LBo~/3% wF4֓ʿ8>bWX@bb@IzP9IvFfQL!2cEP(se4~5RhAŽ90_? cMEteVOaOr B]pȱؓ"Eyx: NJ)bl׋hYuTdԫw=آMgwVPOFΒ25-TD[Z2>]V,xӛIOƅ)Jͺ[)?cn28p#(mk+./phʮQ6?w7HIoSj)1<#-N9O1ͰސkIKr:(ŗ;rR&<93v@w(w:~:TFSޒ" ՊTdT9PIb3JzTQׄBP23ƵW*|@^)Qw?Iq =,<@ B8);50H-=T SA@@f5r[T%#c|Z&w(B)tDQ%vyC(,Ɵ|ʰi&<#u:3EHkzд)ndF>1V2kFGYL KMQlR&TB,igv8]C8Sf#ą4Q'?,= aV9WEXYrr*!cƯ~),=yџ]jlGeE̺5r_2Ԏ}d"a]0M9PZG17nE"Rr\YQ)!|5U(d=^ŗo8+2NU6jB[B5V.]ŲW/^䩬 ;Y"Vi$2ٲ_c(F^Egq{CP/ #K8Y+Q M1>ܞAߏ,gytޕn,zE$V.v.PyLapG9Tn:uiRZ! zI0?Џ1u#$6ɱGMhFdtd|~d\O9Ij**zD؍b)PBҽh-q ql%/{Gz*d7=QS]:RQbUMPᒯ$% du] XefQz$('ИZH#ARXDB ~`0.F|XXK)wFolzyhߚKz>.&n EjU,2' &iw[d[ V)*Qavl QDit[VIQhR@$)y~m|>?cJ+VH'6? 7 i.XH8Fި)dAYUBjE".4w-?l2Y.RjWD@Bج.߆s[H-gASF3Fj]آBP떬_>M%bt ?_rլ -h]r_ž[nȶQ+Gԭ_\Ê Z٦fet(|U('.g VFEN9}Ll4T&nto¨Ӓ X F "_fYzF~y& Gu]$O[v#].@$VA`ⱧTѰZ[2u+/mUC_ TnyѠ |l\ M"G[R$d|:ěFIire"ٵt,+ی1Z11udt*K2 sd; [)xW.z2jTh#DV\NO &e_vU2B^%0FH(/ԘI2>=L]dv UUpk"ijB$,O-0y<}~*T5LErE4B߳XXN:<9>Ed -V*uBLsN**JxRU辖,T( Gu @ůY{u|CJF(OLbnմiKhpFtx8#9FsFڋDTAn1veF^M ^kf.ĆݠVʓǰ3JaY@n&jLl:McӚ…vu?9w!/~#hM ڛ ̴nMA}m W,)(î.N y%$*={P9c DzH>Blu޾K78x->V,'JU \L]l>W*r-hXf~oI Z3f玱>vN3 uZTgg}Վ363:.g /-H+"PKۉSZ4Z_GlXMc7";ҿ (5fMUCOF6 CNft>$S1VaR&4) ٗay]%W A*|gX{Qc>iTX1F M`|![$P4ʊ$#,dɌ(?KTJR۸S%C7jHb浃j+N$,[.@˹_ ?.3ĵH"U$Z^ X02!Kc 8q.NMI6N&3n8exoWfPIJB<pREAdo$*m)e9D 5X[T$LΠ:]C$n#mC[P~Yt*d?\q^WXs!E-2#_mw8;2!vw:DUn$)GiGn3_o EZE3k-EHv.OûzE>"֛}l\/-nرQHԽab*#K׋eIƳd#G et\ ,:MێÜIC}m ٽO?eb%ːٰStB|Aznaz*FlQ/K uu*1wDvE֯SJTK;(4kƣ;v2P9`k{?~_[hʢ^9фǡ;m|]o9<#jz\wD,8V]]%K9er懇0n^FcI>`Ub+kօO1|NO]t+,Ȑl_ˮ6 ĒDbrz^pe7^[aþo確jN+xsNC߅wμ7|za2, omrbZ~,pN>;?Y,z[u◿jq 4aqڶNu6Zid@h!!F9#,#UrOa0=Då ,,,bE#ȮX3ªޏ=a< =&_~ ٵѽacj񫒆LsXuXB (wzEk_QIف*4'ѣSl{.,p۵2`jp^؇nZXPź^]wމ]aQ-oI5O3a] _wb ŭL]$"|sԩȬ= VсLIUbYY搮͢I$tf$2|r;~'GSXkᇦԭF4b4 xo[,04F~<}ۭR%myb׾\mlO.4}tE\7}M)tՉ13xF [-26t䢄&E"9;ٜrq e)K!:bwY }g;Jר)5D$!Kɤ9߫-K$$ hlDUFF J{s2R6rC&&0;@>]/Z3E,k;( 2^09 Ruby on Rails: Welcome aboard

Getting started

Here’s how to get rolling:

  1. Use script/generate to create your models and controllers

    To see all available options, run it without parameters.

  2. Set up a default route and remove or rename this file

    Routes are set up in config/routes.rb.

  3. Create your database

    Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

rabl-0.16.1/fixtures/rails2/public/robots.txt000066400000000000000000000003141432107571000211110ustar00rootroot00000000000000# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-Agent: * # Disallow: / rabl-0.16.1/fixtures/rails2/script/000077500000000000000000000000001432107571000170705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/script/about000077500000000000000000000002371432107571000201320ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about' rabl-0.16.1/fixtures/rails2/script/console000077500000000000000000000001501432107571000204540ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console' rabl-0.16.1/fixtures/rails2/script/dbconsole000077500000000000000000000001521432107571000207640ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole' rabl-0.16.1/fixtures/rails2/script/destroy000077500000000000000000000001501432107571000205030ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy' rabl-0.16.1/fixtures/rails2/script/generate000077500000000000000000000001511432107571000206050ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate' rabl-0.16.1/fixtures/rails2/script/performance/000077500000000000000000000000001432107571000213715ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/script/performance/benchmarker000077500000000000000000000001731432107571000236010ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker' rabl-0.16.1/fixtures/rails2/script/performance/profiler000077500000000000000000000001701432107571000231370ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler' rabl-0.16.1/fixtures/rails2/script/plugin000077500000000000000000000001471432107571000203160ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin' rabl-0.16.1/fixtures/rails2/script/runner000077500000000000000000000001471432107571000203310ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner' rabl-0.16.1/fixtures/rails2/script/server000077500000000000000000000001471432107571000203260ustar00rootroot00000000000000#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server' rabl-0.16.1/fixtures/rails2/test/000077500000000000000000000000001432107571000165435ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/test/functionals/000077500000000000000000000000001432107571000210705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/test/functionals/posts_controller_test.rb000077700000000000000000000000001432107571000374372../../../../test/integration/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/test/functionals/users_controller_test.rb000077700000000000000000000000001432107571000374212../../../../test/integration/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails2/test/test_helper.rb000066400000000000000000000016221432107571000214070ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app ActionController::Dispatcher.new end end class ActiveSupport::TestCase self.use_transactional_fixtures = true self.use_instantiated_fixtures = false end rabl-0.16.1/fixtures/rails3/000077500000000000000000000000001432107571000155655ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/.gitignore000066400000000000000000000000441432107571000175530ustar00rootroot00000000000000.bundle db/*.sqlite3 log/*.log tmp/ rabl-0.16.1/fixtures/rails3/Gemfile000066400000000000000000000016411432107571000170620ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rails', '~> 3.0.17' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'json' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") # TEST gem 'riot', :group => "test" gem 'rack-test', :require => "rack/test", :group => "test" # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) # gem 'ruby-debug' # gem 'ruby-debug19', :require => 'ruby-debug' # Bundle the extra gems: # gem 'bj' # gem 'nokogiri' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' # Bundle gems for the local environment. Make sure to # put test-only gems in this group so their generators # and rake tasks are available in development mode: # group :development, :test do # gem 'webrat' # end rabl-0.16.1/fixtures/rails3/Rakefile000066400000000000000000000005761432107571000172420ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) require 'rake' Rails3::Application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true endrabl-0.16.1/fixtures/rails3/app/000077500000000000000000000000001432107571000163455ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/app/controllers/000077500000000000000000000000001432107571000207135ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/app/controllers/application_controller.rb000066400000000000000000000004251432107571000260070ustar00rootroot00000000000000class ApplicationController < ActionController::Base protect_from_forgery before_filter :default_format_json protected def default_format_json if(request.headers["HTTP_ACCEPT"].nil? && params[:format].nil?) request.format = "json" end end end rabl-0.16.1/fixtures/rails3/app/controllers/posts_controller.rb000066400000000000000000000003041432107571000246500ustar00rootroot00000000000000class PostsController < ApplicationController respond_to :json, :xml, :html def index @posts = Post.all(:order => "id ASC") end def show @post = Post.find(params[:id]) end end rabl-0.16.1/fixtures/rails3/app/controllers/users_controller.rb000066400000000000000000000002751432107571000246500ustar00rootroot00000000000000class UsersController < ApplicationController respond_to :json def index @users = User.all(:order => "username ASC") end def show @user = User.find(params[:id]) end end rabl-0.16.1/fixtures/rails3/app/models000077700000000000000000000000001432107571000230112../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/app/views000077700000000000000000000000001432107571000226142../../ashared/views/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/config.ru000066400000000000000000000002341432107571000174010ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails3::Application rabl-0.16.1/fixtures/rails3/config/000077500000000000000000000000001432107571000170325ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/config/application.rb000066400000000000000000000036041432107571000216650ustar00rootroot00000000000000require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Rails3 class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # JavaScript files you want as :defaults (application.js is always included). # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] end end rabl-0.16.1/fixtures/rails3/config/boot.rb000066400000000000000000000002771432107571000203300ustar00rootroot00000000000000require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) rabl-0.16.1/fixtures/rails3/config/database.yml000066400000000000000000000007651432107571000213310ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 rabl-0.16.1/fixtures/rails3/config/environment.rb000066400000000000000000000002261432107571000217230ustar00rootroot00000000000000# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Rails3::Application.initialize! rabl-0.16.1/fixtures/rails3/config/environments/000077500000000000000000000000001432107571000215615ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/config/environments/development.rb000066400000000000000000000017321432107571000244330ustar00rootroot00000000000000Rails3::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver 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_view.debug_rjs = true config.action_controller.perform_caching = false # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin end rabl-0.16.1/fixtures/rails3/config/environments/production.rb000066400000000000000000000033331432107571000242760ustar00rootroot00000000000000Rails3::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Specifies the header that your server uses for sending files config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files # See everything in the log (default is :info) # config.log_level = :debug # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Use a different cache store in production # config.cache_store = :mem_cache_store # Disable Rails's static asset server # In production, Apache or nginx will already do this config.serve_static_assets = false # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify end rabl-0.16.1/fixtures/rails3/config/environments/test.rb000066400000000000000000000027461432107571000230760ustar00rootroot00000000000000Rails3::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # 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 # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Use SQL instead of Active Record's schema dumper when creating the test database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end rabl-0.16.1/fixtures/rails3/config/initializers/000077500000000000000000000000001432107571000215405ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000260550ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails3/config/initializers/inflections.rb000066400000000000000000000005701432107571000244040ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end rabl-0.16.1/fixtures/rails3/config/initializers/mime_types.rb000066400000000000000000000003151432107571000242370ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone rabl-0.16.1/fixtures/rails3/config/initializers/secret_token.rb000066400000000000000000000007611432107571000245560ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Rails3::Application.config.secret_token = '33a413cf1c720ae36788faebb621dd9350d1c5a17f4787d6c0c9acad23e116507f246cce7fa8f70d1e6ac73c3fe5080b007b774b769166a9515f2eb6c46f47f2' rabl-0.16.1/fixtures/rails3/config/initializers/session_store.rb000066400000000000000000000006351432107571000247700ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. Rails3::Application.config.session_store :cookie_store, :key => '_rails3_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Rails3::Application.config.session_store :active_record_store rabl-0.16.1/fixtures/rails3/config/locales/000077500000000000000000000000001432107571000204545ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/config/locales/en.yml000066400000000000000000000003251432107571000216010ustar00rootroot00000000000000# Sample localization file for English. Add more files in this directory for other locales. # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world" rabl-0.16.1/fixtures/rails3/config/routes.rb000066400000000000000000000034441432107571000207050ustar00rootroot00000000000000Rails3::Application.routes.draw do resources :users resources :posts # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => "welcome#index" # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' end rabl-0.16.1/fixtures/rails3/db/000077500000000000000000000000001432107571000161525ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/db/migrate000077700000000000000000000000001432107571000231302../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/db/schema.rb000066400000000000000000000025611432107571000177430ustar00rootroot00000000000000# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 20111002092024) do create_table "phone_numbers", :force => true do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", :force => true do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/rails3/db/seeds.rb000066400000000000000000000005411432107571000176020ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first) rabl-0.16.1/fixtures/rails3/lib/000077500000000000000000000000001432107571000163335ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/lib/tasks/000077500000000000000000000000001432107571000174605ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/lib/tasks/.gitkeep000066400000000000000000000000001432107571000210770ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/public/000077500000000000000000000000001432107571000170435ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/public/404.html000066400000000000000000000013301432107571000202350ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

rabl-0.16.1/fixtures/rails3/public/422.html000066400000000000000000000013071432107571000202410ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

rabl-0.16.1/fixtures/rails3/public/500.html000066400000000000000000000013301432107571000202320ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

rabl-0.16.1/fixtures/rails3/public/favicon.ico000066400000000000000000000000001432107571000211520ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/public/images/000077500000000000000000000000001432107571000203105ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/public/images/rails.png000066400000000000000000000147661432107571000221460ustar00rootroot00000000000000PNG  IHDR2@X${tEXtSoftwareAdobe ImageReadyqe<IDATxڬ[ \eR֮^;Iwga@`gGgDgtqDFqFDqF@NRU]˫|_-Qy^Ǹ.݋0W_6kbf̻ܸ6<4 w5~*r?9m&"M7@vm' {_S)Vi\WG?իjMd@ lDLX鸺W-TU+@EPo\&*Rnn, fDWrX|3M=\EJB[d6A'=tx^$a86̈{, ϱPepN*_W_3o;ޥ(0E:i6eXnhGf"L|S+(+.gФg=Ych=m#V_#}Ǫ|tR D8VՄM~xg!ni%Dy( B,{(Np$3iر$h.@e[a'eJԂyϠ4>H*MHQ(Jgt-֢QI ^d„@s-'- 51{'0 |n4ۉh{V@ܩw"BT =rzqPpBHȃ?ň ]-qpgsPiSӪg`jn)m 御B2L.x!jJP! K/\ ʮRB[09Trӈu. uH$ DDQ+:ݘٻ 3/nލ%Sjm2!&D/[EHwW A-RR!PeuHim"t6lFgЫ-O.1?ƞksX~VtmZJR11Nu&<⽩,Tb,`w WPx-G5 `մ/5pbAtIVJ_]0/DiH=ô#*77-3 VuQ0.pݔ%yw hљW0),2$b6&I/@bj$I(fx' JnO"`<-/LѮ%^ȫͶn2wҗ2}}XսL'Q-,m/ꤋ4#0Q&00NKrsA,Aײ)aIEC(ERK{8Ȭ[y?iI5$%f{}u F 1~;v1l'@F 'IF'm!K7"&]w 15#4Vižn[v 8Ě)>C=LBo~/3% wF4֓ʿ8>bWX@bb@IzP9IvFfQL!2cEP(se4~5RhAŽ90_? cMEteVOaOr B]pȱؓ"Eyx: NJ)bl׋hYuTdԫw=آMgwVPOFΒ25-TD[Z2>]V,xӛIOƅ)Jͺ[)?cn28p#(mk+./phʮQ6?w7HIoSj)1<#-N9O1ͰސkIKr:(ŗ;rR&<93v@w(w:~:TFSޒ" ՊTdT9PIb3JzTQׄBP23ƵW*|@^)Qw?Iq =,<@ B8);50H-=T SA@@f5r[T%#c|Z&w(B)tDQ%vyC(,Ɵ|ʰi&<#u:3EHkzд)ndF>1V2kFGYL KMQlR&TB,igv8]C8Sf#ą4Q'?,= aV9WEXYrr*!cƯ~),=yџ]jlGeE̺5r_2Ԏ}d"a]0M9PZG17nE"Rr\YQ)!|5U(d=^ŗo8+2NU6jB[B5V.]ŲW/^䩬 ;Y"Vi$2ٲ_c(F^Egq{CP/ #K8Y+Q M1>ܞAߏ,gytޕn,zE$V.v.PyLapG9Tn:uiRZ! zI0?Џ1u#$6ɱGMhFdtd|~d\O9Ij**zD؍b)PBҽh-q ql%/{Gz*d7=QS]:RQbUMPᒯ$% du] XefQz$('ИZH#ARXDB ~`0.F|XXK)wFolzyhߚKz>.&n EjU,2' &iw[d[ V)*Qavl QDit[VIQhR@$)y~m|>?cJ+VH'6? 7 i.XH8Fި)dAYUBjE".4w-?l2Y.RjWD@Bج.߆s[H-gASF3Fj]آBP떬_>M%bt ?_rլ -h]r_ž[nȶQ+Gԭ_\Ê Z٦fet(|U('.g VFEN9}Ll4T&nto¨Ӓ X F "_fYzF~y& Gu]$O[v#].@$VA`ⱧTѰZ[2u+/mUC_ TnyѠ |l\ M"G[R$d|:ěFIire"ٵt,+ی1Z11udt*K2 sd; [)xW.z2jTh#DV\NO &e_vU2B^%0FH(/ԘI2>=L]dv UUpk"ijB$,O-0y<}~*T5LErE4B߳XXN:<9>Ed -V*uBLsN**JxRU辖,T( Gu @ůY{u|CJF(OLbnմiKhpFtx8#9FsFڋDTAn1veF^M ^kf.ĆݠVʓǰ3JaY@n&jLl:McӚ…vu?9w!/~#hM ڛ ̴nMA}m W,)(î.N y%$*={P9c DzH>Blu޾K78x->V,'JU \L]l>W*r-hXf~oI Z3f玱>vN3 uZTgg}Վ363:.g /-H+"PKۉSZ4Z_GlXMc7";ҿ (5fMUCOF6 CNft>$S1VaR&4) ٗay]%W A*|gX{Qc>iTX1F M`|![$P4ʊ$#,dɌ(?KTJR۸S%C7jHb浃j+N$,[.@˹_ ?.3ĵH"U$Z^ X02!Kc 8q.NMI6N&3n8exoWfPIJB<pREAdo$*m)e9D 5X[T$LΠ:]C$n#mC[P~Yt*d?\q^WXs!E-2#_mw8;2!vw:DUn$)GiGn3_o EZE3k-EHv.OûzE>"֛}l\/-nرQHԽab*#K׋eIƳd#G et\ ,:MێÜIC}m ٽO?eb%ːٰStB|Aznaz*FlQ/K uu*1wDvE֯SJTK;(4kƣ;v2P9`k{?~_[hʢ^9фǡ;m|]o9<#jz\wD,8V]]%K9er懇0n^FcI>`Ub+kօO1|NO]t+,Ȑl_ˮ6 ĒDbrz^pe7^[aþo確jN+xsNC߅wμ7|za2, omrbZ~,pN>;?Y,z[u◿jq 4aqڶNu6Zid@h!!F9#,#UrOa0=Då ,,,bE#ȮX3ªޏ=a< =&_~ ٵѽacj񫒆LsXuXB (wzEk_QIف*4'ѣSl{.,p۵2`jp^؇nZXPź^]wމ]aQ-oI5O3a] _wb ŭL]$"|sԩȬ= VсLIUbYY搮͢I$tf$2|r;~'GSXkᇦԭF4b4 xo[,04F~<}ۭR%myb׾\mlO.4}tE\7}M)tՉ13xF [-26t䢄&E"9;ٜrq e)K!:bwY }g;Jר)5D$!Kɤ9߫-K$$ hlDUFF J{s2R6rC&&0;@>]/Z3E,k;( 2^09 Ruby on Rails: Welcome aboard

Getting started

Here’s how to get rolling:

  1. Use rails generate to create your models and controllers

    To see all available options, run it without parameters.

  2. Set up a default route and remove or rename this file

    Routes are set up in config/routes.rb.

  3. Create your database

    Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

rabl-0.16.1/fixtures/rails3/public/robots.txt000066400000000000000000000003141432107571000211120ustar00rootroot00000000000000# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-Agent: * # Disallow: / rabl-0.16.1/fixtures/rails3/public/stylesheets/000077500000000000000000000000001432107571000214175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/public/stylesheets/.gitkeep000066400000000000000000000000001432107571000230360ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/script/000077500000000000000000000000001432107571000170715ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/script/rails000077500000000000000000000004471432107571000201360ustar00rootroot00000000000000#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' rabl-0.16.1/fixtures/rails3/test/000077500000000000000000000000001432107571000165445ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/test/functional/000077500000000000000000000000001432107571000207065ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000372552../../../../test/integration/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000372372../../../../test/integration/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3/test/test_helper.rb000066400000000000000000000014031432107571000214050ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app Rails.application end endrabl-0.16.1/fixtures/rails3_2/000077500000000000000000000000001432107571000160065ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/.gitignore000066400000000000000000000006561432107571000200050ustar00rootroot00000000000000# See http://help.github.com/ignore-files/ for more about ignoring files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile ~/.gitignore_global # Ignore bundler config /.bundle # Ignore the default SQLite database. /db/*.sqlite3 # Ignore all logfiles and tempfiles. /log/*.log /tmp rabl-0.16.1/fixtures/rails3_2/Gemfile000066400000000000000000000015261432107571000173050ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rails', '~> 3.2.9.rc3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'riot', :group => "test" # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # To use Jbuilder templates for JSON # gem 'jbuilder' # Use unicorn as the app server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'debugger' rabl-0.16.1/fixtures/rails3_2/README.rdoc000066400000000000000000000217701432107571000176230ustar00rootroot00000000000000== Welcome to Rails Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Control pattern. This pattern splits the view (also called the presentation) into "dumb" templates that are primarily responsible for inserting pre-built data in between HTML tags. The model contains the "smart" domain objects (such as Account, Product, Person, Post) that holds all the business logic and knows how to persist themselves to a database. The controller handles the incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view. In Rails, the model is handled by what's called an object-relational mapping layer entitled Active Record. This layer allows you to present the data from database rows as objects and embellish these data objects with business logic methods. You can read more about Active Record in link:files/vendor/rails/activerecord/README.html. The controller and view are handled by the Action Pack, which handles both layers by its two parts: Action View and Action Controller. These two layers are bundled in a single package due to their heavy interdependence. This is unlike the relationship between the Active Record and Action Pack that is much more separate. Each of these packages can be used independently outside of Rails. You can read more about Action Pack in link:files/vendor/rails/actionpack/README.html. == Getting Started 1. At the command prompt, create a new Rails application: rails new myapp (where myapp is the application name) 2. Change directory to myapp and start the web server: cd myapp; rails server (run with --help for options) 3. Go to http://localhost:3000/ and you'll see: "Welcome aboard: You're riding Ruby on Rails!" 4. Follow the guidelines to start developing your application. You can find the following resources handy: * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ == Debugging Rails Sometimes your application goes wrong. Fortunately there are a lot of tools that will help you debug it and get it back on the rails. First area to check is the application log files. Have "tail -f" commands running on the server.log and development.log. Rails will automatically display debugging and runtime information to these files. Debugging info will also be shown in the browser on requests from 127.0.0.1. You can also log your own messages directly into the log file from your code using the Ruby logger class from inside your controllers. Example: class WeblogController < ActionController::Base def destroy @weblog = Weblog.find(params[:id]) @weblog.destroy logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") end end The result will be a message in your log file along the lines of: Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! More information on how to use the logger is at http://www.ruby-doc.org/core/ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are several books available online as well: * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) These two books will bring you up to speed on the Ruby language and also on programming in general. == Debugger Debugger support is available through the debugger command when you start your Mongrel or WEBrick server with --debugger. This means that you can break out of execution at any point in the code, investigate and change the model, and then, resume execution! You need to install ruby-debug to run the server in debugging mode. With gems, use sudo gem install ruby-debug. Example: class WeblogController < ActionController::Base def index @posts = Post.all debugger end end So the controller will accept the action, run the first line, then present you with a IRB prompt in the server window. Here you can do things like: >> @posts.inspect => "[#nil, "body"=>nil, "id"=>"1"}>, #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" >> @posts.first.title = "hello from a debugger" => "hello from a debugger" ...and even better, you can examine how your runtime objects actually work: >> f = @posts.first => #nil, "body"=>nil, "id"=>"1"}> >> f. Display all 152 possibilities? (y or n) Finally, when you're ready to resume execution, you can enter "cont". == Console The console is a Ruby shell, which allows you to interact with your application's domain model. Here you'll have all parts of the application configured, just like it is when the application is running. You can inspect domain models, change values, and save to the database. Starting the script without arguments will launch it in the development environment. To start the console, run rails console from the application directory. Options: * Passing the -s, --sandbox argument will rollback any modifications made to the database. * Passing an environment name as an argument will load the corresponding environment. Example: rails console production. To reload your controllers and models after launching the console run reload! More information about irb can be found at: link:http://www.rubycentral.org/pickaxe/irb.html == dbconsole You can go to the command line of your database directly through rails dbconsole. You would be connected to the database with the credentials defined in database.yml. Starting the script without arguments will connect you to the development database. Passing an argument will connect you to a different database, like rails dbconsole production. Currently works for MySQL, PostgreSQL and SQLite 3. == Description of Contents The default directory structure of a generated Ruby on Rails application: |-- app | |-- assets | |-- images | |-- javascripts | `-- stylesheets | |-- controllers | |-- helpers | |-- mailers | |-- models | `-- views | `-- layouts |-- config | |-- environments | |-- initializers | `-- locales |-- db |-- doc |-- lib | `-- tasks |-- log |-- public |-- script |-- test | |-- fixtures | |-- functional | |-- integration | |-- performance | `-- unit |-- tmp | |-- cache | |-- pids | |-- sessions | `-- sockets `-- vendor |-- assets `-- stylesheets `-- plugins app Holds all the code that's specific to this particular application. app/assets Contains subdirectories for images, stylesheets, and JavaScript files. app/controllers Holds controllers that should be named like weblogs_controller.rb for automated URL mapping. All controllers should descend from ApplicationController which itself descends from ActionController::Base. app/models Holds models that should be named like post.rb. Models descend from ActiveRecord::Base by default. app/views Holds the template files for the view that should be named like weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby syntax by default. app/views/layouts Holds the template files for layouts to be used with views. This models the common header/footer method of wrapping views. In your views, define a layout using the layout :default and create a file named default.html.erb. Inside default.html.erb, call <% yield %> to render the view using this layout. app/helpers Holds view helpers that should be named like weblogs_helper.rb. These are generated for you automatically when using generators for controllers. Helpers can be used to wrap functionality for your views into methods. config Configuration files for the Rails environment, the routing map, the database, and other dependencies. db Contains the database schema in schema.rb. db/migrate contains all the sequence of Migrations for your schema. doc This directory is where your application documentation will be stored when generated using rake doc:app lib Application specific libraries. Basically, any kind of custom code that doesn't belong under controllers, models, or helpers. This directory is in the load path. public The directory available for the web server. Also contains the dispatchers and the default HTML files. This should be set as the DOCUMENT_ROOT of your web server. script Helper scripts for automation and generation. test Unit and functional tests along with fixtures. When using the rails generate command, template test files will be generated for you and placed in this directory. vendor External libraries that the application depends on. Also includes the plugins subdirectory. If the app has frozen rails, those gems also go here, under vendor/rails/. This directory is in the load path. rabl-0.16.1/fixtures/rails3_2/Rakefile000066400000000000000000000006041432107571000174530ustar00rootroot00000000000000#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Rails32::Application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true endrabl-0.16.1/fixtures/rails3_2/app/000077500000000000000000000000001432107571000165665ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/assets/000077500000000000000000000000001432107571000200705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/assets/images/000077500000000000000000000000001432107571000213355ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/assets/images/rails.png000066400000000000000000000147661432107571000231730ustar00rootroot00000000000000PNG  IHDR2@X${tEXtSoftwareAdobe ImageReadyqe<IDATxڬ[ \eR֮^;Iwga@`gGgDgtqDFqFDqF@NRU]˫|_-Qy^Ǹ.݋0W_6kbf̻ܸ6<4 w5~*r?9m&"M7@vm' {_S)Vi\WG?իjMd@ lDLX鸺W-TU+@EPo\&*Rnn, fDWrX|3M=\EJB[d6A'=tx^$a86̈{, ϱPepN*_W_3o;ޥ(0E:i6eXnhGf"L|S+(+.gФg=Ych=m#V_#}Ǫ|tR D8VՄM~xg!ni%Dy( B,{(Np$3iر$h.@e[a'eJԂyϠ4>H*MHQ(Jgt-֢QI ^d„@s-'- 51{'0 |n4ۉh{V@ܩw"BT =rzqPpBHȃ?ň ]-qpgsPiSӪg`jn)m 御B2L.x!jJP! K/\ ʮRB[09Trӈu. uH$ DDQ+:ݘٻ 3/nލ%Sjm2!&D/[EHwW A-RR!PeuHim"t6lFgЫ-O.1?ƞksX~VtmZJR11Nu&<⽩,Tb,`w WPx-G5 `մ/5pbAtIVJ_]0/DiH=ô#*77-3 VuQ0.pݔ%yw hљW0),2$b6&I/@bj$I(fx' JnO"`<-/LѮ%^ȫͶn2wҗ2}}XսL'Q-,m/ꤋ4#0Q&00NKrsA,Aײ)aIEC(ERK{8Ȭ[y?iI5$%f{}u F 1~;v1l'@F 'IF'm!K7"&]w 15#4Vižn[v 8Ě)>C=LBo~/3% wF4֓ʿ8>bWX@bb@IzP9IvFfQL!2cEP(se4~5RhAŽ90_? cMEteVOaOr B]pȱؓ"Eyx: NJ)bl׋hYuTdԫw=آMgwVPOFΒ25-TD[Z2>]V,xӛIOƅ)Jͺ[)?cn28p#(mk+./phʮQ6?w7HIoSj)1<#-N9O1ͰސkIKr:(ŗ;rR&<93v@w(w:~:TFSޒ" ՊTdT9PIb3JzTQׄBP23ƵW*|@^)Qw?Iq =,<@ B8);50H-=T SA@@f5r[T%#c|Z&w(B)tDQ%vyC(,Ɵ|ʰi&<#u:3EHkzд)ndF>1V2kFGYL KMQlR&TB,igv8]C8Sf#ą4Q'?,= aV9WEXYrr*!cƯ~),=yџ]jlGeE̺5r_2Ԏ}d"a]0M9PZG17nE"Rr\YQ)!|5U(d=^ŗo8+2NU6jB[B5V.]ŲW/^䩬 ;Y"Vi$2ٲ_c(F^Egq{CP/ #K8Y+Q M1>ܞAߏ,gytޕn,zE$V.v.PyLapG9Tn:uiRZ! zI0?Џ1u#$6ɱGMhFdtd|~d\O9Ij**zD؍b)PBҽh-q ql%/{Gz*d7=QS]:RQbUMPᒯ$% du] XefQz$('ИZH#ARXDB ~`0.F|XXK)wFolzyhߚKz>.&n EjU,2' &iw[d[ V)*Qavl QDit[VIQhR@$)y~m|>?cJ+VH'6? 7 i.XH8Fި)dAYUBjE".4w-?l2Y.RjWD@Bج.߆s[H-gASF3Fj]آBP떬_>M%bt ?_rլ -h]r_ž[nȶQ+Gԭ_\Ê Z٦fet(|U('.g VFEN9}Ll4T&nto¨Ӓ X F "_fYzF~y& Gu]$O[v#].@$VA`ⱧTѰZ[2u+/mUC_ TnyѠ |l\ M"G[R$d|:ěFIire"ٵt,+ی1Z11udt*K2 sd; [)xW.z2jTh#DV\NO &e_vU2B^%0FH(/ԘI2>=L]dv UUpk"ijB$,O-0y<}~*T5LErE4B߳XXN:<9>Ed -V*uBLsN**JxRU辖,T( Gu @ůY{u|CJF(OLbnմiKhpFtx8#9FsFڋDTAn1veF^M ^kf.ĆݠVʓǰ3JaY@n&jLl:McӚ…vu?9w!/~#hM ڛ ̴nMA}m W,)(î.N y%$*={P9c DzH>Blu޾K78x->V,'JU \L]l>W*r-hXf~oI Z3f玱>vN3 uZTgg}Վ363:.g /-H+"PKۉSZ4Z_GlXMc7";ҿ (5fMUCOF6 CNft>$S1VaR&4) ٗay]%W A*|gX{Qc>iTX1F M`|![$P4ʊ$#,dɌ(?KTJR۸S%C7jHb浃j+N$,[.@˹_ ?.3ĵH"U$Z^ X02!Kc 8q.NMI6N&3n8exoWfPIJB<pREAdo$*m)e9D 5X[T$LΠ:]C$n#mC[P~Yt*d?\q^WXs!E-2#_mw8;2!vw:DUn$)GiGn3_o EZE3k-EHv.OûzE>"֛}l\/-nرQHԽab*#K׋eIƳd#G et\ ,:MێÜIC}m ٽO?eb%ːٰStB|Aznaz*FlQ/K uu*1wDvE֯SJTK;(4kƣ;v2P9`k{?~_[hʢ^9фǡ;m|]o9<#jz\wD,8V]]%K9er懇0n^FcI>`Ub+kօO1|NO]t+,Ȑl_ˮ6 ĒDbrz^pe7^[aþo確jN+xsNC߅wμ7|za2, omrbZ~,pN>;?Y,z[u◿jq 4aqڶNu6Zid@h!!F9#,#UrOa0=Då ,,,bE#ȮX3ªޏ=a< =&_~ ٵѽacj񫒆LsXuXB (wzEk_QIف*4'ѣSl{.,p۵2`jp^؇nZXPź^]wމ]aQ-oI5O3a] _wb ŭL]$"|sԩȬ= VсLIUbYY搮͢I$tf$2|r;~'GSXkᇦԭF4b4 xo[,04F~<}ۭR%myb׾\mlO.4}tE\7}M)tՉ13xF [-26t䢄&E"9;ٜrq e)K!:bwY }g;Jר)5D$!Kɤ9߫-K$$ hlDUFF J{s2R6rC&&0;@>]/Z3E,k;( 2^09 "id ASC") end def show @post = Post.find(params[:id]) end def renderer post = Post.find(params[:id]) render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context) end end rabl-0.16.1/fixtures/rails3_2/app/controllers/users_controller.rb000066400000000000000000000002751432107571000250710ustar00rootroot00000000000000class UsersController < ApplicationController respond_to :json def index @users = User.all(:order => "username ASC") end def show @user = User.find(params[:id]) end end rabl-0.16.1/fixtures/rails3_2/app/helpers/000077500000000000000000000000001432107571000202305ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/helpers/application_helper.rb000066400000000000000000000000771432107571000244230ustar00rootroot00000000000000module ApplicationHelper def helper_foo "BAR!" end end rabl-0.16.1/fixtures/rails3_2/app/helpers/posts_helper.rb000066400000000000000000000000271432107571000232630ustar00rootroot00000000000000module PostsHelper end rabl-0.16.1/fixtures/rails3_2/app/helpers/users_helper.rb000066400000000000000000000000271432107571000232540ustar00rootroot00000000000000module UsersHelper end rabl-0.16.1/fixtures/rails3_2/app/mailers/000077500000000000000000000000001432107571000202225ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/mailers/.gitkeep000066400000000000000000000000001432107571000216410ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/models000077700000000000000000000000001432107571000232322../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/app/views000077700000000000000000000000001432107571000244512../../ashared/views_rails_3/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/config.ru000066400000000000000000000002351432107571000176230ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails32::Application rabl-0.16.1/fixtures/rails3_2/config/000077500000000000000000000000001432107571000172535ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/config/application.rb000066400000000000000000000052331432107571000221060ustar00rootroot00000000000000require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end module Rails32 class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] # Use SQL instead of Active Record's schema dumper when creating the database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql # Enforce whitelist mode for mass assignment. # This will create an empty whitelist of attributes available for mass-assignment for all models # in your app. As such, your models will need to explicitly whitelist or blacklist accessible # parameters by using an attr_accessible or attr_protected declaration. # config.active_record.whitelist_attributes = true # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' end end rabl-0.16.1/fixtures/rails3_2/config/boot.rb000066400000000000000000000002771432107571000205510ustar00rootroot00000000000000require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) rabl-0.16.1/fixtures/rails3_2/config/database.yml000066400000000000000000000011001432107571000215320ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 rabl-0.16.1/fixtures/rails3_2/config/environment.rb000066400000000000000000000002271432107571000221450ustar00rootroot00000000000000# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Rails32::Application.initialize! rabl-0.16.1/fixtures/rails3_2/config/environments/000077500000000000000000000000001432107571000220025ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/config/environments/development.rb000066400000000000000000000025361432107571000246570ustar00rootroot00000000000000Rails32::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # 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 # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # 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 # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end rabl-0.16.1/fixtures/rails3_2/config/environments/production.rb000066400000000000000000000046261432107571000245250ustar00rootroot00000000000000Rails32::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true # Defaults to Rails.root.join("public/assets") # config.assets.manifest = YOUR_PATH # Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # See everything in the log (default is :info) # config.log_level = :debug # Prepend all log lines with the following tags # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify # 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 end rabl-0.16.1/fixtures/rails3_2/config/environments/test.rb000066400000000000000000000027671432107571000233220ustar00rootroot00000000000000Rails32::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance 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 # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end rabl-0.16.1/fixtures/rails3_2/config/initializers/000077500000000000000000000000001432107571000217615ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000262760ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails3_2/config/initializers/inflections.rb000066400000000000000000000010251432107571000246210ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections do |inflect| # inflect.acronym 'RESTful' # end rabl-0.16.1/fixtures/rails3_2/config/initializers/mime_types.rb000066400000000000000000000004251432107571000244620ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1 rabl-0.16.1/fixtures/rails3_2/config/initializers/secret_token.rb000066400000000000000000000007621432107571000250000ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Rails32::Application.config.secret_token = '889df7428c5678596588834e106a8ef76583e31ce7cfcd60246419917f91d713ff33f8f9d1267ed80cd10bddfd3e934e9fb1cad0401315cb61dfde1fbdbc75a3' rabl-0.16.1/fixtures/rails3_2/config/initializers/session_store.rb000066400000000000000000000006361432107571000252120ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. Rails32::Application.config.session_store :cookie_store, key: '_Rails3_2_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Rails32::Application.config.session_store :active_record_store rabl-0.16.1/fixtures/rails3_2/config/initializers/wrap_parameters.rb000066400000000000000000000007211432107571000255020ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # Disable root element in JSON by default. ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end rabl-0.16.1/fixtures/rails3_2/config/locales/000077500000000000000000000000001432107571000206755ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/config/locales/en.yml000066400000000000000000000003261432107571000220230ustar00rootroot00000000000000# Sample localization file for English. Add more files in this directory for other locales. # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world" rabl-0.16.1/fixtures/rails3_2/config/routes.rb000066400000000000000000000035301432107571000211220ustar00rootroot00000000000000Rails32::Application.routes.draw do resources :users resources :posts do member do get 'renderer' end end # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => 'welcome#index' # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id))(.:format)' end rabl-0.16.1/fixtures/rails3_2/db/000077500000000000000000000000001432107571000163735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/db/migrate000077700000000000000000000000001432107571000233512../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/db/schema.rb000066400000000000000000000026611432107571000201650ustar00rootroot00000000000000# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended to check this file into your version control system. ActiveRecord::Schema.define(:version => 20111002092024) do create_table "phone_numbers", :force => true do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", :force => true do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end create_table "users", :force => true do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end end rabl-0.16.1/fixtures/rails3_2/db/seeds.rb000066400000000000000000000005411432107571000200230ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first) rabl-0.16.1/fixtures/rails3_2/doc/000077500000000000000000000000001432107571000165535ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/doc/README_FOR_APP000066400000000000000000000003231432107571000206370ustar00rootroot00000000000000Use this README file to introduce your application and point to useful places in the API for learning more. Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. rabl-0.16.1/fixtures/rails3_2/lib/000077500000000000000000000000001432107571000165545ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/lib/assets/000077500000000000000000000000001432107571000200565ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/lib/assets/.gitkeep000066400000000000000000000000001432107571000214750ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/lib/tasks/000077500000000000000000000000001432107571000177015ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/lib/tasks/.gitkeep000066400000000000000000000000001432107571000213200ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/log/000077500000000000000000000000001432107571000165675ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/log/.gitkeep000066400000000000000000000000001432107571000202060ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/public/000077500000000000000000000000001432107571000172645ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/public/404.html000066400000000000000000000013301432107571000204560ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

rabl-0.16.1/fixtures/rails3_2/public/422.html000066400000000000000000000013071432107571000204620ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

rabl-0.16.1/fixtures/rails3_2/public/500.html000066400000000000000000000012031432107571000204520ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

rabl-0.16.1/fixtures/rails3_2/public/favicon.ico000066400000000000000000000000001432107571000213730ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/public/index.html000066400000000000000000000134221432107571000212630ustar00rootroot00000000000000 Ruby on Rails: Welcome aboard

Getting started

Here’s how to get rolling:

  1. Use rails generate to create your models and controllers

    To see all available options, run it without parameters.

  2. Set up a default route and remove public/index.html

    Routes are set up in config/routes.rb.

  3. Create your database

    Run rake db:create to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

rabl-0.16.1/fixtures/rails3_2/public/robots.txt000066400000000000000000000003141432107571000213330ustar00rootroot00000000000000# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-Agent: * # Disallow: / rabl-0.16.1/fixtures/rails3_2/script/000077500000000000000000000000001432107571000173125ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/script/rails000077500000000000000000000004471432107571000203570ustar00rootroot00000000000000#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' rabl-0.16.1/fixtures/rails3_2/test/000077500000000000000000000000001432107571000167655ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/fixtures/000077500000000000000000000000001432107571000206365ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/fixtures/phone_numbers.yml000066400000000000000000000005411432107571000242250ustar00rootroot00000000000000# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # one: {} # column: value # two: {} # column: value rabl-0.16.1/fixtures/rails3_2/test/fixtures/posts.yml000066400000000000000000000005411432107571000225310ustar00rootroot00000000000000# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # one: {} # column: value # two: {} # column: value rabl-0.16.1/fixtures/rails3_2/test/fixtures/users.yml000066400000000000000000000005411432107571000225220ustar00rootroot00000000000000# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # one: {} # column: value # two: {} # column: value rabl-0.16.1/fixtures/rails3_2/test/functional/000077500000000000000000000000001432107571000211275ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000411142../../../../test/integration/rails3_2/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000410762../../../../test/integration/rails3_2/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/integration/000077500000000000000000000000001432107571000213105ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/integration/.gitkeep000066400000000000000000000000001432107571000227270ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/performance/000077500000000000000000000000001432107571000212665ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/performance/browsing_test.rb000066400000000000000000000005621432107571000245070ustar00rootroot00000000000000require 'test_helper' require 'rails/performance_test_help' class BrowsingTest < ActionDispatch::PerformanceTest # Refer to the documentation for all available options # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] # :output => 'tmp/performance', :formats => [:flat] } def test_homepage get '/' end end rabl-0.16.1/fixtures/rails3_2/test/test_helper.rb000066400000000000000000000014031432107571000216260ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app Rails.application end endrabl-0.16.1/fixtures/rails3_2/test/unit/000077500000000000000000000000001432107571000177445ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/unit/helpers/000077500000000000000000000000001432107571000214065ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/test/unit/helpers/posts_helper_test.rb000066400000000000000000000001101432107571000254710ustar00rootroot00000000000000require 'test_helper' class PostsHelperTest < ActionView::TestCase end rabl-0.16.1/fixtures/rails3_2/test/unit/helpers/users_helper_test.rb000066400000000000000000000001101432107571000254620ustar00rootroot00000000000000require 'test_helper' class UsersHelperTest < ActionView::TestCase end rabl-0.16.1/fixtures/rails3_2/test/unit/phone_number_test.rb000066400000000000000000000001751432107571000240140ustar00rootroot00000000000000require 'test_helper' class PhoneNumberTest < ActiveSupport::TestCase # test "the truth" do # assert true # end end rabl-0.16.1/fixtures/rails3_2/test/unit/post_test.rb000066400000000000000000000001661432107571000223200ustar00rootroot00000000000000require 'test_helper' class PostTest < ActiveSupport::TestCase # test "the truth" do # assert true # end end rabl-0.16.1/fixtures/rails3_2/test/unit/user_test.rb000066400000000000000000000001661432107571000223110ustar00rootroot00000000000000require 'test_helper' class UserTest < ActiveSupport::TestCase # test "the truth" do # assert true # end end rabl-0.16.1/fixtures/rails3_2/vendor/000077500000000000000000000000001432107571000173035ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/assets/000077500000000000000000000000001432107571000206055ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/assets/javascripts/000077500000000000000000000000001432107571000231365ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/assets/javascripts/.gitkeep000066400000000000000000000000001432107571000245550ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/assets/stylesheets/000077500000000000000000000000001432107571000231615ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/assets/stylesheets/.gitkeep000066400000000000000000000000001432107571000246000ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/plugins/000077500000000000000000000000001432107571000207645ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails3_2/vendor/plugins/.gitkeep000066400000000000000000000000001432107571000224030ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/000077500000000000000000000000001432107571000155665ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/.gitignore000066400000000000000000000007071432107571000175620ustar00rootroot00000000000000# See http://help.github.com/ignore-files/ for more about ignoring files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. /.bundle # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/*.log /tmp rabl-0.16.1/fixtures/rails4/Gemfile000066400000000000000000000025611432107571000170650ustar00rootroot00000000000000source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.8' # Use sqlite3 as the database for Active Record gem 'sqlite3' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'riot', :group => "test" gem 'pry-rails', :group => "test" gem "oj" # respond_to is its own gem now gem 'responders', '~> 2.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks # gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # gem 'jbuilder', '~> 1.0.1' # group :doc do # # bundle exec rake doc:rails generates the API under doc/api. # gem 'sdoc', require: false # end # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # Use unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano', group: :development # Use debugger gem 'byebug', group: [:development, :test] rabl-0.16.1/fixtures/rails4/README.rdoc000066400000000000000000000007361432107571000174020ustar00rootroot00000000000000== README This README would normally document whatever steps are necessary to get the application up and running. Things you may want to cover: * Ruby version * System dependencies * Configuration * Database creation * Database initialization * How to run the test suite * Services (job queues, cache servers, search engines, etc.) * Deployment instructions * ... Please feel free to use a different markup language if you do not plan to run rake doc:app. rabl-0.16.1/fixtures/rails4/Rakefile000066400000000000000000000005601432107571000172340ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Rails4::Application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true end rabl-0.16.1/fixtures/rails4/app/000077500000000000000000000000001432107571000163465ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/assets/000077500000000000000000000000001432107571000176505ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/assets/javascripts/000077500000000000000000000000001432107571000222015ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/assets/javascripts/application.js000066400000000000000000000012241432107571000250410ustar00rootroot00000000000000// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require turbolinks //= require_tree . rabl-0.16.1/fixtures/rails4/app/assets/stylesheets/000077500000000000000000000000001432107571000222245ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/assets/stylesheets/application.css000066400000000000000000000010421432107571000252360ustar00rootroot00000000000000/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self *= require_tree . */ rabl-0.16.1/fixtures/rails4/app/controllers/000077500000000000000000000000001432107571000207145ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/controllers/application_controller.rb000066400000000000000000000003141432107571000260050ustar00rootroot00000000000000class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end rabl-0.16.1/fixtures/rails4/app/controllers/concerns/000077500000000000000000000000001432107571000225265ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/controllers/concerns/.keep000066400000000000000000000000001432107571000234410ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/controllers/posts_controller.rb000066400000000000000000000005711432107571000246570ustar00rootroot00000000000000class PostsController < ApplicationController respond_to :json, :xml, :html, :rabl_test_v1 def index @posts = Post.order('id ASC').load end def show @post = Post.find(params[:id]) end def renderer post = Post.find(params[:id]) render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context) end end rabl-0.16.1/fixtures/rails4/app/controllers/users_controller.rb000066400000000000000000000002721432107571000246460ustar00rootroot00000000000000class UsersController < ApplicationController respond_to :json def index @users = User.order('username ASC').load end def show @user = User.find(params[:id]) end end rabl-0.16.1/fixtures/rails4/app/helpers/000077500000000000000000000000001432107571000200105ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/helpers/application_helper.rb000066400000000000000000000000771432107571000242030ustar00rootroot00000000000000module ApplicationHelper def helper_foo "BAR!" end end rabl-0.16.1/fixtures/rails4/app/mailers/000077500000000000000000000000001432107571000200025ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/mailers/.keep000066400000000000000000000000001432107571000207150ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/models000077700000000000000000000000001432107571000230122../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/app/views000077700000000000000000000000001432107571000241522../../ashared/views_rails_3ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/bin/000077500000000000000000000000001432107571000163365ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/bin/bundle000077500000000000000000000002011432107571000175260ustar00rootroot00000000000000#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') rabl-0.16.1/fixtures/rails4/bin/rails000077500000000000000000000002221432107571000173720ustar00rootroot00000000000000#!/usr/bin/env ruby APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' rabl-0.16.1/fixtures/rails4/bin/rake000077500000000000000000000001321432107571000172020ustar00rootroot00000000000000#!/usr/bin/env ruby require_relative '../config/boot' require 'rake' Rake.application.run rabl-0.16.1/fixtures/rails4/config.ru000066400000000000000000000002321432107571000174000ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails.application rabl-0.16.1/fixtures/rails4/config/000077500000000000000000000000001432107571000170335ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/config/application.rb000066400000000000000000000017271432107571000216720ustar00rootroot00000000000000require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) module Rails4 class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de end end rabl-0.16.1/fixtures/rails4/config/boot.rb000066400000000000000000000002531432107571000203230ustar00rootroot00000000000000# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) rabl-0.16.1/fixtures/rails4/config/database.yml000066400000000000000000000011001432107571000213120ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 rabl-0.16.1/fixtures/rails4/config/environment.rb000066400000000000000000000002301432107571000217170ustar00rootroot00000000000000# Load the rails application. require File.expand_path('../application', __FILE__) # Initialize the rails application. Rails4::Application.initialize! rabl-0.16.1/fixtures/rails4/config/environments/000077500000000000000000000000001432107571000215625ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/config/environments/development.rb000066400000000000000000000021321432107571000244270ustar00rootroot00000000000000Rails4::Application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true end rabl-0.16.1/fixtures/rails4/config/environments/production.rb000066400000000000000000000062621432107571000243030ustar00rootroot00000000000000Rails4::Application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both thread web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Enable Rack::Cache to put a simple HTTP cache in front of your application # Add `rack-cache` to your Gemfile before enabling this. # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. # config.action_dispatch.rack_cache = true # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Generate digests for assets URLs. config.assets.digest = true # Version of your assets, change this if you want to expire all your assets. config.assets.version = '1.0' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Set to :debug to see everything in the log. config.log_level = :info # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production. # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # config.assets.precompile += %w( search.js ) # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new end rabl-0.16.1/fixtures/rails4/config/environments/test.rb000066400000000000000000000031701432107571000230670ustar00rootroot00000000000000Rails4::Application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Run tests in sorted order (squash test error) config.active_support.test_order = :sorted end rabl-0.16.1/fixtures/rails4/config/initializers/000077500000000000000000000000001432107571000215415ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000260560ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails4/config/initializers/filter_parameter_logging.rb000066400000000000000000000003021432107571000271140ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password] rabl-0.16.1/fixtures/rails4/config/initializers/inflections.rb000066400000000000000000000012071432107571000244030ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end rabl-0.16.1/fixtures/rails4/config/initializers/mime_types.rb000066400000000000000000000004251432107571000242420ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1 rabl-0.16.1/fixtures/rails4/config/initializers/secret_token.rb000066400000000000000000000012241432107571000245520ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. # You can use `rake secret` to generate a secure secret key. # Make sure your secret_key_base is kept private # if you're sharing your code publicly. Rails4::Application.config.secret_key_base = '6e92b4aa4cb4e4f8c4dbb3874d83a205a8821fe0e30311aaf306aa3897e89c78b2ab84fad6905ce0a9c42e7b6ae860603eed6e20f4d3e3361cf599261fadd408' rabl-0.16.1/fixtures/rails4/config/initializers/session_store.rb000066400000000000000000000002141432107571000247620ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. Rails4::Application.config.session_store :cookie_store, key: '_rails4_session' rabl-0.16.1/fixtures/rails4/config/initializers/wrap_parameters.rb000066400000000000000000000010051432107571000252560ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end rabl-0.16.1/fixtures/rails4/config/locales/000077500000000000000000000000001432107571000204555ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/config/locales/en.yml000066400000000000000000000011721432107571000216030ustar00rootroot00000000000000# Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. # # To use the locales, use `I18n.t`: # # I18n.t 'hello' # # In views, this is aliased to just `t`: # # <%= t('hello') %> # # To use a different locale, set it with `I18n.locale`: # # I18n.locale = :es # # This would use the information in config/locales/es.yml. # # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" rabl-0.16.1/fixtures/rails4/config/routes.rb000066400000000000000000000027301432107571000207030ustar00rootroot00000000000000Rails4::Application.routes.draw do resources :users resources :posts do member do get 'renderer' end end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" # root 'welcome#index' # Example of regular route: # get 'products/:id' => 'catalog#view' # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase # Example resource route (maps HTTP verbs to controller actions automatically): # resources :products # Example resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Example resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Example resource route with more complex sub-resources: # resources :products do # resources :comments # resources :sales do # get 'recent', on: :collection # end # end # Example resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end end rabl-0.16.1/fixtures/rails4/db/000077500000000000000000000000001432107571000161535ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/db/migrate000077700000000000000000000000001432107571000231312../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/db/schema.rb000066400000000000000000000025671432107571000177520ustar00rootroot00000000000000# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20111002092024) do create_table "phone_numbers", force: :cascade do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", force: :cascade do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/rails4/db/seeds.rb000066400000000000000000000005271432107571000176070ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) rabl-0.16.1/fixtures/rails4/lib/000077500000000000000000000000001432107571000163345ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/lib/assets/000077500000000000000000000000001432107571000176365ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/lib/assets/.keep000066400000000000000000000000001432107571000205510ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/lib/tasks/000077500000000000000000000000001432107571000174615ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/lib/tasks/.keep000066400000000000000000000000001432107571000203740ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/log/000077500000000000000000000000001432107571000163475ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/log/.keep000066400000000000000000000000001432107571000172620ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/public/000077500000000000000000000000001432107571000170445ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/public/404.html000066400000000000000000000025071432107571000202450ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails4/public/422.html000066400000000000000000000024661432107571000202510ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails4/public/500.html000066400000000000000000000023621432107571000202410ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails4/public/favicon.ico000066400000000000000000000000001432107571000211530ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/public/robots.txt000066400000000000000000000003141432107571000211130ustar00rootroot00000000000000# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-agent: * # Disallow: / rabl-0.16.1/fixtures/rails4/test/000077500000000000000000000000001432107571000165455ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/controllers/000077500000000000000000000000001432107571000211135ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/controllers/.keep000066400000000000000000000000001432107571000220260ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/fixtures/000077500000000000000000000000001432107571000204165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/fixtures/.keep000066400000000000000000000000001432107571000213310ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/functional/000077500000000000000000000000001432107571000207075ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000404542../../../../test/integration/rails4/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000404362../../../../test/integration/rails4/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/helpers/000077500000000000000000000000001432107571000202075ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/helpers/.keep000066400000000000000000000000001432107571000211220ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/integration/000077500000000000000000000000001432107571000210705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/integration/.keep000066400000000000000000000000001432107571000220030ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/mailers/000077500000000000000000000000001432107571000202015ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/mailers/.keep000066400000000000000000000000001432107571000211140ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/models/000077500000000000000000000000001432107571000200305ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/models/.keep000066400000000000000000000000001432107571000207430ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/test/test_helper.rb000066400000000000000000000014041432107571000214070ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app Rails.application end end rabl-0.16.1/fixtures/rails4/vendor/000077500000000000000000000000001432107571000170635ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/vendor/assets/000077500000000000000000000000001432107571000203655ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/vendor/assets/javascripts/000077500000000000000000000000001432107571000227165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/vendor/assets/javascripts/.keep000066400000000000000000000000001432107571000236310ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/vendor/assets/stylesheets/000077500000000000000000000000001432107571000227415ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails4/vendor/assets/stylesheets/.keep000066400000000000000000000000001432107571000236540ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/000077500000000000000000000000001432107571000155675ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/.gitignore000066400000000000000000000010371432107571000175600ustar00rootroot00000000000000# See https://help.github.com/articles/ignoring-files for more about ignoring files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. /.bundle # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/* /tmp/* !/log/.keep !/tmp/.keep # Ignore Byebug command history file. .byebug_history rabl-0.16.1/fixtures/rails5/Gemfile000066400000000000000000000035101432107571000170610ustar00rootroot00000000000000source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri gem 'pry-rails' end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console' gem 'listen', '~> 3.0.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'riot', :group => "test" gem 'responders', '~> 2.0' rabl-0.16.1/fixtures/rails5/README.md000066400000000000000000000005661432107571000170550ustar00rootroot00000000000000# README This README would normally document whatever steps are necessary to get the application up and running. Things you may want to cover: * Ruby version * System dependencies * Configuration * Database creation * Database initialization * How to run the test suite * Services (job queues, cache servers, search engines, etc.) * Deployment instructions * ... rabl-0.16.1/fixtures/rails5/Rakefile000066400000000000000000000006071432107571000172370ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require_relative 'config/application' require 'rake/testtask' Rails.application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true test.warning = false end rabl-0.16.1/fixtures/rails5/app/000077500000000000000000000000001432107571000163475ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/000077500000000000000000000000001432107571000176515ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/config/000077500000000000000000000000001432107571000211165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/config/manifest.js000066400000000000000000000001451432107571000232620ustar00rootroot00000000000000//= link_tree ../images //= link_directory ../javascripts .js //= link_directory ../stylesheets .css rabl-0.16.1/fixtures/rails5/app/assets/images/000077500000000000000000000000001432107571000211165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/images/.keep000066400000000000000000000000001432107571000220310ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/javascripts/000077500000000000000000000000001432107571000222025ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/javascripts/application.js000066400000000000000000000013461432107571000250470ustar00rootroot00000000000000// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require jquery_ujs //= require turbolinks //= require_tree . rabl-0.16.1/fixtures/rails5/app/assets/javascripts/cable.js000066400000000000000000000005461432107571000236130ustar00rootroot00000000000000// Action Cable provides the framework to deal with WebSockets in Rails. // You can generate new channels where WebSocket features live using the rails generate channel command. // //= require action_cable //= require_self //= require_tree ./channels (function() { this.App || (this.App = {}); App.cable = ActionCable.createConsumer(); }).call(this); rabl-0.16.1/fixtures/rails5/app/assets/javascripts/channels/000077500000000000000000000000001432107571000237755ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/javascripts/channels/.keep000066400000000000000000000000001432107571000247100ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/stylesheets/000077500000000000000000000000001432107571000222255ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/assets/stylesheets/application.css000066400000000000000000000013401432107571000252400ustar00rootroot00000000000000/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * *= require_tree . *= require_self */ rabl-0.16.1/fixtures/rails5/app/channels/000077500000000000000000000000001432107571000201425ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/channels/application_cable/000077500000000000000000000000001432107571000235735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/channels/application_cable/channel.rb000066400000000000000000000001171432107571000255270ustar00rootroot00000000000000module ApplicationCable class Channel < ActionCable::Channel::Base end end rabl-0.16.1/fixtures/rails5/app/channels/application_cable/connection.rb000066400000000000000000000001251432107571000262550ustar00rootroot00000000000000module ApplicationCable class Connection < ActionCable::Connection::Base end end rabl-0.16.1/fixtures/rails5/app/controllers/000077500000000000000000000000001432107571000207155ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/controllers/application_controller.rb000066400000000000000000000001411432107571000260040ustar00rootroot00000000000000class ApplicationController < ActionController::Base protect_from_forgery with: :exception end rabl-0.16.1/fixtures/rails5/app/controllers/concerns/000077500000000000000000000000001432107571000225275ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/controllers/concerns/.keep000066400000000000000000000000001432107571000234420ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/controllers/posts_controller.rb000077700000000000000000000000001432107571000370442../../../ashared/controllers_rails_5/posts_controller.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/controllers/users_controller.rb000077700000000000000000000000001432107571000370262../../../ashared/controllers_rails_5/users_controller.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/helpers000077700000000000000000000000001432107571000233512../../ashared/helpersustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/jobs/000077500000000000000000000000001432107571000173045ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/jobs/application_job.rb000066400000000000000000000000531432107571000227640ustar00rootroot00000000000000class ApplicationJob < ActiveJob::Base end rabl-0.16.1/fixtures/rails5/app/mailers/000077500000000000000000000000001432107571000200035ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/mailers/application_mailer.rb000066400000000000000000000001461432107571000241650ustar00rootroot00000000000000class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' end rabl-0.16.1/fixtures/rails5/app/models000077700000000000000000000000001432107571000230132../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/app/views000077700000000000000000000000001432107571000242322../../ashared/views_rails_3/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/bin/000077500000000000000000000000001432107571000163375ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/bin/bundle000077500000000000000000000002011432107571000175270ustar00rootroot00000000000000#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') rabl-0.16.1/fixtures/rails5/bin/rails000077500000000000000000000004101432107571000173720ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' rabl-0.16.1/fixtures/rails5/bin/rake000077500000000000000000000003251432107571000172070ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end require_relative '../config/boot' require 'rake' Rake.application.run rabl-0.16.1/fixtures/rails5/bin/setup000077500000000000000000000016301432107571000174250ustar00rootroot00000000000000#!/usr/bin/env ruby require 'pathname' require 'fileutils' include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'bin/rails restart' end rabl-0.16.1/fixtures/rails5/bin/spring000077500000000000000000000007501432107571000175710ustar00rootroot00000000000000#!/usr/bin/env ruby # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) require 'rubygems' require 'bundler' if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) } gem 'spring', match[1] require 'spring/binstub' end end rabl-0.16.1/fixtures/rails5/bin/update000077500000000000000000000014161432107571000175510ustar00rootroot00000000000000#!/usr/bin/env ruby require 'pathname' require 'fileutils' include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end chdir APP_ROOT do # This script is a way to update your development environment automatically. # Add necessary update steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') puts "\n== Updating database ==" system! 'bin/rails db:migrate' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'bin/rails restart' end rabl-0.16.1/fixtures/rails5/config.ru000066400000000000000000000002021432107571000173760ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require_relative 'config/environment' run Rails.application rabl-0.16.1/fixtures/rails5/config/000077500000000000000000000000001432107571000170345ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/config/application.rb000066400000000000000000000007431432107571000216700ustar00rootroot00000000000000require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Rails5 class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. end end rabl-0.16.1/fixtures/rails5/config/boot.rb000066400000000000000000000002001432107571000203140ustar00rootroot00000000000000ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. rabl-0.16.1/fixtures/rails5/config/cable.yml000066400000000000000000000001641432107571000206260ustar00rootroot00000000000000development: adapter: async test: adapter: async production: adapter: redis url: redis://localhost:6379/1 rabl-0.16.1/fixtures/rails5/config/database.yml000066400000000000000000000010501432107571000213170ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' # default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3 rabl-0.16.1/fixtures/rails5/config/environment.rb000066400000000000000000000002001432107571000217150ustar00rootroot00000000000000# Load the Rails application. require_relative 'application' # Initialize the Rails application. Rails.application.initialize! rabl-0.16.1/fixtures/rails5/config/environments/000077500000000000000000000000001432107571000215635ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/config/environments/development.rb000066400000000000000000000035321432107571000244350ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=172800' } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end rabl-0.16.1/fixtures/rails5/config/environments/production.rb000066400000000000000000000067731432107571000243130ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "rails5_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end rabl-0.16.1/fixtures/rails5/config/environments/test.rb000066400000000000000000000033241432107571000230710ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raises error for missing translations # config.action_view.raise_on_missing_translations = true end rabl-0.16.1/fixtures/rails5/config/initializers/000077500000000000000000000000001432107571000215425ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/config/initializers/application_controller_renderer.rb000066400000000000000000000002421432107571000305210ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( # http_host: 'example.org', # https: false # ) rabl-0.16.1/fixtures/rails5/config/initializers/assets.rb000066400000000000000000000007461432107571000234000ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) rabl-0.16.1/fixtures/rails5/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000260570ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails5/config/initializers/cookies_serializer.rb000066400000000000000000000003641432107571000257570ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. # Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json rabl-0.16.1/fixtures/rails5/config/initializers/filter_parameter_logging.rb000066400000000000000000000003021432107571000271150ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password] rabl-0.16.1/fixtures/rails5/config/initializers/inflections.rb000066400000000000000000000012071432107571000244040ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end rabl-0.16.1/fixtures/rails5/config/initializers/mime_types.rb000066400000000000000000000003441432107571000242430ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1 rabl-0.16.1/fixtures/rails5/config/initializers/new_framework_defaults.rb000066400000000000000000000021201432107571000266170ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. # # Read the Rails 5.0 release notes for more info on each option. # Enable per-form CSRF tokens. Previous versions had false. Rails.application.config.action_controller.per_form_csrf_tokens = true # Enable origin-checking CSRF mitigation. Previous versions had false. Rails.application.config.action_controller.forgery_protection_origin_check = true # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. # Previous versions had false. ActiveSupport.to_time_preserves_timezone = true # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = true # Do not halt callback chains when a callback returns false. Previous versions had true. ActiveSupport.halt_callback_chains_on_return_false = false # Configure SSL options to enable HSTS with subdomains. Previous versions had false. Rails.application.config.ssl_options = { hsts: { subdomains: true } } rabl-0.16.1/fixtures/rails5/config/initializers/session_store.rb000066400000000000000000000002121432107571000247610ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_rails5_session' rabl-0.16.1/fixtures/rails5/config/initializers/wrap_parameters.rb000066400000000000000000000007451432107571000252710ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end rabl-0.16.1/fixtures/rails5/config/locales/000077500000000000000000000000001432107571000204565ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/config/locales/en.yml000066400000000000000000000011721432107571000216040ustar00rootroot00000000000000# Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. # # To use the locales, use `I18n.t`: # # I18n.t 'hello' # # In views, this is aliased to just `t`: # # <%= t('hello') %> # # To use a different locale, set it with `I18n.locale`: # # I18n.locale = :es # # This would use the information in config/locales/es.yml. # # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" rabl-0.16.1/fixtures/rails5/config/puma.rb000066400000000000000000000037251432107571000203320ustar00rootroot00000000000000# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum, this matches the default thread size of Active Record. # threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests, default is 3000. # port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. If you use this option # you need to make sure to reconnect any threads in the `on_worker_boot` # block. # # preload_app! # The code in the `on_worker_boot` will be called if you are using # clustered mode by specifying a number of `workers`. After each worker # process is booted this block will be run, if you are using `preload_app!` # option you will want to use this block to reconnect to any threads # or connections that may have been created at application boot, Ruby # cannot share connections between processes. # # on_worker_boot do # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) # end # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart rabl-0.16.1/fixtures/rails5/config/routes.rb000066400000000000000000000001771432107571000207070ustar00rootroot00000000000000Rails.application.routes.draw do resources :users resources :posts do member do get 'renderer' end end end rabl-0.16.1/fixtures/rails5/config/secrets.yml000066400000000000000000000017051432107571000212320ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. # You can use `rails secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. development: secret_key_base: 30ff78db787c4ed0bb6cd6c12108dadd9adc955263a563ad43a0d1308aa03b1a541b96bdd09f4461c7c4d75e14f54df506f4bb0dac9ca45c4ef95f133e031185 test: secret_key_base: 6bca541a67e4fec74dbdf0f83055ca79b2bc628240957763dd0f5cf3dd191736bf1e04bcd2a545a5bc6a2902a0643c88de0fb88ddf4c5d56cb877f2557074d79 # Do not keep production secrets in the repository, # instead read values from the environment. production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> rabl-0.16.1/fixtures/rails5/config/spring.rb000066400000000000000000000001571432107571000206660ustar00rootroot00000000000000%w( .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt ).each { |path| Spring.watch(path) } rabl-0.16.1/fixtures/rails5/db/000077500000000000000000000000001432107571000161545ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/db/migrate000077700000000000000000000000001432107571000231322../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/db/schema.rb000066400000000000000000000025451432107571000177470ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20111002092024) do create_table "phone_numbers", force: :cascade do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", force: :cascade do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/rails5/db/seeds.rb000066400000000000000000000005621432107571000176070ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) rabl-0.16.1/fixtures/rails5/lib/000077500000000000000000000000001432107571000163355ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/lib/assets/000077500000000000000000000000001432107571000176375ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/lib/assets/.keep000066400000000000000000000000001432107571000205520ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/lib/tasks/000077500000000000000000000000001432107571000174625ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/lib/tasks/.keep000066400000000000000000000000001432107571000203750ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/log/000077500000000000000000000000001432107571000163505ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/log/.keep000066400000000000000000000000001432107571000172630ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/public/000077500000000000000000000000001432107571000170455ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/public/404.html000066400000000000000000000030341432107571000202420ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails5/public/422.html000066400000000000000000000030131432107571000202370ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails5/public/500.html000066400000000000000000000027051432107571000202430ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails5/public/apple-touch-icon-precomposed.png000066400000000000000000000000001432107571000252260ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/public/apple-touch-icon.png000066400000000000000000000000001432107571000227100ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/public/favicon.ico000066400000000000000000000000001432107571000211540ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/public/robots.txt000066400000000000000000000003121432107571000211120ustar00rootroot00000000000000# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-agent: * # Disallow: / rabl-0.16.1/fixtures/rails5/test/000077500000000000000000000000001432107571000165465ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/controllers/000077500000000000000000000000001432107571000211145ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/controllers/.keep000066400000000000000000000000001432107571000220270ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/fixtures/000077500000000000000000000000001432107571000204175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/fixtures/.keep000066400000000000000000000000001432107571000213320ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/fixtures/files/000077500000000000000000000000001432107571000215215ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/fixtures/files/.keep000066400000000000000000000000001432107571000224340ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/functional/000077500000000000000000000000001432107571000207105ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000404562../../../../test/integration/rails5/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000404402../../../../test/integration/rails5/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/helpers/000077500000000000000000000000001432107571000202105ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/helpers/.keep000066400000000000000000000000001432107571000211230ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/integration/000077500000000000000000000000001432107571000210715ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/integration/.keep000066400000000000000000000000001432107571000220040ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/mailers/000077500000000000000000000000001432107571000202025ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/mailers/.keep000066400000000000000000000000001432107571000211150ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/models/000077500000000000000000000000001432107571000200315ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/models/.keep000066400000000000000000000000001432107571000207440ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/test/test_helper.rb000066400000000000000000000014041432107571000214100ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app Rails.application end end rabl-0.16.1/fixtures/rails5/tmp/000077500000000000000000000000001432107571000163675ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/tmp/.keep000066400000000000000000000000001432107571000173020ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/000077500000000000000000000000001432107571000170645ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/assets/000077500000000000000000000000001432107571000203665ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/assets/javascripts/000077500000000000000000000000001432107571000227175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/assets/javascripts/.keep000066400000000000000000000000001432107571000236320ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/assets/stylesheets/000077500000000000000000000000001432107571000227425ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5/vendor/assets/stylesheets/.keep000066400000000000000000000000001432107571000236550ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/000077500000000000000000000000001432107571000164205ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/.gitignore000066400000000000000000000010371432107571000204110ustar00rootroot00000000000000# See https://help.github.com/articles/ignoring-files for more about ignoring files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. /.bundle # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/* /tmp/* !/log/.keep !/tmp/.keep # Ignore Byebug command history file. .byebug_history rabl-0.16.1/fixtures/rails5_api/Gemfile000066400000000000000000000027451432107571000177230ustar00rootroot00000000000000source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.2' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible # gem 'rack-cors' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri gem 'pry-rails' end group :development do gem 'listen', '~> 3.0.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") gem 'riot', :group => "test" gem 'responders', '~> 2.0' rabl-0.16.1/fixtures/rails5_api/README.md000066400000000000000000000005661432107571000177060ustar00rootroot00000000000000# README This README would normally document whatever steps are necessary to get the application up and running. Things you may want to cover: * Ruby version * System dependencies * Configuration * Database creation * Database initialization * How to run the test suite * Services (job queues, cache servers, search engines, etc.) * Deployment instructions * ... rabl-0.16.1/fixtures/rails5_api/Rakefile000066400000000000000000000006071432107571000200700ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require_relative 'config/application' require 'rake/testtask' Rails.application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true test.warning = false end rabl-0.16.1/fixtures/rails5_api/app/000077500000000000000000000000001432107571000172005ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/channels/000077500000000000000000000000001432107571000207735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/channels/application_cable/000077500000000000000000000000001432107571000244245ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/channels/application_cable/channel.rb000066400000000000000000000001171432107571000263600ustar00rootroot00000000000000module ApplicationCable class Channel < ActionCable::Channel::Base end end rabl-0.16.1/fixtures/rails5_api/app/channels/application_cable/connection.rb000066400000000000000000000001251432107571000271060ustar00rootroot00000000000000module ApplicationCable class Connection < ActionCable::Connection::Base end end rabl-0.16.1/fixtures/rails5_api/app/controllers/000077500000000000000000000000001432107571000215465ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/controllers/application_controller.rb000066400000000000000000000000701432107571000266360ustar00rootroot00000000000000class ApplicationController < ActionController::API end rabl-0.16.1/fixtures/rails5_api/app/controllers/concerns/000077500000000000000000000000001432107571000233605ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/controllers/concerns/.keep000066400000000000000000000000001432107571000242730ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/controllers/posts_controller.rb000077700000000000000000000000001432107571000376752../../../ashared/controllers_rails_5/posts_controller.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/controllers/users_controller.rb000077700000000000000000000000001432107571000376572../../../ashared/controllers_rails_5/users_controller.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/helpers000077700000000000000000000000001432107571000242022../../ashared/helpersustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/jobs/000077500000000000000000000000001432107571000201355ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/jobs/application_job.rb000066400000000000000000000000531432107571000236150ustar00rootroot00000000000000class ApplicationJob < ActiveJob::Base end rabl-0.16.1/fixtures/rails5_api/app/mailers/000077500000000000000000000000001432107571000206345ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/mailers/application_mailer.rb000066400000000000000000000001461432107571000250160ustar00rootroot00000000000000class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' end rabl-0.16.1/fixtures/rails5_api/app/models000077700000000000000000000000001432107571000236442../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/app/views000077700000000000000000000000001432107571000250632../../ashared/views_rails_3/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/bin/000077500000000000000000000000001432107571000171705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/bin/bundle000077500000000000000000000002011432107571000203600ustar00rootroot00000000000000#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') rabl-0.16.1/fixtures/rails5_api/bin/rails000077500000000000000000000004101432107571000202230ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' rabl-0.16.1/fixtures/rails5_api/bin/rake000077500000000000000000000003251432107571000200400ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end require_relative '../config/boot' require 'rake' Rake.application.run rabl-0.16.1/fixtures/rails5_api/bin/setup000077500000000000000000000016301432107571000202560ustar00rootroot00000000000000#!/usr/bin/env ruby require 'pathname' require 'fileutils' include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'bin/rails restart' end rabl-0.16.1/fixtures/rails5_api/bin/spring000077500000000000000000000007731432107571000204270ustar00rootroot00000000000000#!/usr/bin/env ruby # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) require 'rubygems' require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) spring = lockfile.specs.detect { |spec| spec.name == "spring" } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version require 'spring/binstub' end end rabl-0.16.1/fixtures/rails5_api/bin/update000077500000000000000000000014161432107571000204020ustar00rootroot00000000000000#!/usr/bin/env ruby require 'pathname' require 'fileutils' include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end chdir APP_ROOT do # This script is a way to update your development environment automatically. # Add necessary update steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') puts "\n== Updating database ==" system! 'bin/rails db:migrate' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'bin/rails restart' end rabl-0.16.1/fixtures/rails5_api/config.ru000066400000000000000000000002021432107571000202270ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require_relative 'config/environment' run Rails.application rabl-0.16.1/fixtures/rails5_api/config/000077500000000000000000000000001432107571000176655ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/config/application.rb000066400000000000000000000020221432107571000225110ustar00rootroot00000000000000require_relative 'boot' require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" require "action_cable/engine" # require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Rails5Api class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Only loads a smaller set of middleware suitable for API only apps. # Middleware like session, flash, cookies can be added back manually. # Skip views, helpers and assets when generating a new resource. config.api_only = true end end rabl-0.16.1/fixtures/rails5_api/config/boot.rb000066400000000000000000000002001432107571000211450ustar00rootroot00000000000000ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. rabl-0.16.1/fixtures/rails5_api/config/cable.yml000066400000000000000000000001641432107571000214570ustar00rootroot00000000000000development: adapter: async test: adapter: async production: adapter: redis url: redis://localhost:6379/1 rabl-0.16.1/fixtures/rails5_api/config/database.yml000066400000000000000000000010501432107571000221500ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' # default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3 rabl-0.16.1/fixtures/rails5_api/config/environment.rb000066400000000000000000000002001432107571000225460ustar00rootroot00000000000000# Load the Rails application. require_relative 'application' # Initialize the Rails application. Rails.application.initialize! rabl-0.16.1/fixtures/rails5_api/config/environments/000077500000000000000000000000001432107571000224145ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/config/environments/development.rb000066400000000000000000000031031432107571000252600ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=172800' } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Raises error for missing translations # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end rabl-0.16.1/fixtures/rails5_api/config/environments/production.rb000066400000000000000000000062701432107571000251340ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "rails5_api_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end rabl-0.16.1/fixtures/rails5_api/config/environments/test.rb000066400000000000000000000033241432107571000237220ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raises error for missing translations # config.action_view.raise_on_missing_translations = true end rabl-0.16.1/fixtures/rails5_api/config/initializers/000077500000000000000000000000001432107571000223735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/config/initializers/application_controller_renderer.rb000066400000000000000000000002421432107571000313520ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( # http_host: 'example.org', # https: false # ) rabl-0.16.1/fixtures/rails5_api/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000267100ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails5_api/config/initializers/cors.rb000066400000000000000000000007701432107571000236720ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. # Read more: https://github.com/cyu/rack-cors # Rails.application.config.middleware.insert_before 0, Rack::Cors do # allow do # origins 'example.com' # # resource '*', # headers: :any, # methods: [:get, :post, :put, :patch, :delete, :options, :head] # end # end rabl-0.16.1/fixtures/rails5_api/config/initializers/filter_parameter_logging.rb000066400000000000000000000003021432107571000277460ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password] rabl-0.16.1/fixtures/rails5_api/config/initializers/inflections.rb000066400000000000000000000012071432107571000252350ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end rabl-0.16.1/fixtures/rails5_api/config/initializers/mime_types.rb000066400000000000000000000003431432107571000250730ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1 rabl-0.16.1/fixtures/rails5_api/config/initializers/new_framework_defaults.rb000066400000000000000000000014741432107571000274630ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. # # Read the Guide for Upgrading Ruby on Rails for more info on each option. # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. # Previous versions had false. ActiveSupport.to_time_preserves_timezone = true # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = true # Do not halt callback chains when a callback returns false. Previous versions had true. ActiveSupport.halt_callback_chains_on_return_false = false # Configure SSL options to enable HSTS with subdomains. Previous versions had false. Rails.application.config.ssl_options = { hsts: { subdomains: true } } rabl-0.16.1/fixtures/rails5_api/config/initializers/wrap_parameters.rb000066400000000000000000000007451432107571000261220ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end rabl-0.16.1/fixtures/rails5_api/config/locales/000077500000000000000000000000001432107571000213075ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/config/locales/en.yml000066400000000000000000000011721432107571000224350ustar00rootroot00000000000000# Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. # # To use the locales, use `I18n.t`: # # I18n.t 'hello' # # In views, this is aliased to just `t`: # # <%= t('hello') %> # # To use a different locale, set it with `I18n.locale`: # # I18n.locale = :es # # This would use the information in config/locales/es.yml. # # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" rabl-0.16.1/fixtures/rails5_api/config/puma.rb000066400000000000000000000037251432107571000211630ustar00rootroot00000000000000# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum, this matches the default thread size of Active Record. # threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests, default is 3000. # port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. If you use this option # you need to make sure to reconnect any threads in the `on_worker_boot` # block. # # preload_app! # The code in the `on_worker_boot` will be called if you are using # clustered mode by specifying a number of `workers`. After each worker # process is booted this block will be run, if you are using `preload_app!` # option you will want to use this block to reconnect to any threads # or connections that may have been created at application boot, Ruby # cannot share connections between processes. # # on_worker_boot do # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) # end # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart rabl-0.16.1/fixtures/rails5_api/config/routes.rb000066400000000000000000000001771432107571000215400ustar00rootroot00000000000000Rails.application.routes.draw do resources :users resources :posts do member do get 'renderer' end end end rabl-0.16.1/fixtures/rails5_api/config/secrets.yml000066400000000000000000000017051432107571000220630ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. # You can use `rails secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. development: secret_key_base: 62de20421b0c0b633ba96ebc33fa2aa67af1a89d2d7a031721526887cef59648b0bdd1cd109db47b865c6edbaa98da992b7f2ae1944ebab515839276e1e0582a test: secret_key_base: c2460a288fb4918b55bd17f4666c2ff1a2460d4003ca06a0c0b1e7f1fb82df7f7ffd4d7b4b185ac198e1e451365dc3b0d535a44ab854086d17d6587dea367f72 # Do not keep production secrets in the repository, # instead read values from the environment. production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> rabl-0.16.1/fixtures/rails5_api/config/spring.rb000066400000000000000000000001571432107571000215170ustar00rootroot00000000000000%w( .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt ).each { |path| Spring.watch(path) } rabl-0.16.1/fixtures/rails5_api/db/000077500000000000000000000000001432107571000170055ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/db/migrate000077700000000000000000000000001432107571000237632../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/db/schema.rb000066400000000000000000000025451432107571000206000ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20111002092024) do create_table "phone_numbers", force: :cascade do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", force: :cascade do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at" t.datetime "updated_at" end end rabl-0.16.1/fixtures/rails5_api/db/seeds.rb000066400000000000000000000005621432107571000204400ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) rabl-0.16.1/fixtures/rails5_api/lib/000077500000000000000000000000001432107571000171665ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/lib/tasks/000077500000000000000000000000001432107571000203135ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/lib/tasks/.keep000066400000000000000000000000001432107571000212260ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/log/000077500000000000000000000000001432107571000172015ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/log/.keep000066400000000000000000000000001432107571000201140ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/public/000077500000000000000000000000001432107571000176765ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/public/robots.txt000066400000000000000000000003121432107571000217430ustar00rootroot00000000000000# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-agent: * # Disallow: / rabl-0.16.1/fixtures/rails5_api/test/000077500000000000000000000000001432107571000173775ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/controllers/000077500000000000000000000000001432107571000217455ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/controllers/.keep000066400000000000000000000000001432107571000226600ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/fixtures/000077500000000000000000000000001432107571000212505ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/fixtures/.keep000066400000000000000000000000001432107571000221630ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/fixtures/files/000077500000000000000000000000001432107571000223525ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/fixtures/files/.keep000066400000000000000000000000001432107571000232650ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/functional/000077500000000000000000000000001432107571000215415ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000413072../../../../test/integration/rails5/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000412712../../../../test/integration/rails5/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/integration/000077500000000000000000000000001432107571000217225ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/integration/.keep000066400000000000000000000000001432107571000226350ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/mailers/000077500000000000000000000000001432107571000210335ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/mailers/.keep000066400000000000000000000000001432107571000217460ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/models/000077500000000000000000000000001432107571000206625ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/models/.keep000066400000000000000000000000001432107571000215750ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/test/test_helper.rb000066400000000000000000000021711432107571000222430ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # silence_stream was removed for Rails 5 because it's not thread-safe. # Duplicate that work here: # See https://github.com/rails/rails/pull/13392 def silence_stream(stream) old_stream = stream.dup stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) old_stream.close end # Run Migrations silence_stream(STDOUT) do dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] ActiveRecord::Base.establish_connection(dbconf) ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } end class Riot::Situation def app Rails.application end end rabl-0.16.1/fixtures/rails5_api/tmp/000077500000000000000000000000001432107571000172205ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails5_api/tmp/.keep000066400000000000000000000000001432107571000201330ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/000077500000000000000000000000001432107571000155705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/.gitignore000066400000000000000000000013711432107571000175620ustar00rootroot00000000000000# See https://help.github.com/articles/ignoring-files for more about ignoring files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. /.bundle # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/* /tmp/* !/log/.keep !/tmp/.keep # Ignore uploaded files in development. /storage/* !/storage/.keep /public/assets .byebug_history # Ignore master key for decrypting credentials and more. /config/master.key /public/packs /public/packs-test /node_modules /yarn-error.log yarn-debug.log* .yarn-integrity rabl-0.16.1/fixtures/rails6/Gemfile000066400000000000000000000041271432107571000170670ustar00rootroot00000000000000source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.0' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server gem 'puma', '~> 3.11' # Use SCSS for stylesheets gem 'sass-rails', '~> 5' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 4.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 2.15' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # gem 'rabl', path: File.expand_path(File.dirname(__FILE__) + '/../../') gem 'rabl', path: '../..' gem 'riot', group: 'test' gem 'rr', '1.1.2', group: 'test' gem 'responders', '~> 3.0' rabl-0.16.1/fixtures/rails6/README.md000066400000000000000000000005661432107571000170560ustar00rootroot00000000000000# README This README would normally document whatever steps are necessary to get the application up and running. Things you may want to cover: * Ruby version * System dependencies * Configuration * Database creation * Database initialization * How to run the test suite * Services (job queues, cache servers, search engines, etc.) * Deployment instructions * ... rabl-0.16.1/fixtures/rails6/Rakefile000066400000000000000000000006101432107571000172320ustar00rootroot00000000000000# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require_relative 'config/application' require 'rake/testtask' Rails.application.load_tasks Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true test.warning = false end rabl-0.16.1/fixtures/rails6/app/000077500000000000000000000000001432107571000163505ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/000077500000000000000000000000001432107571000176525ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/config/000077500000000000000000000000001432107571000211175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/config/manifest.js000066400000000000000000000000771432107571000232670ustar00rootroot00000000000000//= link_tree ../images //= link_directory ../stylesheets .css rabl-0.16.1/fixtures/rails6/app/assets/images/000077500000000000000000000000001432107571000211175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/images/.keep000066400000000000000000000000001432107571000220320ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/stylesheets/000077500000000000000000000000001432107571000222265ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/assets/stylesheets/application.css000066400000000000000000000013051432107571000252420ustar00rootroot00000000000000/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's * vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * *= require_tree . *= require_self */ rabl-0.16.1/fixtures/rails6/app/channels/000077500000000000000000000000001432107571000201435ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/channels/application_cable/000077500000000000000000000000001432107571000235745ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/channels/application_cable/channel.rb000066400000000000000000000001171432107571000255300ustar00rootroot00000000000000module ApplicationCable class Channel < ActionCable::Channel::Base end end rabl-0.16.1/fixtures/rails6/app/channels/application_cable/connection.rb000066400000000000000000000001251432107571000262560ustar00rootroot00000000000000module ApplicationCable class Connection < ActionCable::Connection::Base end end rabl-0.16.1/fixtures/rails6/app/controllers/000077500000000000000000000000001432107571000207165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/controllers/application_controller.rb000066400000000000000000000000711432107571000260070ustar00rootroot00000000000000class ApplicationController < ActionController::Base end rabl-0.16.1/fixtures/rails6/app/controllers/concerns/000077500000000000000000000000001432107571000225305ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/controllers/concerns/.keep000066400000000000000000000000001432107571000234430ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/controllers/posts_controller.rb000066400000000000000000000005721432107571000246620ustar00rootroot00000000000000class PostsController < ApplicationController respond_to :json, :xml, :html, :rabl_test_v1 def index @posts = Post.order('id ASC').load end def show @post = Post.find(params[:id]) end def renderer post = Post.find(params[:id]) render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context) end end rabl-0.16.1/fixtures/rails6/app/controllers/users_controller.rb000066400000000000000000000002721432107571000246500ustar00rootroot00000000000000class UsersController < ApplicationController respond_to :json def index @users = User.order('username ASC').load end def show @user = User.find(params[:id]) end end rabl-0.16.1/fixtures/rails6/app/helpers000077700000000000000000000000001432107571000233522../../ashared/helpersustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/javascript/000077500000000000000000000000001432107571000205165ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/javascript/channels/000077500000000000000000000000001432107571000223115ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/javascript/channels/consumer.js000066400000000000000000000004121432107571000244770ustar00rootroot00000000000000// Action Cable provides the framework to deal with WebSockets in Rails. // You can generate new channels where WebSocket features live using the `rails generate channel` command. import { createConsumer } from "@rails/actioncable" export default createConsumer() rabl-0.16.1/fixtures/rails6/app/javascript/channels/index.js000066400000000000000000000003241432107571000237550ustar00rootroot00000000000000// Load all the channels within this directory and all subdirectories. // Channel files must be named *_channel.js. const channels = require.context('.', true, /_channel\.js$/) channels.keys().forEach(channels) rabl-0.16.1/fixtures/rails6/app/javascript/packs/000077500000000000000000000000001432107571000216175ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/javascript/packs/application.js000066400000000000000000000013521432107571000244610ustar00rootroot00000000000000// This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) // or the `imagePath` JavaScript helper below. // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true) rabl-0.16.1/fixtures/rails6/app/jobs/000077500000000000000000000000001432107571000173055ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/jobs/application_job.rb000066400000000000000000000004151432107571000227670ustar00rootroot00000000000000class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError end rabl-0.16.1/fixtures/rails6/app/mailers/000077500000000000000000000000001432107571000200045ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/mailers/application_mailer.rb000066400000000000000000000001461432107571000241660ustar00rootroot00000000000000class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' end rabl-0.16.1/fixtures/rails6/app/models000077700000000000000000000000001432107571000230142../../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/app/views000077700000000000000000000000001432107571000242362../../ashared/views_rails_6/ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/babel.config.js000066400000000000000000000035241432107571000204430ustar00rootroot00000000000000module.exports = function(api) { var validEnv = ['development', 'test', 'production'] var currentEnv = api.env() var isDevelopmentEnv = api.env('development') var isProductionEnv = api.env('production') var isTestEnv = api.env('test') if (!validEnv.includes(currentEnv)) { throw new Error( 'Please specify a valid `NODE_ENV` or ' + '`BABEL_ENV` environment variables. Valid values are "development", ' + '"test", and "production". Instead, received: ' + JSON.stringify(currentEnv) + '.' ) } return { presets: [ isTestEnv && [ require('@babel/preset-env').default, { targets: { node: 'current' } } ], (isProductionEnv || isDevelopmentEnv) && [ require('@babel/preset-env').default, { forceAllTransforms: true, useBuiltIns: 'entry', corejs: 3, modules: false, exclude: ['transform-typeof-symbol'] } ] ].filter(Boolean), plugins: [ require('babel-plugin-macros'), require('@babel/plugin-syntax-dynamic-import').default, isTestEnv && require('babel-plugin-dynamic-import-node'), require('@babel/plugin-transform-destructuring').default, [ require('@babel/plugin-proposal-class-properties').default, { loose: true } ], [ require('@babel/plugin-proposal-object-rest-spread').default, { useBuiltIns: true } ], [ require('@babel/plugin-transform-runtime').default, { helpers: false, regenerator: true, corejs: false } ], [ require('@babel/plugin-transform-regenerator').default, { async: false } ] ].filter(Boolean) } } rabl-0.16.1/fixtures/rails6/bin/000077500000000000000000000000001432107571000163405ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/bin/bundle000077500000000000000000000054311432107571000175420ustar00rootroot00000000000000#!/usr/bin/env ruby # frozen_string_literal: true # # This file was generated by Bundler. # # The application 'bundle' is installed as part of a gem, and # this file is here to facilitate running it. # require "rubygems" m = Module.new do module_function def invoked_as_script? File.expand_path($0) == File.expand_path(__FILE__) end def env_var_version ENV["BUNDLER_VERSION"] end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ bundler_version = $1 || ">= 0.a" update_index = i end bundler_version end def gemfile gemfile = ENV["BUNDLE_GEMFILE"] return gemfile if gemfile && !gemfile.empty? File.expand_path("../../Gemfile", __FILE__) end def lockfile lockfile = case File.basename(gemfile) when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) else "#{gemfile}.lock" end File.expand_path(lockfile) end def lockfile_version return unless File.file?(lockfile) lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ Regexp.last_match(1) end def bundler_version @bundler_version ||= begin env_var_version || cli_arg_version || lockfile_version || "#{Gem::Requirement.default}.a" end end def load_bundler! ENV["BUNDLE_GEMFILE"] ||= gemfile # must dup string for RG < 1.8 compatibility activate_bundler(bundler_version.dup) end def activate_bundler(bundler_version) if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") bundler_version = "< 2" end gem_error = activation_error_handling do gem "bundler", bundler_version end return if gem_error.nil? require_error = activation_error_handling do require "bundler/version" end return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" exit 42 end def activation_error_handling yield nil rescue StandardError, LoadError => e e end end m.load_bundler! if m.invoked_as_script? load Gem.bin_path("bundler", "bundle") end rabl-0.16.1/fixtures/rails6/bin/rails000077500000000000000000000004101432107571000173730ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' rabl-0.16.1/fixtures/rails6/bin/rake000077500000000000000000000003251432107571000172100ustar00rootroot00000000000000#!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError => e raise unless e.message.include?('spring') end require_relative '../config/boot' require 'rake' Rake.application.run rabl-0.16.1/fixtures/rails6/bin/setup000077500000000000000000000020541432107571000174270ustar00rootroot00000000000000#!/usr/bin/env ruby require 'fileutils' # path to your application root. APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end FileUtils.chdir APP_ROOT do # This script is a way to setup or update your development environment automatically. # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') # Install JavaScript dependencies # system('bin/yarn') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" system! 'bin/rails restart' end rabl-0.16.1/fixtures/rails6/bin/spring000077500000000000000000000007731432107571000175770ustar00rootroot00000000000000#!/usr/bin/env ruby # This file loads Spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) require 'rubygems' require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) spring = lockfile.specs.detect { |spec| spec.name == 'spring' } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version require 'spring/binstub' end end rabl-0.16.1/fixtures/rails6/bin/webpack000077500000000000000000000006611432107571000177050ustar00rootroot00000000000000#!/usr/bin/env ruby ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" ENV["NODE_ENV"] ||= "development" require "pathname" ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) require "rubygems" require "bundler/setup" require "webpacker" require "webpacker/webpack_runner" APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do Webpacker::WebpackRunner.run(ARGV) end rabl-0.16.1/fixtures/rails6/bin/webpack-dev-server000077500000000000000000000006661432107571000217720ustar00rootroot00000000000000#!/usr/bin/env ruby ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" ENV["NODE_ENV"] ||= "development" require "pathname" ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) require "rubygems" require "bundler/setup" require "webpacker" require "webpacker/dev_server_runner" APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do Webpacker::DevServerRunner.run(ARGV) end rabl-0.16.1/fixtures/rails6/bin/yarn000077500000000000000000000004571432107571000172450ustar00rootroot00000000000000#!/usr/bin/env ruby APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do begin exec "yarnpkg", *ARGV rescue Errno::ENOENT $stderr.puts "Yarn executable was not detected in the system." $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" exit 1 end end rabl-0.16.1/fixtures/rails6/config.ru000066400000000000000000000002021432107571000173770ustar00rootroot00000000000000# This file is used by Rack-based servers to start the application. require_relative 'config/environment' run Rails.application rabl-0.16.1/fixtures/rails6/config/000077500000000000000000000000001432107571000170355ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/config/application.rb000066400000000000000000000012211432107571000216610ustar00rootroot00000000000000require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Rails6 class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.0 # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. end end rabl-0.16.1/fixtures/rails6/config/boot.rb000066400000000000000000000003171432107571000203260ustar00rootroot00000000000000ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bootsnap/setup' # Speed up boot time by caching expensive operations. rabl-0.16.1/fixtures/rails6/config/cable.yml000066400000000000000000000002731432107571000206300ustar00rootroot00000000000000development: adapter: async test: adapter: test production: adapter: redis url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> channel_prefix: rails6_production rabl-0.16.1/fixtures/rails6/config/credentials.yml.enc000066400000000000000000000007201432107571000226200ustar00rootroot00000000000000ktYYtJbsh3y4BRILzT20SK4Fxc7oJz/tB9XKNKM2KYvIN/UhHYKyKdeSQmGmyGMgl8q2f5UukxMrp3eheRKcXb1PmkeD3x5VhYDi11iWbo8/buG1u4KWugT33iJu6AacUb10A71i2BBUGQHsUTmqm3sRCD96T+w8GHo8geDyqyCCT0cmsR04REXOIBB7Pg6AfbZLqQGC8PwFz4Lkn+OJmZ/RnWvbjzOmn7DxuEq0dhW2+vSVxSI06fJdyX7LPndo0xl+PinyUcN3uGEiNqyzuOXnaIyP7mGZtyhT5j4NN+HBVM7nfa7bLFVGlgIke4wKZcpqW5C1nAQPR/rKwqk8PtHqwPPvKCHDZdEcbIR5ByzX8du2dsrdmOH/Zm2F43YvlOnOoij2snnyA5ncPF1g/46S6Jx1dipVz4zd--WlaatyHNWBV1atxX--BOaXG/24ZPpiR3+SGx7/tg==rabl-0.16.1/fixtures/rails6/config/database.yml000066400000000000000000000011221432107571000213200ustar00rootroot00000000000000# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' # default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3 rabl-0.16.1/fixtures/rails6/config/environment.rb000066400000000000000000000002001432107571000217160ustar00rootroot00000000000000# Load the Rails application. require_relative 'application' # Initialize the Rails application. Rails.application.initialize! rabl-0.16.1/fixtures/rails6/config/environments/000077500000000000000000000000001432107571000215645ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/config/environments/development.rb000066400000000000000000000043031432107571000244330ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end rabl-0.16.1/fixtures/rails6/config/environments/production.rb000066400000000000000000000116171432107571000243050ustar00rootroot00000000000000Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "rails6_production" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false # Inserts middleware to perform automatic connection switching. # The `database_selector` hash is used to pass options to the DatabaseSelector # middleware. The `delay` is used to determine how long to wait after a write # to send a subsequent read to the primary. # # The `database_resolver` class is used by the middleware to determine which # database is appropriate to use based on the time delay. # # The `database_resolver_context` class is used by the middleware to set # timestamps for the last write to the primary. The resolver uses the context # class timestamps to determine how long to wait before reading from the # replica. # # By default Rails will store a last write timestamp in the session. The # DatabaseSelector middleware is designed as such you can define your own # strategy for connection switching and pass that into the middleware through # these configuration options. # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end rabl-0.16.1/fixtures/rails6/config/environments/test.rb000066400000000000000000000035641432107571000231000ustar00rootroot00000000000000# The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true end rabl-0.16.1/fixtures/rails6/config/initializers/000077500000000000000000000000001432107571000215435ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/config/initializers/application_controller_renderer.rb000066400000000000000000000003301432107571000305200ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do # ApplicationController.renderer.defaults.merge!( # http_host: 'example.org', # https: false # ) # end rabl-0.16.1/fixtures/rails6/config/initializers/assets.rb000066400000000000000000000011661432107571000233760ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Add Yarn node_modules folder to the asset load path. Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) rabl-0.16.1/fixtures/rails6/config/initializers/backtrace_silencers.rb000066400000000000000000000006241432107571000260600ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! rabl-0.16.1/fixtures/rails6/config/initializers/content_security_policy.rb000066400000000000000000000024021432107571000270460ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Define an application-wide content security policy # For further information see the following documentation # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy # Rails.application.config.content_security_policy do |policy| # policy.default_src :self, :https # policy.font_src :self, :https, :data # policy.img_src :self, :https, :data # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https # # If you are using webpack-dev-server then specify webpack-dev-server host # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" # end # If you are using UJS then enable automatic nonce generation # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } # Report CSP violations to a specified URI # For further information see the following documentation: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only # Rails.application.config.content_security_policy_report_only = true rabl-0.16.1/fixtures/rails6/config/initializers/cookies_serializer.rb000066400000000000000000000003641432107571000257600ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. # Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json rabl-0.16.1/fixtures/rails6/config/initializers/filter_parameter_logging.rb000066400000000000000000000003021432107571000271160ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password] rabl-0.16.1/fixtures/rails6/config/initializers/inflections.rb000066400000000000000000000012071432107571000244050ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end rabl-0.16.1/fixtures/rails6/config/initializers/mime_types.rb000066400000000000000000000003441432107571000242440ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register 'application/vnd.rabl-test_v1+json', :rabl_test_v1 rabl-0.16.1/fixtures/rails6/config/initializers/wrap_parameters.rb000066400000000000000000000007451432107571000252720ustar00rootroot00000000000000# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end rabl-0.16.1/fixtures/rails6/config/locales/000077500000000000000000000000001432107571000204575ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/config/locales/en.yml000066400000000000000000000015211432107571000216030ustar00rootroot00000000000000# Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. # # To use the locales, use `I18n.t`: # # I18n.t 'hello' # # In views, this is aliased to just `t`: # # <%= t('hello') %> # # To use a different locale, set it with `I18n.locale`: # # I18n.locale = :es # # This would use the information in config/locales/es.yml. # # The following keys must be escaped otherwise they will not be retrieved by # the default I18n backend: # # true, false, on, off, yes, no # # Instead, surround them with single quotes. # # en: # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide # available at https://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" rabl-0.16.1/fixtures/rails6/config/puma.rb000066400000000000000000000027131432107571000203270ustar00rootroot00000000000000# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # # preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart rabl-0.16.1/fixtures/rails6/config/routes.rb000066400000000000000000000001771432107571000207100ustar00rootroot00000000000000Rails.application.routes.draw do resources :users resources :posts do member do get 'renderer' end end end rabl-0.16.1/fixtures/rails6/config/spring.rb000066400000000000000000000001411432107571000206600ustar00rootroot00000000000000Spring.watch( ".ruby-version", ".rbenv-vars", "tmp/restart.txt", "tmp/caching-dev.txt" ) rabl-0.16.1/fixtures/rails6/config/storage.yml000066400000000000000000000021051432107571000212220ustar00rootroot00000000000000test: service: Disk root: <%= Rails.root.join("tmp/storage") %> local: service: Disk root: <%= Rails.root.join("storage") %> # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) # amazon: # service: S3 # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> # region: us-east-1 # bucket: your_own_bucket # Remember not to checkin your GCS keyfile to a repository # google: # service: GCS # project: your_project # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> # bucket: your_own_bucket # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) # microsoft: # service: AzureStorage # storage_account_name: your_account_name # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> # container: your_container_name # mirror: # service: Mirror # primary: local # mirrors: [ amazon, google, microsoft ] rabl-0.16.1/fixtures/rails6/config/webpack/000077500000000000000000000000001432107571000204515ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/config/webpack/development.js000066400000000000000000000002331432107571000233270ustar00rootroot00000000000000process.env.NODE_ENV = process.env.NODE_ENV || 'development' const environment = require('./environment') module.exports = environment.toWebpackConfig() rabl-0.16.1/fixtures/rails6/config/webpack/environment.js000066400000000000000000000001221432107571000233460ustar00rootroot00000000000000const { environment } = require('@rails/webpacker') module.exports = environment rabl-0.16.1/fixtures/rails6/config/webpack/production.js000066400000000000000000000002321432107571000231720ustar00rootroot00000000000000process.env.NODE_ENV = process.env.NODE_ENV || 'production' const environment = require('./environment') module.exports = environment.toWebpackConfig() rabl-0.16.1/fixtures/rails6/config/webpack/test.js000066400000000000000000000002331432107571000217640ustar00rootroot00000000000000process.env.NODE_ENV = process.env.NODE_ENV || 'development' const environment = require('./environment') module.exports = environment.toWebpackConfig() rabl-0.16.1/fixtures/rails6/config/webpacker.yml000066400000000000000000000036211432107571000215250ustar00rootroot00000000000000# Note: You must restart bin/webpack-dev-server for changes to take effect default: &default source_path: app/javascript source_entry_path: packs public_root_path: public public_output_path: packs cache_path: tmp/cache/webpacker check_yarn_integrity: false webpack_compile_output: false # Additional paths webpack should lookup modules # ['app/assets', 'engine/foo/app/assets'] resolved_paths: [] # Reload manifest.json on all requests so we reload latest compiled packs cache_manifest: false # Extract and emit a css file extract_css: false static_assets_extensions: - .jpg - .jpeg - .png - .gif - .tiff - .ico - .svg - .eot - .otf - .ttf - .woff - .woff2 extensions: - .mjs - .js - .sass - .scss - .css - .module.sass - .module.scss - .module.css - .png - .svg - .gif - .jpeg - .jpg development: <<: *default compile: true # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules check_yarn_integrity: true # Reference: https://webpack.js.org/configuration/dev-server/ dev_server: https: false host: localhost port: 3035 public: localhost:3035 hmr: false # Inline should be set to true if using HMR inline: true overlay: true compress: true disable_host_check: true use_local_ip: false quiet: false headers: 'Access-Control-Allow-Origin': '*' watch_options: ignored: '**/node_modules/**' test: <<: *default compile: true # Compile test packs to a separate directory public_output_path: packs-test production: <<: *default # Production depends on precompilation of packs prior to booting for performance. compile: false # Extract and emit a css file extract_css: true # Cache manifest.json for performance cache_manifest: true rabl-0.16.1/fixtures/rails6/db/000077500000000000000000000000001432107571000161555ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/db/migrate/000077500000000000000000000000001432107571000176055ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/db/migrate/20111002092016_create_users.rb000066400000000000000000000003471432107571000242520ustar00rootroot00000000000000class CreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| t.string :username t.string :email t.string :location t.boolean :is_admin t.timestamps end end end rabl-0.16.1/fixtures/rails6/db/migrate/20111002092019_create_posts.rb000066400000000000000000000003101432107571000242520ustar00rootroot00000000000000class CreatePosts < ActiveRecord::Migration[6.0] def change create_table :posts do |t| t.integer :user_id t.string :title t.text :body t.timestamps end end end rabl-0.16.1/fixtures/rails6/db/migrate/20111002092024_create_phone_numbers.rb000066400000000000000000000004201432107571000257440ustar00rootroot00000000000000class CreatePhoneNumbers < ActiveRecord::Migration[6.0] def change create_table :phone_numbers do |t| t.integer :user_id t.boolean :is_primary t.string :area_code t.string :prefix t.string :suffix t.string :name end end end rabl-0.16.1/fixtures/rails6/db/schema.rb000066400000000000000000000026551432107571000177520ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `rails # db:schema:load`. When creating a new database, `rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2011_10_02_092024) do create_table "phone_numbers", force: :cascade do |t| t.integer "user_id" t.boolean "is_primary" t.string "area_code" t.string "prefix" t.string "suffix" t.string "name" end create_table "posts", force: :cascade do |t| t.integer "user_id" t.string "title" t.text "body" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end create_table "users", force: :cascade do |t| t.string "username" t.string "email" t.string "location" t.boolean "is_admin" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end end rabl-0.16.1/fixtures/rails6/db/seeds.rb000066400000000000000000000005621432107571000176100ustar00rootroot00000000000000# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) rabl-0.16.1/fixtures/rails6/lib/000077500000000000000000000000001432107571000163365ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/lib/assets/000077500000000000000000000000001432107571000176405ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/lib/assets/.keep000066400000000000000000000000001432107571000205530ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/lib/tasks/000077500000000000000000000000001432107571000174635ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/lib/tasks/.keep000066400000000000000000000000001432107571000203760ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/log/000077500000000000000000000000001432107571000163515ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/log/.keep000066400000000000000000000000001432107571000172640ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/package.json000066400000000000000000000005151432107571000200570ustar00rootroot00000000000000{ "name": "rails6", "private": true, "dependencies": { "@rails/actioncable": "^6.0.0-alpha", "@rails/activestorage": "^6.0.0-alpha", "@rails/ujs": "^6.0.0-alpha", "@rails/webpacker": "^4.0.7", "turbolinks": "^5.2.0" }, "version": "0.1.0", "devDependencies": { "webpack-dev-server": "^3.7.2" } } rabl-0.16.1/fixtures/rails6/postcss.config.js000066400000000000000000000003401432107571000210650ustar00rootroot00000000000000module.exports = { plugins: [ require('postcss-import'), require('postcss-flexbugs-fixes'), require('postcss-preset-env')({ autoprefixer: { flexbox: 'no-2009' }, stage: 3 }) ] } rabl-0.16.1/fixtures/rails6/public/000077500000000000000000000000001432107571000170465ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/public/404.html000066400000000000000000000032721432107571000202470ustar00rootroot00000000000000 The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails6/public/422.html000066400000000000000000000032511432107571000202440ustar00rootroot00000000000000 The change you wanted was rejected (422)

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails6/public/500.html000066400000000000000000000031431432107571000202410ustar00rootroot00000000000000 We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

rabl-0.16.1/fixtures/rails6/public/apple-touch-icon-precomposed.png000066400000000000000000000000001432107571000252270ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/public/apple-touch-icon.png000066400000000000000000000000001432107571000227110ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/public/favicon.ico000066400000000000000000000000001432107571000211550ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/public/robots.txt000066400000000000000000000001421432107571000211140ustar00rootroot00000000000000# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file rabl-0.16.1/fixtures/rails6/storage/000077500000000000000000000000001432107571000172345ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/storage/.keep000066400000000000000000000000001432107571000201470ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/000077500000000000000000000000001432107571000165475ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/application_system_test_case.rb000066400000000000000000000002351432107571000250350ustar00rootroot00000000000000require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] end rabl-0.16.1/fixtures/rails6/test/channels/000077500000000000000000000000001432107571000203425ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/channels/application_cable/000077500000000000000000000000001432107571000237735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/channels/application_cable/connection_test.rb000066400000000000000000000003701432107571000275160ustar00rootroot00000000000000require "test_helper" class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase # test "connects with cookies" do # cookies.signed[:user_id] = 42 # # connect # # assert_equal connection.user_id, "42" # end end rabl-0.16.1/fixtures/rails6/test/controllers/000077500000000000000000000000001432107571000211155ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/controllers/.keep000066400000000000000000000000001432107571000220300ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/fixtures/000077500000000000000000000000001432107571000204205ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/fixtures/.keep000066400000000000000000000000001432107571000213330ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/fixtures/files/000077500000000000000000000000001432107571000215225ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/fixtures/files/.keep000066400000000000000000000000001432107571000224350ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/functional/000077500000000000000000000000001432107571000207115ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000404602../../../../test/integration/rails6/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000404422../../../../test/integration/rails6/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/helpers/000077500000000000000000000000001432107571000202115ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/helpers/.keep000066400000000000000000000000001432107571000211240ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/integration/000077500000000000000000000000001432107571000210725ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/integration/.keep000066400000000000000000000000001432107571000220050ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/mailers/000077500000000000000000000000001432107571000202035ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/mailers/.keep000066400000000000000000000000001432107571000211160ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/models/000077500000000000000000000000001432107571000200325ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/models/.keep000066400000000000000000000000001432107571000207450ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/system/000077500000000000000000000000001432107571000200735ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/system/.keep000066400000000000000000000000001432107571000210060ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/test/test_helper.rb000066400000000000000000000014711432107571000214150ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") # Load Environment silence_warnings do ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") # Run Migrations silence_stream(STDOUT) do # dbconf = YAML::load(File.open('config/database.yml'))[Rails.env] # ActiveRecord::Base.establish_connection(dbconf) # ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a')) # silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } ActiveRecord::Tasks::DatabaseTasks.migrate end class Riot::Situation def app Rails.application end end rabl-0.16.1/fixtures/rails6/tmp/000077500000000000000000000000001432107571000163705ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/tmp/.keep000066400000000000000000000000001432107571000173030ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/vendor/000077500000000000000000000000001432107571000170655ustar00rootroot00000000000000rabl-0.16.1/fixtures/rails6/vendor/.keep000066400000000000000000000000001432107571000200000ustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/000077500000000000000000000000001432107571000170705ustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/Gemfile000066400000000000000000000005051432107571000203630ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rake' gem 'activerecord', :require => "active_record" gem 'sqlite3' gem 'sinatra', '>= 1.3.3' gem 'json' gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../") # Test requirements gem 'riot', :group => "test" gem 'rack-test', :require => "rack/test", :group => "test" rabl-0.16.1/fixtures/sinatra_test/Rakefile000066400000000000000000000002141432107571000205320ustar00rootroot00000000000000require 'rake/testtask' Rake::TestTask.new("test:rabl") do |test| test.pattern = "test/functional/**/*_test.rb" test.verbose = true endrabl-0.16.1/fixtures/sinatra_test/app.rb000066400000000000000000000023071432107571000201770ustar00rootroot00000000000000require 'rubygems' require 'sinatra' require 'rabl' require 'active_support/core_ext' require 'active_support/inflector' require 'active_record' require 'builder' ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ':memory:' ) Dir[File.dirname(__FILE__) + "/models/*.rb"].each do |file| require File.expand_path(file) end # Register RABL Rabl.configure do |config| config.perform_caching = true end Rabl.register! class SinatraTest < Sinatra::Application set :root, File.expand_path(File.dirname(__FILE__)) set :views, Proc.new { File.join(root, "views") } get "/posts" do @posts = Post.order("id ASC") render :rabl, :"posts/index", :format => "json" end get "/posts/:id" do @post = Post.find(params[:id]) render :rabl, :"posts/show", :format => "json" end get "/users" do @users = User.order("username ASC") render :rabl, :"users/index.json", :format => "json" end get "/users/:id" do @user = User.find(params[:id]) render :rabl, :"users/show.json", :format => "json" end end # Patch times to return as iso8601 class Time alias_method :old_to_s, :to_s def to_s(format=nil) format ? old_to_s(format) : iso8601 end endrabl-0.16.1/fixtures/sinatra_test/config.ru000066400000000000000000000001261432107571000207040ustar00rootroot00000000000000require 'rubygems' require 'bundler' Bundler.require require './app' run SinatraTestrabl-0.16.1/fixtures/sinatra_test/db/000077500000000000000000000000001432107571000174555ustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/db/migrate000077700000000000000000000000001432107571000244332../../ashared/migrateustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/models000077700000000000000000000000001432107571000233212../ashared/modelsustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/test/000077500000000000000000000000001432107571000200475ustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/test/functional/000077500000000000000000000000001432107571000222115ustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/test/functional/posts_controller_test.rb000077700000000000000000000000001432107571000405602../../../../test/integration/posts_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/test/functional/users_controller_test.rb000077700000000000000000000000001432107571000405422../../../../test/integration/users_controller_test.rbustar00rootroot00000000000000rabl-0.16.1/fixtures/sinatra_test/test/test_helper.rb000066400000000000000000000010751432107571000227150ustar00rootroot00000000000000# Load Silence Functionality require File.expand_path(File.dirname(__FILE__) + "/../../../test/silence.rb") silence_warnings do PADRINO_ENV = 'test' unless defined?(PADRINO_ENV) require 'bundler' Bundler.require require File.expand_path(File.dirname(__FILE__) + "/../app.rb") silence_stream(STDOUT) { ActiveRecord::Migrator.up('db/migrate') } # Load up test migrations end # Load Riot Test Environment require File.expand_path(File.dirname(__FILE__) + "/../../../test/integration/test_init.rb") class Riot::Situation def app @app || SinatraTest end endrabl-0.16.1/fixtures/sinatra_test/views000077700000000000000000000000001432107571000231242../ashared/views/ustar00rootroot00000000000000rabl-0.16.1/lib/000077500000000000000000000000001432107571000132655ustar00rootroot00000000000000rabl-0.16.1/lib/rabl.rb000066400000000000000000000046551432107571000145440ustar00rootroot00000000000000require 'active_support' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' require 'rabl/version' require 'rabl/helpers' require 'rabl/sources' require 'rabl/partials' require 'rabl/engine' require 'rabl/builder' require 'rabl/multi_builder' require 'rabl/configuration' require 'rabl/renderer' require 'rabl/cache_engine' if defined?(Rails) && Rails.respond_to?(:version) require 'rabl/tracker' if Rails.version =~ /^[4567]/ require 'rabl/digestor' if Rails.version =~ /^[4567]/ require 'rabl/railtie' if Rails.version =~ /^[34567]/ end # Rabl.register! module Rabl class << self # Initialize RABL within an application # Rabl.register! def register! require 'rabl/template' end # Yields a RABL configuration block # Rabl.configure do |config| # config.include_json_root = false # config.enable_json_callbacks = true # end def configure(&block) yield(configuration) configuration end # Returns the configuration options set for RABL # Rabl.configuration.include_json_root => false def configuration @_configuration ||= Configuration.new end # Resets the RABL configuration back to the defaults. def reset_configuration! @_configuration = nil end # Fetches from the source_cache, stores block result in cache if nil # Used to cache the contents and paths to various rabl templates # source_cache("users/index", "path/to/view") { "/full/path/to/template/users/index" } def source_cache(file, view_path, &block) return yield unless Rabl.configuration.cache_sources cache_key = [file, view_path].compact.join(":") @_source_cache ||= {} @_source_cache[cache_key] ||= yield end # Resets the RABL source cache def reset_source_cache! @_source_cache = {} end # Renders an object using a specified template within an application. # render(@post, 'posts/show', :view_path => "/path/to/app/views") def render(object, source, options = {}) Rabl::Renderer.new(source, object, options).render end end end # Register if defined?(Padrino) require 'padrino-core' Padrino.after_load { Rabl.register! } elsif defined?(Rails.version) && Rails.version =~ /^2/ Rabl.register! end rabl-0.16.1/lib/rabl/000077500000000000000000000000001432107571000142055ustar00rootroot00000000000000rabl-0.16.1/lib/rabl/builder.rb000066400000000000000000000207311432107571000161630ustar00rootroot00000000000000require 'active_support/inflector' # for the sake of camelcasing keys module Rabl class Builder include Helpers include Partials SETTING_TYPES = { :attributes => :name, :node => :name, :child => :data, :glue => :data, :extends => :file } unless const_defined?(:SETTING_TYPES) # Constructs a new rabl hash based on given object and options # options = { :format => "json", :root => true, :child_root => true, # :attributes, :node, :child, :glue, :extends } # def initialize(object, settings = {}, options = {}) @_object = object @settings = settings @options = options @_context_scope = options[:scope] @_view_path = options[:view_path] end def engines return @_engines if defined?(@_engines) @_engines = [] # Append onto @_engines compile_settings(:extends) compile_settings(:child) compile_settings(:glue) @_engines end def replace_engine(engine, value) engines[engines.index(engine)] = value end def to_hash(object = nil, settings = nil, options = nil) @_object = object if object @options.merge!(options) if options @settings.merge!(settings) if settings cache_results do @_result = {} # Merges directly into @_result compile_settings(:attributes) merge_engines_into_result # Merges directly into @_result compile_settings(:node) replace_nil_values if Rabl.configuration.replace_nil_values_with_empty_strings replace_empty_string_values if Rabl.configuration.replace_empty_string_values_with_nil_values remove_nil_values if Rabl.configuration.exclude_nil_values result = @_result result = { @options[:root_name] => result } if @options[:root_name].present? result end end protected def replace_nil_values @_result = deep_replace_nil_values(@_result) end def deep_replace_nil_values(hash) hash.inject({}) do |new_hash, (k, v)| new_hash[k] = if v.is_a?(Hash) deep_replace_nil_values(v) else v.nil? ? '' : v end new_hash end end def replace_empty_string_values @_result = deep_replace_empty_string_values(@_result) end def deep_replace_empty_string_values(hash) hash.inject({}) do |new_hash, (k, v)| new_hash[k] = if v.is_a?(Hash) deep_replace_empty_string_values(v) else (!v.nil? && v != "") ? v : nil end new_hash end end def remove_nil_values @_result = @_result.inject({}) do |new_hash, (k, v)| new_hash[k] = v unless v.nil? new_hash end end def compile_settings(type) return unless @settings.has_key?(type) settings_type = SETTING_TYPES[type] @settings[type].each do |setting| send(type, setting[settings_type], setting[:options] || {}, &setting[:block]) end end def merge_engines_into_result engines.each do |engine| case engine when Hash # engine was stored in the form { name => # } engine.each do |key, value| engine[key] = value.render if value.is_a?(Engine) end when Engine engine = engine.render end @_result.merge!(engine) if engine.is_a?(Hash) end end # Indicates an attribute or method should be included in the json output # attribute :foo, :as => "bar" # attribute :foo, :as => "bar", :if => lambda { |m| m.foo } def attribute(name, options = {}) return unless @_object && attribute_present?(name) && resolve_condition(options) attribute = data_object_attribute(name) name = create_key(options[:as] || name) @_result[name] = attribute end alias_method :attributes, :attribute # Creates an arbitrary node that is included in the json output # node(:foo) { "bar" } # node(:foo, :if => lambda { |m| m.foo.present? }) { "bar" } def node(name, options = {}, &block) return unless resolve_condition(options) return if @options.has_key?(:except) && [@options[:except]].flatten.include?(name) result = block.call(@_object) if name.present? @_result[create_key(name)] = result elsif result.is_a?(Hash) # merge hash into root hash @_result.merge!(result) end end alias_method :code, :node # Creates a child node that is included in json output # child(@user) { attribute :full_name } # child(@user => :person) { ... } # child(@users => :people) { ... } def child(data, options = {}, &block) return unless data.present? && resolve_condition(options) name = is_name_value?(options[:root]) ? options[:root] : data_name(data) object = data_object(data) engine_options = @options.slice(:child_root) engine_options[:root] = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users engine_options[:object_root_name] = options[:object_root] if is_name_value?(options[:object_root]) object = { object => name } if data.is_a?(Hash) && object # child :users => :people engines << { create_key(name) => object_to_engine(object, engine_options, &block) } end # Glues data from a child node to the json_output # glue(@user) { attribute :full_name => :user_full_name } def glue(data, options = {}, &block) return unless data.present? && resolve_condition(options) object = data_object(data) engine = object_to_engine(object, :root => false, &block) engines << engine if engine end # Extends an existing rabl template with additional attributes in the block # extends("users/show") { attribute :full_name } def extends(file, options = {}, &block) return unless resolve_condition(options) options = @options.slice(:child_root).merge!(:object => @_object).merge!(options) engines << partial_as_engine(file, options, &block) end # Evaluate conditions given a symbol/proc/lambda/variable to evaluate def call_condition_proc(condition, object) case condition when Proc then condition.call(object) when Symbol then condition.to_proc.call(object) else condition end end # resolve_condition(:if => true) => true # resolve_condition(:if => 'Im truthy') => true # resolve_condition(:if => lambda { |m| false }) => false # resolve_condition(:unless => lambda { |m| false }) => true # resolve_condition(:unless => lambda { |m| false }, :if => proc { true}) => true def resolve_condition(options) result = true result &&= call_condition_proc(options[:if], @_object) if options.key?(:if) result &&= !call_condition_proc(options[:unless], @_object) if options.key?(:unless) result end private # Checks if an attribute is present. If not, check if the configuration specifies that this is an error # attribute_present?(created_at) => true def attribute_present?(name) @_object.respond_to?(name) || (Rabl.configuration.raise_on_missing_attribute && raise("Failed to render missing attribute #{name}")) end # Returns a guess at the format in this context_scope # request_format => "xml" def request_format format = @options[:format] format = "json" if !format || format == "hash" format end # Caches the results of the block based on object cache_key # cache_results { compile_hash(options) } def cache_results(&block) if template_cache_configured? && Rabl.configuration.cache_all_output && @_object.respond_to?(:cache_key) cache_key = [@_object, @options[:root_name], @options[:format]] fetch_result_from_cache(cache_key, &block) else # skip cache yield end end def create_key(name) if Rabl.configuration.camelize_keys name.to_s.camelize(Rabl.configuration.camelize_keys == :upper ? :upper : :lower).to_sym else name.to_sym end end end end rabl-0.16.1/lib/rabl/cache_engine.rb000066400000000000000000000027401432107571000171250ustar00rootroot00000000000000# Defines the default cache engine for RABL when caching is invoked for a template. # You can define your own caching engines by creating an object that responds to fetch and # setting the configuration option: # # config.cache_engine = AdvancedCacheEngine.new # class LRU < Hash attr_accessor :max_size def initialize super self.max_size = 100_000 end def []= k,v r = super limit_size r end def limit_size if size > max_size then delete keys.shift while size > max_size end end end module Rabl class CacheEngine def initialize unless defined?(Rails) @cache = LRU.new end end # Fetch given a key and options and a fallback block attempts to find the key in the cache # and stores the block result in there if no key is found. # # cache = Rabl::CacheEngine.new; cache.fetch("some_key") { "fallback data" } # def fetch(key, cache_options, &block) if defined?(Rails) Rails.cache.fetch(key, cache_options, &block) else @cache[key] ||= yield end end def write(key, value, options = {}) if defined?(Rails) Rails.cache.write(key, value, options) else @cache[key] = yield end end def read_multi(*keys) options = keys.extract_options! if defined?(Rails) Rails.cache.read_multi(*keys, options) else keys.inject({}) { |hash, key| hash[key] = nil; hash } end end end end rabl-0.16.1/lib/rabl/configuration.rb000066400000000000000000000077321432107571000174120ustar00rootroot00000000000000# We load the msgpack library if it is available. begin require 'msgpack' rescue LoadError end # We load the bson library if it is available. begin require 'bson' rescue LoadError end # We load the plist library if it is available. begin require 'plist' rescue LoadError end # Set default options for Oj json parser (if exists) begin require 'oj' Oj.default_options = { :mode => :compat, :time_format => :ruby, :use_to_json => true } rescue LoadError end module Rabl # Rabl.host class Configuration attr_accessor :include_json_root attr_accessor :include_child_root attr_accessor :include_msgpack_root attr_accessor :include_plist_root attr_accessor :include_xml_root attr_accessor :include_bson_root attr_accessor :enable_json_callbacks attr_accessor :bson_check_keys attr_accessor :bson_move_id attr_writer :json_engine attr_writer :msgpack_engine attr_writer :bson_engine attr_writer :plist_engine attr_writer :xml_options attr_accessor :cache_sources attr_accessor :cache_all_output attr_accessor :escape_all_output attr_accessor :view_paths attr_accessor :cache_engine attr_accessor :raise_on_missing_attribute attr_accessor :perform_caching attr_accessor :use_read_multi attr_accessor :replace_nil_values_with_empty_strings attr_accessor :replace_empty_string_values_with_nil_values attr_accessor :exclude_nil_values attr_accessor :exclude_empty_values_in_collections attr_accessor :camelize_keys DEFAULT_XML_OPTIONS = { :dasherize => true, :skip_types => false } def initialize @include_json_root = true @include_child_root = true @include_msgpack_root = true @include_plist_root = true @include_xml_root = false @include_bson_root = true @enable_json_callbacks = false @bson_check_keys = false @bson_move_id = false @json_engine = nil @msgpack_engine = nil @bson_engine = nil @plist_engine = nil @xml_options = {} @cache_sources = false @cache_all_output = false @escape_all_output = false @view_paths = [] @cache_engine = Rabl::CacheEngine.new @perform_caching = false @use_read_multi = true @replace_nil_values_with_empty_strings = false @replace_empty_string_values_with_nil_values = false @exclude_nil_values = false @exclude_empty_values_in_collections = false @camelize_keys = false end # @return The JSON engine used to encode Rabl templates into JSON def json_engine @json_engine || (defined?(::Oj) ? ::Oj : ::JSON) end ## # @return the MessagePack encoder/engine to use. def msgpack_engine @msgpack_engine || ::MessagePack end ## # @return the Bson encoder/engine to use. def bson_engine @bson_engine || ::BSON end ## # @return the Plist encoder/engine to use. def plist_engine @plist_engine || ::Plist::Emit end # Allows config options to be read like a hash # # @param [Symbol] option Key for a given attribute def [](option) __send__(option) end # Returns merged default and inputted xml options def default_xml_options @_default_xml_options ||= @xml_options.reverse_merge(DEFAULT_XML_OPTIONS) end end end rabl-0.16.1/lib/rabl/digestor.rb000066400000000000000000000016441432107571000163570ustar00rootroot00000000000000require 'action_view' module Rabl class Digestor < ActionView::Digestor # Override the original digest function to ignore partial which # rabl doesn't use the Rails conventional _ symbol. if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0.beta1') require 'rabl/digestor/rails5' elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1') require 'rabl/digestor/rails41' else require 'rabl/digestor/rails3' end private def dependency_digest template_digests = (dependencies - [template.virtual_path]).collect do |template_name| if Gem::Version.new(Rails.version) >= Gem::Version.new('4.1') Digestor.digest(:name => template_name, :finder => finder) else Digestor.digest(template_name, format, finder) end end (template_digests + injected_dependencies).join("-") end end end rabl-0.16.1/lib/rabl/digestor/000077500000000000000000000000001432107571000160255ustar00rootroot00000000000000rabl-0.16.1/lib/rabl/digestor/rails3.rb000066400000000000000000000005151432107571000175500ustar00rootroot00000000000000require 'action_view' module Rabl class Digestor < ActionView::Digestor def self.digest(name, format, finder, options = {}) cache_key = [name, format] + Array.wrap(options[:dependencies]) @@cache[cache_key.join('.')] ||= begin Digestor.new(name, format, finder, options).digest end end end end rabl-0.16.1/lib/rabl/digestor/rails41.rb000066400000000000000000000005441432107571000176340ustar00rootroot00000000000000require 'action_view' module Rabl class Digestor < ActionView::Digestor def self.digest(options = {}) cache_key = [options[:name]] + Array.wrap(options[:dependencies]) @@cache[cache_key.join('.')] ||= begin Digestor.new({ :name => options[:name], :finder => options[:finder] }.merge!(options)).digest end end end end rabl-0.16.1/lib/rabl/digestor/rails5.rb000066400000000000000000000001251432107571000175470ustar00rootroot00000000000000require 'action_view' module Rabl class Digestor < ActionView::Digestor end end rabl-0.16.1/lib/rabl/engine.rb000066400000000000000000000360641432107571000160100ustar00rootroot00000000000000module Rabl class Engine include Helpers include Partials include Helpers::Escaper # List of supported rendering formats FORMATS = [:json, :xml, :plist, :bson, :msgpack] SAFE_FORMATS = FORMATS + [:mpac, :dumpable, :hash] # Constructs a new ejs engine based on given vars, handler and declarations # Rabl::Engine.new("...source...", { :format => "xml", :root => true, :view_path => "/path/to/views" }) def initialize(source, options = {}) @_source = source @_settings = {} @_options = options @_view_path = options[:view_path] @_context_scope = options[:scope] @_cache_read_on_render = true end def source=(source) @_source = source end # Renders the representation based on source, object, context_scope and locals # Rabl::Engine.new("...source...", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user }) def apply(context_scope, locals, &block) locals = locals.dup unless locals.nil? set_instance_variables!(context_scope, locals) reset_settings! reset_options! eval_source(locals, &block) instance_exec(root_object, &block) if block_given? self end # Renders the representation based on a previous apply # Rabl::Engine.new("...source...", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user }).render def render(context_scope = nil, locals = nil, &block) apply(context_scope, locals, &block) if context_scope || locals || block cache_results do send("to_#{@_options[:format]}") end end def cache_key return unless defined?(@_cache_key) @_full_cache_key ||= begin cache_key = Array(@_cache_key) + [@_options[:root_name], @_options[:format]] if digestor_available? && respond_to?(:lookup_context) && lookup_context template = @_options[:template] || @virtual_path digest = if Rails.version.to_s =~ /^[67]/ Digestor.digest(name: template, finder: lookup_context, format: :rabl) elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1') Digestor.digest(:name => template, :finder => lookup_context) else Digestor.digest(template, :rabl, lookup_context) end cache_key << digest end cache_key end end # Returns a hash representation of the data object # to_hash(:root => true, :child_root => true) def to_hash(options = {}) options.reverse_merge!(@_options) data = root_object options[:root_name] = determine_object_root(data, root_name, options[:root]) result = if is_object?(data) || !data # object @user Builder.new(data, @_settings, options).to_hash elsif is_collection?(data) # collection @users MultiBuilder.new(data, @_settings, options).to_a end result = escape_output(result) if Rabl.configuration.escape_all_output result end def to_dumpable(options = {}) options.reverse_merge!({ :child_root => Rabl.configuration.include_child_root }) result = to_hash(options) result = { collection_root_name => result } if collection_root_name result end # Returns a json representation of the data object # to_json(:root => true) def to_json(options = {}) options.reverse_merge!({ :root => Rabl.configuration.include_json_root }) result = to_dumpable(options) format_json(result) end # Returns a msgpack representation of the data object # to_msgpack(:root => true) def to_msgpack(options = {}) options = { :root => Rabl.configuration.include_msgpack_root }.merge(options) result = to_dumpable(options) Rabl.configuration.msgpack_engine.pack(result) end alias_method :to_mpac, :to_msgpack # Returns a plist representation of the data object # to_plist(:root => true) def to_plist(options = {}) options = { :root => Rabl.configuration.include_plist_root }.merge(options) result = to_dumpable(options) Rabl.configuration.plist_engine.dump(result) end # Returns an xml representation of the data object # to_xml(:root => true) def to_xml(options = {}) options = { :root => (include_root = Rabl.configuration.include_xml_root), :child_root => include_root && Rabl.configuration.include_child_root }.merge(options) xml_options = Rabl.configuration.default_xml_options.merge(:root => collection_root_name || root_name) result = to_hash(options) result.to_xml(xml_options) end # Returns a bson representation of the data object # to_bson(:root => true) def to_bson(options = {}) options = { :root => Rabl.configuration.include_bson_root }.merge(options) result = to_dumpable(options) if !collection_root_name && is_collection?(root_object) && root_object.is_a?(Array) result = { root_name => result } end Rabl.configuration.bson_engine.serialize(result).to_s end # Sets the object to be used as the data source for this template # object(@user) # object @user => :person # object @users def object(template_data) current_data = (@_locals[:object].nil? || template_data == false) ? template_data : @_locals[:object] @_data_object = data_object(current_data) @_root_name_data = template_data.is_a?(Hash) && !current_data.is_a?(Hash) ? template_data : current_data @_root_name_data = @_root_name_data.values.first if @_root_name_data.is_a?(Hash) # If we turn this around, `@_root_name_date ==` may trigger data to be loaded unnecessarily. # TODO: is nil a different semantic? otherwise don't use `false ==`, use ! if false == @_root_name_data @_object_root_name = false @_collection_name = false end end # Returns the current object that is the topic of this template # Can be the collection or the object depending on topic assigned # root_object => @user def root_object return @_data_object if defined?(@_data_object) data = @_locals[:object].nil? ? default_object : @_locals[:object] @_data_object = data_object(data) end def root_name return @_data_name if defined?(@_data_name) @_data_name = @_options[:object_root_name] || begin data = defined?(@_root_name_data) ? @_root_name_data : (@_locals[:object].nil? ? root_object : @_locals[:object]) data_name(data) end end # Sets the object as a collection casted to a simple array # collection @users # collection @users => :people # collection @users, :root => :person # collection @users, :object_root => :person def collection(data, options = {}) @_collection_name = options[:root] if options[:root] @_collection_name ||= data.values.first if data.is_a?(Hash) @_object_root_name = options[:object_root] if options.has_key?(:object_root) object(data_object(data) || []) end # Sets the cache key to be used by ActiveSupport::Cache.expand_cache_key # cache @user # calls @user.cache_key # cache ['rabl', @user] # calls @user.cache_key and prefixes with rabl/ # cache 'user' # explicit key of 'user' # cache # uses the current item within a collection # cache 'user', expires_in: 1.hour # options is passed through to the cache store def cache(key = nil, options = {}) key ||= root_object # if called but missing, use object @_cache_key = key @_cache_options = options end # Indicates an attribute or method should be included in the json output # attribute :foo, :as => "bar" # attribute :foo => :bar, :bar => :baz # attribute :foo => :bar, :bar => :baz, :if => lambda { |r| r.foo } def attribute(*args) if args.first.is_a?(Hash) # :foo => :bar, :bar => :baz attr_aliases = args.first.except(:if, :unless) conditions = args.first.slice(:if, :unless) attr_aliases.each do |key, as| attribute(key, conditions.merge(:as => as)) end else # array of attributes i.e :foo, :bar, :baz options = args.extract_options! args.each do |name| @_settings[:attributes] << { :name => name, :options => options } end end end alias_method :attributes, :attribute # Creates an arbitrary node that is included in the json output. # node(:foo) { "bar" } # node(:foo, :if => lambda { ... }) { "bar" } def node(name = nil, options = {}, &block) @_settings[:node] << { :name => name, :options => options, :block => block } end alias_method :code, :node # Creates a child node that is included in json output # child(@user) { attribute :full_name } def child(data, options = {}, &block) @_settings[:child] << { :data => data, :options => options, :block => block } end # Glues data from a child node to the json_output # glue(@user) { attribute :full_name => :user_full_name } def glue(data, options = {}, &block) @_settings[:glue] << { :data => data, :options => options, :block => block } end # Extends an existing rabl template with additional attributes in the block # extends("users/show", :object => @user) { attribute :full_name } def extends(file, options = {}, &block) options.reverse_merge!({ :view_path => options[:view_path] || view_path }) @_settings[:extends] << { :file => file, :options => options, :block => block } end # Includes a helper module with a RABL template # helper ExampleHelper def helper(*klasses) klasses.each { |klass| self.class.__send__(:include, klass) } end alias_method :helpers, :helper # Returns a hash representing the partial # partial("users/show", :object => @user) # options must have :object # options can have :view_path, :child_root, :root def partial(file, options = {}, &block) engine = partial_as_engine(file, options, &block) engine = engine.render if engine.is_a?(Engine) engine end # Disables reading (but not writing) from the cache when rendering. def cache_read_on_render=(read) @_cache_read_on_render = read end def cache_read_on_render? @_cache_read_on_render end protected # Returns a guess at the default object for this template # default_object => @user def default_object return unless context_scope.respond_to?(:controller) controller_name = context_scope.controller.controller_name stripped_name = controller_name.split(%r{::|\/}).last ivar_object = instance_variable_get("@#{stripped_name}") ivar_object if is_object?(ivar_object) end # Returns a guess at the format in this context_scope # request_format => "xml" def request_format format = request_params[:format] if format.nil? && context_scope.respond_to?(:request) request = context_scope.request format = request.format.to_sym.to_s if request.respond_to?(:format) end format = "json" unless format && respond_to?("to_#{format}") format end # Returns the request parameters if available in the context_scope # request_params => { :foo => "bar" } def request_params (context_scope.params if context_scope.respond_to?(:params)) || {} end # Returns data as json embraced with callback when detected # format_json({ :foo => "bar" }) => "test({ foo : 'bar' })" # format_json("{ foo : "bar" }") => "test({ foo : 'bar' })" def format_json(json_output) unless json_output.is_a?(String) json_engine = Rabl.configuration.json_engine json_output = if json_engine.respond_to?(:dump) json_engine.dump(json_output) else json_engine.encode(json_output) end end use_callback = Rabl.configuration.enable_json_callbacks && request_params[:callback].present? json_output = "#{request_params[:callback]}(#{json_output})" if use_callback json_output end # Augments respond to supporting context_scope methods def respond_to?(name, include_private = false) context_scope.respond_to?(name, include_private) || super end # Supports calling helpers defined for the template context_scope using method_missing hook def method_missing(name, *args, **kwargs, &block) return super unless context_scope.respond_to?(name, true) if kwargs.empty? context_scope.__send__(name, *args, &block) else context_scope.__send__(name, *args, **kwargs, &block) end end def copy_instance_variables_from(object, exclude = []) #:nodoc: vars = object.instance_variables - exclude vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) } end def reset_settings! @_settings[:attributes] = [] @_settings[:node] = [] @_settings[:child] = [] @_settings[:glue] = [] @_settings[:extends] = [] end # Resets the options parsed from a rabl template. def reset_options! @_options[:root_name] = nil @_options[:read_multi] = false @_options[:scope] = context_scope end # Caches the results of the block based on object cache_key # cache_results { compile_hash(options) } def cache_results(&block) return yield unless template_cache_configured? && defined?(@_cache_key) if cache_read_on_render? fetch_result_from_cache(cache_key, @_cache_options, &block) else write_result_to_cache(cache_key, @_cache_options, &block) end end def digestor_available? defined?(Rails) && Rails.version =~ /^[4567]/ end def valid_format?(format) SAFE_FORMATS.include?(format.to_sym) && respond_to?("to_#{format}") end def set_instance_variables!(context_scope, locals) @_context_scope = context_scope @_locals = locals || {} copy_instance_variables_from(context_scope, [:@assigns, :@helpers]) @_options[:format] ||= request_format # Prevent calls to inherited methods `to_yaml`, `to_enum`, etc. @_options[:format] = 'json' unless valid_format?(@_options[:format]) set_locals(@_locals) end def set_locals(locals) locals.merge!(locals.delete(:locals) || {}) locals.each { |key, value| instance_variable_set(:"@#{key}", value) } end def eval_source(locals, &block) return unless @_source.present? msg = "cached_source_#{@_source.hash.abs}" unless self.respond_to? msg then src = "def #{msg} locals, &block\n#{@_source}\nend" if @_options[:source_location] self.class.class_eval(src, @_options[:source_location]) else self.class.class_eval(src) end end send msg, locals, &block end end end rabl-0.16.1/lib/rabl/helpers.rb000066400000000000000000000147041432107571000162020ustar00rootroot00000000000000require 'active_support/inflector' # for the sake of pluralizing module Rabl module Helpers # data_object(data) => # data_object(@user => :person) => @user # data_object(:user => :person) => @_object.send(:user) def data_object(data) data = data.keys.first if data.is_a?(Hash) && data.keys.size == 1 data = @_object.__send__(data) if data.is_a?(Symbol) && defined?(@_object) && @_object && @_object.respond_to?(data) data end # data_object_attribute(data) => @_object.send(data) def data_object_attribute(data) attribute = @_object.__send__(data) attribute = attribute.as_json if is_collection?(attribute, false) && attribute.respond_to?(:as_json) attribute end # data_name(data) => "user" # data_name(@user => :person) => :person # data_name(@users) => :user # data_name([@user]) => "users" # data_name([]) => "array" def data_name(data_token) return unless data_token # nil or false return data_token.values.first if data_token.is_a?(Hash) # @user => :user data = data_object(data_token) if is_collection?(data) # data is a collection object_name = collection_root_name if collection_root_name object_name ||= data.table_name if data.respond_to?(:table_name) if object_name.nil? && data.respond_to?(:first) first = data.first object_name = data_name(first).to_s.pluralize if first.present? end object_name ||= data_token if data_token.is_a?(Symbol) object_name elsif is_object?(data) # data is an object object_name = object_root_name if object_root_name object_name ||= data if data.is_a?(Symbol) object_name ||= collection_root_name.to_s.singularize if collection_root_name object_name ||= data.class.respond_to?(:model_name) ? data.class.model_name.element : data.class.to_s.downcase object_name else data_token end end # Returns the object rootname based on if the root should be included # Can be called with data as a collection or object # determine_object_root(@user, :user, true) => "user" # determine_object_root(@user, :person) => "person" # determine_object_root([@user, @user]) => "user" def determine_object_root(data_token, data_name = nil, include_root = true) return if object_root_name == false root_name = data_name.to_s if include_root if is_object?(data_token) || data_token.nil? root_name elsif is_collection?(data_token) object_root_name || (root_name.singularize if root_name) end end # Returns true if obj is not a collection # is_object?(@user) => true # is_object?([]) => false # is_object?({}) => false def is_object?(obj, follow_symbols = true) obj && !is_collection?(obj, follow_symbols) end # Returns true if the obj is a collection of items # is_collection?(@user) => false # is_collection?([]) => true def is_collection?(obj, follow_symbols = true) data_obj = follow_symbols ? data_object(obj) : obj data_obj && data_obj.respond_to?(:map) && data_obj.respond_to?(:each) && !(data_obj.is_a?(Struct) || defined?(Hashie::Mash) && data_obj.is_a?(Hashie::Mash)) end # Returns the context_scope wrapping this engine, used for retrieving data, invoking methods, etc # In Rails, this is the controller and in Padrino this is the request context def context_scope defined?(@_context_scope) ? @_context_scope : nil end def view_path defined?(@_view_path) ? @_view_path : nil end # Returns the root (if any) name for an object within a collection # Sets the name of the object i.e "person" # => { "users" : [{ "person" : {} }] } def object_root_name defined?(@_object_root_name) ? @_object_root_name : nil end # Returns the root for the collection # Sets the name of the collection i.e "people" # => { "people" : [] } def collection_root_name defined?(@_collection_name) ? @_collection_name : nil end # Returns true if the value is a name value (symbol or string) def is_name_value?(val) val.is_a?(String) || val.is_a?(Symbol) end # Returns an Engine based representation of any data object given ejs template block # object_to_engine(@user) { attribute :full_name } => { ... } # object_to_engine(@user, :source => "...") { attribute :full_name } => { ... } # object_to_engine([@user], :source => "...") { attribute :full_name } => { ... } # options must have :source (rabl file contents) # options can have :source_location (source filename) def object_to_engine(object, options = {}, &block) return if object.nil? options.reverse_merge!({ :format => "hash".freeze, :view_path => view_path, :root => (options[:root] || false) }) Engine.new(options[:source], options).apply(context_scope, :object => object, :locals => options[:locals], &block) end # Fetches a key from the cache and stores rabl template result otherwise # fetch_from_cache('some_key') { ...rabl template result... } def fetch_result_from_cache(cache_key, cache_options = {}, &block) expanded_cache_key = ActiveSupport::Cache.expand_cache_key(cache_key, :rabl) Rabl.configuration.cache_engine.fetch(expanded_cache_key, cache_options, &block) end def write_result_to_cache(cache_key, cache_options = {}, &block) expanded_cache_key = ActiveSupport::Cache.expand_cache_key(cache_key, :rabl) result = yield Rabl.configuration.cache_engine.write(expanded_cache_key, result, cache_options) result end # Returns true if the cache has been enabled for the application def template_cache_configured? if defined?(Rails) defined?(ActionController::Base) && ActionController::Base.perform_caching else Rabl.configuration.perform_caching end end module Escaper def escape_output(response) case response when Hash response.each{|k,v| response[k] = escape_value(v) } when Array response.map!{|v| escape_value(v) } else response end end def escape_value(value) case value when String ERB::Util.h(value) when Array, Hash escape_output(value) else value end end end end end rabl-0.16.1/lib/rabl/multi_builder.rb000066400000000000000000000055021432107571000173740ustar00rootroot00000000000000module Rabl class MultiBuilder include Helpers # Constructs a new MultiBuilder given the data and options. # The options will be re-used for all Rabl::Builders. # Rabl::MultiBuilder.new([#, #, ...], { :format => 'json', :child_root => true }) def initialize(data, settings = {}, options = {}) @data = data @settings = settings @options = options @builders = [] @engine_to_builder = {} @cache_key_to_engine = {} end # Returns the result of all of the builders as an array def to_a generate_builders if template_cache_configured? && Rabl.configuration.use_read_multi map_engines_to_builders read_cache_results replace_engines_with_cache_results end result = @builders.map(&:to_hash) result = result.map(&:presence).compact if Rabl.configuration.exclude_empty_values_in_collections result end private # Creates a builder for each of the data objects # and maps the cache keys for each of the engines # the builders generated def generate_builders @builders = @data.map do |object| Builder.new(object, @settings, @options) end end def map_engines_to_builders @builders.each do |builder| builder.engines.each do |engine| @engine_to_builder[engine] = builder map_cache_key_to_engine(engine) end end end # Maps a cache key to an engine def map_cache_key_to_engine(engine) if cache_key = cache_key_for(engine) result_cache_key = ActiveSupport::Cache.expand_cache_key(cache_key, :rabl) @cache_key_to_engine[result_cache_key] = engine disable_cache_read_on_render(engine) end end def disable_cache_read_on_render(engine) case engine when Hash disable_cache_read_on_render(engine.values.first) when Engine engine.cache_read_on_render = false end end def cache_key_for(engine) case engine when Hash cache_key_for(engine.values.first) when Engine engine.cache_key end end # Returns the items that were found in the cache def read_cache_results @cache_results ||= begin mutable_keys = @cache_key_to_engine.keys.map { |k| k.dup } if mutable_keys.empty? {} else Rabl.configuration.cache_engine.read_multi(*mutable_keys) end end end # Maps the results from the cache back to the builders def replace_engines_with_cache_results @cache_results.each do |key, value| engine = @cache_key_to_engine[key] builder = @engine_to_builder[engine] builder.replace_engine(engine, value) if value end end end end rabl-0.16.1/lib/rabl/partials.rb000066400000000000000000000010741432107571000163530ustar00rootroot00000000000000module Rabl module Partials include Helpers include Sources def partial_as_engine(file, options = {}, &block) raise ArgumentError, "Must provide an :object option to render a partial" unless options.has_key?(:object) object = options.delete(:object) view_path = options[:view_path] || self.view_path source, location = fetch_source(file, :view_path => view_path) options = options.merge(:source => source, :source_location => location, :template => file) object_to_engine(object, options, &block) end end end rabl-0.16.1/lib/rabl/railtie.rb000066400000000000000000000017471432107571000161740ustar00rootroot00000000000000module Rabl class Railtie < Rails::Railtie initializer "rabl.initialize" do |app| # Force Rails to load view templates even in API mode # Stolen shamelessly from jbuilder: https://github.com/rails/jbuilder/blob/master/lib/jbuilder/railtie.rb if Rails::VERSION::MAJOR >= 5 module ::ActionController module ApiRendering include ActionView::Rendering end end ActiveSupport.on_load :action_controller do if self == ActionController::API include ActionController::Helpers include ActionController::ImplicitRender end end end ActiveSupport.on_load(:action_view) do Rabl.register! # Inject dependency tracker for :rabl if Rails.version =~ /^[4567]/ require 'action_view/dependency_tracker' ActionView::DependencyTracker.register_tracker :rabl, Rabl::Tracker end end end end # Railtie end # Rabl rabl-0.16.1/lib/rabl/renderer.rb000066400000000000000000000055621432107571000163500ustar00rootroot00000000000000module Rabl class Renderer # Defines class method rendering in supported formats # Rabl::Renderer.json(@post, 'posts/show') # Rabl::Renderer.xml(@post, 'posts/show') Rabl::Engine::FORMATS.each do |fmt| instance_eval <<-CODE def #{fmt}(object, source, options = {}) new(source, object, options.merge(:format => :#{fmt})).render end CODE end attr_reader :object, :options # Public: Instantiate a new renderer # This is a standalone class used for rendering rabl templates # outside of a framework like Rails. You may want to use # this when using Rabl to render the request objects passed to # message queues. # # Example: # renderer = Rabl::Renderer.new('template_name', user, { :format => 'json', :view_path => 'app/views' }) # renderer.render # => '{"user":{"name": "ivan" }}' # def initialize(source, object = nil, options = {}) options = { :format => :json, :scope => self, :view_path => [], :template => source }.merge(options) @options = options @object = object engine.source = process_source(source) end # Public: Actually render the template to the requested output format. # # - context_scope: # Override the render context_scope to the 'context_scope' object. Defaults to self. # # Returns: And object representing the tranformed object in the requested format. # e.g. json, xml, bson, plist def render(context_scope = nil) context_scope ||= options[:scope] || self set_object_instance_variable if context_scope == self locals = { :object => object }.merge(options.fetch(:locals, {})) engine.apply(context_scope, locals).render end protected def engine @engine ||= Rabl::Engine.new(nil, options) end # Returns the source given a relative template path def process_source(source) return source if source.is_a?(String) && source =~ /\n/ source, _ = engine.fetch_source(source, { :view_path => options[:view_path] }) source end # Internal: Sets an instance variable named after the class of `object` # # Example: # object.class.name # => User # set_object_instance_variable # => @user == object # def set_object_instance_variable instance_variable_set(:"@#{object_model_name}", object) end # Internal: Returns the model name for an object # # Example: # object.class.name # => User # object_model_name => "user" # def object_model_name item = object is_collection = item.is_a?(Array) item = item.first if is_collection name = item.class.name.underscore name = name.pluralize if is_collection name.split("/").last end end end rabl-0.16.1/lib/rabl/sources.rb000066400000000000000000000076721432107571000162310ustar00rootroot00000000000000module Rabl module Sources include Helpers # Returns source for a given relative file # fetch_source("show", :view_path => "...") => "...contents..." def fetch_source(file, options = {}) view_paths = Array(options[:view_path]) + Array(Rabl.configuration.view_paths) Rabl.source_cache(file, view_paths) do file_path = \ if defined?(Padrino) && context_scope.respond_to?(:settings) && context_scope.respond_to?(:resolve_template) fetch_padrino_source(file, options) elsif defined?(Rails) && context_scope.respond_to?(:view_paths) _view_paths = view_paths + Array(context_scope.view_paths.to_a) fetch_rails_source(file, options) || fetch_manual_template(_view_paths, file) elsif defined?(Sinatra) && context_scope.respond_to?(:settings) && context_scope.settings.respond_to?(:views) fetch_sinatra_source(file, options) else # generic template resolution fetch_manual_template(view_paths, file) end unless File.exist?(file_path.to_s) raise "Cannot find rabl template '#{file}' within registered (#{view_paths.map(&:to_s).inspect}) view paths!" end [File.read(file_path.to_s), file_path.to_s] end end private # Returns the rabl template path for padrino views using configured views def fetch_padrino_source(file, options = {}) view_path = Array(options[:view_path] || context_scope.settings.views) # use Padrino's own template resolution mechanism file_path, _ = context_scope.instance_eval { resolve_template(file) } # Padrino chops the extension, stitch it back on File.join(view_path.first.to_s, (file_path.to_s + ".rabl")) end # Returns the rabl template path for Rails, including special lookups for Rails 2 and 3 def fetch_rails_source(file, options = {}) # use Rails template resolution mechanism if possible (find_template) source_format = request_format if defined?(request_format) if source_format && context_scope.respond_to?(:lookup_context) # Rails 3 lookup_proc = lambda do |partial| if ActionPack::VERSION::MAJOR == 3 && ActionPack::VERSION::MINOR < 2 context_scope.lookup_context.find(file, [], partial) else # Rails 3.2 and higher # pull format directly from rails unless it is html request_format = context_scope.request.format.to_sym source_format = request_format unless request_format == :html context_scope.lookup_context.find(file, [], partial, [], { :formats => [source_format] }) end end template = lookup_proc.call(false) rescue nil template ||= lookup_proc.call(true) rescue nil template.identifier if template elsif source_format && context_scope.respond_to?(:view_paths) # Rails 2 template = context_scope.view_paths.find_template(file, source_format, false) template.filename if template end end # Returns the rabl template path for sinatra views using configured views def fetch_sinatra_source(file, options = {}) view_path = Array(options[:view_path] || context_scope.settings.views) fetch_manual_template(view_path, file) end # Returns the rabl template by looking up files within the view_path and specified file path def fetch_manual_template(view_path, file) Dir[File.join("{#{view_path.join(",")}}", "{#{file},#{partialized(file)}}" + ".{*.,}rabl")].first end # Returns a partialized version of a file path # partialized("v1/variants/variant") => "v1/variants/_variant" def partialized(file) partial_file = file.split(File::SEPARATOR) partial_file[-1] = "_#{partial_file[-1]}" unless partial_file[-1].start_with?("_") partial_file.join(File::SEPARATOR) end end # Partials end # Rabl rabl-0.16.1/lib/rabl/template.rb000066400000000000000000000046331432107571000163530ustar00rootroot00000000000000# TILT Template if defined?(Tilt) class RablTemplate < Tilt::Template def initialize_engine return if defined?(::Rabl) require_template_library 'rabl' end def prepare #left empty so each invocation has a new hash of options and new rabl engine for thread safety end def evaluate(context_scope, locals, &block) options = @options.merge(:source_location => file) ::Rabl::Engine.new(data, options).apply(context_scope, locals, &block).render end end Tilt.register 'rabl', RablTemplate end # Rails 2.X Template if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^2/ require 'action_view/base' require 'action_view/template' module ActionView module TemplateHandlers class RablHandler < TemplateHandler include Compilable def compile(template) %{ ::Rabl::Engine.new(#{template.source.inspect}, { :format => #{template.format.inspect} }). render(self, assigns.merge(local_assigns)) } end end end end ActionView::Template.register_template_handler :rabl, ActionView::TemplateHandlers::RablHandler end # Rails 3.X / 4.X / 5.X Template if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[345]/ module ActionView module Template::Handlers class Rabl class_attribute :default_format self.default_format = Mime[:json] def self.call(template) source = template.source %{ ::Rabl::Engine.new(#{source.inspect}). apply(self, assigns.merge(local_assigns)). render } end # call end # rabl class end # handlers end ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl end # Rails 6.X / 7.X Template if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[67]/ module ActionView module Template::Handlers class Rabl class_attribute :default_format self.default_format = :json def self.call(template, source) %{ ::Rabl::Engine.new(#{source.inspect}). apply(self, assigns.merge(local_assigns)). render } end # call end # rabl class end # handlers end ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl end rabl-0.16.1/lib/rabl/tracker.rb000066400000000000000000000024551432107571000161730ustar00rootroot00000000000000module Rabl # DependencyTracker for ActionView to support cache digest class Tracker # Matches: # extends "categories/show" EXTENDS_DEPENDENCY = / extends\s* # extends, followed by optional whitespace \(? # start an optional parenthesis for the extends call \s*["']([0-9a-z_\/\.]+) # the template name itself /x # Matches: # partial "categories/show" PARTIAL_DEPENDENCY = / partial\s* # partial, followed by optional whitespace \(? # start an optional parenthesis for the partial call \s*["']([0-9a-z_\/\.]+) # the template name itself /x def self.call(name, template) new(name, template).dependencies end def initialize(name, template) @name, @template = name, template end def dependencies (extends_dependencies + partial_dependencies).uniq end attr_reader :name, :template private :name, :template private def source template.source end def directory name.split("/")[0..-2].join("/") end def extends_dependencies source.scan(EXTENDS_DEPENDENCY).flatten end def partial_dependencies source.scan(PARTIAL_DEPENDENCY).flatten end end end rabl-0.16.1/lib/rabl/version.rb000066400000000000000000000000451432107571000162160ustar00rootroot00000000000000module Rabl VERSION = "0.16.1" end rabl-0.16.1/rabl.gemspec000066400000000000000000000022161432107571000150050ustar00rootroot00000000000000# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "rabl/version" Gem::Specification.new do |s| s.name = "rabl" s.version = Rabl::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Nathan Esquenazi"] s.email = ["nesquena@gmail.com"] s.homepage = "https://github.com/nesquena/rabl" s.summary = %q{General ruby templating with json, bson, xml and msgpack support} s.description = %q{General ruby templating with json, bson, xml and msgpack support} s.license = 'MIT' s.files = `git ls-files -z -- {*.md,MIT-LICENSE,lib}`.split("\x0").sort s.require_paths = ["lib"] if RUBY_VERSION < "1.9" s.add_dependency 'activesupport', '>= 2.3.14', '<= 4' else s.add_dependency "activesupport", '>= 2.3.14' end s.add_development_dependency 'riot', '~> 0.12.3' s.add_development_dependency 'rr' s.add_development_dependency 'rake' s.add_development_dependency 'tilt' s.add_development_dependency 'oj' s.add_development_dependency 'msgpack', '~> 1.0.0' s.add_development_dependency 'bson', '~> 1.7.0' s.add_development_dependency 'plist' end rabl-0.16.1/test.watchr000066400000000000000000000016571432107571000147210ustar00rootroot00000000000000ENV["WATCHR"] = "1" system 'clear' def run(cmd) puts(cmd) system cmd end def run_test_file(file) system('clear') run(%Q(ruby -I"lib:test" -rubygems #{file})) end def run_all_tests system('clear') run('rake test') end def related_test_files(path) Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ } end watch('test/teststrap\.rb') { run_all_tests } watch('test/(.*).*_test\.rb') { |m| run_test_file(m[0]) } watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } } # Ctrl-\ Signal.trap 'QUIT' do puts " --- Running all tests ---\n\n" run_all_tests end @interrupted = false # Ctrl-C Signal.trap 'INT' do if @interrupted then @wants_to_quit = true abort("\n") else puts "Interrupt a second time to quit" @interrupted = true Kernel.sleep 1.5 # raise Interrupt, nil # let the run loop catch it run_all_tests end end rabl-0.16.1/test/000077500000000000000000000000001432107571000134765ustar00rootroot00000000000000rabl-0.16.1/test/bson_engine_test.rb000066400000000000000000000261531432107571000173570ustar00rootroot00000000000000require File.expand_path('../teststrap', __FILE__) require 'rabl/template' context "Rabl::Engine" do helper(:rabl) { |t| RablTemplate.new("code", :format => 'bson') { t } } context "with bson defaults" do setup do Rabl.configure do |config| # Comment this line out because include_bson_root is default. #config.include_bson_root = true end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "\x10\x00\x00\x00\x03user\x00\x05\x00\x00\x00\x00\x00" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope).split("").sort end.equals "\x12\x00\x00\x00\x03person\x00\x05\x00\x00\x00\x00\x00".split("").sort end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope).split("").sort end.equals "7\x00\x00\x00\x04users\x00+\x00\x00\x00\x030\x00\x10\x00\x00\x00\x03user\x00\x05\x00\x00\x00\x00\x00\x031\x00\x10\x00\x00\x00\x03user\x00\x05\x00\x00\x00\x00\x00\x00\x00".split("").sort asserts "that it sets root node for objects" do template = rabl %{ collection @users => :people } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope).split("").sort end.equals "<\x00\x00\x00\x04people\x00/\x00\x00\x00\x030\x00\x12\x00\x00\x00\x03person\x00\x05\x00\x00\x00\x00\x00\x031\x00\x12\x00\x00\x00\x03person\x00\x05\x00\x00\x00\x00\x00\x00\x00".split("").sort end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "!\x00\x00\x00\x03user\x00\x16\x00\x00\x00\x02name\x00\a\x00\x00\x00irvine\x00\x00\x00".split("").sort asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "!\x00\x00\x00\x03user\x00\x16\x00\x00\x00\x02city\x00\a\x00\x00\x00irvine\x00\x00\x00".split("").sort asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "!\x00\x00\x00\x03user\x00\x16\x00\x00\x00\x02city\x00\a\x00\x00\x00irvine\x00\x00\x00".split("").sort end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new).split("").sort end.equals "\x12\x00\x00\x00\x02foo\x00\x04\x00\x00\x00bar\x00\x00".split("").sort asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new).split("").sort end.equals "\x05\x00\x00\x00\x00".split("").sort end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope).split("").sort end.equals "6\x00\x00\x00\x03user\x00+\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x03user\x00\x12\x00\x00\x00\x02city\x00\x03\x00\x00\x00LA\x00\x00\x00\x00".split("").sort asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope).split("").sort end.equals "8\x00\x00\x00\x03user\x00-\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x03person\x00\x12\x00\x00\x00\x02city\x00\x03\x00\x00\x00LA\x00\x00\x00\x00".split("").sort end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) template.render(scope).split("").sort end.equals "4\x00\x00\x00\x03user\x00)\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x02city\x00\x03\x00\x00\x00LA\x00\x10age\x00\f\x00\x00\x00\x00\x00".split("").sort end teardown do Rabl.reset_configuration! end end context "with bson_engine" do setup do class CustomEncodeEngine def self.serialize string 42 end end Rabl.configure do |config| config.bson_engine = CustomEncodeEngine end end asserts 'that it returns process by custom to_json' do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "42" teardown do Rabl.reset_configuration! end end context "without bson root" do setup do Rabl.configure do |config| config.include_bson_root = false end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "\x05\x00\x00\x00\x00" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "\x05\x00\x00\x00\x00" end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope).split("").sort end.equals "!\x00\x00\x00\x04users\x00\x15\x00\x00\x00\x030\x00\x05\x00\x00\x00\x00\x031\x00\x05\x00\x00\x00\x00\x00\x00".split("").sort asserts "that it sets root node for objects" do template = rabl %{ collection @users => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope).split("").sort end.equals "\"\x00\x00\x00\x04person\x00\x15\x00\x00\x00\x030\x00\x05\x00\x00\x00\x00\x031\x00\x05\x00\x00\x00\x00\x00\x00".split("").sort end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "\x16\x00\x00\x00\x02name\x00\a\x00\x00\x00irvine\x00\x00".split("").sort asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "\x16\x00\x00\x00\x02city\x00\a\x00\x00\x00irvine\x00\x00".split("").sort asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope).split("").sort end.equals "\x16\x00\x00\x00\x02city\x00\a\x00\x00\x00irvine\x00\x00".split("").sort end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new).split("").sort end.equals "\x12\x00\x00\x00\x02foo\x00\x04\x00\x00\x00bar\x00\x00".split("").sort asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new).split("").sort end.equals "\x05\x00\x00\x00\x00".split("").sort end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope).split("").sort end.equals "+\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x03user\x00\x12\x00\x00\x00\x02city\x00\x03\x00\x00\x00LA\x00\x00\x00".split("").sort asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope).split("").sort end.equals "-\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x03person\x00\x12\x00\x00\x00\x02city\x00\x03\x00\x00\x00LA\x00\x00\x00".split("").sort end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) template.render(scope).split("").sort end.equals ")\x00\x00\x00\x02name\x00\x04\x00\x00\x00leo\x00\x02city\x00\x03\x00\x00\x00LA\x00\x10age\x00\f\x00\x00\x00\x00".split("").sort end teardown do Rabl.reset_configuration! end end end rabl-0.16.1/test/builder_test.rb000066400000000000000000000430551432107571000165170ustar00rootroot00000000000000require File.expand_path('../teststrap', __FILE__) context "Rabl::Builder" do helper(:builder) { |*args| Rabl::Builder.new(*args) } helper(:build_hash) { |*args| builder(*args).to_hash } setup do @users = [User.new, User.new] @user = User.new builder(nil, nil, {:view_path => '/path/to/views'}) end context "#initialize" do asserts_topic.assigns :options asserts_topic.assigns :_view_path end context "#to_hash" do context "when given a simple object" do setup { builder(nil, { :attributes => [ { :name => :name } ] }) } asserts "that the object is set properly" do topic.to_hash(User.new, nil, :root_name => "user") end.equivalent_to({ "user" => { :name => "rabl" } }) end context "when given an object alias" do setup { builder(nil, { :attributes => [ { :name => :name, :options => { :as => :foo } } ] }) } asserts "that the object is set properly" do topic.to_hash(User.new, nil, :root_name => "person") end.equivalent_to({ "person" => { :foo => "rabl" } }) end context "when specified with no root" do setup { builder(nil, { :attributes => [ { :name => :name, :options => { :as => :name } } ] }) } asserts "that the object is set properly" do topic.to_hash(User.new, nil, :root => false) end.equivalent_to({ :name => "rabl" }) end context "when nil values are replaced with empty strings" do setup do Rabl.configuration.replace_nil_values_with_empty_strings = true builder(nil, { :attributes => [ { :name => :name } ], :node => [{ :name => :extra, :options => {}, :block => lambda { |u| { :twitter => u.twitter } } }] }) end asserts "that an empty string is returned as the value" do topic.to_hash(User.new(:name => nil, :twitter => nil)) end.equivalent_to({ :name => '', :extra => { :twitter => '' } }) asserts "that it handles existing non nil values correctly" do topic.to_hash(User.new(:name => 10, :twitter => 'twitter')) end.equivalent_to({ :name => 10, :extra => { :twitter => 'twitter' } }) teardown do Rabl.configuration.replace_nil_values_with_empty_strings = false end end context "when empty string values are replaced with nil values" do setup do Rabl.configuration.replace_empty_string_values_with_nil_values = true builder(nil, { :attributes => [ { :name => :name } ], :node => [{ :name => :extra, :options => {}, :block => lambda { |u| { :twitter => u.twitter } } }] }) end asserts "that nil is returned as the value" do topic.to_hash(User.new(:name => "", :twitter => '')) end.equivalent_to({ :name => nil, :extra => { :twitter => nil } }) asserts "that it handles existing nil values correctly" do topic.to_hash(User.new(:name => nil, :twitter => nil)) end.equivalent_to({ :name => nil, :extra => { :twitter => nil } }) asserts "that it handles existing non nil values correctly" do topic.to_hash(User.new(:name => 10, :twitter => 'twitter')) end.equivalent_to({ :name => 10, :extra => { :twitter => 'twitter' } }) teardown do Rabl.configuration.replace_empty_string_values_with_nil_values = false end end context "when nil values are excluded" do setup do Rabl.configuration.exclude_nil_values = true builder(nil, { :attributes => [ { :name => :name } ] }) end asserts "that an nil attribute is not returned" do topic.to_hash(User.new(:name => nil)) end.equivalent_to({ }) teardown do Rabl.configuration.exclude_nil_values = false end end context "when keys are camelized" do setup do Rabl.configuration.camelize_keys = true builder(nil, { :attributes => [ { :name => :first_pets_name } ] }) end asserts "that the key is camelized" do topic.to_hash(User.new) end.equivalent_to({ :firstPetsName => 'jack' }) teardown do Rabl.configuration.camelize_keys = false end end context "when keys are camelized with upper case first letter" do setup do Rabl.configuration.camelize_keys = :upper builder(nil, { :attributes => [ { :name => :first_pets_name } ] }) end asserts "that the key is camelized with upper case first letter" do topic.to_hash(User.new) end.equivalent_to({ :FirstPetsName => 'jack' }) teardown do Rabl.configuration.camelize_keys = false end end end context "#attribute" do asserts "that the node" do build_hash @user, :attributes => [ { :name => :name }, { :name => :city, :options => { :as => :city } } ] end.equivalent_to({:name => 'rabl', :city => 'irvine'}) context "that with a non-existent attribute" do context "when non-existent attributes are allowed by the configuration" do setup { stub(Rabl.configuration).raise_on_missing_attribute { false } } asserts "the node" do build_hash @user, :attributes => [ { :name => :fake } ] end.equals({}) end context "when non-existent attributes are forbidden by the configuration" do setup { stub(Rabl.configuration).raise_on_missing_attribute { true } } asserts "the node" do build_hash @user, :attributes => [ { :name => :fake } ] end.raises(RuntimeError) end end context "that with a string key" do setup { builder(nil, { :attributes => [ { :name => "name" } ] }) } asserts "the node name is converted to a symbol" do topic.to_hash(User.new, :name => "user") end.equivalent_to({ :name => "rabl" }) end context "that with the same node names as strings and symbols" do setup { builder(nil, { :attributes => [ { :name => "name" }, { :name => :name } ] }) } asserts "the nodes aren't duplicated" do topic.to_hash(User.new, :name => "user") end.equivalent_to({ :name => "rabl" }) end end context "#node" do asserts "that it has node :foo" do build_hash @user, :node => [{ :name => :foo, :options => {}, :block => lambda { |u| "bar" } }] end.equivalent_to({:foo => 'bar'}) asserts "that it excludes nodes in the :except list" do build_hash @user, {:node => [{ :name => :foo, :block => lambda { |u| "bar" } }]}, {except: [:foo]} end.equivalent_to({}) asserts "that it excludes nodes in the :except attribute" do build_hash @user, {:node => [{ :name => :foo, :block => lambda { |u| "bar" } }]}, {except: :foo} end.equivalent_to({}) asserts "that it has node not in except list" do build_hash @user, {:node => [{ :name => :foo, :block => lambda { |u| "bar" } }]}, {except: [:unknown]} end.equivalent_to({:foo => 'bar'}) asserts "that it has multiple nodes" do build_hash(@user, {:node => [{ :name => :foo, :block => lambda { |u| "bar" } }, {:name => :baz, :block => lambda{|_u| "bar"}}, {:name => :bam, :block => lambda{|_u| "boom"}}]}, {except: [:unknown, :baz]}) end.equivalent_to({:foo => 'bar', :bam => 'boom'}) asserts "that using object it has node :boo" do build_hash @user, :node => [ { :name => :foo, :options => {}, :block => lambda { |u| "bar" } }, { :name => :baz, :options => {}, :block => lambda { |u| u.city } } ] end.equivalent_to({:foo => 'bar', :baz => 'irvine'}) asserts "that it converts the node name to a symbol" do build_hash @user, :node => [{ :name => "foo", :options => {}, :block => lambda { |u| "bar" } }] end.equivalent_to({:foo => 'bar'}) asserts "that the same node names as a string and symbol aren't duplicated" do build_hash @user, :node => [ { :name => "foo", :options => {}, :block => lambda { |u| "bar" } }, { :name => :foo, :options => {}, :block => lambda { |u| "bar" } } ] end.equivalent_to({:foo => 'bar'}) end context "#child" do asserts "that it generates if no data present" do builder(nil, :child => []).to_hash(@user) end.equals({}) asserts "that it generates with a hash" do b = builder(nil, :child => [ { :data => { @user => :user }, :options => { }, :block => lambda { |u| attribute :name } } ]) b.to_hash(@user) end.equivalent_to({ :user => { :name => "rabl" } }) asserts "that it generates with a hash alias" do b = builder nil, :child => [{ :data => { @user => :person }, :options => {}, :block => lambda { |u| attribute :name } }] b.to_hash(@user) end.equivalent_to({ :person => { :name => "rabl" } }) asserts "that it generates with an object" do b = builder nil, :child => [{ :data => @user, :options => {}, :block => lambda { |u| attribute :name } }] e = Rabl::Engine.new('') mock(b).data_name(@user) { :user } mock(e).render.returns('xyz') mock(b).object_to_engine(@user, { :root => false }).returns(e).subject b.to_hash(@user) end.equivalent_to({ :user => 'xyz'}) asserts "that it generates with an collection and child_root" do b = builder nil, { :child => [{ :data => @users, :options => {}, :block => lambda { |u| attribute :name } }] }, { :child_root => true } e = Rabl::Engine.new('') mock(b).data_name(@users) { :users } mock(e).render.returns('xyz') mock(b).object_to_engine(@users, { :root => true, :child_root => true }).returns(e).subject b.to_hash(@user) end.equivalent_to({ :users => 'xyz'}) asserts "that it generates with an collection and no child root" do b = builder nil, { :child => [{ :data => @users, :options => {}, :block => lambda { |u| attribute :name } }] }, { :child_root => false } e = Rabl::Engine.new('') mock(b).data_name(@users) { :users } mock(e).render.returns('xyz') mock(b).object_to_engine(@users, { :root => false, :child_root => false }).returns(e).subject b.to_hash(@user) end.equivalent_to({ :users => 'xyz'}) asserts "that it generates with an collection and a specified object_root_name and root" do ops = { :object_root => "person", :root => :people } b = builder nil, { :child => [{ :data => @users, :options => ops, :block => lambda { |u| attribute :name } }] }, { :child_root => true } e = Rabl::Engine.new('') mock(e).render.returns('xyz') mock(b).object_to_engine(@users, { :root => "person", :object_root_name => "person", :child_root => true }).returns(e).subject b.to_hash(@user) end.equivalent_to({ :people => 'xyz'}) asserts "that it converts the child name to a symbol" do b = builder(nil, :child => [ { :data => { @user => "user" }, :options => { }, :block => lambda { |u| attribute :name } } ]) b.to_hash(@user) end.equivalent_to({ :user => { :name => "rabl" } }) asserts "that it does't duplicate childs with the same name as a string and symbol" do b = builder(nil, :child => [ { :data => { @user => "user" }, :options => { }, :block => lambda { |u| attribute :name } }, { :data => { @user => :user }, :options => { }, :block => lambda { |u| attribute :name } } ]) b.to_hash(@user) end.equivalent_to({ :user => { :name => "rabl" } }) end context "#glue" do asserts "that it generates if no data present" do builder(nil, :glue => []).to_hash(@user) end.equals({}) asserts "that it generates the glue attributes" do b = builder nil, :glue => [{ :data => @user, :options => {}, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('') mock(e).render.returns({:user => 'xyz'}) mock(b).object_to_engine(@user, :root => false).returns(e).subject b.to_hash(@user) end.equivalent_to({ :user => 'xyz' }) asserts "that it appends the glue attributes to result" do b = builder nil, :glue => [{ :data => @user, :options => {}, :block => lambda { |u| attribute :name => :user_name }}] b.to_hash(@user) end.equivalent_to({ :user_name => 'rabl' }) asserts "that it does not generate new attributes if no glue attributes are present" do b = builder nil, :glue => [{ :data => @user, :options => {}, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('') mock(e).render.returns({}) mock(b).object_to_engine(@user, :root => false).returns(e).subject b.to_hash(@user) end.equals({}) end context "#extends" do asserts "that it does not generate if no data is present" do b = builder nil, :extends => [{ :file => 'users/show', :options => {}, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('users/show') mock(b).partial_as_engine('users/show',{ :object => @user}).returns(e) mock(e).render.returns({}).subject b.to_hash(@user) end.equals({}) asserts "that it generates if data is present" do b = builder nil, :extends => [{ :file => 'users/show', :options => {}, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('users/show') mock(b).partial_as_engine('users/show',{ :object => @user}).returns(e) mock(e).render.returns({:user => 'xyz'}).subject b.to_hash(@user) end.equivalent_to({:user => 'xyz'}) asserts "that it generates if local data is present but object is false" do b = builder nil, :extends => [{ :file => 'users/show', :options => { :object => @user }, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('users/show') mock(b).partial_as_engine('users/show',{ :object => @user}).returns(e) mock(e).render.returns({:user => 'xyz'}).subject b.to_hash(false) end.equivalent_to({:user => 'xyz'}) asserts "that it generates with exclude 'except' option" do b = builder nil, :extends => [{ :file => 'users/show', :options => { :except => :user_id }, :block => lambda { |u| attribute :name }}] e = Rabl::Engine.new('users/show') mock(b).partial_as_engine('users/show',{ :object => @user, except: :user_id}).returns(e) mock(e).render.returns({:user => 'xyz'}).subject b.to_hash(@user) end.equivalent_to({:user => 'xyz'}) end context "#resolve_conditionals" do class ArbObj def cool? false end def smooth? true end end asserts "that it can use symbols on if condition and return false if method returns false" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => :cool? }) end.equals(false) asserts "that it can use symbols on if condition and return true if method returns true" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :if => :smooth? } end.equals(true) asserts "that it can use symbols as unless condition and return true if method returns false" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :unless => :cool? } end.equals(true) asserts "that it can use symbols as unless condition and return false if method returns true" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :unless => :smooth? } end.equals(false) asserts "that it can use :unless and :if at the same time and return true when if is true and unless is false" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :if => true, :unless => false } end.equals(true) asserts "that it can use :unless and :if at the same time and return false when if is false and unless is false" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :if => false, :unless => false } end.equals(false) asserts "that it can use :unless and :if at the same time and return false when if is true and unless is true" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :if => true, :unless => true } end.equals(false) asserts "that it can use :unless and :if at the same time and return false when if is false and unless is true" do scope = Rabl::Builder.new(ArbObj.new) scope.send :resolve_condition, { :if => false, :unless => true } end.equals(false) asserts "that it can use lambda on if condition and return false if lambda returns false" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => lambda { |obj| false } }) end.equals(false) asserts "that it can use lambda on if condition and return true if lambda returns true" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => lambda { |obj| true } }) end.equals(true) asserts "that it can use proc on if condition and return false if proc returns false" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => proc { false } }) end.equals(false) asserts "that it can use proc on if condition and return true if proc returns true" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => proc { true } }) end.equals(true) asserts "that it can use a variable on if condition and return true if variable is truthy" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => 'Im truthy' }) end.equals('Im truthy') asserts "that it can use a variable on if condition and return false if variable is falsy" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => nil }) end.equals(nil) asserts "that it can use a hash variable on if condition and return true" do scope = Rabl::Builder.new(ArbObj.new) scope.send(:resolve_condition, { :if => { some: 'data' } }) end.equals({some: 'data'}) end end rabl-0.16.1/test/configuration_test.rb000066400000000000000000000050441432107571000177340ustar00rootroot00000000000000require File.expand_path('../teststrap', __FILE__) context 'Rabl::Configuration' do context 'defaults' do # multi_json compatibility TODO helper(:json_engine) { ::Oj } setup { Rabl.configuration } asserts(:include_json_root).equals true asserts(:include_child_root).equals true asserts(:include_xml_root).equals false asserts(:enable_json_callbacks).equals false asserts(:view_paths).equals [] asserts(:json_engine).equals { json_engine } asserts(:cache_engine).is_a?(Rabl::CacheEngine) asserts(:replace_nil_values_with_empty_strings).equals false asserts(:replace_empty_string_values_with_nil_values).equals false asserts(:exclude_nil_values).equals false asserts(:exclude_empty_values_in_collections).equals false end context 'custom JSON engine configured as Symbol' do setup do Rabl.configure do |c| c.json_engine = :oj end end asserts('uses a custom JSON engine') { topic.json_engine.to_s =~ /oj/i } end # custom json, symbol context 'custom JSON engine configured as Class' do setup do Rabl.configure do |c| c.json_engine = ActiveSupport::JSON end end asserts('uses a custom JSON engine') { topic.json_engine.to_s == 'ActiveSupport::JSON' } end # custom JSON, class context 'raise on missing attributes' do setup do Rabl.configure do |c| c.raise_on_missing_attribute = true end end asserts(:raise_on_missing_attribute).equals true end # raise on missing context 'replace nil values with empty strings' do setup do Rabl.configure do |c| c.replace_nil_values_with_empty_strings = true end end asserts(:replace_nil_values_with_empty_strings).equals true end # replace nil values with empty strings context 'replace empty string values with nil values' do setup do Rabl.configure do |c| c.replace_empty_string_values_with_nil_values = true end end asserts(:replace_empty_string_values_with_nil_values).equals true end # replace empty string values with nil values context 'exclude nil values' do setup do Rabl.configure do |c| c.exclude_nil_values = true end end asserts(:exclude_nil_values).equals true end # exclude nil values context 'exclude empty values in collections' do setup do Rabl.configure do |c| c.exclude_empty_values_in_collections = true end end asserts(:exclude_empty_values_in_collections).equals true end # exclude empty values in collections end rabl-0.16.1/test/engine_test.rb000066400000000000000000000727651432107571000163500ustar00rootroot00000000000000require 'json' require File.expand_path('../teststrap', __FILE__) require 'rabl/template' require File.expand_path('../models/ormless', __FILE__) context "Rabl::Engine" do helper(:rabl) { |t| RablTemplate.new { t } } # context_scope 'users', [@user] helper(:context_scope) { |name, value| scope = Object.new stub(scope).controller { stub(Object).controller_name { name } } scope.instance_variable_set :"@#{name}", value scope } context "#initialize" do setup do Rabl::Engine.new("...source...", { :format => 'xml', :root => true, :view_path => '/path/to/views' }) end asserts_topic.assigns :_source asserts_topic.assigns :_options asserts_topic.assigns :_view_path end context "#apply" do denies("that it raises exception when given frozen locals").raises(RuntimeError) do Rabl::Engine.new("").apply(Object.new, {}.freeze) end asserts "that it can call method in block without arguments" do template = RablTemplate.new("code") { 'node(:foo) { func }' } obj = Object.new def obj.func "bar" end template.render(obj) end.equals "{\"foo\":\"bar\"}" asserts "that it can call method in block with positional arguments" do template = RablTemplate.new("code") { 'node(:foo) { func("bar") }' } obj = Object.new def obj.func(arg) "#{arg}" end template.render(obj) end.equals "{\"foo\":\"bar\"}" asserts "that it can call method in block with positional and keyword arguments" do template = RablTemplate.new("code") { 'node(:foo) { func("bar", kw: "baz") }' } obj = Object.new def obj.func(arg, kw:) "#{arg}-#{kw}" end template.render(obj) end.equals "{\"foo\":\"bar-baz\"}" end context "#request_format" do context "is json by default" do setup do template = RablTemplate.new("code") { 'node(:foo) { "bar" }' } template.render(Object.new) end asserts_topic.equivalent_to('{"foo":"bar"}') end context "with a specified format" do setup do template = RablTemplate.new("code", :format => 'xml') { 'node(:foo) { "bar" }' } template.render(Object.new) end asserts_topic.includes('bar') end context "don't allow calls to inherited methods; default to JSON" do code = 'node(:foo) { "bar" }' expected_json = '{"foo":"bar"}' setup do template = RablTemplate.new("code", :format => 's') { code } template.render(Object.new) end asserts_topic.equivalent_to(expected_json) setup do template = RablTemplate.new("code", :format => 'ruby') { code } template.render(Object.new) end asserts_topic.equivalent_to(expected_json) setup do template = RablTemplate.new("code", :format => 'enum') { code } template.render(Object.new) end asserts_topic.equivalent_to(expected_json) end end context "#cache" do context "with cache" do setup do template = Rabl::Engine.new(%q{ cache 'foo' }) template.render(Object.new) template end asserts_topic.assigns(:_cache_key) { 'foo' } end context "with cache and options" do setup do template = Rabl::Engine.new(%q{ cache 'foo', :expires_in => 'bar' }) template.render(Object.new) template end asserts_topic.assigns(:_cache_key) { 'foo' } asserts_topic.assigns(:_cache_options) { { :expires_in => 'bar' } } end context "without cache" do setup do template = Rabl::Engine.new("") template.render(Object.new) template end denies(:instance_variable_defined?, :@_cache_key) end end context "with defaults" do setup do Rabl.configure do |config| config.include_json_root = true config.include_xml_root = false config.enable_json_callbacks = false end end context "#cache" do asserts "does not modify output" do template = rabl %q{ object @user cache @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "{\"user\":{}}" end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "{\"user\":{}}" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "{\"person\":{}}" asserts "that it can set root node with a nil object and explicit name" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, nil template.render(scope) end.equals "{\"person\":{}}" asserts "that it can set false root node" do template = rabl %q{ object @user => false } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "{}" asserts "that it can set false root node and correctly render object without root node" do template = rabl %q{ object @user => false attribute :name } user = User.new(:name => "John Doe") scope = Object.new scope.instance_variable_set :@user, user template.render(scope) end.equals "{\"name\":\"John Doe\"}" asserts "that it can use non-ORM objects" do template = rabl %q{ object @other } scope = Object.new scope.instance_variable_set :@other, Ormless.new template.render(scope) end.equals "{\"ormless\":{}}" asserts "that it works with nested controllers" do template = rabl "" scope = NestedScope::User.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "{}" end context "#collection" do asserts "that it sets object to be blank array" do template = rabl %{ collection [] } scope = Object.new template.render(scope) end.equals "[]" asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "[{\"user\":{}},{\"user\":{}}]" asserts "that it sets root node for objects" do template = rabl %{ collection @users => :people } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"people\":[{\"person\":{}},{\"person\":{}}]}" asserts "that it doesn't set root node for objects when specified" do template = rabl %{ collection @users, :root => :people, :object_root => false } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"people\":[{},{}]}" asserts "that it sets proper object and root names when specified" do template = rabl %{ collection @users, :root => :people, :object_root => :user } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"people\":[{\"user\":{}},{\"user\":{}}]}" asserts "that it can use non-ORM objects" do template = rabl %q{ object @others } scope = Object.new scope.instance_variable_set :@others, [Ormless.new, Ormless.new] template.render(scope) end.equals "[{\"ormless\":{}},{\"ormless\":{}}]" end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"name\":\"irvine\"}}") asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\"}}") asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\"}}") end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new) end.equals "{\"foo\":\"bar\"}" asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new) end.equals "{}" asserts "that it can merge the result with a collection element given no name" do template = rabl %{ collection @users code do |user| {:name => user.name} end } scope = Object.new scope.instance_variable_set :@users, [User.new(:name => 'a'), User.new(:name => 'b')] JSON.parse(template.render(scope)) end.equals JSON.parse("[{\"user\":{\"name\":\"a\"}},{\"user\":{\"name\":\"b\"}}]") asserts "that it can merge the result on a child node given no name" do template = rabl %{ object @user attribute :name child(@user) do code do |user| {:city => user.city} end end } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}}") end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}}") asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"name\":\"leo\",\"person\":{\"city\":\"LA\"}}}") asserts "that it passes the data object to the block" do template = rabl %{ object @user child(@user => :person) do |user| attribute :name if user.name == 'leo' end } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo') template.render(scope) end.equals "{\"user\":{\"person\":{\"name\":\"leo\"}}}" asserts "it sets root node for child collection" do template = rabl %{ object @user attribute :name child(@users) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')] template.render(scope) end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"user\":{\"city\":\"UNO\"}},{\"user\":{\"city\":\"DOS\"}}]}}" asserts "that it chooses a name based on symbol if no elements" do template = rabl %{ object @bar => :bar child(:foos) { attribute :city } } scope = Object.new bar = Object.new stub(bar).foos { [] } scope.instance_variable_set :@bar, bar template.render(scope) end.equals "{\"bar\":{\"foos\":[]}}" asserts "that it chooses a name based on symbol if nil" do template = rabl %{ object @bar => :bar child(:foos) { attribute :city } } scope = Object.new bar = Object.new stub(bar).foos { nil } scope.instance_variable_set :@bar, bar template.render(scope) end.equals "{\"bar\":{\"foos\":null}}" asserts "it allows suppression of root node for child collection" do template = rabl %{ object @user attribute :name child(@users, :object_root => false) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')] template.render(scope) end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"city\":\"UNO\"},{\"city\":\"DOS\"}]}}" asserts "it allows modification of object root node for child collection" do template = rabl %{ object @user attribute :name child(@users, :object_root => 'person') { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')] template.render(scope) end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"person\":{\"city\":\"UNO\"}},{\"person\":{\"city\":\"DOS\"}}]}}" asserts "it allows modification of both labels for a child collection" do template = rabl %{ object @user attribute :name child(@users, :root => "people", :object_root => 'item') { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')] template.render(scope) end.equals "{\"user\":{\"name\":\"leo\",\"people\":[{\"item\":{\"city\":\"UNO\"}},{\"item\":{\"city\":\"DOS\"}}]}}" end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"user\":{\"name\":\"leo\",\"city\":\"LA\",\"age\":12}}") asserts "that it passes the data object to the block" do template = rabl %{ object @user glue(@user) {|user| attribute :age if user.name == 'leo' } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :age => 12) template.render(scope) end.equals "{\"user\":{\"age\":12}}" end context "#partial" do asserts "that it creates object from partial and passes local" do template = rabl %{ object false node :foo do partial("foo/bar", :object => @user, :locals => { :foo => "bar" }) end } scope = Object.new @user = User.new(:name => 'leo', :city => 'LA', :age => 12) scope.instance_variable_set :@user, @user e = Rabl::Engine.new(nil) mock(e).render.returns({ :name => 'leo', :city => 'LA', :age => 12 }) any_instance_of(Rabl::Engine) do |b| mock(b).fetch_source("foo/bar", :view_path => nil).once mock(b).object_to_engine(@user, { :locals => { :foo => "bar" }, :source => nil, :source_location => nil, :template => 'foo/bar' }).returns(e) end JSON.parse(template.render(scope)) end.equals JSON.parse("{ \"foo\" : {\"name\":\"leo\",\"city\":\"LA\",\"age\":12} }") end teardown do Rabl.reset_configuration! end end # with json root context "without json root" do setup do Rabl.configure do |config| config.include_json_root = false config.include_xml_root = false config.enable_json_callbacks = false end end context "#object" do asserts "that it sets default object" do template = rabl %{ attribute :name } scope = context_scope('user', User.new) template.render(scope).split end.equals "{\"name\":\"rabl\"}".split asserts "that it does not set a collection as default object" do template = rabl %{ attribute :name } scope = context_scope('user', []) template.render(scope).split end.equals "{}".split asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "{}" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "{}" asserts "that it can set root node with a nil object and explicit name" do template = rabl %q{ object @user => :person attributes :name } scope = Object.new scope.instance_variable_set :@user, nil template.render(scope) end.equals "{}" end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "[{},{}]" asserts "that it sets root node for objects using hash" do template = rabl %{ collection @users => :people } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"people\":[{},{}]}" asserts "that it sets root node for objects using root option" do template = rabl %{ collection @users, :root => :people } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"people\":[{},{}]}" asserts "that it sets root node for objects using object_root option" do template = rabl %{ collection @users, :root => :humans, :object_root => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals %Q^{"humans":[{"person":{}},{"person":{}}]}^ end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "{\"name\":\"irvine\"}" asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "{\"city\":\"irvine\"}" asserts "that it exposes root_object" do template = rabl %q{ object @user attribute :name, :as => root_object.city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "{\"irvine\":\"irvine\"}" asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "{\"city\":\"irvine\"}" asserts "that it handle structs correctly as child elements" do template = rabl %{ object @user child(:city) do attributes :name end } City = Struct.new(:name) scope = Object.new scope.instance_variable_set :@user, User.new(:city => City.new('San Francisco')) template.render(scope) end.equals "{\"city\":{\"name\":\"San Francisco\"}}" asserts "that it can be passed an if cond for single real attr" do template = rabl %{ object @user attribute :name attributes :age, :first, :if => lambda { |i| i.name != 'irvine' } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"irvine\"}") asserts "that it can be passed an if cond for aliased attrs" do template = rabl %{ object @user attributes :name => :title, :age => :year, :if => lambda { |i| i.name == 'irvine' } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"title\":\"irvine\",\"year\":24}") asserts "that it can be passed an unless cond to hide attrs" do template = rabl %{ object @user attribute :name attributes :age, :unless => lambda { |i| i.name == 'irvine' } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"irvine\"}") asserts "that it can be passed an unless cond for aliased attrs" do template = rabl %{ object @user attributes :name => :title, :age => :year, :unless => lambda { |i| i.name == 'irvine' } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') JSON.parse(template.render(scope)) end.equals JSON.parse("{}") end # attribute context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new) end.equals "{\"foo\":\"bar\"}" asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new) end.equals "{}" end context "#child" do asserts "that it can create a singular child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}") asserts "that it can create a singular child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\",\"person\":{\"city\":\"LA\"}}") asserts "that it can create a many child node" do template = rabl %{ object @user attribute :name child(:hobbies) { attribute :name } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse(%q^{"name":"leo", "hobbies":[{"hobby":{"name":"Photography"}}]}^) asserts "that it can create a many child node with different key" do template = rabl %{ object @user attribute :name child(:hobbies => :interests) { attribute :name } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') JSON.parse(template.render(scope)) end.equals JSON.parse(%q^{"name":"leo", "interests":[{"interest":{"name":"Photography"}}]}^) asserts "that it can create a many child node with no data" do template = rabl %{ object @user attribute :name child(:hobbies) { attribute :name } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :hobbies => []) JSON.parse(template.render(scope)) end.equals JSON.parse(%q^{"name":"leo", "hobbies":[]}^) asserts "that it can be passed conditionals" do template = rabl %{ object @user attribute :name child({:children => :children}, {:if => lambda { |user| user.respond_to?('children') }}) { attribute :test } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope) end.equals "{\"name\":\"leo\"}" end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\",\"city\":\"LA\",\"age\":12}") asserts "that it can be passed conditionals" do template = rabl %{ object @user attribute :name glue(@user, {:if => lambda { |i| false }}) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\"}") end context "#extends" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do Rabl.configure do |config| config.view_paths = tmp_path end File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ attributes :age node(:city) { "Gotham" } if locals[:show_city] } end end asserts "that it extends the template with attributes from the file" do template = rabl %{ object @user attribute :name extends 'test' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\",\"age\":12}") asserts "that it can be passed locals" do template = rabl %{ object @user attribute :name extends 'test', :locals => { :show_city => true } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\",\"age\":12,\"city\":\"Gotham\"}") asserts "that it can be passed conditionals" do template = rabl %{ object @user attribute :name extends('test', {:if => lambda { |i| false }}) } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :age => 12) JSON.parse(template.render(scope)) end.equals JSON.parse("{\"name\":\"leo\"}") end teardown do Rabl.reset_configuration! end end # without json root context "without child root" do setup do Rabl.configure do |config| config.include_child_root = false config.include_xml_root = false config.enable_json_callbacks = false end end context "#child" do asserts "that it can create a child node without child root" do template = rabl %{ child @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "{\"users\":[{},{}]}" end teardown do Rabl.reset_configuration! end end end rabl-0.16.1/test/helpers_test.rb000066400000000000000000000105011432107571000165210ustar00rootroot00000000000000require 'tmpdir' require 'pathname' require File.expand_path('../teststrap', __FILE__) class TestHelperMethods include Rabl::Helpers end context "Rabl::Helpers" do setup do @helper_class = TestHelperMethods.new @user = User.new end # determine_object_root(@user, :user, true) => "user" # determine_object_root(@user, :person) => "person" # determine_object_root([@user, @user]) => "user" # def determine_object_root(data_token, data_name=nil, include_root=true) context "for determine_object_root method" do asserts "returns nil if include_root is false" do @helper_class.determine_object_root(@user, :user, false) end.equals(nil) asserts "returns user root name if include_root is true" do @helper_class.determine_object_root(@user, :user, true) end.equals("user") asserts "returns explicit alias if specified" do @helper_class.determine_object_root(@user, :person) end.equals("person") asserts "returns explicit alias if object is nil" do @helper_class.determine_object_root(nil, :person) end.equals("person") end context "for data_name method" do asserts "returns nil if no data" do @helper_class.data_name(nil) end.equals(nil) asserts "returns symbol if symbol with empty children" do @helper_class.data_name(:user) end.equals(:user) asserts "returns alias if hash with symbol is passed" do @helper_class.data_name(@user => :user) end.equals(:user) asserts "returns name of first object of a collection" do @helper_class.data_name([@user, @user]) end.equals('users') asserts "returns name of an object" do @helper_class.data_name(@user) end.equals('user') asserts "returns table_name of collection if responds" do @coll = [@user, @user] mock(@coll).table_name { "people" } @helper_class.data_name(@coll) end.equals('people') end # data_name method context "for is_object method" do asserts "returns nil if no data" do @helper_class.is_object?(nil) end.equals(nil) asserts "returns true for an object" do @helper_class.is_object?(@user) end.equals(true) asserts "returns true for an object with each" do obj = Class.new { def each; end } @helper_class.is_object?(obj.new) end.equals(true) asserts "returns true for a hash alias" do @helper_class.is_object?(@user => :user) end.equals(true) asserts "returns true for a struct" do obj = Struct.new(:name) @helper_class.is_object?(obj.new('foo')) end.equals(true) asserts "returns true for a Hashie::Mash" do obj = Hashie::Mash.new({:name => 'hello'}) @helper_class.is_object?(obj) end.equals(true) asserts "returns false for an array" do @helper_class.is_object?([@user]) end.equals(false) end # is_object method context "for is_collection method" do asserts "returns nil if no data" do @helper_class.is_collection?(nil) end.equals(nil) asserts "returns false for a struct" do obj = Struct.new(:name) @helper_class.is_collection?(obj.new('foo')) end.equals(false) asserts "returns false for an object" do @helper_class.is_collection?(@user) end.equals(false) asserts "returns false for an object with each" do obj = Class.new { def each; end } @helper_class.is_collection?(obj.new) end.equals(false) asserts "returns false for an object with map" do obj = Class.new { def map; end } @helper_class.is_collection?(obj.new) end.equals(false) asserts "returns true for an object with each and map" do obj = Class.new { def each; end; def map; end } @helper_class.is_collection?(obj.new) end.equals(true) asserts "returns false for a hash alias" do @helper_class.is_collection?(@user => :user) end.equals(false) asserts "returns true for an array" do @helper_class.is_collection?([@user]) end.equals(true) asserts "returns false for a Hashie::Mash with 1 key" do obj = Hashie::Mash.new({:name => 'hello'}) @helper_class.is_collection?(obj) end.equals(false) asserts "returns false for a Hashie::Mash with 2 keys" do obj = Hashie::Mash.new({:name => 'hello', :key2 => 'key2'}) @helper_class.is_collection?(obj) end.equals(false) end # is_collection method end rabl-0.16.1/test/integration/000077500000000000000000000000001432107571000160215ustar00rootroot00000000000000rabl-0.16.1/test/integration/posts_controller_test.rb000066400000000000000000000102131432107571000230150ustar00rootroot00000000000000# Lives in /test/integration/posts_controller_test.rb # Symlinked to fixture applications begin # Padrino require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "PostsController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! Post.delete_all @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id) @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id) @post3 = Post.create(:title => "Kaz", :body => "Paz", :user_id => @user3.id) @posts = [@post1, @post2, @post3] end context "for index action" do setup do get "/posts", :format => :json end # Attributes (regular) asserts("contains post titles") do json_output['articles'].map { |o| o["article"]["title"] } end.equals { @posts.map(&:title) } asserts("contains post bodies") do json_output['articles'].map { |o| o["article"]["body"] } end.equals { @posts.map(&:body) } # Attributes (custom name) asserts("contains post posted_at") do json_output['articles'].map { |o| o["article"]["posted_at"] } end.equals { @posts.map(&:created_at).map(&:iso8601) } # Child asserts("contains post user child username") do json_output['articles'].map { |o| o["article"]["user"]["username"] } end.equals { @posts.map(&:user).map(&:username) } asserts("contains post user child role") do json_output['articles'].map { |o| o["article"]["user"]["role"] } end.equals { ["normal", "normal", "admin"] } # Child Numbers of the Child User asserts("contains post user child numbers") do json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] } end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) } # Glue (username to article) asserts("contains glued usernames") do json_output['articles'].map { |o| o["article"]["author_name"] } end.equals { @posts.map(&:user).map(&:username) } # Conditional Child (admin) asserts("contains admin child only for admins") do json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact end.equals { [@user3.username] } # Conditional Node (created_by_admin) asserts("contains created_by_admin node for admins") do json_output['articles'].last['article']['created_by_admin'] end.equals { true } denies("contains no created_by_admin node for non-admins") do json_output['articles'].first['article'] end.includes(:created_by_admin) end # index action context "for show action" do setup do get "/posts/#{@post1.id}", :format => :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (custom name) asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.iso8601 } # Child asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username } asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" } # Child Numbers of the Child User asserts("contains post user child numbers") do topic["user"]["pnumbers"][0]["pnumber"]["formatted"] end.equals { @post1.user.phone_numbers[0].formatted } # Glue (username to article) asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username } # Non-ORM Date Node Partial context "for date node" do setup { json_output['post']['created_date'] } asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day } asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour } asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 } end # date node end # show action end rabl-0.16.1/test/integration/rails3_2/000077500000000000000000000000001432107571000174375ustar00rootroot00000000000000rabl-0.16.1/test/integration/rails3_2/posts_controller_test.rb000077500000000000000000000220571432107571000244470ustar00rootroot00000000000000# Lives in /test/integration/posts_controller_test.rb # Symlinked to fixture applications begin # Padrino require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end require 'rexml/document' context "PostsController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! Post.delete_all @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id) @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id) @post3 = Post.create(:title => "Kaz", :body => "", :user_id => @user3.id) @posts = [@post1, @post2, @post3] end context "for index action" do setup do get "/posts", format: :json end # Attributes (regular) asserts("contains post titles") do json_output['articles'].map { |o| o["article"]["title"] } end.equals { @posts.map(&:title) } asserts("contains post bodies") do json_output['articles'].map { |o| o["article"]["body"] } end.equals { @posts.map(&:body) } # Attributes (custom name) asserts("contains post posted_at") do json_output['articles'].map { |o| o["article"]["posted_at"] } end.equals { @posts.map(&:created_at).map(&:iso8601) } # Child asserts("contains post user child username") do json_output['articles'].map { |o| o["article"]["user"]["username"] } end.equals { @posts.map(&:user).map(&:username) } asserts("contains post user child role") do json_output['articles'].map { |o| o["article"]["user"]["role"] } end.equals { ["normal", "normal", "admin"] } # Child Numbers of the Child User asserts("contains post user child numbers") do json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] } end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) } # Glue (username to article) asserts("contains glued usernames") do json_output['articles'].map { |o| o["article"]["author_name"] } end.equals { @posts.map(&:user).map(&:username) } # Conditional Child (admin) asserts("contains admin child only for admins") do json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact end.equals { [@user3.username] } # Conditional Node (created_by_admin) asserts("contains created_by_admin node for admins") do json_output['articles'].last['article']['created_by_admin'] end.equals { true } denies("contains no created_by_admin node for non-admins") do json_output['articles'].first['article'] end.includes(:created_by_admin) context "mime types" do setup do get "/posts", format: :rabl_test_v1 end asserts("contains post title") do json_output['articles'].first['article'] end.includes("title_v1") asserts("contains post user child username") do json_output['articles'].first['article']["user"] end.includes("username_v1") end end context "escaping output in index action" do context "for first post" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } end context "for third post with script tags" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post3.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post3.title } asserts("contains escaped post body") { topic['body'] }.equals { ERB::Util.h(@post3.body) } end end # escaping output context "for show action" do setup do get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (custom name) asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.iso8601 } # Child asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username } asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" } # Child Numbers of the Child User asserts("contains post user child numbers") do topic["user"]["pnumbers"][0]["pnumber"]["formatted"] end.equals { @post1.user.phone_numbers[0].formatted } # Glue (username to article) asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username } # Non-ORM Date Node Partial context "for date node" do setup { json_output['post']['created_date'] } asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day } asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour } asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 } end # date node asserts("contains helper action") { topic["foo"] }.equals { "BAR!" } denies("contains helper action") { topic["created_at_in_words"] }.nil asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] } end # show action, json context "renderer" do setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } get "/posts/#{@post1.id}/renderer" json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (partial) asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title } asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body } end # renderer action, json context "for index action rendering JSON within HTML" do setup do get "/posts", format: :html end asserts(:body).includes { "" } end # index action, html context "for show action rendering JSON within HTML" do setup do get "/posts/#{@post1.id}", format: :html end asserts(:body).includes { "" } end # show action, html context "mime_type" do setup do get "/posts/#{@post1.id}", format: :rabl_test_v1 end asserts("contains post title") { json_output['post']['title_v1'] }.equals { @post1.title } asserts("contains username") { json_output['post']['user']['username_v1'] }.equals { @post1.user.username } end context "caching" do helper(:cache_hit) do |key| Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl)) end setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } Rails.cache.clear end context "for index action with caching in json" do setup do get "/posts", format: :json end asserts("contains post titles") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map(&:title) } asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'json'] } asserts("contains cache hits per object (posts by title)") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map{ |p| cache_hit([p, nil, 'hash'])[:title] } } end # index action, caching, json context "for index action with caching in xml" do setup do get "/posts", format: :xml end asserts("contains post titles") do doc = REXML::Document.new topic.body doc.elements.inject('articles/article/title', []) {|arr, ele| arr << ele.text} end.equals { @posts.map(&:title) } asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'xml'] } end # index action, caching, xml context "for show action with caching" do setup do get "/posts/#{@post1.id}", format: :json end asserts("contains post title") { json_output['post']['title'] }.equals { @post1.title } asserts(:body).equals { cache_hit [@post1, nil, 'json'] } end # show action, caching, json context "cache_all_output" do helper(:cache_hit) do |key| Rails.cache.read(ActiveSupport::Cache.expand_cache_key([key, 'article', 'json'], :rabl)) end setup do Rabl.configuration.cache_all_output = true get "/posts", format: :json end asserts("contains cache hits per object (posts by title)") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map{ |p| cache_hit(p)['article'][:title] } } end # index action, cache_all_output end end rabl-0.16.1/test/integration/rails3_2/users_controller_test.rb000066400000000000000000000063671432107571000244430ustar00rootroot00000000000000# Lives in /test/integration/users_controller_test.rb # Symlinked to fixture applications begin # Sinatra require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "UsersController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! end context "for index action" do # Tests `collection @users` extending from 'show' template setup do get "/users" end # Attributes (regular) asserts("contains user usernames") do json_output.map { |u| u["user"]["username"] } end.equals { @users.map(&:username) } asserts("contains email") do json_output.map { |u| u["user"]["email"] } end.equals { @users.map(&:email) } asserts("contains location") do json_output.map { |u| u["user"]["location"] } end.equals { @users.map(&:location) } # Attributes (custom name) asserts("contains registered_at") do json_output.map { |u| u["user"]["registered_at"] } end.equals { @users.map(&:created_at).map { |t| t.iso8601 } } # Node (renders based on attribute) asserts("contains role") do json_output.map { |u| u["user"]["role"] } end.equals ['normal', 'normal', 'admin'] # Child (custom collection name) asserts("contains formatted phone numbers") do json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } # Node (renders collection partial) asserts("contains reversed node numbers") do json_output.map { |u| u["user"]["node_numbers"].map { |n| n["reversed"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted).map(&:reverse) } } end # index context "for show action" do # Tests `object :user => :person` custom parent node name setup do get "/users/#{@user1.id}" end # Attributes (regular) asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username } asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email } asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location } # Attributes (custom name) asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.iso8601 } # Node (renders based on attribute) asserts("contains role node") { json_output["person"]["role"] }.equals "normal" # Child (custom collection name) asserts("contains first phone number") { json_output["person"]["pnumbers"][0]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second phone number") { json_output["person"]["pnumbers"][1]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[1].formatted } # Node (renders collection partial) asserts("contains first node number") { json_output["person"]["node_numbers"][0]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second node number") { json_output["person"]["node_numbers"][1]["formatted"] }.equals { @user1.phone_numbers[1].formatted } end # show endrabl-0.16.1/test/integration/rails4/000077500000000000000000000000001432107571000172175ustar00rootroot00000000000000rabl-0.16.1/test/integration/rails4/posts_controller_test.rb000077500000000000000000000215531432107571000242270ustar00rootroot00000000000000# Lives in /test/integration/posts_controller_test.rb # Symlinked to fixture applications begin # Padrino require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end require 'rexml/document' context "PostsController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! Post.delete_all @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id) @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id) @post3 = Post.create(:title => "Kaz", :body => "", :user_id => @user3.id) @posts = [@post1, @post2, @post3] end context "for index action" do setup do get "/posts", format: :json end # Attributes (regular) asserts("contains post titles") do json_output['articles'].map { |o| o["article"]["title"] } end.equals { @posts.map(&:title) } asserts("contains post bodies") do json_output['articles'].map { |o| o["article"]["body"] } end.equals { @posts.map(&:body) } # Attributes (custom name) asserts("contains post posted_at") do json_output['articles'].map { |o| o["article"]["posted_at"] } end.equals { @posts.map(&:created_at).map{ |t| t.iso8601(3) } } # Child asserts("contains post user child username") do json_output['articles'].map { |o| o["article"]["user"]["username"] } end.equals { @posts.map(&:user).map(&:username) } asserts("contains post user child role") do json_output['articles'].map { |o| o["article"]["user"]["role"] } end.equals { ["normal", "normal", "admin"] } # Child Numbers of the Child User asserts("contains post user child numbers") do json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] } end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) } # Glue (username to article) asserts("contains glued usernames") do json_output['articles'].map { |o| o["article"]["author_name"] } end.equals { @posts.map(&:user).map(&:username) } # Conditional Child (admin) asserts("contains admin child only for admins") do json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact end.equals { [@user3.username] } # Conditional Node (created_by_admin) asserts("contains created_by_admin node for admins") do json_output['articles'].last['article']['created_by_admin'] end.equals { true } denies("contains no created_by_admin node for non-admins") do json_output['articles'].first['article'] end.includes(:created_by_admin) end # index action, json context "escaping output in index action" do context "for first post" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } end context "for third post with script tags" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post3.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post3.title } asserts("contains escaped post body") { topic['body'] }.equals { ERB::Util.h(@post3.body) } end end # escaping output context "for show action" do setup do get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (custom name) asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.iso8601(3) } # Child asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username } asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" } # Child Numbers of the Child User asserts("contains post user child numbers") do topic["user"]["pnumbers"][0]["pnumber"]["formatted"] end.equals { @post1.user.phone_numbers[0].formatted } # Glue (username to article) asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username } # Non-ORM Date Node Partial context "for date node" do setup { json_output['post']['created_date'] } asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day } asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour } asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 } end # date node asserts("contains helper action") { topic["foo"] }.equals { "BAR!" } denies("contains helper action") { topic["created_at_in_words"] }.nil asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] } end # show action, json context "renderer" do setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } get "/posts/#{@post1.id}/renderer" json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (partial) asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title } asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body } end # renderer action, json context "for index action rendering JSON within HTML" do setup do get "/posts", format: :html end asserts(:body).includes { "" } end # index action, html context "for show action rendering JSON within HTML" do setup do get "/posts/#{@post1.id}", format: :html end asserts(:body).includes { "" } end # show action, html context "mime_type" do setup do get "/posts/#{@post1.id}", format: :rabl_test_v1 end asserts("contains post title") { json_output['post']['title_v1'] }.equals { @post1.title } asserts("contains username") { json_output['post']['user']['username_v1'] }.equals { @post1.user.username } end context "caching" do helper(:cache_hit) do |key| Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl)) end setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } Rails.cache.clear end context "for index action with caching in json" do setup do get "/posts", format: :json end asserts("contains post titles") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map(&:title) } asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'json', 'e83f65eee5ffb454c418a59105f222c4'] } asserts("contains cache hits per object (posts by title)") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map { |p| cache_hit([p, nil, 'hash', 'e373525f49a3b3b044af05255e84839d'])[:title] } } end # index action, caching, json context "for index action with caching in xml" do setup do get "/posts", format: :xml end asserts("contains post titles") do doc = REXML::Document.new topic.body doc.elements.inject('articles/article/title', []) {|arr, ele| arr << ele.text} end.equals { @posts.map(&:title) } asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'xml', 'e83f65eee5ffb454c418a59105f222c4'] } end # index action, caching, xml context "for show action with caching" do setup do get "/posts/#{@post1.id}", format: :json end asserts("contains post title") { json_output['post']['title'] }.equals { @post1.title } asserts(:body).equals { cache_hit [@post1, nil, 'json', 'e373525f49a3b3b044af05255e84839d'] } end # show action, caching, json context "cache_all_output" do helper(:cache_hit) do |key| Rails.cache.read(ActiveSupport::Cache.expand_cache_key([key, 'article', 'json'], :rabl)) end setup do Rabl.configuration.cache_all_output = true get "/posts", format: :json end asserts("contains cache hits per object (posts by title)") do json_output['articles'].map { |o| o['article']['title'] } end.equals { @posts.map{ |p| cache_hit(p)['article'][:title] } } end # index action, cache_all_output end end rabl-0.16.1/test/integration/rails4/users_controller_test.rb000066400000000000000000000064341432107571000242160ustar00rootroot00000000000000# Lives in /test/integration/users_controller_test.rb # Symlinked to fixture applications begin # Sinatra require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "UsersController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! end context "for index action" do # Tests `collection @users` extending from 'show' template setup do get "/users", format: :json end # Attributes (regular) asserts("contains user usernames") do json_output.map { |u| u["user"]["username"] } end.equals { @users.map(&:username) } asserts("contains email") do json_output.map { |u| u["user"]["email"] } end.equals { @users.map(&:email) } asserts("contains location") do json_output.map { |u| u["user"]["location"] } end.equals { @users.map(&:location) } # Attributes (custom name) asserts("contains registered_at") do json_output.map { |u| u["user"]["registered_at"] } end.equals { @users.map(&:created_at).map { |t| t.iso8601(3) } } # Node (renders based on attribute) asserts("contains role") do json_output.map { |u| u["user"]["role"] } end.equals ['normal', 'normal', 'admin'] # Child (custom collection name) asserts("contains formatted phone numbers") do json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } # Node (renders collection partial) asserts("contains reversed node numbers") do json_output.map { |u| u["user"]["node_numbers"].map { |n| n["reversed"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted).map(&:reverse) } } end # index context "for show action" do # Tests `object :user => :person` custom parent node name setup do get "/users/#{@user1.id}", format: :json end # Attributes (regular) asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username } asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email } asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location } # Attributes (custom name) asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.iso8601(3) } # Node (renders based on attribute) asserts("contains role node") { json_output["person"]["role"] }.equals "normal" # Child (custom collection name) asserts("contains first phone number") { json_output["person"]["pnumbers"][0]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second phone number") { json_output["person"]["pnumbers"][1]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[1].formatted } # Node (renders collection partial) asserts("contains first node number") { json_output["person"]["node_numbers"][0]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second node number") { json_output["person"]["node_numbers"][1]["formatted"] }.equals { @user1.phone_numbers[1].formatted } end # show end rabl-0.16.1/test/integration/rails5/000077500000000000000000000000001432107571000172205ustar00rootroot00000000000000rabl-0.16.1/test/integration/rails5/posts_controller_test.rb000077500000000000000000000222231432107571000242230ustar00rootroot00000000000000# Lives in /test/integration/posts_controller_test.rb # Symlinked to fixture applications begin # Padrino require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end require 'rexml/document' context "PostsController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! Post.delete_all @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id) @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id) @post3 = Post.create(:title => "Kaz", :body => "", :user_id => @user3.id) @posts = [@post1, @post2, @post3] end context "for index action" do setup do get "/posts", format: :json end # Attributes (regular) asserts("contains post titles") do json_output['articles'].map { |o| o["article"]["title"] } end.equals { @posts.map(&:title) } asserts("contains post bodies") do json_output['articles'].map { |o| o["article"]["body"] } end.equals { @posts.map(&:body) } # Attributes (custom name) asserts("contains post posted_at") do json_output['articles'].map { |o| o["article"]["posted_at"] } end.equals { @posts.map(&:created_at).map{ |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } } # Child asserts("contains post user child username") do json_output['articles'].map { |o| o["article"]["user"]["username"] } end.equals { @posts.map(&:user).map(&:username) } asserts("contains post user child role") do json_output['articles'].map { |o| o["article"]["user"]["role"] } end.equals { ["normal", "normal", "admin"] } # Child Numbers of the Child User asserts("contains post user child numbers") do json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] } end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) } # Glue (username to article) asserts("contains glued usernames") do json_output['articles'].map { |o| o["article"]["author_name"] } end.equals { @posts.map(&:user).map(&:username) } # Conditional Child (admin) asserts("contains admin child only for admins") do json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact end.equals { [@user3.username] } # Conditional Node (created_by_admin) asserts("contains created_by_admin node for admins") do json_output['articles'].last['article']['created_by_admin'] end.equals { true } denies("contains no created_by_admin node for non-admins") do json_output['articles'].first['article'] end.includes(:created_by_admin) end # index action, json context "escaping output in index action" do context "for first post" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } end context "for third post with script tags" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post3.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post3.title } asserts("contains escaped post body") { topic['body'] }.equals { ERB::Util.h(@post3.body) } end end # escaping output context "for show action" do setup do get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (custom name) asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") } # Child asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username } asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" } # Child Numbers of the Child User asserts("contains post user child numbers") do topic["user"]["pnumbers"][0]["pnumber"]["formatted"] end.equals { @post1.user.phone_numbers[0].formatted } # Glue (username to article) asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username } # Non-ORM Date Node Partial context "for date node" do setup { json_output['post']['created_date'] } asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day } asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour } asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 } end # date node asserts("contains helper action") { topic["foo"] }.equals { "BAR!" } denies("contains helper action") { topic["created_at_in_words"] }.nil asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] } end # show action, json context "renderer" do setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } get "/posts/#{@post1.id}/renderer" json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (partial) asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title } asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body } end # renderer action, json # HTML isn't supported in API mode unless Rails.application.config.api_only context "for index action rendering JSON within HTML" do setup do get "/posts", format: :html end asserts(:body).includes { "" } end # index action, html context "for show action rendering JSON within HTML" do setup do get "/posts/#{@post1.id}", format: :html end asserts(:body).includes { "" } end # show action, html end context "mime_type" do setup do get "/posts/#{@post1.id}", format: :rabl_test_v1 end asserts("contains post title") { json_output['post']['title_v1'] }.equals { @post1.title } asserts("contains username") { json_output['post']['user']['username_v1'] }.equals { @post1.user.username } end # context "caching" do # helper(:cache_hit) do |key| # Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl)) # end # # setup do # mock(ActionController::Base).perform_caching.any_number_of_times { true } # Rails.cache.clear # end # # context "for index action with caching in json" do # setup do # get "/posts", format: :json # end # # asserts("contains post titles") do # json_output['articles'].map { |o| o['article']['title'] } # end.equals { @posts.map(&:title) } # # asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'json', 'e83f65eee5ffb454c418a59105f222c4'] } # # asserts("contains cache hits per object (posts by title)") do # json_output['articles'].map { |o| o['article']['title'] } # end.equals { @posts.map { |p| cache_hit([p, nil, 'hash', 'e373525f49a3b3b044af05255e84839d'])[:title] } } # end # index action, caching, json # # context "for index action with caching in xml" do # setup do # get "/posts", format: :xml # end # # asserts("contains post titles") do # doc = REXML::Document.new topic.body # doc.elements.inject('articles/article/title', []) {|arr, ele| arr << ele.text} # end.equals { @posts.map(&:title) } # # asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'xml', 'e83f65eee5ffb454c418a59105f222c4'] } # end # index action, caching, xml # # context "for show action with caching" do # setup do # get "/posts/#{@post1.id}", format: :json # end # # asserts("contains post title") { json_output['post']['title'] }.equals { @post1.title } # # asserts(:body).equals { cache_hit [@post1, nil, 'json', 'e373525f49a3b3b044af05255e84839d'] } # end # show action, caching, json # # context "cache_all_output" do # helper(:cache_hit) do |key| # Rails.cache.read(ActiveSupport::Cache.expand_cache_key([key, 'article', 'json'], :rabl)) # end # # setup do # Rabl.configuration.cache_all_output = true # get "/posts", format: :json # end # # asserts("contains cache hits per object (posts by title)") do # json_output['articles'].map { |o| o['article']['title'] } # end.equals { @posts.map{ |p| cache_hit(p)['article'][:title] } } # end # index action, cache_all_output # end end rabl-0.16.1/test/integration/rails5/users_controller_test.rb000066400000000000000000000065101432107571000242120ustar00rootroot00000000000000# Lives in /test/integration/users_controller_test.rb # Symlinked to fixture applications begin # Sinatra require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "UsersController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! end context "for index action" do # Tests `collection @users` extending from 'show' template setup do get "/users", format: :json end # Attributes (regular) asserts("contains user usernames") do json_output.map { |u| u["user"]["username"] } end.equals { @users.map(&:username) } asserts("contains email") do json_output.map { |u| u["user"]["email"] } end.equals { @users.map(&:email) } asserts("contains location") do json_output.map { |u| u["user"]["location"] } end.equals { @users.map(&:location) } # Attributes (custom name) asserts("contains registered_at") do json_output.map { |u| u["user"]["registered_at"] } end.equals { @users.map(&:created_at).map { |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } } # Node (renders based on attribute) asserts("contains role") do json_output.map { |u| u["user"]["role"] } end.equals ['normal', 'normal', 'admin'] # Child (custom collection name) asserts("contains formatted phone numbers") do json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } # Node (renders collection partial) asserts("contains reversed node numbers") do json_output.map { |u| u["user"]["node_numbers"].map { |n| n["reversed"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted).map(&:reverse) } } end # index context "for show action" do # Tests `object :user => :person` custom parent node name setup do get "/users/#{@user1.id}", format: :json end # Attributes (regular) asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username } asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email } asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location } # Attributes (custom name) asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") } # Node (renders based on attribute) asserts("contains role node") { json_output["person"]["role"] }.equals "normal" # Child (custom collection name) asserts("contains first phone number") { json_output["person"]["pnumbers"][0]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second phone number") { json_output["person"]["pnumbers"][1]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[1].formatted } # Node (renders collection partial) asserts("contains first node number") { json_output["person"]["node_numbers"][0]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second node number") { json_output["person"]["node_numbers"][1]["formatted"] }.equals { @user1.phone_numbers[1].formatted } end # show end rabl-0.16.1/test/integration/rails6/000077500000000000000000000000001432107571000172215ustar00rootroot00000000000000rabl-0.16.1/test/integration/rails6/posts_controller_test.rb000066400000000000000000000154041432107571000242240ustar00rootroot00000000000000# Lives in /test/integration/posts_controller_test.rb # Symlinked to fixture applications begin # Padrino require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end require 'rexml/document' context "PostsController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! Post.delete_all @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id) @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id) @post3 = Post.create(:title => "Kaz", :body => "", :user_id => @user3.id) @posts = [@post1, @post2, @post3] end context "for index action" do setup do get "/posts", format: :json end # Attributes (regular) asserts("contains post titles") do json_output['articles'].map { |o| o["article"]["title"] } end.equals { @posts.map(&:title) } asserts("contains post bodies") do json_output['articles'].map { |o| o["article"]["body"] } end.equals { @posts.map(&:body) } # Attributes (custom name) asserts("contains post posted_at") do json_output['articles'].map { |o| o["article"]["posted_at"] } end.equals { @posts.map(&:created_at).map{ |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } } # Child asserts("contains post user child username") do json_output['articles'].map { |o| o["article"]["user"]["username"] } end.equals { @posts.map(&:user).map(&:username) } asserts("contains post user child role") do json_output['articles'].map { |o| o["article"]["user"]["role"] } end.equals { ["normal", "normal", "admin"] } # Child Numbers of the Child User asserts("contains post user child numbers") do json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] } end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) } # Glue (username to article) asserts("contains glued usernames") do json_output['articles'].map { |o| o["article"]["author_name"] } end.equals { @posts.map(&:user).map(&:username) } # Conditional Child (admin) asserts("contains admin child only for admins") do json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact end.equals { [@user3.username] } # Conditional Node (created_by_admin) asserts("contains created_by_admin node for admins") do json_output['articles'].last['article']['created_by_admin'] end.equals { true } denies("contains no created_by_admin node for non-admins") do json_output['articles'].first['article'] end.includes(:created_by_admin) end # index action, json context "escaping output in index action" do context "for first post" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } end context "for third post with script tags" do setup do Rabl.configuration.escape_all_output = true get "/posts/#{@post3.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post3.title } asserts("contains escaped post body") { topic['body'] }.equals { ERB::Util.h(@post3.body) } end end # escaping output context "for show action" do setup do get "/posts/#{@post1.id}", format: :json json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (custom name) asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") } # Child asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username } asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" } # Child Numbers of the Child User asserts("contains post user child numbers") do topic["user"]["pnumbers"][0]["pnumber"]["formatted"] end.equals { @post1.user.phone_numbers[0].formatted } # Glue (username to article) asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username } # Non-ORM Date Node Partial context "for date node" do setup { json_output['post']['created_date'] } asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day } asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour } asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 } end # date node asserts("contains helper action") { topic["foo"] }.equals { "BAR!" } denies("contains helper action") { topic["created_at_in_words"] }.nil asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] } end # show action, json context "renderer" do setup do mock(ActionController::Base).perform_caching.any_number_of_times { true } get "/posts/#{@post1.id}/renderer" json_output['post'] end # Attributes (regular) asserts("contains post title") { topic['title'] }.equals { @post1.title } asserts("contains post body") { topic['body'] }.equals { @post1.body } # Attributes (partial) asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title } asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body } end # renderer action, json # HTML isn't supported in API mode unless Rails.application.config.api_only context "for index action rendering JSON within HTML" do setup do get "/posts", format: :html end asserts(:body).includes { "" } end # index action, html context "for show action rendering JSON within HTML" do setup do get "/posts/#{@post1.id}", format: :html end asserts(:body).includes { "" } end # show action, html end context "mime_type" do setup do get "/posts/#{@post1.id}", format: :rabl_test_v1 end asserts("contains post title") { json_output['post']['title_v1'] }.equals { @post1.title } asserts("contains username") { json_output['post']['user']['username_v1'] }.equals { @post1.user.username } end end rabl-0.16.1/test/integration/rails6/users_controller_test.rb000066400000000000000000000065101432107571000242130ustar00rootroot00000000000000# Lives in /test/integration/users_controller_test.rb # Symlinked to fixture applications begin # Sinatra require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "UsersController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! end context "for index action" do # Tests `collection @users` extending from 'show' template setup do get "/users", format: :json end # Attributes (regular) asserts("contains user usernames") do json_output.map { |u| u["user"]["username"] } end.equals { @users.map(&:username) } asserts("contains email") do json_output.map { |u| u["user"]["email"] } end.equals { @users.map(&:email) } asserts("contains location") do json_output.map { |u| u["user"]["location"] } end.equals { @users.map(&:location) } # Attributes (custom name) asserts("contains registered_at") do json_output.map { |u| u["user"]["registered_at"] } end.equals { @users.map(&:created_at).map { |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } } # Node (renders based on attribute) asserts("contains role") do json_output.map { |u| u["user"]["role"] } end.equals ['normal', 'normal', 'admin'] # Child (custom collection name) asserts("contains formatted phone numbers") do json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } # Node (renders collection partial) asserts("contains reversed node numbers") do json_output.map { |u| u["user"]["node_numbers"].map { |n| n["reversed"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted).map(&:reverse) } } end # index context "for show action" do # Tests `object :user => :person` custom parent node name setup do get "/users/#{@user1.id}", format: :json end # Attributes (regular) asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username } asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email } asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location } # Attributes (custom name) asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") } # Node (renders based on attribute) asserts("contains role node") { json_output["person"]["role"] }.equals "normal" # Child (custom collection name) asserts("contains first phone number") { json_output["person"]["pnumbers"][0]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second phone number") { json_output["person"]["pnumbers"][1]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[1].formatted } # Node (renders collection partial) asserts("contains first node number") { json_output["person"]["node_numbers"][0]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second node number") { json_output["person"]["node_numbers"][1]["formatted"] }.equals { @user1.phone_numbers[1].formatted } end # show end rabl-0.16.1/test/integration/test_init.rb000066400000000000000000000026221432107571000203520ustar00rootroot00000000000000require 'rack/test' require 'riot' require 'riot/rr' Riot.pretty_dots class Riot::Situation include Rack::Test::Methods # Construct all the users needed for testing def create_users! User.delete_all; PhoneNumber.delete_all @user1 = User.create!(:username => "billybob", :email => "billy@bob.com", :location => "SF", :is_admin => false) @user2 = User.create!(:username => "joefrank", :email => "joe@frank.com", :location => "LA", :is_admin => false) @user3 = User.create!(:username => "suziesmith", :email => "suzie@smith.com", :location => "NYC", :is_admin => true) @users = [@user1, @user2, @user3] pn_ops = { :area_code => "#{rand(9).to_s*3}", :prefix => "#{rand(9).to_s*3}", :suffix => "#{rand(9).to_s*4}"} PhoneNumber.create(pn_ops.merge(:is_primary => true, :name => "Home", :user_id => @user1.id)) PhoneNumber.create(pn_ops.merge(:is_primary => false, :name => "Work", :user_id => @user1.id)) PhoneNumber.create(pn_ops.merge(:is_primary => true, :name => "Home", :user_id => @user2.id)) PhoneNumber.create(pn_ops.merge(:is_primary => true, :name => "Home", :user_id => @user3.id)) end end class Riot::Context # Set the Rack app which is to be tested. # # context "MyApp" do # app { [200, {}, "Hello!"] } # setup { get '/' } # asserts(:status).equals(200) # end def app(app=nil, &block) setup { @app = (app || block.call) } end endrabl-0.16.1/test/integration/users_controller_test.rb000066400000000000000000000063431432107571000230170ustar00rootroot00000000000000# Lives in /test/integration/users_controller_test.rb # Symlinked to fixture applications begin # Sinatra require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') rescue LoadError # Rails require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb') end context "UsersController" do helper(:json_output) { JSON.parse(last_response.body) } setup do create_users! end context "for index action" do # Tests `collection @users` extending from 'show' template setup do get "/users" end # Attributes (regular) asserts("contains user usernames") do json_output.map { |u| u["user"]["username"] } end.equals { @users.map(&:username) } asserts("contains email") do json_output.map { |u| u["user"]["email"] } end.equals { @users.map(&:email) } asserts("contains location") do json_output.map { |u| u["user"]["location"] } end.equals { @users.map(&:location) } # Attributes (custom name) asserts("contains registered_at") do json_output.map { |u| u["user"]["registered_at"] } end.equals { @users.map(&:created_at).map(&:iso8601) } # Node (renders based on attribute) asserts("contains role") do json_output.map { |u| u["user"]["role"] } end.equals ['normal', 'normal', 'admin'] # Child (custom collection name) asserts("contains formatted phone numbers") do json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } # Node (renders collection partial) asserts("contains formatted node numbers") do json_output.map { |u| u["user"]["node_numbers"].map { |n| n["formatted"] } } end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } } end # index context "for show action" do # Tests `object :user => :person` custom parent node name setup do get "/users/#{@user1.id}" end # Attributes (regular) asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username } asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email } asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location } # Attributes (custom name) asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.iso8601 } # Node (renders based on attribute) asserts("contains role node") { json_output["person"]["role"] }.equals "normal" # Child (custom collection name) asserts("contains first phone number") { json_output["person"]["pnumbers"][0]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second phone number") { json_output["person"]["pnumbers"][1]["pnumber"]["formatted"] }.equals { @user1.phone_numbers[1].formatted } # Node (renders collection partial) asserts("contains first node number") { json_output["person"]["node_numbers"][0]["formatted"] }.equals { @user1.phone_numbers[0].formatted } asserts("contains second node number") { json_output["person"]["node_numbers"][1]["formatted"] }.equals { @user1.phone_numbers[1].formatted } end # show endrabl-0.16.1/test/models/000077500000000000000000000000001432107571000147615ustar00rootroot00000000000000rabl-0.16.1/test/models/ormless.rb000066400000000000000000000000431432107571000167670ustar00rootroot00000000000000class Ormless # Nothing here end rabl-0.16.1/test/models/user.rb000066400000000000000000000020401432107571000162600ustar00rootroot00000000000000unless defined?(User) class User attr_accessor :age, :city, :name, :first, :float, :hobbies, :twitter, :first_pets_name DEFAULT_AGE = 24 DEFAULT_CITY = 'irvine' DEFAULT_NAME = 'rabl' DEFAULT_FIRST = 'bob' DEFAULT_FLOAT = 1234.56 DEFAULT_HOBBIES = ['Photography'] DEFAULT_TWITTER = 'rablgem' DEFAULT_FIRST_PETS_NAME = 'jack' def initialize(attributes = {}) %w(age city name first float hobbies twitter first_pets_name).each do |attr| self.send "#{attr}=", (attributes.has_key?(attr.to_sym) ? attributes[attr.to_sym] : self.class.const_get("DEFAULT_#{attr.upcase}")) end self.hobbies = self.hobbies.map { |h| Hobby.new(h) } end end class Hobby attr_accessor :name def initialize(name); @name = name; end end end unless defined?(NestedScope::User) module NestedScope class User def controller; self; end def controller_name; self.class.name.downcase; end end end end rabl-0.16.1/test/msgpack_engine_test.rb000066400000000000000000000233431432107571000200410ustar00rootroot00000000000000# encoding: iso-8859-1 require File.expand_path('../teststrap', __FILE__) require 'rabl/template' context "Rabl::Engine" do helper(:rabl) { |t| RablTemplate.new("code", :format => 'msgpack') { t } } context "with msgpack defaults" do setup do Rabl.configure do |config| # Comment this line out because include_msgpack_root is default. #config.include_msgpack_root = true end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new char_split template.render(scope) end.equals char_split("\x81\xA4user\x80") asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new char_split template.render(scope) end.equals char_split("\x81\xA6person\x80") end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] char_split template.render(scope) end.equals char_split("\x92\x81\xA4user\x80\x81\xA4user\x80") asserts "that it sets root node for objects" do template = rabl %{ collection @users => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] char_split template.render(scope) end.equals char_split("\x81\xA6person\x92\x81\xA6person\x80\x81\xA6person\x80") end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4user\x81\xA4name\xA6irvine") asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4user\x81\xA4city\xA6irvine") asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4user\x81\xA4city\xA6irvine") end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } char_split template.render(Object.new) end.equals char_split("\x81\xA3foo\xA3bar") asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } char_split template.render(Object.new) end.equals char_split("\x80") end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') char_split template.render(scope) end.equals char_split("\x81\xA4user\x82\xA4name\xA3leo\xA4user\x81\xA4city\xA2LA") asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') char_split template.render(scope) end.equals char_split("\x81\xA4user\x82\xA4name\xA3leo\xA6person\x81\xA4city\xA2LA") end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) char_split template.render(scope) end.equals char_split("\x81\xA4user\x83\xA4name\xA3leo\xA4city\xA2LA\xA3age\f") end teardown do Rabl.reset_configuration! end end context "with msgpack_engine" do setup do class CustomEncodeEngine def self.pack string 42 end end Rabl.configure do |config| config.msgpack_engine = CustomEncodeEngine end end asserts 'that it returns process by custom to_json' do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals 42 teardown do Rabl.reset_configuration! end end context "without msgpack root" do setup do Rabl.configure do |config| config.include_msgpack_root = false end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new char_split template.render(scope) end.equals char_split("\x80") asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new char_split template.render(scope) end.equals char_split("\x80") end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] char_split template.render(scope) end.equals char_split("\x92\x80\x80") asserts "that it sets root node for objects" do template = rabl %{ collection @users => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] char_split template.render(scope) end.equals char_split("\x81\xA6person\x92\x80\x80") end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4name\xA6irvine") asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4city\xA6irvine") asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') char_split template.render(scope) end.equals char_split("\x81\xA4city\xA6irvine") end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } char_split template.render(Object.new) end.equals char_split("\x81\xA3foo\xA3bar") asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } char_split template.render(Object.new) end.equals char_split("\x80") end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user attribute :name child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') char_split template.render(scope) end.equals char_split("\x82\xA4name\xA3leo\xA4user\x81\xA4city\xA2LA") asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') char_split template.render(scope) end.equals char_split("\x82\xA4name\xA3leo\xA6person\x81\xA4city\xA2LA") end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) char_split template.render(scope) end.equals char_split("\x83\xA4name\xA3leo\xA4city\xA2LA\xA3age\f") end teardown do Rabl.reset_configuration! end end end rabl-0.16.1/test/multi_builder_test.rb000066400000000000000000000041641432107571000177270ustar00rootroot00000000000000require 'json' require File.expand_path('../teststrap', __FILE__) require 'rabl/template' require File.expand_path('../models/ormless', __FILE__) context "Rabl::MultiBuilder" do helper(:multi_builder) { |objects, options| Rabl::MultiBuilder.new(objects, options) } helper(:builder) { Rabl::Builder.new(nil, {}) } helper(:engine) { |object| Rabl::Engine.new("").apply(nil, :object => object) } context "#initialize" do setup do Rabl::MultiBuilder.new([], {}) end asserts_topic.assigns :options asserts_topic.assigns :data asserts_topic.assigns :engine_to_builder asserts_topic.assigns :cache_key_to_engine end context "#to_a" do setup do Rabl::MultiBuilder.new([], {}) end asserts "returns an array" do topic.to_a end.is_a?(Array) end context "#map_cache_key_to_engine" do asserts "maps the cache keys to the engines" do mb = multi_builder [], {} e = engine User.new mock(e).cache_key.returns(['cache key']) mb.send(:map_cache_key_to_engine, e) mb.instance_variable_get('@cache_key_to_engine').values.include?(e) end.equals(true) end context "#read_cache_results" do setup do mb = multi_builder [], {} mb.instance_variable_set('@cache_key_to_engine', { 'cache_key' => engine(User.new) }) mb end asserts "uses read_multi to find all of the cached values with keys" do mock(Rabl.configuration.cache_engine).read_multi('cache_key').returns({}) topic.send(:read_cache_results) end end context "replace_engines_with_cache_results" do asserts "replaces the builders' engines with the cache results" do mb = multi_builder [], {} e = engine User.new b = builder mb.instance_variable_set('@cache_key_to_engine', { 'cache_key' => e }) mb.instance_variable_set('@engine_to_builder', { e => b }) b.instance_variable_set('@_engines', [e]) mb.instance_variable_set('@cache_results', { 'cache_key' => '{}' }) mock(b).replace_engine(e, '{}') mb.send(:replace_engines_with_cache_results) end end end rabl-0.16.1/test/partials_test.rb000066400000000000000000000141411432107571000167020ustar00rootroot00000000000000require 'tmpdir' require 'pathname' require File.expand_path('../teststrap', __FILE__) class TestPartial include Rabl::Partials end context "Rabl::Partials" do context "fetch_source with json" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Sinatra = stub(Class.new) File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts "content" end File.open(tmp_path + "test_v1.json.rabl", "w") do |f| f.puts "content_v1" end FileUtils.touch tmp_path + "test_v2.json.rabl" [TestPartial.new.fetch_source('test', :view_path => tmp_path.to_s), TestPartial.new.fetch_source('test_v1', :view_path => tmp_path.to_s)] end asserts(:first).equals {["content\n", (tmp_path + "test.json.rabl").to_s ]} asserts(:last).equals {["content_v1\n", (tmp_path + "test_v1.json.rabl").to_s ]} teardown { Object.send(:remove_const, :Sinatra) } end context "fetch_source with rabl" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Sinatra = stub(Class.new) File.open(tmp_path + "test.rabl", "w") do |f| f.puts "content" end TestPartial.new.fetch_source('test', :view_path => tmp_path.to_s) end asserts('detects file.rabl') { topic }.equals do ["content\n", (tmp_path + 'test.rabl').to_s] end teardown { Object.send(:remove_const, :Sinatra) } end context "fetch_source with view_path" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Sinatra = stub(Class.new) File.open(tmp_path + "test.rabl", "w") do |f| f.puts "content" end File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts "content2" end TestPartial.new.fetch_source('test', :view_path => tmp_path.to_s) end asserts('detects file.json.rabl first') { topic }.equals do ["content2\n", (tmp_path + 'test.json.rabl').to_s] end teardown { Object.send(:remove_const, :Sinatra) } end context "fetch source using configured view paths" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do Rabl.configure do |config| config.view_paths = tmp_path end ::Sinatra = stub(Class.new) File.open(tmp_path + "test.rabl", "w") do |f| f.puts "content" end File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts "content2" end TestPartial.new.fetch_source('test') end asserts('detects file.json.rabl first') { topic }.equals do ["content2\n", (tmp_path + 'test.json.rabl').to_s] end teardown do Object.send(:remove_const, :Sinatra) Rabl.configuration.view_paths = [] end end context "partial_as_engine using configured view paths" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do File.open(tmp_path + "_test.rabl", "w") Rabl::Engine.new('', :view_path => tmp_path) end asserts('returns new engine with given view_path') do topic.partial_as_engine('test', :object => {}).view_path end.equals do tmp_path end teardown do Rabl.configuration.view_paths = [] end end context "fetch source with custom scope" do context "when Padrino is defined" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Padrino = stub(Class.new) Rabl.configuration.cache_sources = false @it = TestPartial.new def @it.context_scope; @context_scope ||= Object.new; end context_scope = @it.context_scope def context_scope.settings; end File.open(tmp_path + "test.json.rabl", "w") { |f| f.puts "content" } end asserts('Padrino constant dont break manual lookup') do @it.fetch_source('test', :view_path => tmp_path.to_s) end.equals do ["content\n", (tmp_path + "test.json.rabl").to_s ] end teardown { Object.send(:remove_const, :Padrino) } end context "when Sinatra is defined" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Sinatra = stub(Class.new) Rabl.configuration.cache_sources = false @it = TestPartial.new def @it.context_scope; @context_scope ||= Object.new; end context_scope = @it.context_scope def context_scope.settings; @settings ||= Object.new end File.open(tmp_path + "test.json.rabl", "w") { |f| f.puts "content" } end asserts('Sinatra constant dont break manual lookup') do @it.fetch_source((tmp_path + "test").to_s) end.equals do ["content\n", "/" + (tmp_path + "test.json.rabl").to_s ] end teardown { Object.send(:remove_const, :Sinatra) } end end context "fetch source with Rails" do context "and :view_path" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } setup do ::Rails = stub(Class.new) ::ActionPack = Module.new ::ActionPack::VERSION = Module.new ::ActionPack::VERSION::MAJOR = 3 ::ActionPack::VERSION::MINOR = 2 @it = TestPartial.new def @it.context_scope; @context_scope ||= Object.new; end def @it.request_format; :json; end context_scope = @it.context_scope def context_scope.view_paths; []; end def context_scope.lookup_context; @lookup_context ||= Object.new; end lookup_context = context_scope.lookup_context def lookup_context.rendered_format; :json; end def lookup_context.find(*args) raise RuntimeError, 'Something happen with Rails lookup' end File.open(tmp_path + "test.json.rabl", "w") { |f| f.puts "content" } @it end asserts('rails lookups dont break manual') do @it.fetch_source('test', :view_path => tmp_path.to_s) end.equals do ["content\n", (tmp_path + "test.json.rabl").to_s ] end teardown do Object.send(:remove_const, :Rails) Object.send(:remove_const, :ActionPack) Rabl.configuration.view_paths = [] end end end # Rails end # Rabl::Partials rabl-0.16.1/test/plist_engine_test.rb000066400000000000000000000375501432107571000175540ustar00rootroot00000000000000require File.expand_path('../teststrap', __FILE__) require 'rabl/template' context "Rabl::Engine" do helper(:rabl) { |t| RablTemplate.new("code", :format => 'plist') { t } } context "with plist defaults" do setup do Rabl.configure do |config| # Comment this line out because include_plist_root is default. #config.include_plist_root = true end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new clean_plist(template.render(scope)) end.matches clean_plist("\n\n\n\n\tuser\n\t\n\n\n") asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tperson\n\t\n\n\n").split("").sort end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\t\n\t\tuser\n\t\t\n\t\n\t\n\t\tuser\n\t\t\n\t\n\n\n").split("").sort asserts "that it sets root node for objects" do template = rabl %{ collection @users => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tperson\n\t\n\t\t\n\t\t\tperson\n\t\t\t\n\t\t\n\t\t\n\t\t\tperson\n\t\t\t\n\t\t\n\t\n\n\n").split("").sort end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tname\n\t\tirvine\n\t\n\n\n").split("").sort asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tcity\n\t\tirvine\n\t\n\n\n").split("").sort asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tcity\n\t\tirvine\n\t\n\n\n").split("").sort end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } clean_plist(template.render(Object.new)).split("").sort end.equals clean_plist("\n\n\n\n\tfoo\n\tbar\n\n\n").split("").sort asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } clean_plist(template.render(Object.new)).split("").sort end.equals clean_plist("\n\n\n\n\n").split("").sort end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tuser\n\t\t\n\t\t\tcity\n\t\t\tLA\n\t\t\n\t\n\n\n").split("").sort asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tname\n\t\tleo\n\t\tperson\n\t\t\n\t\t\tcity\n\t\t\tLA\n\t\t\n\t\n\n\n") end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tage\n\t\t12\n\t\tcity\n\t\tLA\n\t\tname\n\t\tleo\n\t\n\n\n") end teardown do Rabl.reset_configuration! end end context "with plist_engine" do setup do class CustomPlistEncodeEngine def self.dump string 42 end end Rabl.configure do |config| config.plist_engine = CustomPlistEncodeEngine end end asserts 'that it returns process by custom to_json' do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals 42 teardown do Rabl.reset_configuration! end end context "without plist root" do setup do Rabl.configure do |config| config.include_plist_root = false end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new clean_plist(template.render(scope)) end.matches clean_plist("\n\n\n\n\n") asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\n") end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\t\n\t\n\n\n") asserts "that it sets root node for objects" do template = rabl %{ collection @users => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tperson\n\t\n\t\t\n\t\t\n\t\n\n\n") end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tname\n\tirvine\n\n\n") asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tcity\n\tirvine\n\n\n") asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tcity\n\tirvine\n\n\n") end context "#code" do asserts "that it can create an arbitrary code node" do template = rabl %{ code(:foo) { 'bar' } } clean_plist(template.render(Object.new)) end.equals clean_plist("\n\n\n\n\tfoo\n\tbar\n\n\n") asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } clean_plist(template.render(Object.new)) end.equals clean_plist("\n\n\n\n\n") end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') clean_plist(template.render(scope)).split("").sort end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tcity\n\t\tLA\n\t\n\n\n").split("").sort asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tname\n\tleo\n\tperson\n\t\n\t\tcity\n\t\tLA\n\t\n\n\n") end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) clean_plist(template.render(scope)) end.equals clean_plist("\n\n\n\n\tage\n\t12\n\tcity\n\tLA\n\tname\n\tleo\n\n\n") end teardown do Rabl.reset_configuration! end end end rabl-0.16.1/test/renderer_test.rb000066400000000000000000000275111432107571000166760ustar00rootroot00000000000000require 'tmpdir' require 'pathname' require 'json' require File.expand_path('../teststrap', __FILE__) context "Rabl::Renderer" do helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) } # context_scope 'users', [@user] helper(:context_scope) { |name, value| scope = Object.new stub(scope).controller { stub(Object).controller_name { name } } scope.instance_variable_set :"@#{name.pluralize}", nil scope.instance_variable_set :"@#{name}", value scope } context "#render" do asserts 'renders empty array' do source = %q{ collection @users attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@users, [] renderer = Rabl::Renderer.new(source, [], { :format => 'json', :root => true, :view_path => '/path/to/views', :scope => scope }) renderer.render end.equals "[]" asserts 'renders string as source' do source = %q{ object @user attribute :name, :as => 'city' } user = User.new(:name => 'irvine') renderer = Rabl::Renderer.new(source, user, { :format => 'json', :root => true, :view_path => '/path/to/views' }) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\"}}") asserts 'allows redirecting scope to another object' do source = %q{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') renderer = Rabl::Renderer.new(source, nil, { :format => 'json', :scope => scope }) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\"}}") asserts 'accepts scope on render' do source = %q{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') renderer = Rabl::Renderer.new(source) JSON.parse(renderer.render(scope)) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\"}}") asserts 'passes :locals to render' do source = %q{ attribute :name, :as => 'city' node(:zipcode) { @zipcode } } user = User.new(:name => 'irvine') renderer = Rabl::Renderer.new(source, nil, { :format => 'json', :locals => {:object => user, :zipcode => "92602"} }) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"city\":\"irvine\",\"zipcode\":\"92602\"}}") asserts 'loads source from file' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name } end user = User.new(:name => 'irvine') renderer = Rabl::Renderer.new('test', user, :view_path => tmp_path) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}") asserts 'uses globally configured view paths' do Rabl.configure do |config| config.view_paths << tmp_path end File.open(tmp_path + "test.rabl", "w") do |f| f.puts %q{ attributes :age } end user = User.new(:name => 'irvine') renderer = Rabl::Renderer.new('test', user) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}") asserts 'handles paths for extends' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ attributes :age } end File.open(tmp_path + "user.json.rabl", "w") do |f| f.puts %( object @user attribute :name extends 'test' ) end user = User.new(:name => 'irvine') renderer = Rabl::Renderer.new('user', user, :view_path => tmp_path) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}") asserts 'handles extends with child as nil' do File.open(tmp_path + "foo.json.rabl", "w") do |f| f.puts %q{ object @foo node(:test) do |foo| { test: "#{foo.attribute}" } end } end File.open(tmp_path + "bar.json.rabl", "w") do |f| f.puts %q{ object false node do { test_attribute: 'test_value' } end child(@foos => :foo_collection) do extends 'foo' end } end sc = Object.new sc.instance_variable_set :@foos, nil renderer = Rabl::Renderer.new('bar', false, :view_path => tmp_path, :scope => sc) JSON.parse(renderer.render) end.equals JSON.parse("{\"test_attribute\":\"test_value\", \"foo_collection\":null}") asserts 'handles extends with custom node and object set false' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ node(:foo) { 'baz' } } end File.open(tmp_path + "user.json.rabl", "w") do |f| f.puts %( object false node(:baz) { "bar" } extends 'test' ) end scope = context_scope('users', [User.new, User.new, User.new]) renderer = Rabl::Renderer.new('user', false, :view_path => tmp_path, :scope => scope) JSON.parse(renderer.render) end.equals(JSON.parse(%Q^{"foo":"baz", "baz":"bar" }^)) asserts 'handles extends with attributes and object set false' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ attributes :foo, :bar, :baz node(:test) { |bar| bar.demo if bar } } end File.open(tmp_path + "user.json.rabl", "w") do |f| f.puts %( object false extends 'test' ) end renderer = Rabl::Renderer.new('user', false, :view_path => tmp_path) JSON.parse(renderer.render) end.equals(JSON.parse(%Q^{"test": null}^)) # FIXME template is found and rendered but not included in final results # asserts 'handles paths for partial' do # File.open(tmp_path + "test.json.rabl", "w") do |f| # f.puts %q{ # attributes :age # } # end # File.open(tmp_path + "user.json.rabl", "w") do |f| # f.puts %( # object @user # attribute :name # partial 'test', :object => @user # ) # end # user = User.new(:name => 'irvine') # renderer = Rabl::Renderer.new('user', user, :view_path => tmp_path) # JSON.parse(renderer.render) # end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}") asserts 'Rabl.render calls Renderer' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name } end user = User.new(:name => 'irvine') JSON.parse(Rabl.render(user, 'test', :view_path => tmp_path)) end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}") asserts 'it renders collections' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ collection @users => :users attributes :age, :name } end sc = Object.new sc.instance_variable_set :@users, nil Rabl.render([], 'test', :view_path => tmp_path, :scope => sc) end.equals "{\"users\":[]}" asserts 'it renders an array when given an empty collection' do File.open(tmp_path + "test.json.rabl", "w") do |f| f.puts %q{ collection @users attribute :name, :age } end scope = Object.new scope.instance_variable_set :@users, nil Rabl.render([], 'test', :view_path => tmp_path, :root => false, :scope => scope) end.equals "[]" asserts 'handles view path for when it specified and config is empty' do Rabl.configuration.view_paths = [] File.open(tmp_path + "profile.json.rabl", "w") do |f| f.puts %q{ attributes :gender } end File.open(tmp_path + "user.json.rabl", "w") do |f| f.puts %( object @user attribute :name glue(:profile) do extends 'profile' end child(:profile) do extends 'profile' end ) end user = User.new(:name => 'irvine') stub(user).profile { stub!.gender { "male" } } renderer = Rabl::Renderer.new('user', user, :view_path => tmp_path) JSON.parse(renderer.render) end.equals JSON.parse("{\"user\":{\"name\":\"irvine\",\"object\":{\"gender\":\"male\"},\"gender\":\"male\"}}") asserts "it renders for object false" do File.open(tmp_path + "test2.rabl", "w") do |f| f.puts %q{ object false node(:foo) { 'bar' } } end user = User.new(:name => 'ivan') JSON.parse(Rabl.render(user, 'test2', :view_path => tmp_path)) end.equals JSON.parse("{\"foo\":\"bar\"}") asserts "it renders for object key specified in template" do File.open(tmp_path + "test3.rabl", "w") do |f| f.puts %q{ object @user => :person attributes :age, :name } end user = User.new(:name => 'ivan') JSON.parse(Rabl.render(user, 'test3', :view_path => tmp_path)) end.equals JSON.parse("{\"person\":{\"age\":24,\"name\":\"ivan\"} }") asserts "it renders for overwriting object key specified in render" do File.open(tmp_path + "test4.rabl", "w") do |f| f.puts %q{ object @user => :person attributes :age, :name } end sc = Object.new sc.instance_variable_set :@user, nil user = User.new(:name => 'ivan') JSON.parse(Rabl.render({ user => :human }, 'test4', :view_path => tmp_path, :scope => sc)) end.equals JSON.parse("{\"human\":{\"age\":24,\"name\":\"ivan\"} }") asserts "it renders for specific object key passed to render" do File.open(tmp_path + "test5.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name } end sc = Object.new sc.instance_variable_set :@user, nil user = User.new(:name => 'ivan') JSON.parse(Rabl.render({ user => :person }, 'test5', :view_path => tmp_path, :scope => sc)) end.equals JSON.parse("{\"person\":{\"age\":24,\"name\":\"ivan\"} }") end # render context '.json' do asserts 'it renders json' do File.open(tmp_path + "test.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name, :float } end user = User.new(:name => 'ivan') JSON.parse(Rabl::Renderer.json(user, 'test', :view_path => tmp_path)) end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"ivan\",\"float\":1234.56}}") end # json context '.msgpack' do asserts 'it renders msgpack' do File.open(tmp_path + "test.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name, :float } end user = User.new(:name => 'ivan') char_split Rabl::Renderer.msgpack(user, 'test', :view_path => tmp_path) end.equals char_split("\x81\xA4user\x83\xA3age\x18\xA4name\xA4ivan\xA5float\xCB@\x93J=p\xA3\xD7\n") end context '.plist' do asserts 'it renders xml' do File.open(tmp_path + "test.rabl", "w") do |f| f.puts %q{ object @user attributes :age, :name, :float } end user = User.new(:name => 'ivan') clean_plist(Rabl::Renderer.plist(user, 'test', :view_path => tmp_path)) end.equals clean_plist("\n\n\n\n\tuser\n\t\n\t\tage\n\t\t24\n\t\tfloat\n\t\t1234.56\n\t\tname\n\t\tivan\n\t\n\n\n") end end rabl-0.16.1/test/silence.rb000066400000000000000000000010211432107571000154370ustar00rootroot00000000000000module Kernel def silence_warnings with_warnings(nil) { yield } end def with_warnings(flag) old_verbose, $VERBOSE = $VERBOSE, flag yield ensure $VERBOSE = old_verbose end end unless Kernel.respond_to? :silence_warnings module Kernel def silence_stream(stream) old_stream = stream.dup stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) end end unless Kernel.respond_to? :silence_stream rabl-0.16.1/test/template_test.rb000066400000000000000000000035721432107571000167040ustar00rootroot00000000000000require File.expand_path('../teststrap',__FILE__) require 'rabl/template' class Scope end context "RablTemplate" do asserts "that it registers for .rabl files" do Tilt['test.rabl'] end.equals RablTemplate context "#render" do setup do RablTemplate.new { |t| "code(:lol) { 'wut' }" } end asserts "preparing and evaluating templates on #render" do topic.render end.matches %r{"lol":"wut"} 3.times do |n| asserts "can be rendered #{n} time(s)" do topic.render end.matches %r{"lol":"wut"} end # asserts "that it can be passed locals" do # template = RablTemplate.new { "code(:name) { @name }" } # template.render(Object.new, :object => 'Bob') # end.matches %r{"name":"Bob"} asserts "that it evaluates in object scope" do template = RablTemplate.new { "code(:lol) { @name }" } scope = Object.new scope.instance_variable_set :@name, 'Joe' template.render(scope) end.matches %r{"lol":"Joe"} asserts "that it can pass a block for yield" do template = RablTemplate.new { "code(:lol) { 'Hey ' + yield + '!' }" } template.render { 'Joe' } end.matches %r{"lol":"Hey Joe!"} end context "#render compiled" do # asserts "that it can be passed locals" do # template = RablTemplate.new { "code(:name) { @name }" } # template.render(Scope.new, :object => 'Bob') # end.matches %r{"name":"Bob"} asserts "that it evaluates in an object scope" do template = RablTemplate.new { "code(:lol) { @name }" } scope = Scope.new scope.instance_variable_set :@name, 'Joe' template.render(scope) end.matches %r{"lol":"Joe"} asserts "that it can pass a block for yield" do template = RablTemplate.new { "code(:lol) { 'Hey ' + yield + '!' }" } template.render(Scope.new) { 'Joe' } end.matches %r{"lol":"Hey Joe!"} end end rabl-0.16.1/test/teststrap.rb000066400000000000000000000016501432107571000160560ustar00rootroot00000000000000$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__)) module Kernel def silence_warnings with_warnings(nil) { yield } end def with_warnings(flag) old_verbose, $VERBOSE = $VERBOSE, flag yield ensure $VERBOSE = old_verbose end end unless Kernel.respond_to? :silence_warnings silence_warnings do require 'riot' require 'riot/rr' require 'tilt' require 'rabl' require 'hashie' require File.expand_path('../models/user', __FILE__) end if $stdout.tty? then Riot.pretty_dots else Riot.dots Riot.plain! end module RiotTestHelpers def char_split(str) str.force_encoding("iso-8859-1").split("").sort end def clean_plist(text) text.gsub(%r{ 'xml') { t } } # TODO fix annoying warnings in this file: # gems/builder-3.0.3/lib/builder/xmlbase.rb:181: warning: method redefined; discarding old user setup { @old_verbose, $VERBOSE = $VERBOSE, nil } teardown { $VERBOSE = @old_verbose } context "with xml defaults" do setup do Rabl.configure do |config| # Comment this line out because include_xml_root to false is default. #config.include_xml_root = false end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "\n\n\n" end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "\n\n \n \n \n \n\n" asserts "that it sets root node for objects" do template = rabl %{ collection @users => :smors } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "\n\n \n \n \n \n\n" end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n irvine\n\n" asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n irvine\n\n" asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n irvine\n\n" end context "#code" do asserts "that it can create an arbitraty code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new) end.equals "\n\n bar\n\n" asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new) end.equals "\n\n\n" end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope) end.equals "\n\n \n LA\n \n\n" asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope) end.equals "\n\n leo\n \n LA\n \n\n" end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) template.render(scope) end.equals "\n\n leo\n LA\n 12\n\n" end teardown do Rabl.reset_configuration! end end context "with xml root" do setup do Rabl.configure do |config| config.include_xml_root = true end end context "#object" do asserts "that it sets data source" do template = rabl %q{ object @user } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.matches "\n\n \n \n\n" asserts "that it can set root node" do template = rabl %q{ object @user => :person } scope = Object.new scope.instance_variable_set :@user, User.new template.render(scope) end.equals "\n\n \n \n\n" end context "#collection" do asserts "that it sets object to be casted as a simple array" do template = rabl %{ collection @users } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "\n\n \n \n \n \n \n \n \n \n\n" asserts "that it sets root node for objects" do template = rabl %{ collection @users => :people } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "\n\n \n \n \n \n \n \n \n \n\n" asserts "that it sets root node for objects with :root parameter" do template = rabl %{ collection @users, :root => :people, :object_root => :person } scope = Object.new scope.instance_variable_set :@users, [User.new, User.new] template.render(scope) end.equals "\n\n \n \n \n \n \n \n \n \n\n" end context "#attribute" do asserts "that it adds an attribute or method to be included in output" do template = rabl %{ object @user attribute :name } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n \n irvine\n \n\n" asserts "that it can add attribute under a different key name through :as" do template = rabl %{ object @user attribute :name, :as => 'city' } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n \n irvine\n \n\n" asserts "that it can add attribute under a different key name through hash" do template = rabl %{ object @user attribute :name => :city } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'irvine') template.render(scope) end.equals "\n\n \n irvine\n \n\n" end context "#code" do asserts "that it can create an arbitrary code node" do template = rabl %{ code(:foo) { 'bar' } } template.render(Object.new) end.equals "\n\n bar\n\n" asserts "that it can be passed conditionals" do template = rabl %{ code(:foo, :if => lambda { |i| false }) { 'bar' } } template.render(Object.new) end.equals "\n\n\n" end context "#child" do asserts "that it can create a child node" do template = rabl %{ object @user child(@user) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope) end.equals "\n\n \n \n LA\n \n \n\n" asserts "that it can create a child node with different key" do template = rabl %{ object @user attribute :name child(@user => :person) { attribute :city } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA') template.render(scope) end.equals "\n\n \n leo\n \n LA\n \n \n\n" end context "#glue" do asserts "that it glues data from a child node" do template = rabl %{ object @user attribute :name glue(@user) { attribute :city } glue(@user) { attribute :age } } scope = Object.new scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12) template.render(scope) end.equals "\n\n \n leo\n LA\n 12\n \n\n" end teardown do Rabl.reset_configuration! end end end