acts_as_api-0.4.3/0000755000004100000410000000000012763720301014015 5ustar www-datawww-dataacts_as_api-0.4.3/Rakefile0000644000004100000410000000206412763720301015464 0ustar www-datawww-datarequire 'bundler' require 'rspec/core' require 'rspec/core/rake_task' Bundler::GemHelper.install_tasks RSpec::Core::RakeTask.new namespace :spec do supported_orms = %w(mongoid active_record) supported_orms.each do |orm| desc "Run #{orm} specs only" RSpec::Core::RakeTask.new(orm) do |t| t.rspec_opts = ["--color"] end task "prepare_#{orm}" do ENV['ACTS_AS_API_ORM'] = orm end Rake::Task["spec:#{orm}"].prerequisites << "spec:prepare_#{orm}" end # task :all => supported_orms.map{|orm| "spec:#{orm}"} desc "Runs specs for all ORMs (#{supported_orms.join(', ')})" task :all do supported_orms.each do |orm| puts "Starting to run specs for #{orm}..." system("bundle exec rake spec:#{orm}") raise "#{orm} failed!" unless $?.exitstatus == 0 end end end gemspec = Gem::Specification.load("acts_as_api.gemspec") task :default => "spec:all" desc "Generate the gh_pages site" task :rocco do system "bundle exec rocco examples/introduction/index.rb -t examples/introduction/layout.mustache" end acts_as_api-0.4.3/Gemfile0000644000004100000410000000060512763720301015311 0ustar www-datawww-datasource "http://rubygems.org" # Specify your gem's dependencies in acts_as_api.gemspec gemspec group :test do gem 'test-unit', '~> 3.0' gem 'sqlite3-ruby' gem 'mongoid', '>= 3.0.1' gem 'rspec', '>= 2.9.0' gem 'rspec-its' gem 'rspec-collection_matchers' gem 'capybara' gem 'rspec-rails', '>= 2.5.0' gem 'webrat' gem 'shared_engine', :path => './spec/shared_engine' end acts_as_api-0.4.3/examples/0000755000004100000410000000000012763720301015633 5ustar www-datawww-dataacts_as_api-0.4.3/examples/introduction/0000755000004100000410000000000012763720301020354 5ustar www-datawww-dataacts_as_api-0.4.3/examples/introduction/index.rb0000644000004100000410000001075712763720301022022 0ustar www-datawww-data# The built-in XML/JSON support of Rails is great but: # You surely don’t want to expose your models always with all attributes. # # acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your API responses should look like. ### Features # * DRY templates for your api responses # * Ships with support for **ActiveRecord** and **Mongoid** # * Support for Rails 3 Responders # * Plays very well together with client libs like [Backbone.js][b1] or [RestKit][r1] (iOS). # * Easy but very flexible syntax for defining the templates # * XML, JSON and JSON-P support out of the box, easy to extend # * Support for meta data like pagination info, etc... # * Minimal dependecies (you can also use it without Rails) # * Supports multiple api rendering templates for a models. This is especially useful for API versioning or for example for private vs. public access points to a user’s profile. # [b1]: http://documentcloud.github.com/backbone # [r1]: http://restkit.org # *** ### Rails 3.x Quickstart # Add to gemfile gem 'acts_as_api' # Update your bundle bundle install #### Setting up your Model # Given you have a model `User`. # If you only want to expose the `first_name` and `last_name` attribute of a user via your api, you would do something like this: # Within your model: # # First you activate acts_as_api for your model by calling `acts_as_api`. # # Then you define an api template to render the model with `api_accessible`. class User < ActiveRecord::Base acts_as_api api_accessible :name_only do |template| template.add :first_name template.add :last_name end end # An API template with the name `:name_only` was created. # # See below how to use it in the controller: #### Setting up your Controller # Now you just have to exchange the `render` method in your controller for the `render_for_api` method. class UsersController < ApplicationController def index @users = User.all # Note that it's wise to add a `root` param when rendering lists. respond_to do |format| format.xml { render_for_api :name_only, :xml => @users, :root => :users } format.json { render_for_api :name_only, :json => @users, :root => :users } end end def show @user = User.find(params[:id]) respond_to do |format| format.xml { render_for_api :name_only, :xml => @user } format.json { render_for_api :name_only, :json => @user } end end end #### That's it! # Try it. The JSON response of #show should now look like this: # # Other attributes of the model like `created_at` or `updated_at` won’t be included # because they were not listed by `api_accessible` in the model. { "user": { "first_name": "John", "last_name": "Doe" } } # *** ### But wait! ... there's more # # Often the pure rendering of database values is just not enough, so acts_as_api # provides you some tools to customize your API responses. #### What can I include in my responses? # # You can do basically anything: # # * [Include attributes and all other kinds of methods of your model][w1] # * [Include child associations (if they also act_as_api this will be considered)][w2] # * [Include lambdas and Procs][w3] # * [Call methods of a parent association][w4] # * [Call scopes of your model or child associations][w5] # * [Rename attributes, methods, associations][w6] # * [Create your own hierarchies][w7] # # You can find more advanced examples in the [Github Wiki][wi] # # [wi]: https://github.com/fabrik42/acts_as_api/wiki/ # [w1]: https://github.com/fabrik42/acts_as_api/wiki/Calling-a-method-of-the-model # [w2]: https://github.com/fabrik42/acts_as_api/wiki/Including-a-child-association # [w3]: https://github.com/fabrik42/acts_as_api/wiki/Calling-a-lambda-in-the-api-template # [w4]: https://github.com/fabrik42/acts_as_api/wiki/Calling-a-method-of-the-model # [w5]: https://github.com/fabrik42/acts_as_api/wiki/Calling-a-scope-of-a-sub-resource # [w6]: https://github.com/fabrik42/acts_as_api/wiki/Renaming-an-attribute # [w7]: https://github.com/fabrik42/acts_as_api/wiki/Creating-a-completely-different-response-structure # *** ### Links # * Check out the [source code on Github][so] # * For more usage examples visit the [wiki][wi] # * Found a bug or do you have a feature request? [issue tracker][to] # * [Docs][do] # # [so]: https://github.com/fabrik42/acts_as_api/ # [wi]: https://github.com/fabrik42/acts_as_api/wiki/ # [to]: https://github.com/fabrik42/acts_as_api/issues # [do]: http://rdoc.info/github/fabrik42/acts_as_api acts_as_api-0.4.3/examples/introduction/docco.css0000644000004100000410000001567512763720301022173 0ustar www-datawww-data/*--------------------- Layout and Typography ----------------------------*/ body { font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; font-size: 15px; line-height: 22px; color: #252519; margin: 0; padding: 0; } a { color: #261a3b; } a:visited { color: #261a3b; } p { margin: 0 0 15px 0; } h1, h2, h3, h4, h5, h6 { margin: 0px 0 15px 0; } h1 { margin-top: 40px; } #container { position: relative; } #background { position: fixed; top: 0; left: 525px; right: 0; bottom: 0; background: #f5f5ff; border-left: 1px solid #e5e5ee; z-index: -1; } #jump_to, #jump_page { background: white; -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777; -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px; font: 10px Arial; text-transform: uppercase; cursor: pointer; text-align: right; } #jump_to, #jump_wrapper { position: fixed; right: 0; top: 0; padding: 5px 10px; } #jump_wrapper { padding: 0; display: none; } #jump_to:hover #jump_wrapper { display: block; } #jump_page { padding: 5px 0 3px; margin: 0 0 25px 25px; } #jump_page .source { display: block; padding: 5px 10px; text-decoration: none; border-top: 1px solid #eee; } #jump_page .source:hover { background: #f5f5ff; } #jump_page .source:first-child { } table td { border: 0; outline: 0; } td.docs, th.docs { max-width: 450px; min-width: 450px; min-height: 5px; padding: 10px 25px 1px 50px; overflow-x: hidden; vertical-align: top; text-align: left; } .docs pre { margin: 15px 0 15px; padding-left: 15px; } .docs p tt, .docs p code { background: #f8f8ff; border: 1px solid #dedede; font-size: 12px; padding: 0 0.2em; } .pilwrap { position: relative; } .pilcrow { font: 12px Arial; text-decoration: none; color: #454545; position: absolute; top: 3px; left: -20px; padding: 1px 2px; opacity: 0; -webkit-transition: opacity 0.2s linear; } td.docs:hover .pilcrow { opacity: 1; } td.code, th.code { padding: 14px 15px 16px 25px; width: 100%; vertical-align: top; background: #f5f5ff; border-left: 1px solid #e5e5ee; } pre, tt, code { font-size: 12px; line-height: 18px; font-family: Monaco, Consolas, "Lucida Console", monospace; margin: 0; padding: 0; } /*---------------------- Syntax Highlighting -----------------------------*/ td.linenos { background-color: #f0f0f0; padding-right: 10px; } span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } body .hll { background-color: #ffffcc } body .c { color: #408080; font-style: italic } /* Comment */ body .err { border: 1px solid #FF0000 } /* Error */ body .k { color: #954121 } /* Keyword */ body .o { color: #666666 } /* Operator */ body .cm { color: #408080; font-style: italic } /* Comment.Multiline */ body .cp { color: #BC7A00 } /* Comment.Preproc */ body .c1 { color: #408080; font-style: italic } /* Comment.Single */ body .cs { color: #408080; font-style: italic } /* Comment.Special */ body .gd { color: #A00000 } /* Generic.Deleted */ body .ge { font-style: italic } /* Generic.Emph */ body .gr { color: #FF0000 } /* Generic.Error */ body .gh { color: #000080; font-weight: bold } /* Generic.Heading */ body .gi { color: #00A000 } /* Generic.Inserted */ body .go { color: #808080 } /* Generic.Output */ body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ body .gs { font-weight: bold } /* Generic.Strong */ body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ body .gt { color: #0040D0 } /* Generic.Traceback */ body .kc { color: #954121 } /* Keyword.Constant */ body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */ body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */ body .kp { color: #954121 } /* Keyword.Pseudo */ body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */ body .kt { color: #B00040 } /* Keyword.Type */ body .m { color: #666666 } /* Literal.Number */ body .s { color: #219161 } /* Literal.String */ body .na { color: #7D9029 } /* Name.Attribute */ body .nb { color: #954121 } /* Name.Builtin */ body .nc { color: #0000FF; font-weight: bold } /* Name.Class */ body .no { color: #880000 } /* Name.Constant */ body .nd { color: #AA22FF } /* Name.Decorator */ body .ni { color: #999999; font-weight: bold } /* Name.Entity */ body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ body .nf { color: #0000FF } /* Name.Function */ body .nl { color: #A0A000 } /* Name.Label */ body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ body .nt { color: #954121; font-weight: bold } /* Name.Tag */ body .nv { color: #19469D } /* Name.Variable */ body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ body .w { color: #bbbbbb } /* Text.Whitespace */ body .mf { color: #666666 } /* Literal.Number.Float */ body .mh { color: #666666 } /* Literal.Number.Hex */ body .mi { color: #666666 } /* Literal.Number.Integer */ body .mo { color: #666666 } /* Literal.Number.Oct */ body .sb { color: #219161 } /* Literal.String.Backtick */ body .sc { color: #219161 } /* Literal.String.Char */ body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */ body .s2 { color: #219161 } /* Literal.String.Double */ body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ body .sh { color: #219161 } /* Literal.String.Heredoc */ body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ body .sx { color: #954121 } /* Literal.String.Other */ body .sr { color: #BB6688 } /* Literal.String.Regex */ body .s1 { color: #219161 } /* Literal.String.Single */ body .ss { color: #19469D } /* Literal.String.Symbol */ body .bp { color: #954121 } /* Name.Builtin.Pseudo */ body .vc { color: #19469D } /* Name.Variable.Class */ body .vg { color: #19469D } /* Name.Variable.Global */ body .vi { color: #19469D } /* Name.Variable.Instance */ body .il { color: #666666 } /* Literal.Number.Integer.Long */acts_as_api-0.4.3/examples/introduction/layout.mustache0000644000004100000410000000375512763720301023436 0ustar www-datawww-data acts_as_api
{{#sources?}}
Jump To …
{{#sources}} {{ basename }} {{/sources}}
{{/sources?}} {{#sections}} {{/sections}}

acts_as_api

Makes creating XML/JSON responses in Rails 3 easy and fun.

{{{ docs }}}
{{{ code }}}
Fork me on GitHub acts_as_api-0.4.3/examples/introduction/index.html0000644000004100000410000003500312763720301022352 0ustar www-datawww-data acts_as_api

acts_as_api

Makes creating XML/JSON responses in Rails 3 easy and fun.

The built-in XML/JSON support of Rails is great but: You surely don’t want to expose your models always with all attributes.

acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your API responses should look like.

Features

  • DRY templates for your api responses
  • Ships with support for ActiveRecord and Mongoid
  • Support for Rails 3 Responders
  • Plays very well together with client libs like Backbone.js or RestKit (iOS).
  • Easy but very flexible syntax for defining the templates
  • XML, JSON and JSON-P support out of the box, easy to extend
  • Support for meta data like pagination info, etc…
  • Minimal dependecies (you can also use it without Rails)
  • Supports multiple api rendering templates for a models. This is especially useful for API versioning or for example for private vs. public access points to a user’s profile.

Rails 3.x Quickstart

Add to gemfile

gem 'acts_as_api'

Update your bundle

bundle install

Setting up your Model

Given you have a model User. If you only want to expose the first_name and last_name attribute of a user via your api, you would do something like this:

Within your model:

First you activate acts_as_api for your model by calling acts_as_api.

Then you define an api template to render the model with api_accessible.

class User < ActiveRecord::Base

  acts_as_api

  api_accessible :name_only do |template|
    template.add :first_name
    template.add :last_name
  end

end

An API template with the name :name_only was created.

See below how to use it in the controller:

Setting up your Controller

Now you just have to exchange the render method in your controller for the render_for_api method.

class UsersController < ApplicationController

  def index
    @users = User.all

Note that it’s wise to add a root param when rendering lists.

    respond_to do |format|
      format.xml  { render_for_api :name_only, :xml => @users, :root => :users  }
      format.json { render_for_api :name_only, :json => @users, :root => :users }
    end
  end

  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.xml  { render_for_api :name_only, :xml  => @user }
      format.json { render_for_api :name_only, :json => @user }
    end
  end

end

That’s it!

Try it. The JSON response of #show should now look like this:

Other attributes of the model like created_at or updated_at won’t be included because they were not listed by api_accessible in the model.

{
  "user": {
    "first_name": "John",
    "last_name":  "Doe"
  }
}

But wait! … there’s more

Often the pure rendering of database values is just not enough, so acts_as_api provides you some tools to customize your API responses.

What can I include in my responses?

You can do basically anything:

You can find more advanced examples in the Github Wiki


Fork me on GitHub acts_as_api-0.4.3/History.txt0000644000004100000410000000437312763720301016226 0ustar www-datawww-data=== 0.4.2 2013-12-28 * Fixed problem with rendering of POROs (see PR #88) === 0.4.1 2012-07-18 * Added support for Mongoid 3 === 0.4 2012-04-30 * Added support for a second parameter (options) to pass to as_api_response === 0.3.11 2011-11-06 * Added :postfix, :prefix options for template rendering === 0.3.10 2011-10-03 * Fixed Mongoid problems, when no ActiveRecord is available (Ticket #36) === 0.3.9 2011-09-24 * Spec suite now running on Rails 3.1 * Fixed naming issue with ActiveRecord::Relation (Ticket #35) === 0.3.8 2011-06-21 * Fixed Rails 3.1 deprecation warning === 0.3.7 2011-06-13 * Added before/around/after callbacks === 0.3.6 2011-05-13 * Finally added Mongoid Support out of the box * Support for Rails 3 Responders === 0.3.4 2011-04-26 * Fixed a bug concerning the inheritance of sub templates/additional options === 0.3.3 2011-04-24 * Added support for :if and :unless options === 0.3.2 2011-04-20 * Raise an exception if a specified api template is not found === 0.3.1 2011-04-08 * Added the :template option to specify sub templates * Fixed a bug concerning extended api templates === 0.3.0 2011-02-22 * Added bundler support * Added mongoid support * Removed lots of unnecessary dependencies esp. ActiveRecord === 0.2.2 2010-10-21 * Version bump only for changing the github account in the docs. === 0.2.1 2010-09-20 * Updated to work with Rails 3.0.0 * Added support for multiple renderings of the same model (e.g. useful for versioning). Note that the interface of acts as api changed, soyou have to update your code. * Updated dependecies to user Rails 3.0.0 libs instead of beta. === 0.1.10 2010-07-23 * More Bugfixes. When you want to render an Array of records (e.g. from MyRecord.all) make sure you pass the :root options to render_as_api - in case it will return an empty array === 0.1.7 2010-07-05 * Fixed bug with multi-word models. === 0.1.4 2010-07-04 * Added better documentation. === 0.1.3 2010-07-04 * Support for including methods of associated models. * Better root name determination for arrays. === 0.0.3 2010-07-01 * 1 small bugfix === 0.0.2 2010-07-01 * 1 major enhancement: * Added a wrapping root node for JSON responses by default. === 0.0.1 2010-06-27 * 1 major enhancement: * Initial release acts_as_api-0.4.3/spec/0000755000004100000410000000000012763720301014747 5ustar www-datawww-dataacts_as_api-0.4.3/spec/controllers/0000755000004100000410000000000012763720301017315 5ustar www-datawww-dataacts_as_api-0.4.3/spec/controllers/respond_with_users_controller_spec.rb0000644000004100000410000000755212763720301027056 0ustar www-datawww-datarequire 'spec_helper' # # RSpec.configure do |config| # config.include SharedEngine::Engine.routes.url_helpers # end describe SharedEngine::RespondWithUsersController, type: :controller do before(:each) do setup_models end after(:each) do clean_up_models end # see spec/support/controller_examples.rb it_behaves_like "a controller with ActsAsApi responses" describe "default ActionController::Responder behavior" do context 'json responses' do context "creating valid models" do before(:each) do post :create, :user => { :first_name => "Luke", :last_name => "Skywalker" }, :api_template => :name_only, :format => 'json' end it "should return HTTP 201 status" do response.code.should == "201" end it "should contain the specified attributes" do response_body_json["user"].should have_key("first_name") response_body_json["user"].should have_key("last_name") end it "should contain the specified values" do response_body_json["user"]["first_name"].should eql("Luke") response_body_json["user"]["last_name"].should eql("Skywalker") end end context "creating invalid models" do before(:each) do post :create, :user => {}, :api_template => :name_only, :format => 'json' end it "should return HTTP 422 status" do response.code.should == "422" end it "should return errors as json" do response_body_json['errors']['first_name'].should include("can't be blank") response_body_json['errors']['last_name'].should include("can't be blank") end end context "returning all models without default root and no order" do before(:each) do get :index_no_root_no_order, :api_template => :name_only, :format => 'json' end it "should return HTTP 200 status" do response.code.should == "200" end it "should contain the specified attributes" do response_body_json["users"].each do |user| user.should have_key( "first_name" ) user.should have_key( "last_name" ) end end end end context 'xml responses' do context "creating valid models" do before(:each) do post :create, :user => { :first_name => "Luke", :last_name => "Skywalker" }, :api_template => :name_only, :format => 'xml' end it "should return HTTP 201 status" do response.code.should == "201" end it "should include HTTP Location header" do response.headers["Location"].should match "/shared/users/#{User.last.id}" end it "should contain the specified attributes" do response_body.should have_selector("user > first-name") response_body.should have_selector("user > last-name") end end context "creating invalid models" do before(:each) do post :create, :user => {}, :api_template => :name_only, :format => 'xml' end it "should return HTTP 422 status" do response.code.should == "422" end it "should return errors as xml" do response_body.should have_selector("errors > error") end end context "returning all models without default root and no order" do before(:each) do get :index_no_root_no_order, :api_template => :name_only, :format => 'xml' end it "should return HTTP 200 status" do response.code.should == "200" end it "should contain the specified attributes" do response_body.should have_selector( "users > user > first-name", :count => 3 ) response_body.should have_selector( "users > user > last-name", :count => 3 ) end end end end end acts_as_api-0.4.3/spec/controllers/plain_objects_controller_spec.rb0000644000004100000410000000207212763720301025734 0ustar www-datawww-datarequire 'spec_helper' describe SharedEngine::PlainObjectsController, type: :controller do include ApiTestHelpers before(:each) do class SharedEngine::PlainObjectsController include SimpleFixtures end end describe 'get all users as a an array of plain objects, autodetecting the root node name' do before(:each) do get :index, :format => 'json', :api_template => :name_only end it "should have a root node named users" do response_body_json.should have_key("plain_objects") end it "should contain all users" do response_body_json["plain_objects"].should be_a(Array) end it "should contain the specified attributes" do response_body_json["plain_objects"].first.should have_key("first_name") response_body_json["plain_objects"].first.should have_key("last_name") end it "should contain the specified values" do response_body_json["plain_objects"].first["first_name"].should eql("Han") response_body_json["plain_objects"].first["last_name"].should eql("Solo") end end end acts_as_api-0.4.3/spec/controllers/users_controller_spec.rb0000644000004100000410000000042612763720301024262 0ustar www-datawww-datarequire 'spec_helper' describe SharedEngine::UsersController, type: :controller do before(:each) do setup_models end after(:each) do clean_up_models end # see spec/support/controller_examples.rb it_behaves_like "a controller with ActsAsApi responses" end acts_as_api-0.4.3/spec/mongoid_dummy/0000755000004100000410000000000012763720301017616 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/Rakefile0000644000004100000410000000042512763720301021264 0ustar www-datawww-data#!/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__) MongoidDummy::Application.load_tasks acts_as_api-0.4.3/spec/mongoid_dummy/Gemfile0000644000004100000410000000052712763720301021115 0ustar www-datawww-datasource 'https://rubygems.org' gem 'rails', '3.2.22.2' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem "bson_ext" gem "mongoid", ">= 3.0.0.rc" gem 'shared_engine', :path => '../shared_engine' gem 'acts_as_api', :path => '../../' group :test do gem 'rspec-rails', '>= 2.5.0' gem 'webrat' end acts_as_api-0.4.3/spec/mongoid_dummy/doc/0000755000004100000410000000000012763720301020363 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/doc/README_FOR_APP0000644000004100000410000000032312763720301022447 0ustar www-datawww-dataUse 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. acts_as_api-0.4.3/spec/mongoid_dummy/script/0000755000004100000410000000000012763720301021122 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/script/rails0000755000004100000410000000044712763720301022167 0ustar www-datawww-data#!/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' acts_as_api-0.4.3/spec/mongoid_dummy/log/0000755000004100000410000000000012763720301020377 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/log/.gitkeep0000644000004100000410000000000012763720301022016 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/db/0000755000004100000410000000000012763720301020203 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/db/seeds.rb0000644000004100000410000000052712763720301021637 0ustar www-datawww-data# 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) acts_as_api-0.4.3/spec/mongoid_dummy/vendor/0000755000004100000410000000000012763720301021113 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/assets/0000755000004100000410000000000012763720301022415 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/assets/javascripts/0000755000004100000410000000000012763720301024746 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep0000644000004100000410000000000012763720301026365 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/assets/stylesheets/0000755000004100000410000000000012763720301024771 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep0000644000004100000410000000000012763720301026410 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/plugins/0000755000004100000410000000000012763720301022574 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/vendor/plugins/.gitkeep0000644000004100000410000000000012763720301024213 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/public/0000755000004100000410000000000012763720301021074 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/public/422.html0000644000004100000410000000130712763720301022272 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/mongoid_dummy/public/favicon.ico0000644000004100000410000000000012763720301023203 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/public/robots.txt0000644000004100000410000000031412763720301023143 0ustar www-datawww-data# 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: / acts_as_api-0.4.3/spec/mongoid_dummy/public/404.html0000644000004100000410000000133012763720301022266 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/mongoid_dummy/public/500.html0000644000004100000410000000120312763720301022262 0ustar www-datawww-data We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts_as_api-0.4.3/spec/mongoid_dummy/public/index.html0000644000004100000410000001342212763720301023073 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/mongoid_dummy/README.rdoc0000644000004100000410000002177012763720301021433 0ustar www-datawww-data== 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. acts_as_api-0.4.3/spec/mongoid_dummy/lib/0000755000004100000410000000000012763720301020364 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/lib/assets/0000755000004100000410000000000012763720301021666 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/lib/assets/.gitkeep0000644000004100000410000000000012763720301023305 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/lib/tasks/0000755000004100000410000000000012763720301021511 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/lib/tasks/.gitkeep0000644000004100000410000000000012763720301023130 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/.gitignore0000644000004100000410000000065612763720301021615 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/0000755000004100000410000000000012763720301021063 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/config/application.rb0000644000004100000410000000556212763720301023723 0ustar www-datawww-datarequire File.expand_path('../boot', __FILE__) # Pick the frameworks you want: # require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "sprockets/railtie" require "rails/test_unit/railtie" 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 MongoidDummy 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/0000755000004100000410000000000012763720301023571 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/secret_token.rb0000644000004100000410000000076712763720301026615 0ustar www-datawww-data# 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. MongoidDummy::Application.config.secret_token = '6b56ce25197cabc62558d2cea0a7577dbf7b23e9a3003e34f0e2831fa1438e1f7545d7ab4959632d502a98651f4933e97fcf89ae22be67c4b06f1b8988fc8761' acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb0000644000004100000410000000014212763720301030064 0ustar www-datawww-dataif defined?(Mongoid::Document) Mongoid::Document.send :include, ActsAsApi::Adapters::Mongoid endacts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/session_store.rb0000644000004100000410000000066012763720301027017 0ustar www-datawww-data# Be sure to restart your server when you modify this file. MongoidDummy::Application.config.session_store :cookie_store, :key => '_mongoid_dummy_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") # MongoidDummy::Application.config.session_store :active_record_store acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/mime_types.rb0000644000004100000410000000031512763720301026270 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/wrap_parameters.rb0000644000004100000410000000053012763720301027310 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/generators.rb0000644000004100000410000000005712763720301026271 0ustar www-datawww-dataRails.application.config.generators do |g| end acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb0000644000004100000410000000062412763720301030106 0ustar www-datawww-data# 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! acts_as_api-0.4.3/spec/mongoid_dummy/config/initializers/inflections.rb0000644000004100000410000000102512763720301026431 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/boot.rb0000644000004100000410000000027712763720301022361 0ustar www-datawww-datarequire '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']) acts_as_api-0.4.3/spec/mongoid_dummy/config/environments/0000755000004100000410000000000012763720301023612 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/config/environments/test.rb0000644000004100000410000000256612763720301025127 0ustar www-datawww-dataMongoidDummy::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 # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end acts_as_api-0.4.3/spec/mongoid_dummy/config/environments/production.rb0000644000004100000410000000436212763720301026332 0ustar www-datawww-dataMongoidDummy::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 end acts_as_api-0.4.3/spec/mongoid_dummy/config/environments/development.rb0000644000004100000410000000206512763720301026464 0ustar www-datawww-dataMongoidDummy::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 # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end acts_as_api-0.4.3/spec/mongoid_dummy/config/mongoid.yml0000644000004100000410000001046212763720301023245 0ustar www-datawww-datadevelopment: # Configure available database sessions. (required) sessions: # Defines the default session. (required) default: # Defines the name of the default database that Mongoid can connect to. # (required). database: mongoid_dummy_development # Provides the hosts the default session can connect to. Must be an array # of host:port pairs. (required) hosts: - localhost:27017 options: # Change whether the session persists in safe mode by default. # (default: false) # safe: false # Change the default consistency model to :eventual or :strong. # :eventual will send reads to secondaries, :strong sends everything # to master. (default: :eventual) consistency: :strong # Configure Mongoid specific options. (optional) options: # Configuration for whether or not to allow access to fields that do # not have a field definition on the model. (default: true) # allow_dynamic_fields: true # Enable the identity map, needed for eager loading. (default: false) # identity_map_enabled: false # Includes the root model name in json serialization. (default: false) # include_root_in_json: false # Include the _type field in serializaion. (default: false) # include_type_for_serialization: false # Preload all models in development, needed when models use # inheritance. (default: false) # preload_models: false # Protect id and type from mass assignment. (default: true) # protect_sensitive_fields: true # Raise an error when performing a #find and the document is not found. # (default: true) # raise_not_found_error: true # Raise an error when defining a scope with the same name as an # existing method. (default: false) # scope_overwrite_exception: false # Skip the database version check, used when connecting to a db without # admin access. (default: false) # skip_version_check: false # User Active Support's time zone in conversions. (default: true) # use_activesupport_time_zone: true # Ensure all times are UTC in the app side. (default: false) # use_utc: false test: # Configure available database sessions. (required) sessions: # Defines the default session. (required) default: # Defines the name of the default database that Mongoid can connect to. # (required). database: mongoid_dummy_test # Provides the hosts the default session can connect to. Must be an array # of host:port pairs. (required) hosts: - localhost:27017 options: # Change whether the session persists in safe mode by default. # (default: false) # safe: false # Change the default consistency model to :eventual or :strong. # :eventual will send reads to secondaries, :strong sends everything # to master. (default: :eventual) consistency: :strong # Configure Mongoid specific options. (optional) options: # Configuration for whether or not to allow access to fields that do # not have a field definition on the model. (default: true) # allow_dynamic_fields: true # Enable the identity map, needed for eager loading. (default: false) # identity_map_enabled: false # Includes the root model name in json serialization. (default: false) # include_root_in_json: false # Include the _type field in serializaion. (default: false) # include_type_for_serialization: false # Preload all models in development, needed when models use # inheritance. (default: false) # preload_models: false # Protect id and type from mass assignment. (default: true) # protect_sensitive_fields: true # Raise an error when performing a #find and the document is not found. # (default: true) # raise_not_found_error: true # Raise an error when defining a scope with the same name as an # existing method. (default: false) # scope_overwrite_exception: false # Skip the database version check, used when connecting to a db without # admin access. (default: false) # skip_version_check: false # User Active Support's time zone in conversions. (default: true) # use_activesupport_time_zone: true # Ensure all times are UTC in the app side. (default: false) # use_utc: false acts_as_api-0.4.3/spec/mongoid_dummy/config/routes.rb0000644000004100000410000000347612763720301022743 0ustar www-datawww-dataMongoidDummy::Application.routes.draw do mount SharedEngine::Engine => "/shared", :as => "shared" # 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 acts_as_api-0.4.3/spec/mongoid_dummy/config/environment.rb0000644000004100000410000000023412763720301023753 0ustar www-datawww-data# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application MongoidDummy::Application.initialize! acts_as_api-0.4.3/spec/mongoid_dummy/config/locales/0000755000004100000410000000000012763720301022505 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/config/locales/en.yml0000644000004100000410000000032612763720301023633 0ustar www-datawww-data# 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" acts_as_api-0.4.3/spec/mongoid_dummy/app/0000755000004100000410000000000012763720301020376 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/views/0000755000004100000410000000000012763720301021533 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/views/layouts/0000755000004100000410000000000012763720301023233 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/views/layouts/application.html.erb0000644000004100000410000000035712763720301027200 0ustar www-datawww-data MongoidDummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts_as_api-0.4.3/spec/mongoid_dummy/app/controllers/0000755000004100000410000000000012763720301022744 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/controllers/application_controller.rb0000644000004100000410000000012012763720301030030 0ustar www-datawww-dataclass ApplicationController < ActionController::Base protect_from_forgery end acts_as_api-0.4.3/spec/mongoid_dummy/app/mailers/0000755000004100000410000000000012763720301022032 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/mailers/.gitkeep0000644000004100000410000000000012763720301023451 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/assets/0000755000004100000410000000000012763720301021700 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/assets/images/0000755000004100000410000000000012763720301023145 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/assets/images/rails.png0000644000004100000410000001476612763720301025003 0ustar www-datawww-dataPNG  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 String field :description, :type => String field :time_spent, :type => Integer field :done, :type => Boolean field :created_at, :type => DateTime field :updated_at, :type => DateTime embedded_in :user, :class_name => "User", :inverse_of => :task endacts_as_api-0.4.3/spec/mongoid_dummy/app/models/profile.rb0000644000004100000410000000040512763720301023645 0ustar www-datawww-dataclass Profile include Mongoid::Document field :avatar, :type => String field :homepage, :type => String field :created_at, :type => DateTime field :updated_at, :type => DateTime embedded_in :user, :class_name => "User", :inverse_of => :profile endacts_as_api-0.4.3/spec/mongoid_dummy/app/models/.gitkeep0000644000004100000410000000000012763720301023300 0ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/models/untouched.rb0000644000004100000410000000024512763720301024205 0ustar www-datawww-dataclass Untouched include Mongoid::Document field :nothing, :type => String field :created_at, :type => DateTime field :updated_at, :type => DateTime end acts_as_api-0.4.3/spec/mongoid_dummy/app/models/user.rb0000644000004100000410000000144112763720301023164 0ustar www-datawww-dataclass User include Mongoid::Document field :first_name, :type => String field :last_name, :type => String field :age, :type => Integer field :active, :type => Boolean field :created_at, :type => DateTime field :updated_at, :type => DateTime embeds_one :profile, :class_name => "Profile", :inverse_of => :user embeds_many :tasks, :class_name => "Task", :inverse_of => :user validates :first_name, :last_name, :presence => true acts_as_api include UserTemplate def over_thirty? age > 30 end def under_thirty? age < 30 end def return_nil nil end def full_name '' << first_name.to_s << ' ' << last_name.to_s end def say_something "something" end def sub_hash { :foo => "bar", :hello => "world" } end end acts_as_api-0.4.3/spec/mongoid_dummy/app/helpers/0000755000004100000410000000000012763720301022040 5ustar www-datawww-dataacts_as_api-0.4.3/spec/mongoid_dummy/app/helpers/application_helper.rb0000644000004100000410000000003512763720301026225 0ustar www-datawww-datamodule ApplicationHelper end acts_as_api-0.4.3/spec/mongoid_dummy/config.ru0000644000004100000410000000024212763720301021431 0ustar www-datawww-data# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run MongoidDummy::Application acts_as_api-0.4.3/spec/spec.opts0000644000004100000410000000001112763720301016600 0ustar www-datawww-data--colour acts_as_api-0.4.3/spec/spec_helper.rb0000644000004100000410000000120312763720301017561 0ustar www-datawww-dataENV["RAILS_ENV"] = "test" if ENV['ACTS_AS_API_ORM'] == 'active_record' require "active_record_dummy/config/environment" load_schema = lambda { load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default # ActiveRecord::Migrator.up('db/migrate') # use migrations } silence_stream(STDOUT, &load_schema) elsif ENV['ACTS_AS_API_ORM'] == 'mongoid' require "mongoid_dummy/config/environment" end require 'rspec/rails' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file } acts_as_api-0.4.3/spec/shared_engine/0000755000004100000410000000000012763720301017542 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/Rakefile0000644000004100000410000000117512763720301021213 0ustar www-datawww-data#!/usr/bin/env rake begin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end begin require 'rdoc/task' rescue LoadError require 'rdoc/rdoc' require 'rake/rdoctask' RDoc::Task = Rake::RDocTask end RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'SharedEngine' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end APP_RAKEFILE = File.expand_path("../active_record_dummy/Rakefile", __FILE__) load 'rails/tasks/engine.rake' Bundler::GemHelper.install_tasks acts_as_api-0.4.3/spec/shared_engine/Gemfile0000644000004100000410000000106712763720301021041 0ustar www-datawww-datasource "http://rubygems.org" # Declare your gem's dependencies in shared_engine.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. gemspec # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing # your gem to rubygems.org. # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' acts_as_api-0.4.3/spec/shared_engine/script/0000755000004100000410000000000012763720301021046 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/script/rails0000755000004100000410000000050412763720301022105 0ustar www-datawww-data#!/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. ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../../lib/shared_engine/engine', __FILE__) require 'rails/all' require 'rails/engine/commands' acts_as_api-0.4.3/spec/shared_engine/MIT-LICENSE0000644000004100000410000000203012763720301021171 0ustar www-datawww-dataCopyright 2012 YOURNAME 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. acts_as_api-0.4.3/spec/shared_engine/README.rdoc0000644000004100000410000000007012763720301021345 0ustar www-datawww-data= SharedEngine This project rocks and uses MIT-LICENSE.acts_as_api-0.4.3/spec/shared_engine/lib/0000755000004100000410000000000012763720301020310 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/lib/shared_engine/0000755000004100000410000000000012763720301023103 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/lib/shared_engine/engine.rb0000644000004100000410000000014212763720301024672 0ustar www-datawww-datamodule SharedEngine class Engine < ::Rails::Engine isolate_namespace SharedEngine end end acts_as_api-0.4.3/spec/shared_engine/lib/shared_engine/version.rb0000644000004100000410000000005412763720301025114 0ustar www-datawww-datamodule SharedEngine VERSION = "0.0.1" end acts_as_api-0.4.3/spec/shared_engine/lib/shared_engine.rb0000644000004100000410000000007012763720301023425 0ustar www-datawww-datarequire "shared_engine/engine" module SharedEngine end acts_as_api-0.4.3/spec/shared_engine/lib/tasks/0000755000004100000410000000000012763720301021435 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/lib/tasks/shared_engine_tasks.rake0000644000004100000410000000013312763720301026276 0ustar www-datawww-data# desc "Explaining what the task does" # task :shared_engine do # # Task goes here # end acts_as_api-0.4.3/spec/shared_engine/lib/magic/0000755000004100000410000000000012763720301021370 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/lib/magic/rails/0000755000004100000410000000000012763720301022502 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/lib/magic/rails/engine.rb0000644000004100000410000000561312763720301024301 0ustar www-datawww-datamodule Magic module Rails module Engine ## # Automatically append all of the current engine's routes to the main # application's route set. This needs to be done for ALL functional tests that # use engine routes, since the mounted routes don't work during tests. # # @param [Symbol] engine_symbol Optional; if provided, uses this symbol to # locate the engine class by name, otherwise uses the module of the calling # test case as the presumed name of the engine. # # @author Jason Hamilton (jhamilton@greatherorift.com) # @author Matthew Ratzloff (matt@urbaninfluence.com) # @author Xavier Dutreilh (xavier@dutreilh.fr) def load_engine_routes(engine_symbol = nil) if engine_symbol engine_name = engine_symbol.to_s.camelize else # No engine provided, so presume the current engine is the one to load engine_name = self.class.name.split("::").first.split("(").last end engine = ("#{engine_name}::Engine").constantize # Append the routes for this module to the existing routes ::Rails.application.routes.disable_clear_and_finalize = true ::Rails.application.routes.clear! ::Rails.application.routes_reloader.paths.each { |path| load(path) } ::Rails.application.routes.draw do resourced_routes = [] named_routes = engine.routes.named_routes.routes engine.routes.routes.each do |route| # Call the method by hand based on the symbol path = "/#{engine_name.underscore}#{route.path.spec}" verb = route.verb.to_s.downcase.gsub(/^.+\^(.+)\$.+$/, '\1').to_sym requirements = route.requirements if path_helper = named_routes.key(route) requirements[:as] = path_helper elsif route.requirements[:controller].present? # Presume that all controllers referenced in routes should also be # resources and append that routing on the end so that *_path helpers # will still work resourced_routes << route.requirements[:controller].gsub("#{engine_name.underscore}/", "").to_sym end send(verb, path, requirements) if respond_to?(verb) end # Add each route, once, to the end under a scope to trick path helpers. # This will probably break as soon as there is route name overlap, but # we'll cross that bridge when we get to it. resourced_routes.uniq! scope engine_name.underscore do resourced_routes.each do |resource| resources resource end end end # Finalize the routes ::Rails.application.routes.finalize! ::Rails.application.routes.disable_clear_and_finalize = false end end end end Rails::Engine.send(:include, Magic::Rails::Engine) acts_as_api-0.4.3/spec/shared_engine/.gitignore0000644000004100000410000000013012763720301021524 0ustar www-datawww-data.bundle/ log/*.log pkg/ dummy/db/*.sqlite3 dummy/log/*.log dummy/tmp/ dummy/.sass-cache acts_as_api-0.4.3/spec/shared_engine/config/0000755000004100000410000000000012763720301021007 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/config/routes.rb0000644000004100000410000000101712763720301022654 0ustar www-datawww-dataSharedEngine::Engine.routes.draw do resources :users do collection do get 'index_meta' get 'index_relation' end member do get 'show_meta' get 'show_default' get 'show_prefix_postfix' end end resources :respond_with_users do collection do get 'index_meta' get 'index_relation' get 'index_no_root_no_order' end member do get 'show_meta' get 'show_default' get 'show_prefix_postfix' end end resources :plain_objects end acts_as_api-0.4.3/spec/shared_engine/dummy/0000755000004100000410000000000012763720301020675 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/Rakefile0000644000004100000410000000041612763720301022343 0ustar www-datawww-data#!/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__) Dummy::Application.load_tasks acts_as_api-0.4.3/spec/shared_engine/dummy/script/0000755000004100000410000000000012763720301022201 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/script/rails0000755000004100000410000000044712763720301023246 0ustar www-datawww-data#!/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' acts_as_api-0.4.3/spec/shared_engine/dummy/log/0000755000004100000410000000000012763720301021456 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/log/.gitkeep0000644000004100000410000000000012763720301023075 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/public/0000755000004100000410000000000012763720301022153 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/public/422.html0000644000004100000410000000130712763720301023351 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/shared_engine/dummy/public/favicon.ico0000644000004100000410000000000012763720301024262 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/public/404.html0000644000004100000410000000133012763720301023345 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/shared_engine/dummy/public/500.html0000644000004100000410000000120312763720301023341 0ustar www-datawww-data We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts_as_api-0.4.3/spec/shared_engine/dummy/README.rdoc0000644000004100000410000002177012763720301022512 0ustar www-datawww-data== 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. acts_as_api-0.4.3/spec/shared_engine/dummy/lib/0000755000004100000410000000000012763720301021443 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/lib/assets/0000755000004100000410000000000012763720301022745 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/lib/assets/.gitkeep0000644000004100000410000000000012763720301024364 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/config/0000755000004100000410000000000012763720301022142 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/config/application.rb0000644000004100000410000000516112763720301024775 0ustar www-datawww-datarequire File.expand_path('../boot', __FILE__) # Pick the frameworks you want: require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "sprockets/railtie" # require "rails/test_unit/railtie" Bundler.require require "shared_engine" module Dummy 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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/0000755000004100000410000000000012763720301024650 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/secret_token.rb0000644000004100000410000000076012763720301027665 0ustar www-datawww-data# 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. Dummy::Application.config.secret_token = 'd7f814755d70d615d32ad7cbf4bfbcf2c42546dfd4cb0f893063d89986adbfca609029280fb55197379a9494110237790c033534aa4a8cc02aacf985564d368d' acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/session_store.rb0000644000004100000410000000063212763720301030075 0ustar www-datawww-data# Be sure to restart your server when you modify this file. Dummy::Application.config.session_store :cookie_store, :key => '_dummy_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") # Dummy::Application.config.session_store :active_record_store acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/mime_types.rb0000644000004100000410000000031512763720301027347 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb0000644000004100000410000000072412763720301030374 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb0000644000004100000410000000062412763720301031165 0ustar www-datawww-data# 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! acts_as_api-0.4.3/spec/shared_engine/dummy/config/initializers/inflections.rb0000644000004100000410000000102512763720301027510 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/boot.rb0000644000004100000410000000035312763720301023433 0ustar www-datawww-datarequire 'rubygems' gemfile = File.expand_path('../../../../Gemfile', __FILE__) if File.exist?(gemfile) ENV['BUNDLE_GEMFILE'] = gemfile require 'bundler' Bundler.setup end $:.unshift File.expand_path('../../../../lib', __FILE__)acts_as_api-0.4.3/spec/shared_engine/dummy/config/environments/0000755000004100000410000000000012763720301024671 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/config/environments/test.rb0000644000004100000410000000276512763720301026207 0ustar www-datawww-dataDummy::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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/environments/production.rb0000644000004100000410000000462412763720301027412 0ustar www-datawww-dataDummy::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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/environments/development.rb0000644000004100000410000000253412763720301027544 0ustar www-datawww-dataDummy::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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/database.yml0000644000004100000410000000110012763720301024421 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/shared_engine/dummy/config/routes.rb0000644000004100000410000000012712763720301024010 0ustar www-datawww-dataRails.application.routes.draw do mount SharedEngine::Engine => "/shared_engine" end acts_as_api-0.4.3/spec/shared_engine/dummy/config/environment.rb0000644000004100000410000000022512763720301025032 0ustar www-datawww-data# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize! acts_as_api-0.4.3/spec/shared_engine/dummy/config/locales/0000755000004100000410000000000012763720301023564 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/config/locales/en.yml0000644000004100000410000000032612763720301024712 0ustar www-datawww-data# 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" acts_as_api-0.4.3/spec/shared_engine/dummy/app/0000755000004100000410000000000012763720301021455 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/views/0000755000004100000410000000000012763720301022612 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/views/layouts/0000755000004100000410000000000012763720301024312 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/views/layouts/application.html.erb0000644000004100000410000000035012763720301030250 0ustar www-datawww-data Dummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts_as_api-0.4.3/spec/shared_engine/dummy/app/controllers/0000755000004100000410000000000012763720301024023 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/controllers/application_controller.rb0000644000004100000410000000012012763720301031107 0ustar www-datawww-dataclass ApplicationController < ActionController::Base protect_from_forgery end acts_as_api-0.4.3/spec/shared_engine/dummy/app/mailers/0000755000004100000410000000000012763720301023111 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/mailers/.gitkeep0000644000004100000410000000000012763720301024530 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/assets/0000755000004100000410000000000012763720301022757 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/assets/javascripts/0000755000004100000410000000000012763720301025310 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/assets/javascripts/application.js0000644000004100000410000000120112763720301030143 0ustar www-datawww-data// 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 // 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_tree . acts_as_api-0.4.3/spec/shared_engine/dummy/app/assets/stylesheets/0000755000004100000410000000000012763720301025333 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/assets/stylesheets/application.css0000644000004100000410000000104112763720301030344 0ustar www-datawww-data/* * 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 . */ acts_as_api-0.4.3/spec/shared_engine/dummy/app/models/0000755000004100000410000000000012763720301022740 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/models/.gitkeep0000644000004100000410000000000012763720301024357 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/helpers/0000755000004100000410000000000012763720301023117 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/dummy/app/helpers/application_helper.rb0000644000004100000410000000003512763720301027304 0ustar www-datawww-datamodule ApplicationHelper end acts_as_api-0.4.3/spec/shared_engine/dummy/config.ru0000644000004100000410000000023312763720301022510 0ustar www-datawww-data# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Dummy::Application acts_as_api-0.4.3/spec/shared_engine/shared_engine.gemspec0000644000004100000410000000117612763720301023707 0ustar www-datawww-data$:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "shared_engine/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "shared_engine" s.version = SharedEngine::VERSION s.authors = ["Your name"] s.email = ["Your email"] s.summary = "Summary of SharedEngine." s.description = "Description of SharedEngine." s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] s.add_dependency "rails", "~> 3.2.22.2" # s.add_dependency "jquery-rails" s.add_development_dependency "sqlite3" end acts_as_api-0.4.3/spec/shared_engine/app/0000755000004100000410000000000012763720301020322 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/views/0000755000004100000410000000000012763720301021457 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/views/layouts/0000755000004100000410000000000012763720301023157 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/views/layouts/shared_engine/0000755000004100000410000000000012763720301025752 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb0000644000004100000410000000041312763720301031710 0ustar www-datawww-data SharedEngine <%= stylesheet_link_tag "shared_engine/application", :media => "all" %> <%= javascript_include_tag "shared_engine/application" %> <%= csrf_meta_tags %> <%= yield %> acts_as_api-0.4.3/spec/shared_engine/app/controllers/0000755000004100000410000000000012763720301022670 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/controllers/shared_engine/0000755000004100000410000000000012763720301025463 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/controllers/shared_engine/users_controller.rb0000644000004100000410000000513512763720301031420 0ustar www-datawww-datamodule SharedEngine class UsersController < SharedEngine::ApplicationController def index @users = User.all.sort_by(&:first_name) respond_to do |format| format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users } format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users } end end def index_meta @users = User.all meta_hash = { :page => 1, :total => 999 } respond_to do |format| format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users, :meta => meta_hash } format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash } end end def index_relation @users = User.limit(100).sort_by(&:first_name) respond_to do |format| format.xml { render_for_api params[:api_template].to_sym, :xml => @users } format.json { render_for_api params[:api_template].to_sym, :json => @users } end end def show @user = User.find(params[:id]) respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user } format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user } end end def show_meta @user = User.find(params[:id]) meta_hash = { :page => 1, :total => 999 } respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user } format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user, :meta => meta_hash } end end def show_default @user = User.find(params[:id]) respond_to do |format| format.xml { render :xml => @user } format.json { render :json => @user } end end def show_prefix_postfix @user = User.find(params[:id]) template = {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]} respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model format.xml { render_for_api template, :xml => @user, :root => :user } format.json { render_for_api template, :json => @user, :root => :user } end end end end acts_as_api-0.4.3/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb0000644000004100000410000000377312763720301034213 0ustar www-datawww-datamodule SharedEngine class RespondWithUsersController < SharedEngine::ApplicationController respond_to :json, :xml self.responder = ActsAsApi::Responder def index @users = User.all.sort_by(&:first_name) respond_with @users, :api_template => params[:api_template].to_sym, :root => :users end def index_no_root_no_order @users = User.all respond_with @users, :api_template => params[:api_template].to_sym end def index_meta @users = User.all meta_hash = { :page => 1, :total => 999 } respond_with @users, :api_template => params[:api_template].to_sym, :root => :users, :meta => meta_hash end def index_relation @users = User.limit(100).sort_by(&:first_name) respond_with @users, :api_template => params[:api_template].to_sym end def show @user = User.find(params[:id]) # :root => :user is only used here because we need it for the node name of the MongoUser model respond_with @user, :api_template => params[:api_template].to_sym, :root => :user end def show_meta @user = User.find(params[:id]) meta_hash = { :page => 1, :total => 999 } # :root => :user is only used here because we need it for the node name of the MongoUser model respond_with @user, :api_template => params[:api_template].to_sym, :root => :user, :meta => meta_hash end def show_default @user = User.find(params[:id]) respond_with @user end def show_prefix_postfix @user = User.find(params[:id]) # :root => :user is only used here because we need it for the node name of the MongoUser model respond_with @user, :api_template => {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}, :root => :user end def create @user = User.new(params[:user]) if @user.save respond_with @user, :api_template => params[:api_template] else respond_with @user end end end end acts_as_api-0.4.3/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb0000644000004100000410000000062012763720301033065 0ustar www-datawww-datamodule SharedEngine class PlainObjectsController < SharedEngine::ApplicationController before_filter :setup_objects def index @users = [@han, @luke, @leia] respond_to do |format| format.xml { render_for_api params[:api_template].to_sym, :xml => @users } format.json { render_for_api params[:api_template].to_sym, :json => @users } end end end end acts_as_api-0.4.3/spec/shared_engine/app/controllers/shared_engine/application_controller.rb0000644000004100000410000000012512763720301032554 0ustar www-datawww-datamodule SharedEngine class ApplicationController < ActionController::Base end end acts_as_api-0.4.3/spec/shared_engine/app/assets/0000755000004100000410000000000012763720301021624 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/images/0000755000004100000410000000000012763720301023071 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/images/shared_engine/0000755000004100000410000000000012763720301025664 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/images/shared_engine/.gitkeep0000644000004100000410000000000012763720301027303 0ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/javascripts/0000755000004100000410000000000012763720301024155 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/javascripts/shared_engine/0000755000004100000410000000000012763720301026750 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/javascripts/shared_engine/application.js0000644000004100000410000000120112763720301031603 0ustar www-datawww-data// 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 // 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_tree . acts_as_api-0.4.3/spec/shared_engine/app/assets/stylesheets/0000755000004100000410000000000012763720301024200 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/stylesheets/shared_engine/0000755000004100000410000000000012763720301026773 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css0000644000004100000410000000104112763720301032004 0ustar www-datawww-data/* * 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 . */ acts_as_api-0.4.3/spec/shared_engine/app/models/0000755000004100000410000000000012763720301021605 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/models/user_template.rb0000644000004100000410000000745412763720301025015 0ustar www-datawww-datamodule UserTemplate extend ActiveSupport::Concern included do api_accessible :name_only do |t| t.add :first_name t.add :last_name end api_accessible :only_full_name do |t| t.add :full_name end api_accessible :rename_last_name do |t| t.add :last_name, :as => :family_name end api_accessible :rename_full_name do |t| t.add :full_name, :as => :other_full_name end api_accessible :with_former_value do |t| t.add :first_name t.add :last_name end api_accessible :age_and_first_name, :extend => :with_former_value do |t| t.add :age t.remove :last_name end api_accessible :calling_a_proc do |t| t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param end api_accessible :calling_a_lambda do |t| t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name t.add lambda{|model| Time.now.class.to_s }, :as => :without_param end api_accessible :include_tasks do |t| t.add :tasks end api_accessible :include_profile do |t| t.add :profile end api_accessible :other_sub_template do |t| t.add :first_name t.add :tasks, :template => :other_template end api_accessible :include_completed_tasks do |t| t.add "tasks.completed.all", :as => :completed_tasks end api_accessible :sub_node do |t| t.add Hash[:foo => :say_something], :as => :sub_nodes end api_accessible :nested_sub_node do |t| t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes end api_accessible :nested_sub_hash do |t| t.add :sub_hash end api_accessible :if_over_thirty do |t| t.add :first_name t.add :last_name, :if => :over_thirty? end api_accessible :if_returns_nil do |t| t.add :first_name t.add :last_name, :if => :return_nil end api_accessible :if_over_thirty_proc do |t| t.add :first_name t.add :last_name, :if => lambda{|u| u.over_thirty? } end api_accessible :if_returns_nil_proc do |t| t.add :first_name t.add :last_name, :if => lambda{|u| nil } end api_accessible :unless_under_thirty do |t| t.add :first_name t.add :last_name, :unless => :under_thirty? end api_accessible :unless_returns_nil do |t| t.add :first_name t.add :last_name, :unless => :return_nil end api_accessible :unless_under_thirty_proc do |t| t.add :first_name t.add :last_name, :unless => lambda{|u| u.under_thirty? } end api_accessible :unless_returns_nil_proc do |t| t.add :first_name t.add :last_name, :unless => lambda{|u| nil } end api_accessible :with_prefix_name_only do |t| t.add lambda{|model| 'true' }, :as => :prefix t.add :first_name t.add :last_name end api_accessible :name_only_with_postfix do |t| t.add :first_name t.add :last_name t.add lambda{|model| 'true' }, :as => :postfix end api_accessible :with_prefix_name_only_with_postfix do |t| t.add lambda{|model| 'true' }, :as => :prefix t.add :first_name t.add :last_name t.add lambda{|model| 'true' }, :as => :postfix end def before_api_response(api_response) @before_api_response_called = true end def before_api_response_called? !!@before_api_response_called end def after_api_response(api_response) @after_api_response_called = true end def after_api_response_called? !!@after_api_response_called end def skip_api_response=(should_skip) @skip_api_response = should_skip end def around_api_response(api_response) @skip_api_response ? { :skipped => true } : yield end end endacts_as_api-0.4.3/spec/shared_engine/app/models/plain_object.rb0000644000004100000410000000043112763720301024561 0ustar www-datawww-dataclass PlainObject < Struct.new(:first_name, :last_name, :age, :active) extend ActsAsApi::Base def initialize(opts) opts.each do |k, v| send("#{k}=", v) end end def model_name 'plain_object' end acts_as_api include SharedEngine::UserTemplate end acts_as_api-0.4.3/spec/shared_engine/app/helpers/0000755000004100000410000000000012763720301021764 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/helpers/shared_engine/0000755000004100000410000000000012763720301024557 5ustar www-datawww-dataacts_as_api-0.4.3/spec/shared_engine/app/helpers/shared_engine/application_helper.rb0000644000004100000410000000007112763720301030744 0ustar www-datawww-datamodule SharedEngine module ApplicationHelper end end acts_as_api-0.4.3/spec/models/0000755000004100000410000000000012763720301016232 5ustar www-datawww-dataacts_as_api-0.4.3/spec/models/model_spec.rb0000644000004100000410000000164412763720301020676 0ustar www-datawww-datarequire 'spec_helper' describe "Models" do before(:each) do setup_models end after(:each) do clean_up_models end describe :act_as_api do it_supports "including an association in the api template" it_supports "calling a closure in the api template" it_supports "conditional if statements" it_supports "conditional unless statements" it_supports "acts_as_api is enabled" it_supports "extending a given api template" it_supports "calling a method in the api template" it_supports "renaming" it_supports "listing attributes in the api template" it_supports "creating a sub hash in the api template" it_supports "trying to render an api template that is not defined" # deactivated for vanilla ruby as acts_as_api won't get mixed into any class it_supports "untouched models" it_supports "defining a model callback" it_supports "options" end endacts_as_api-0.4.3/spec/active_record_dummy/0000755000004100000410000000000012763720301020773 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/Rakefile0000644000004100000410000000043212763720301022437 0ustar www-datawww-data#!/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__) ActiveRecordDummy::Application.load_tasks acts_as_api-0.4.3/spec/active_record_dummy/Gemfile0000644000004100000410000000046712763720301022275 0ustar www-datawww-datasource 'https://rubygems.org' gem 'rails', '3.2.3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'shared_engine', :path => '../shared_engine' gem 'acts_as_api', :path => '../../' group :test do gem 'rspec-rails', '>= 2.5.0' gem 'webrat' end acts_as_api-0.4.3/spec/active_record_dummy/doc/0000755000004100000410000000000012763720301021540 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/doc/README_FOR_APP0000644000004100000410000000032312763720301023624 0ustar www-datawww-dataUse 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. acts_as_api-0.4.3/spec/active_record_dummy/script/0000755000004100000410000000000012763720301022277 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/script/rails0000755000004100000410000000044712763720301023344 0ustar www-datawww-data#!/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' acts_as_api-0.4.3/spec/active_record_dummy/log/0000755000004100000410000000000012763720301021554 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/log/.gitkeep0000644000004100000410000000000012763720301023173 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/db/0000755000004100000410000000000012763720301021360 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/db/schema.rb0000644000004100000410000000276312763720301023155 0ustar www-datawww-data# 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 => 20110214201640) do create_table "tasks", :force => true do |t| t.integer "user_id" t.string "heading" t.string "description" t.integer "time_spent" t.boolean "done" t.datetime "created_at" t.datetime "updated_at" end create_table "profiles", :force => true do |t| t.integer "user_id" t.string "avatar" t.string "homepage" t.datetime "created_at" t.datetime "updated_at" end create_table "users", :force => true do |t| t.string "first_name" t.string "last_name" t.integer "age" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "untoucheds", :force => true do |t| t.string "nothing" t.timestamps end end acts_as_api-0.4.3/spec/active_record_dummy/db/seeds.rb0000644000004100000410000000054112763720301023010 0ustar www-datawww-data# 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) acts_as_api-0.4.3/spec/active_record_dummy/db/migrate/0000755000004100000410000000000012763720301023010 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb0000644000004100000410000000172212763720301027563 0ustar www-datawww-dataclass CreateTables < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.string "first_name" t.string "last_name" t.integer "age" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "tasks", :force => true do |t| t.integer "user_id" t.string "heading" t.string "description" t.integer "time_spent" t.boolean "done" t.datetime "created_at" t.datetime "updated_at" end create_table "profiles", :force => true do |t| t.integer "user_id" t.string "avatar" t.string "homepage" t.datetime "created_at" t.datetime "updated_at" end create_table :untoucheds do |t| t.string "nothing" t.timestamps end end def self.down drop_table :untoucheds drop_table :profiles drop_table :tasks drop_table :users end end acts_as_api-0.4.3/spec/active_record_dummy/vendor/0000755000004100000410000000000012763720301022270 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/assets/0000755000004100000410000000000012763720301023572 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/assets/javascripts/0000755000004100000410000000000012763720301026123 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep0000644000004100000410000000000012763720301027542 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/assets/stylesheets/0000755000004100000410000000000012763720301026146 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep0000644000004100000410000000000012763720301027565 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/plugins/0000755000004100000410000000000012763720301023751 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/vendor/plugins/.gitkeep0000644000004100000410000000000012763720301025370 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/public/0000755000004100000410000000000012763720301022251 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/public/422.html0000644000004100000410000000130712763720301023447 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/active_record_dummy/public/favicon.ico0000644000004100000410000000000012763720301024360 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/public/robots.txt0000644000004100000410000000031412763720301024320 0ustar www-datawww-data# 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: / acts_as_api-0.4.3/spec/active_record_dummy/public/404.html0000644000004100000410000000133012763720301023443 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/active_record_dummy/public/500.html0000644000004100000410000000120312763720301023437 0ustar www-datawww-data We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts_as_api-0.4.3/spec/active_record_dummy/public/index.html0000644000004100000410000001342212763720301024250 0ustar www-datawww-data 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.

acts_as_api-0.4.3/spec/active_record_dummy/README.rdoc0000644000004100000410000002177012763720301022610 0ustar www-datawww-data== 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. acts_as_api-0.4.3/spec/active_record_dummy/lib/0000755000004100000410000000000012763720301021541 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/lib/assets/0000755000004100000410000000000012763720301023043 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/lib/assets/.gitkeep0000644000004100000410000000000012763720301024462 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/lib/tasks/0000755000004100000410000000000012763720301022666 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/lib/tasks/.gitkeep0000644000004100000410000000000012763720301024305 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/.gitignore0000644000004100000410000000065612763720301022772 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/active_record_dummy/config/0000755000004100000410000000000012763720301022240 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/config/application.rb0000644000004100000410000000524312763720301025074 0ustar www-datawww-datarequire 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 ActiveRecordDummy 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 acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/0000755000004100000410000000000012763720301024746 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/config/initializers/secret_token.rb0000644000004100000410000000077412763720301027770 0ustar www-datawww-data# 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. ActiveRecordDummy::Application.config.secret_token = '937dff1ad181db43bc2170d1d12ae4bff955f0b2a657d6e2cfa006976ed6e4311de228e9321fc530ff00157be4189022b715832ffb0c6fa8be12e7185b41d7a4' acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/session_store.rb0000644000004100000410000000070012763720301030167 0ustar www-datawww-data# Be sure to restart your server when you modify this file. ActiveRecordDummy::Application.config.session_store :cookie_store, :key => '_active_record_dummy_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") # ActiveRecordDummy::Application.config.session_store :active_record_store acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/mime_types.rb0000644000004100000410000000031512763720301027445 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/wrap_parameters.rb0000644000004100000410000000072412763720301030472 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/generators.rb0000644000004100000410000000005712763720301027446 0ustar www-datawww-dataRails.application.config.generators do |g| end acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/backtrace_silencers.rb0000644000004100000410000000062412763720301031263 0ustar www-datawww-data# 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! acts_as_api-0.4.3/spec/active_record_dummy/config/initializers/inflections.rb0000644000004100000410000000102512763720301027606 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/active_record_dummy/config/boot.rb0000644000004100000410000000027712763720301023536 0ustar www-datawww-datarequire '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']) acts_as_api-0.4.3/spec/active_record_dummy/config/environments/0000755000004100000410000000000012763720301024767 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/config/environments/test.rb0000644000004100000410000000300112763720301026265 0ustar www-datawww-dataActiveRecordDummy::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 acts_as_api-0.4.3/spec/active_record_dummy/config/environments/production.rb0000644000004100000410000000464012763720301027506 0ustar www-datawww-dataActiveRecordDummy::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 acts_as_api-0.4.3/spec/active_record_dummy/config/environments/development.rb0000644000004100000410000000255012763720301027640 0ustar www-datawww-dataActiveRecordDummy::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 acts_as_api-0.4.3/spec/active_record_dummy/config/database.yml0000644000004100000410000000110012763720301024517 0ustar www-datawww-data# 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 acts_as_api-0.4.3/spec/active_record_dummy/config/routes.rb0000644000004100000410000000350412763720301024110 0ustar www-datawww-dataActiveRecordDummy::Application.routes.draw do mount SharedEngine::Engine => "/shared", :as => "shared" # 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 acts_as_api-0.4.3/spec/active_record_dummy/config/environment.rb0000644000004100000410000000024112763720301025126 0ustar www-datawww-data# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application ActiveRecordDummy::Application.initialize! acts_as_api-0.4.3/spec/active_record_dummy/config/locales/0000755000004100000410000000000012763720301023662 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/config/locales/en.yml0000644000004100000410000000032612763720301025010 0ustar www-datawww-data# 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" acts_as_api-0.4.3/spec/active_record_dummy/app/0000755000004100000410000000000012763720301021553 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/views/0000755000004100000410000000000012763720301022710 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/views/layouts/0000755000004100000410000000000012763720301024410 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/views/layouts/application.html.erb0000644000004100000410000000036412763720301030353 0ustar www-datawww-data ActiveRecordDummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts_as_api-0.4.3/spec/active_record_dummy/app/controllers/0000755000004100000410000000000012763720301024121 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/controllers/application_controller.rb0000644000004100000410000000012012763720301031205 0ustar www-datawww-dataclass ApplicationController < ActionController::Base protect_from_forgery end acts_as_api-0.4.3/spec/active_record_dummy/app/mailers/0000755000004100000410000000000012763720301023207 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/mailers/.gitkeep0000644000004100000410000000000012763720301024626 0ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/assets/0000755000004100000410000000000012763720301023055 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/assets/images/0000755000004100000410000000000012763720301024322 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/assets/images/rails.png0000644000004100000410000001476612763720301026160 0ustar www-datawww-dataPNG  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 true has_many :tasks has_one :profile acts_as_api api_accessible :name_only do |t| t.add :first_name t.add :last_name end api_accessible :only_full_name do |t| t.add :full_name end api_accessible :rename_last_name do |t| t.add :last_name, :as => :family_name end api_accessible :rename_full_name do |t| t.add :full_name, :as => :other_full_name end api_accessible :with_former_value do |t| t.add :first_name t.add :last_name end api_accessible :age_and_first_name, :extend => :with_former_value do |t| t.add :age t.remove :last_name end api_accessible :calling_a_proc do |t| t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param end api_accessible :calling_a_lambda do |t| t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name t.add lambda{|model| Time.now.class.to_s }, :as => :without_param end api_accessible :include_tasks do |t| t.add :tasks end api_accessible :include_profile do |t| t.add :profile end api_accessible :other_sub_template do |t| t.add :first_name t.add :tasks, :template => :other_template end api_accessible :include_completed_tasks do |t| t.add "tasks.completed.all", :as => :completed_tasks end api_accessible :sub_node do |t| t.add Hash[:foo => :say_something], :as => :sub_nodes end api_accessible :nested_sub_node do |t| t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes end api_accessible :nested_sub_hash do |t| t.add :sub_hash end api_accessible :if_over_thirty do |t| t.add :first_name t.add :last_name, :if => :over_thirty? end api_accessible :if_returns_nil do |t| t.add :first_name t.add :last_name, :if => :return_nil end api_accessible :if_over_thirty_proc do |t| t.add :first_name t.add :last_name, :if => lambda{|u| u.over_thirty? } end api_accessible :if_returns_nil_proc do |t| t.add :first_name t.add :last_name, :if => lambda{|u| nil } end api_accessible :unless_under_thirty do |t| t.add :first_name t.add :last_name, :unless => :under_thirty? end api_accessible :unless_returns_nil do |t| t.add :first_name t.add :last_name, :unless => :return_nil end api_accessible :unless_under_thirty_proc do |t| t.add :first_name t.add :last_name, :unless => lambda{|u| u.under_thirty? } end api_accessible :unless_returns_nil_proc do |t| t.add :first_name t.add :last_name, :unless => lambda{|u| nil } end api_accessible :with_prefix_name_only do |t| t.add lambda{|model| 'true' }, :as => :prefix t.add :first_name t.add :last_name end api_accessible :name_only_with_postfix do |t| t.add :first_name t.add :last_name t.add lambda{|model| 'true' }, :as => :postfix end api_accessible :with_prefix_name_only_with_postfix do |t| t.add lambda{|model| 'true' }, :as => :prefix t.add :first_name t.add :last_name t.add lambda{|model| 'true' }, :as => :postfix end def before_api_response(api_response) @before_api_response_called = true end def before_api_response_called? !!@before_api_response_called end def after_api_response(api_response) @after_api_response_called = true end def after_api_response_called? !!@after_api_response_called end def skip_api_response=(should_skip) @skip_api_response = should_skip end def around_api_response(api_response) @skip_api_response ? { :skipped => true } : yield end def over_thirty? age > 30 end def under_thirty? age < 30 end def return_nil nil end def full_name '' << first_name.to_s << ' ' << last_name.to_s end def say_something "something" end def sub_hash { :foo => "bar", :hello => "world" } end end acts_as_api-0.4.3/spec/active_record_dummy/app/helpers/0000755000004100000410000000000012763720301023215 5ustar www-datawww-dataacts_as_api-0.4.3/spec/active_record_dummy/app/helpers/application_helper.rb0000644000004100000410000000003512763720301027402 0ustar www-datawww-datamodule ApplicationHelper end acts_as_api-0.4.3/spec/active_record_dummy/config.ru0000644000004100000410000000024712763720301022613 0ustar www-datawww-data# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run ActiveRecordDummy::Application acts_as_api-0.4.3/spec/support/0000755000004100000410000000000012763720301016463 5ustar www-datawww-dataacts_as_api-0.4.3/spec/support/controller_examples.rb0000644000004100000410000003150412763720301023074 0ustar www-datawww-datashared_examples_for "a controller with ActsAsApi responses" do include ApiTestHelpers describe 'xml responses' do describe 'get all users' do before(:each) do get :index, :format => 'xml', :api_template => :name_only end it "should have a root node named users" do response_body.should have_selector("users") end it "should contain all users" do response_body.should have_selector("users > user") do |users| users.size.should eql(3) end end it "should contain the specified attributes" do response_body.should have_selector("users > user > first-name") response_body.should have_selector("users > user > last-name") end end describe 'get a single user' do before(:each) do get :show, :format => 'xml', :api_template => :name_only, :id => @luke.id end it "should have a root node named user" do response_body.should have_selector("user") end it "should contain the specified attributes" do response_body.should have_selector("user > first-name") response_body.should have_selector("user > last-name") end end describe 'get a user without specifying an api template' do before(:each) do get :show_default, :format => 'xml', :id => @luke.id end it "should respond with HTTP 200" do response.code.should == "200" end it "should render the model with standard to_xml" do # TODO: figure out how to compare xml generated by mongo models. # This line works fine with ActiveRecord, but not Mongoid: # response.body.should == @luke.to_xml response.body.length.should == @luke.to_xml.length end end end describe 'json responses' do describe 'get all users' do before(:each) do get :index, :format => 'json', :api_template => :name_only end it "should have a root node named users" do response_body_json.should have_key("users") end it "should contain all users" do response_body_json["users"].should be_a(Array) end it "should contain the specified attributes" do response_body_json["users"].first.should have_key("first_name") response_body_json["users"].first.should have_key("last_name") end it "should contain the specified values" do response_body_json["users"].first["first_name"].should eql("Han") response_body_json["users"].first["last_name"].should eql("Solo") end end describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do before(:each) do get :index_relation, :format => 'json', :api_template => :name_only end it "should have a root node named users" do response_body_json.should have_key("users") end it "should contain all users" do response_body_json["users"].should be_a(Array) end it "should contain the specified attributes" do response_body_json["users"].first.should have_key("first_name") response_body_json["users"].first.should have_key("last_name") end it "should contain the specified values" do response_body_json["users"].first["first_name"].should eql("Han") response_body_json["users"].first["last_name"].should eql("Solo") end end describe 'get a single user' do before(:each) do get :show, :format => 'json', :api_template => :name_only, :id => @luke.id end it "should have a root node named user" do response_body_json.should have_key("user") end it "should contain the specified attributes" do response_body_json["user"].should have_key("first_name") response_body_json["user"].should have_key("last_name") end it "should contain the specified values" do response_body_json["user"]["first_name"].should eql("Luke") response_body_json["user"]["last_name"].should eql("Skywalker") end end describe 'get a single user with a nil profile' do before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| t.add :avatar t.add :homepage end get :show, :format => 'json', :api_template => :include_profile, :id => @han.id end it "should have a root node named user" do response_body_json.should have_key("user") end it "should contain the specified attributes" do response_body_json["user"].should have(1).keys response_body_json["user"].should have_key("profile") end it "should contain the specified values" do response_body_json["user"]["profile"].should be_nil end end describe 'get a user without specifying an api template' do before(:each) do get :show_default, :format => 'json', :id => @luke.id end it "should respond with HTTP 200" do response.code.should == "200" end it "should render the model with to_json" do response.body.should == @luke.to_json end end end describe 'Rails 3 default style json responses' do before(:each) do @org_include_root_in_json_collections = ActsAsApi::Config.include_root_in_json_collections ActsAsApi::Config.include_root_in_json_collections = true end after(:each) do ActsAsApi::Config.include_root_in_json_collections = @org_include_root_in_json_collections end describe 'get all users' do before(:each) do get :index, :format => 'json', :api_template => :name_only end it "should have a root node named users" do response_body_json.should have_key("users") end it "should contain all users" do response_body_json["users"].should be_a(Array) end it "should contain the specified attributes" do response_body_json["users"].first["user"].should have_key("first_name") response_body_json["users"].first["user"].should have_key("last_name") end it "contains the user root nodes" do response_body_json["users"].collect(&:keys).flatten.uniq.should eql(["user"]) end it "should contain the specified values" do response_body_json["users"].first["user"]["first_name"].should eql("Han") response_body_json["users"].first["user"]["last_name"].should eql("Solo") end end describe 'get a single user' do before(:each) do get :show, :format => 'json', :api_template => :name_only, :id => @luke.id end it "should have a root node named user" do response_body_json.should have_key("user") end it "should contain the specified attributes" do response_body_json["user"].should have_key("first_name") response_body_json["user"].should have_key("last_name") end it "should contain the specified values" do response_body_json["user"]["first_name"].should eql("Luke") response_body_json["user"]["last_name"].should eql("Skywalker") end end end describe 'jsonp responses with callback' do it "should be disabled by default" do @callback = "mycallback" get :index, :format => 'json', :api_template => :name_only, :callback => @callback response_body_jsonp(@callback).should be_nil end describe "enabled jsonp callbacks" do before(:each) do @callback = "mycallback" User.acts_as_api do |config| config.allow_jsonp_callback = true end end after(:each) do # put things back to the way they were User.acts_as_api do |config| config.allow_jsonp_callback = false end end describe 'get all users' do before(:each) do get :index, :format => 'json', :api_template => :name_only, :callback => @callback end it "should wrap the response in the callback" do response_body_jsonp(@callback).should_not be_nil end end describe 'get a single user' do before(:each) do get :show, :format => 'json', :api_template => :name_only, :id => @luke.id, :callback => @callback end it "should wrap the response in the callback" do response_body_jsonp(@callback).should_not be_nil end end describe 'Requesting the JSONP content as JavaScript' do before(:each) do get :index, :format => :js, :api_template => :name_only, :callback => @callback end it "should set the content type to JavaScript" do response.content_type.should == Mime::JS end end end end describe 'config.add_root_node_for is empty, so no root node is created' do before(:each) do @org_add_root_node_for_config = ActsAsApi::Config.add_root_node_for.dup ActsAsApi::Config.add_root_node_for = [] end after(:each) do ActsAsApi::Config.add_root_node_for = @org_add_root_node_for_config end describe 'get all users' do before(:each) do get :index, :format => 'json', :api_template => :name_only, :callback => @callback end its "response has no named root node" do response_body_json.should be_an(Array) end end describe 'get a single user' do before(:each) do get :show, :format => 'json', :api_template => :name_only, :id => @luke.id end its "response has no named root node" do response_body_json.should be_a(Hash) response_body_json.should have_key("first_name") end end end describe 'pass meta information on rendering' do describe 'get all users' do before(:each) do get :index_meta, :format => 'json', :api_template => :name_only end it "shows model response fields" do response_body_json.should be_a(Hash) response_body_json.should have_key("users") response_body_json["users"].should be_an(Array) end it "shows page field" do response_body_json.should have_key("page") end it "shows total field" do response_body_json.should have_key("total") end end describe 'get a single user' do before(:each) do get :show_meta, :format => 'json', :api_template => :name_only, :id => @luke.id end it "shows model response fields" do response_body_json.should be_a(Hash) response_body_json.should have_key("user") end it "shows page field" do response_body_json.should have_key("page") end it "shows total field" do response_body_json.should have_key("total") end end end describe 'api prefix' do describe 'get single user' do before(:each) do get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :id => @luke.id end it "should have a root node named user" do response_body.should have_selector("user") end it "should contain the specified attributes" do response_body.should have_selector("user > prefix") response_body.should have_selector("user > first-name") response_body.should have_selector("user > last-name") end it "should not contain the specified attributes" do response_body.should_not have_selector("user > postfix") end end end describe 'api postfix' do describe 'get single user' do before(:each) do get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_postfix => :with_postfix, :id => @luke.id end it "should have a root node named user" do response_body.should have_selector("user") end it "should contain the specified attributes" do response_body.should have_selector("user > first-name") response_body.should have_selector("user > last-name") response_body.should have_selector("user > postfix") end it "should not contain the specified attributes" do response_body.should_not have_selector("user > prefix") end end end describe 'api prefix and api postfix' do describe 'get single user' do before(:each) do get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :api_postfix => :with_postfix, :id => @luke.id end it "should have a root node named user" do response_body.should have_selector("user") end it "should contain the specified attributes" do response_body.should have_selector("user > prefix") response_body.should have_selector("user > first-name") response_body.should have_selector("user > last-name") response_body.should have_selector("user > postfix") end end end end acts_as_api-0.4.3/spec/support/routing.rb0000644000004100000410000000020212763720301020471 0ustar www-datawww-datarequire 'magic/rails/engine' # Replace RspecRouting by the namespace used by your engine SharedEngine::Engine.load_engine_routes acts_as_api-0.4.3/spec/support/simple_fixtures.rb0000644000004100000410000000552512763720301022241 0ustar www-datawww-datamodule SimpleFixtures def setup_models @luke = User.create({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) @han = User.create({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) @leia = User.create({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) @luke.profile = Profile.new({ :avatar => 'picard.jpg', :homepage => 'lukasarts.com' }) @luke.profile.save @destroy_deathstar = @luke.tasks.create({ :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true }) @study_with_yoda = @luke.tasks.create({ :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true }) @win_rebellion = @luke.tasks.create({ :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false }) @luke.save! @han.save! @leia.save! end def clean_up_models User.delete_all end def setup_objects @luke = PlainObject.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) @han = PlainObject.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) @leia = PlainObject.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) end # def setup_roflscale_models # @orm_for_testing = :vanilla # @user_model = VanillaUser # @task_model = VanillaTask # @profile_model = VanillaProfile # @untouched_model = VanillaUntouched # # @luke = @user_model.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) # @han = @user_model.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) # @leia = @user_model.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) # # @luke.profile = @profile_model.new({ :user => @luke, :avatar => 'picard.jpg', :homepage => 'lukasarts.com' }) # # @destroy_deathstar = @task_model.new({ :user => @luke, :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true }) # @study_with_yoda = @task_model.new({ :user => @luke, :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true }) # @win_rebellion = @task_model.new({ :user => @luke, :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false }) # # @luke.tasks << @destroy_deathstar << @study_with_yoda << @win_rebellion # end # # def clean_up_roflscale_models # # nothing to do ;) # end end RSpec.configure do |c| c.include SimpleFixtures end acts_as_api-0.4.3/spec/support/model_examples/0000755000004100000410000000000012763720301021461 5ustar www-datawww-dataacts_as_api-0.4.3/spec/support/model_examples/conditional_if.rb0000644000004100000410000001002212763720301024762 0ustar www-datawww-datashared_examples_for "conditional if statements" do describe "using the :if option" do describe "passing a symbol" do describe "that returns false" do before(:each) do @response = @luke.as_api_response(:if_over_thirty) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns nil" do before(:each) do @response = @luke.as_api_response(:if_returns_nil) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns true" do before(:each) do @response = @han.as_api_response(:if_over_thirty) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end it "the other specified fields have the correct value" do @response.values.should include(@han.first_name, @han.last_name) end end end end describe "passing a proc" do describe "that returns false" do before(:each) do @response = @luke.as_api_response(:if_over_thirty_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns nil" do before(:each) do @response = @luke.as_api_response(:if_returns_nil_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns true" do before(:each) do @response = @han.as_api_response(:if_over_thirty_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end it "the other specified fields have the correct value" do @response.values.should include(@han.first_name, @han.last_name) end end end end acts_as_api-0.4.3/spec/support/model_examples/sub_nodes.rb0000644000004100000410000000477212763720301024001 0ustar www-datawww-datashared_examples_for "creating a sub hash in the api template" do describe "and putting an attribute in it" do before(:each) do @response = @luke.as_api_response(:sub_node) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:sub_nodes) end it "returns the correct values for the specified fields" do @response[:sub_nodes].should be_a Hash end it "provides the correct number of sub nodes" do @response[:sub_nodes].should have(1).keys end it "provides the correct sub nodes values" do @response[:sub_nodes][:foo].should eql("something") end end describe "multiple times and putting an attribute in it" do before(:each) do @response = @luke.as_api_response(:nested_sub_node) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:sub_nodes) end it "returns the correct values for the specified fields" do @response[:sub_nodes].should be_a Hash end it "provides the correct number of sub nodes" do @response[:sub_nodes].should have(1).keys end it "provides the correct number of sub nodes in the second level" do @response[:sub_nodes][:foo].should have(1).keys end it "provides the correct sub nodes values" do @response[:sub_nodes][:foo].tap do |foo| foo[:bar].tap do |bar| bar.should eql(@luke.last_name) end end end end describe "using a method" do before(:each) do @response = @luke.as_api_response(:nested_sub_hash) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:sub_hash) end it "provides the correct number of sub nodes" do @response[:sub_hash].should have(2).keys end it "provides the correct sub nodes" do @response[:sub_hash].keys.should include(:foo, :hello) end it "provides the correct values in its sub nodes" do @response[:sub_hash].values.should include("bar", "world") end end endacts_as_api-0.4.3/spec/support/model_examples/options.rb0000644000004100000410000000310412763720301023477 0ustar www-datawww-datashared_examples_for "options" do describe "options in the api template" do before :each do User.api_accessible :with_options do |t| t.add lambda{|model,options| options }, :as => :options t.add :profile t.add :first_name, :if => lambda{|m,options| options[:with_name] } end Profile.acts_as_api Profile.api_accessible :with_options do |t| t.add lambda{|model,options| options }, :as => :options end Task.acts_as_api Task.api_accessible :other_template do |t| t.add :description t.add :time_spent t.add lambda{|model,options| options }, :as => :options end end context "as_api_response accept options" do before :each do @response = @luke.as_api_response(:with_options, :loc => [12, 13]) end it "returns the options field as specified" do @response[:options][:loc].should == [12, 13] end it "returns the option for the associations " do @response[:profile][:options][:loc].should == [12, 13] end end context "allowed_to_render accept options" do it "should not contains first_name when options[:with_name] is false" do @response = @luke.as_api_response(:with_options, :with_name => false) @response.should_not include(:first_name) end it "should contains first_name when options[:with_name] is true" do @response = @luke.as_api_response(:with_options, :with_name => true) @response[:first_name].should == 'Luke' end end end end acts_as_api-0.4.3/spec/support/model_examples/conditional_unless.rb0000644000004100000410000001007712763720301025707 0ustar www-datawww-datashared_examples_for "conditional unless statements" do describe "using the :unless option" do describe "passing a symbol" do describe "that returns false" do before(:each) do @response = @luke.as_api_response(:unless_under_thirty) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns nil" do before(:each) do @response = @luke.as_api_response(:unless_returns_nil) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name, @luke.last_name) end end describe "that returns true" do before(:each) do @response = @han.as_api_response(:unless_under_thirty) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end it "the other specified fields have the correct value" do @response.values.should include(@han.first_name, @han.last_name) end end end end describe "passing a proc" do describe "that returns false" do before(:each) do @response = @luke.as_api_response(:unless_under_thirty_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns nil" do before(:each) do @response = @luke.as_api_response(:if_returns_nil_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end it "the other specified fields have the correct value" do @response.values.should include(@luke.first_name) end end describe "that returns true" do before(:each) do @response = @han.as_api_response(:unless_under_thirty_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "won't add the conditional field but all others" do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end it "the other specified fields have the correct value" do @response.values.should include(@han.first_name, @han.last_name) end end end end acts_as_api-0.4.3/spec/support/model_examples/simple.rb0000644000004100000410000000104112763720301023273 0ustar www-datawww-datashared_examples_for "listing attributes in the api template" do before(:each) do @response = @luke.as_api_response(:name_only) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns the specified fields only" do @response.keys.should include(:first_name, :last_name) end it "the specified fields have the correct value" do @response.values.should include(@luke.first_name, @luke.last_name) end end acts_as_api-0.4.3/spec/support/model_examples/untouched.rb0000644000004100000410000000050012763720301023777 0ustar www-datawww-datashared_examples_for "untouched models" do describe "has disabled acts_as_api by default" do it "indicates that acts_as_api is disabled" do Untouched.acts_as_api?.should == false end it "does not respond to api_accessible" do Untouched.should_not respond_to :api_accessible end end end acts_as_api-0.4.3/spec/support/model_examples/closures.rb0000644000004100000410000000240212763720301023643 0ustar www-datawww-datashared_examples_for "calling a closure in the api template" do describe "i.e. a proc (the record is passed as only parameter)" do before(:each) do @response = @luke.as_api_response(:calling_a_proc) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns all specified fields" do @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param]) end it "returns the correct values for the specified fields" do @response.values.sort.should eql(["LUKE SKYWALKER", "Time"]) end end describe "i.e. a lambda (the record is passed as only parameter)" do before(:each) do @response = @luke.as_api_response(:calling_a_lambda) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns all specified fields" do @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param]) end it "returns the correct values for the specified fields" do @response.values.sort.should eql(["LUKE SKYWALKER", "Time"]) end end end acts_as_api-0.4.3/spec/support/model_examples/associations.rb0000644000004100000410000001665212763720301024517 0ustar www-datawww-datashared_examples_for "including an association in the api template" do describe "which doesn't acts_as_api" do before(:each) do @response = @luke.as_api_response(:include_tasks) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:tasks) end it "returns the correct values for the specified fields" do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end it "should contain the associated sub models" do @response[:tasks].should include(@destroy_deathstar, @study_with_yoda, @win_rebellion) end end describe "which does acts_as_api" do context "has_many" do before(:each) do Task.acts_as_api Task.api_accessible :include_tasks do |t| t.add :heading t.add :done end @response = @luke.as_api_response(:include_tasks) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:tasks) end it "returns the correct values for the specified fields" do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end it "contains the associated child models with the determined api template" do @response[:tasks].each do |task| task.keys.should include(:heading, :done) task.keys.should have(2).attributes end end it "contains the correct data of the child models" do task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :done => t.done, :heading => t.heading } } @response[:tasks].should eql task_hash end end context "has_one" do before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| t.add :avatar t.add :homepage end @response = @luke.as_api_response(:include_profile) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:profile) end it "returns the correct values for the specified fields" do @response[:profile].should be_a Hash @response[:profile].should have(2).attributes end it "contains the associated child models with the determined api template" do @response[:profile].keys.should include(:avatar, :homepage) end it "contains the correct data of the child models" do profile_hash = { :avatar => @luke.profile.avatar, :homepage => @luke.profile.homepage } @response[:profile].should eql profile_hash end end end describe "which does acts_as_api, but with using another template name" do before(:each) do Task.acts_as_api Task.api_accessible :other_template do |t| t.add :description t.add :time_spent end @response = @luke.as_api_response(:other_sub_template) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns all specified fields" do @response.keys.should include(:first_name) end it "returns the correct values for the specified fields" do @response.values.should include(@luke.first_name) end it "returns all specified fields" do @response.keys.should include(:tasks) end it "returns the correct values for the specified fields" do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end it "contains the associated child models with the determined api template" do @response[:tasks].each do |task| task.keys.should include(:description, :time_spent) task.keys.should have(2).attributes end end it "contains the correct data of the child models" do task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } } @response[:tasks].should eql task_hash end end describe "that is scoped" do before(:each) do # extend task model with scope #class Task < ActiveRecord::Base Task.class_eval do scope :completed, where(:done => true) end Task.acts_as_api Task.api_accessible :include_completed_tasks do |t| t.add :heading t.add :done end @response = @luke.as_api_response(:include_completed_tasks) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:completed_tasks) end it "returns the correct values for the specified fields" do @response[:completed_tasks].should be_an Array @response[:completed_tasks].should have(2).tasks end it "contains the associated child models with the determined api template" do @response[:completed_tasks].each do |task| task.keys.should include(:heading, :done) task.keys.should have(2).attributes end end it "contains the correct data of the child models" do task_hash = [ @destroy_deathstar, @study_with_yoda ].collect{|t| { :done => t.done, :heading => t.heading } } @response[:completed_tasks].should eql task_hash end end describe "handling nil values" do context "has_many" do before(:each) do Task.acts_as_api Task.api_accessible :include_tasks do |t| t.add :heading t.add :done end @response = @han.as_api_response(:include_tasks) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:tasks) end it "returns the correct values for the specified fields" do @response[:tasks].should be_kind_of(Array) end it "contains no associated child models" do @response[:tasks].should have(0).items end end context "has one" do before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| t.add :avatar t.add :homepage end @response = @han.as_api_response(:include_profile) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:profile) end it "returns nil for the association" do @response[:profile].should be_nil end end end end acts_as_api-0.4.3/spec/support/model_examples/extending.rb0000644000004100000410000000607412763720301024002 0ustar www-datawww-datashared_examples_for "extending a given api template" do describe "multiple times" do before(:each) do User.api_accessible :public do |t| t.add :first_name end User.api_accessible :for_buddies, :extend => :public do |t| t.add :age end User.api_accessible :private, :extend => :for_buddies do |t| t.add :last_name end @response = @luke.as_api_response(:private) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(3).keys end it "returns all specified fields" do @response.keys.sort_by(&:to_s).should eql([:age, :first_name, :last_name]) end it "returns the correct values for the specified fields" do @response.values.sort_by(&:to_s).should eql([@luke.age, @luke.first_name, @luke.last_name].sort_by(&:to_s)) end end describe "and removing a former added value" do before(:each) do @response = @luke.as_api_response(:age_and_first_name) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns all specified fields" do @response.keys.sort_by(&:to_s).should eql([:first_name, :age].sort_by(&:to_s)) end it "returns the correct values for the specified fields" do @response.values.sort_by(&:to_s).should eql([@luke.first_name, @luke.age].sort_by(&:to_s)) end end describe "and inherit a field using another template name", :meow => true do before(:each) do Task.acts_as_api Task.api_accessible :other_template do |t| t.add :description t.add :time_spent end User.api_accessible :extending_other_template, :extend => :other_sub_template @response = @luke.as_api_response(:extending_other_template) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(2).keys end it "returns all specified fields" do @response.keys.should include(:first_name) end it "returns the correct values for the specified fields" do @response.values.should include(@luke.first_name) end it "returns all specified fields" do @response.keys.should include(:tasks) end it "returns the correct values for the specified fields" do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end it "contains the associated child models with the determined api template" do @response[:tasks].each do |task| task.keys.should include(:description, :time_spent) task.keys.should have(2).attributes end end it "contains the correct data of the child models" do task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } } @response[:tasks].should eql task_hash end end endacts_as_api-0.4.3/spec/support/model_examples/callbacks.rb0000644000004100000410000000153612763720301023732 0ustar www-datawww-datashared_examples_for "defining a model callback" do describe "for a" do describe "around_api_response" do it "skips rendering if not yielded" do @luke.skip_api_response = true @luke.as_api_response(:name_only).keys.should include(:skipped) end it "renders if yielded" do @luke.as_api_response(:name_only).keys.should_not include(:skipped) end end describe "before_api_response" do it "is called properly" do @luke.as_api_response(:name_only) @luke.before_api_response_called?.should eql(true) end end describe "after_api_response" do it "is called properly" do @luke.as_api_response(:name_only) @luke.after_api_response_called?.should eql(true) end end end endacts_as_api-0.4.3/spec/support/model_examples/enabled.rb0000644000004100000410000000035312763720301023401 0ustar www-datawww-datashared_examples_for "acts_as_api is enabled" do it "indicates that acts_as_api is enabled" do User.acts_as_api?.should == true end it "does respond to api_accessible" do User.should respond_to :api_accessible end end acts_as_api-0.4.3/spec/support/model_examples/renaming.rb0000644000004100000410000000216612763720301023613 0ustar www-datawww-datashared_examples_for "renaming" do describe "an attribute in the api template" do before(:each) do @response = @luke.as_api_response(:rename_last_name) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:family_name) end it "returns the correct values for the specified fields" do @response.values.should include(@luke.last_name) end end describe "the node/key of a method in the api template" do before(:each) do @response = @luke.as_api_response(:rename_full_name) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields" do @response.keys.should include(:other_full_name) end it "returns the correct values for the specified fields" do @response.values.should include(@luke.full_name) end end end acts_as_api-0.4.3/spec/support/model_examples/methods.rb0000644000004100000410000000101712763720301023450 0ustar www-datawww-datashared_examples_for "calling a method in the api template" do before(:each) do @response = @luke.as_api_response(:only_full_name) end it "returns a hash" do @response.should be_kind_of(Hash) end it "returns the correct number of fields" do @response.should have(1).keys end it "returns all specified fields by name" do @response.keys.should include(:full_name) end it "returns the correct values for the specified fields" do @response.values.should include(@luke.full_name) end endacts_as_api-0.4.3/spec/support/model_examples/undefined.rb0000644000004100000410000000035112763720301023746 0ustar www-datawww-datashared_examples_for "trying to render an api template that is not defined" do it "raises an descriptive error" do lambda{ @luke.as_api_response(:does_not_exist) }.should raise_error(ActsAsApi::TemplateNotFoundError) end endacts_as_api-0.4.3/spec/support/it_supports.rb0000644000004100000410000000012712763720301021403 0ustar www-datawww-dataRSpec.configure do |c| c.alias_it_should_behave_like_to :it_supports, 'supports:' endacts_as_api-0.4.3/spec/support/api_test_helpers.rb0000644000004100000410000000057512763720301022351 0ustar www-datawww-datamodule ApiTestHelpers def response_body response.body.strip end def response_body_json ActiveSupport::JSON.decode(response_body) end def response_body_jsonp(callback) jsonp_callback(callback).match(response_body) end def jsonp_callback(callback) /\A#{callback}\((.*),\s+\d{3}\)\z/ end end RSpec.configure do |c| c.include ApiTestHelpers end acts_as_api-0.4.3/spec/README.md0000644000004100000410000000413112763720301016225 0ustar www-datawww-data# Spec folder intro ## Running specs Every ORM has a rake task. Run `rake -T` to see them all. `rake spec:all` will run all spec suites in a row. `rake spec:#{orm_name}` will run the spec suite for a specific ORM. ## Working with the specs acts_as_api can be used with lots of different configurations, depending e.g. on the ORM (ActiveRecord, Mongoid, vanilla ruby) or the way the content is rendered (usual Rails controller, vs. Responder). A goal of the lib is to stay consistent in its behaviour over these different configurations, so it won't get in your way, once you change other parts of your application. To achieve this goal and because of the need to keep the specs as DRY as possible, the following spec setup was created: ### A shared engine In order to keep the spec suite DRY it uses a Rails engine, available at `./shared_engine`. It contains the controllers that are re-used by the ORM-specific Rails apps and some mixins that can be shared over the models of different ORMs. ### Dummy Rails apps There used to be one Rails app that contained all supported ORMs. But multiple times this setup veiled problems e.g. with ORM-specific dependencies. Now there are multiple Rails apps, one for every supported ORM: `./active_record_dummy` and `./mongoid_dummy`. These are very simple apps, basically just clicked together on [railswizard.org](http://railswizard.org). They contain **no controllers** to be tested, just models that match the tested ones. ### Adding a dummy Rails app * Create a new Rails app in the folder `./spec/#{orm_name}_dummy`. * Create to Models used in the spec (`User, Profile, Untouched, Task`). * Include `UserTemplate` in your `User` model. * Add `mount SharedEngine::Engine => "/shared", :as => "shared"` to your `routes.rb` * Add the following lines to your Gemfile: ```ruby gem 'shared_engine', :path => '../shared_engine' gem 'acts_as_api', :path => '../../' ``` * Add your dummy app to the `Rakefile` in the root folder by adding it to the `supported_orms` array. If you have to do some special setup (e.g. creating a schema) you can do this in `./spec_helper.rb`. acts_as_api-0.4.3/.travis.yml0000644000004100000410000000014212763720301016123 0ustar www-datawww-datalanguage: ruby sudo: false script: bundle exec rake spec:all services: - mongodb rvm: - 2.3.1 acts_as_api-0.4.3/lib/0000755000004100000410000000000012763720301014563 5ustar www-datawww-dataacts_as_api-0.4.3/lib/acts_as_api/0000755000004100000410000000000012763720301017031 5ustar www-datawww-dataacts_as_api-0.4.3/lib/acts_as_api/adapters/0000755000004100000410000000000012763720301020634 5ustar www-datawww-dataacts_as_api-0.4.3/lib/acts_as_api/adapters/mongoid.rb0000644000004100000410000000025012763720301022612 0ustar www-datawww-datamodule ActsAsApi module Adapters module Mongoid extend ActiveSupport::Concern included do extend ActsAsApi::Base end end end end acts_as_api-0.4.3/lib/acts_as_api/adapters.rb0000644000004100000410000000014312763720301021157 0ustar www-datawww-datamodule ActsAsApi module Adapters autoload :Mongoid, "acts_as_api/adapters/mongoid" end end acts_as_api-0.4.3/lib/acts_as_api/responder.rb0000644000004100000410000000237012763720301021361 0ustar www-datawww-datamodule ActsAsApi # A custom Rails responder class to automatically use render_for_api in your # controller actions. # # Example: # # class UsersController < ApplicationController # # Set this controller to use our custom responder # # (This could be done in a base controller class, if desired) # self.responder = ActsAsApi::Responder # # respond_to :json, :xml # # def index # @users = User.all # respond_with @users, :api_template => :name_only # end # end # # The `:api_template` parameter is required so the responder knows which api template it should render. class Responder < ActionController::Responder module Module # Overrides the base implementation of display, replacing it with # the render_for_api method whenever api_template is specified. def display(resource, given_options={}) api_template = options[:api_template] if api_template.nil? || !resource.respond_to?(:as_api_response) controller.render given_options.merge!(options).merge!(format => resource) else controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource) end end end include Module end end acts_as_api-0.4.3/lib/acts_as_api/rails_renderer.rb0000644000004100000410000000113712763720301022360 0ustar www-datawww-datamodule ActsAsApi # Contains rails specific renderers used by acts_as_api to render a jsonp response # # See ActsAsApi::Config about the possible configurations module RailsRenderer def self.setup ActionController.add_renderer :acts_as_api_jsonp do |json, options| json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json}, #{response.status})" unless options[:callback].blank? self.content_type ||= options[:callback].blank ? Mime::JSON : Mime::JS self.response_body = json end end end end acts_as_api-0.4.3/lib/acts_as_api/rendering.rb0000644000004100000410000000711012763720301021332 0ustar www-datawww-datamodule ActsAsApi # The methods of this module are included into the AbstractController::Rendering # module. module Rendering # Provides an alternative to the +render+ method used within the controller # to simply generate API outputs. # # The default Rails serializers are used to serialize the data. def render_for_api(api_template_or_options, render_options) if api_template_or_options.is_a?(Hash) api_template = [] api_template << api_template_or_options.delete(:prefix) api_template << api_template_or_options.delete(:template) api_template << api_template_or_options.delete(:postfix) api_template = api_template.reject(&:blank?).join('_') else api_template = api_template_or_options end # extract the api format and model api_format_options = {} ActsAsApi::Config.accepted_api_formats.each do |item| if render_options.has_key?(item) api_format_options[item] = render_options[item] render_options.delete item end end meta_hash = render_options[:meta] if render_options.has_key?(:meta) api_format = api_format_options.keys.first api_model = api_format_options.values.first # set the params to render output_params = render_options api_root_name = nil if !output_params[:root].nil? api_root_name = output_params[:root].to_s elsif api_model.class.respond_to?(:model_name) api_root_name = api_model.class.model_name elsif api_model.respond_to?(:collection_name) api_root_name = api_model.collection_name elsif api_model.is_a?(Array) && !api_model.empty? && api_model.first.class.respond_to?(:model_name) api_root_name = api_model.first.class.model_name elsif api_model.is_a?(Array) && !api_model.empty? && api_model.first.respond_to?(:model_name) api_root_name = api_model.first.model_name elsif api_model.respond_to?(:model_name) api_root_name = api_model.model_name else api_root_name = ActsAsApi::Config.default_root.to_s end api_root_name = api_root_name.to_s.underscore.tr('/', '_') if api_model.is_a?(Array) || (defined?(ActiveRecord) && api_model.is_a?(ActiveRecord::Relation)) api_root_name = api_root_name.pluralize end api_root_name = api_root_name.dasherize if ActsAsApi::Config.dasherize_for.include? api_format.to_sym output_params[:root] = api_root_name #output_params[:root] = output_params[:root].camelize if render_options.has_key?(:camelize) && render_options[:camelize] #output_params[:root] = output_params[:root].dasherize if !render_options.has_key?(:dasherize) || render_options[:dasherize] api_response = api_model.as_api_response(api_template) if api_response.is_a?(Array) && api_format.to_sym == :json && ActsAsApi::Config.include_root_in_json_collections api_response = api_response.collect{|f| { api_root_name.singularize => f } } end if meta_hash or ActsAsApi::Config.add_root_node_for.include? api_format api_response = { api_root_name.to_sym => api_response} end api_response = meta_hash.merge api_response if meta_hash if ActsAsApi::Config.allow_jsonp_callback && params[:callback] output_params[:callback] = params[:callback] api_format = :acts_as_api_jsonp if ActsAsApi::Config.add_http_status_to_jsonp_response end # create the Hash as response output_params[api_format] = api_response render output_params end end end acts_as_api-0.4.3/lib/acts_as_api/version.rb0000644000004100000410000000005112763720301021037 0ustar www-datawww-datamodule ActsAsApi VERSION = "0.4.3" end acts_as_api-0.4.3/lib/acts_as_api/config.rb0000644000004100000410000000345312763720301020630 0ustar www-datawww-datamodule ActsAsApi module Config class << self attr_writer :accepted_api_formats, :dasherize_for, :include_root_in_json_collections, :add_root_node_for, :default_root, :allow_jsonp_callback, :add_http_status_to_jsonp_response # The accepted response formats # Default is [:xml, :json] def accepted_api_formats @accepted_api_formats || [:xml, :json] end # Holds formats that should be dasherized # Default is [:xml] def dasherize_for @dasherize_for || [:xml] end # If true, the root node in json collections will be added # so the response will look like the default Rails 3 json # response def include_root_in_json_collections @include_root_in_json_collections || false end # Holds references to formats that need # to get added an additional root node # with the name of the model. def add_root_node_for @add_root_node_for || [:json] end # The default name of a root node of a response # if no root paramter is passed in render_for_api # and the gem is not able to determine a root name # automatically def default_root @default_root || :record end # If true a json response will be automatically wrapped into # a JavaScript function call in case a :callback param is passed. def allow_jsonp_callback @allow_jsonp_callback || false end # If true the jsonp function call will get the http status passed # as a second parameter def add_http_status_to_jsonp_response @add_http_status_to_jsonp_response.nil? ? true : @add_http_status_to_jsonp_response end end end end acts_as_api-0.4.3/lib/acts_as_api/array.rb0000644000004100000410000000110412763720301020470 0ustar www-datawww-data# The standard ruby Array class is extended by one instance method. class Array # Neccessary to render an Array of models, e.g. the result of a search. # # The Array checks all its items if they respond to the +as_api_response+ method. # If they do, the result of this method will be collected. # If they don't, the item itself will be collected. def as_api_response(api_template, options = {}) collect do |item| if item.respond_to?(:as_api_response) item.as_api_response(api_template,options) else item end end end end acts_as_api-0.4.3/lib/acts_as_api/base.rb0000644000004100000410000000507512763720301020277 0ustar www-datawww-datamodule ActsAsApi # This module enriches the ActiveRecord::Base module of Rails. module Base # Indicates if the current model acts as api. # False by default. def acts_as_api? false end # When invoked, it enriches the current model with the # class and instance methods to act as api. def acts_as_api class_eval do include ActsAsApi::Base::InstanceMethods extend ActsAsApi::Base::ClassMethods end if block_given? yield ActsAsApi::Config end end module ClassMethods def acts_as_api?#:nodoc: self.included_modules.include?(InstanceMethods) end # Determines the attributes, methods of the model that are accessible in the api response. # *Note*: There is only whitelisting for api accessible attributes. # So once the model acts as api, you have to determine all attributes here that should # be contained in the api responses. def api_accessible(api_template, options = {}, &block) attributes = api_accessible_attributes(api_template).try(:dup) || ApiTemplate.new(api_template) attributes.merge!(api_accessible_attributes(options[:extend])) if options[:extend] if block_given? yield attributes end class_attribute "api_accessible_#{api_template}".to_sym send "api_accessible_#{api_template}=", attributes end # Returns an array of all the attributes that have been made accessible to the api response. def api_accessible_attributes(api_template) begin send "api_accessible_#{api_template}".to_sym rescue nil end end end module InstanceMethods # Creates the api response of the model and returns it as a Hash. # Will raise an exception if the passed api template is not defined for the model def as_api_response(api_template, options = {}) api_attributes = self.class.api_accessible_attributes(api_template) raise ActsAsApi::TemplateNotFoundError.new("acts_as_api template :#{api_template.to_s} was not found for model #{self.class}") if api_attributes.nil? before_api_response(api_template) response_hash = around_api_response(api_template) do api_attributes.to_response_hash(self, api_attributes, options) end after_api_response(api_template) response_hash end protected def before_api_response(api_remplate) end def after_api_response(api_remplate) end def around_api_response(api_remplate) yield end end end end acts_as_api-0.4.3/lib/acts_as_api/api_template.rb0000644000004100000410000001002612763720301022021 0ustar www-datawww-datamodule ActsAsApi # Represents an api template for a model. # This class should not be initiated by yourself, api templates # are created by defining them in the model by calling: +api_accessible+. # # The api template is configured in the block passed to +api_accessible+. # # Please note that +ApiTemplate+ inherits from +Hash+ so you can use all # kind of +Hash+ and +Enumerable+ methods to manipulate the template. class ApiTemplate < Hash # The name of the api template as a Symbol. attr_accessor :api_template attr_reader :options def initialize(api_template) self.api_template = api_template @options ||= {} end def merge!(other_hash, &block) super self.options.merge!(other_hash.options) if other_hash.respond_to?(:options) end # Adds a field to the api template # # The value passed can be one of the following: # * Symbol - the method with the same name will be called on the model when rendering. # * String - must be in the form "method1.method2.method3", will call this method chain. # * Hash - will be added as a sub hash and all its items will be resolved the way described above. # # Possible options to pass: # * :template - Determine the template that should be used to render the item if it is # +api_accessible+ itself. def add(val, options = {}) item_key = (options[:as] || val).to_sym self[item_key] = val @options[item_key] = options end # Removes a field from the template def remove(field) self.delete(field) end # Returns the options of a field in the api template def options_for(field) @options[field] end # Returns the passed option of a field in the api template def option_for(field, option) @options[field][option] if @options[field] end # If a special template name for the passed item is specified # it will be returned, if not the original api template. def api_template_for(fieldset, field) fieldset.option_for(field, :template) || api_template end # Decides if the passed item should be added to # the response based on the conditional options passed. def allowed_to_render?(fieldset, field, model, options) return true unless fieldset.is_a? ActsAsApi::ApiTemplate fieldset_options = fieldset.options_for(field) if fieldset_options[:unless] !(condition_fulfilled?(model, fieldset_options[:unless], options)) elsif fieldset_options[:if] condition_fulfilled?(model, fieldset_options[:if], options) else true end end # Checks if a condition is fulfilled # (result is not nil or false) def condition_fulfilled?(model, condition, options) case condition when Symbol result = model.send(condition) when Proc result = call_proc(condition, model, options) end !!result end # Generates a hash that represents the api response based on this # template for the passed model instance. def to_response_hash(model, fieldset = self, options = {}) api_output = {} fieldset.each do |field, value| next unless allowed_to_render?(fieldset, field, model, options) out = process_value(model, value, options) if out.respond_to?(:as_api_response) sub_template = api_template_for(fieldset, field) out = out.as_api_response(sub_template, options) end api_output[field] = out end api_output end private def process_value(model, value, options) case value when Symbol model.send(value) when Proc call_proc(value,model,options) when String value.split('.').inject(model) { |result, method| result.send(method) } when Hash to_response_hash(model, value) end end def call_proc(the_proc,model,options) if the_proc.arity == 2 the_proc.call(model, options) else the_proc.call(model) end end end end acts_as_api-0.4.3/lib/acts_as_api/exceptions.rb0000644000004100000410000000016512763720301021541 0ustar www-datawww-datamodule ActsAsApi class ActsAsApiError < RuntimeError; end class TemplateNotFoundError < ActsAsApiError; end endacts_as_api-0.4.3/lib/acts_as_api.rb0000644000004100000410000000274212763720301017363 0ustar www-datawww-datarequire 'active_model' require 'active_support/core_ext/class' $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) require "acts_as_api/array" require "acts_as_api/rails_renderer" require "acts_as_api/exceptions" # acts_as_api is a gem that aims to make the construction of JSON and XML # responses in rails 3 easy and fun. # # Therefore it attaches a couple of helper methods to active record and # the action controller base classes. # # acts_as_api uses the default serializers of your rails app and doesn't # force you into more dependencies. module ActsAsApi autoload :Config, "acts_as_api/config" autoload :ApiTemplate, "acts_as_api/api_template" autoload :Base, "acts_as_api/base" autoload :Rendering, "acts_as_api/rendering" autoload :Responder, "acts_as_api/responder" autoload :Adapters, "acts_as_api/adapters" end # Attach ourselves to ActiveRecord if defined?(ActiveRecord::Base) ActiveRecord::Base.extend ActsAsApi::Base end # Attach ourselves to ActiveResource if defined?(ActiveResource::Base) ActiveResource::Base.extend ActsAsApi::Base end # Attach ourselves to Mongoid if defined?(Mongoid::Document) Mongoid::Document.send :include, ActsAsApi::Adapters::Mongoid end # Attach ourselves to the action controller of Rails if defined?(ActionController::Base) ActionController::Base.send :include, ActsAsApi::Rendering ActsAsApi::RailsRenderer.setup end acts_as_api-0.4.3/acts_as_api.gemspec0000644000004100000410000000221112763720301017624 0ustar www-datawww-data# encoding: UTF-8 $:.push File.expand_path("../lib", __FILE__) require "acts_as_api/version" Gem::Specification.new do |s| s.name = "acts_as_api" s.version = ActsAsApi::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Christian Bäuerlein"] s.email = ["christian@ffwdme.com"] s.homepage = "https://github.com/fabrik42/acts_as_api" s.summary = %q{Makes creating XML/JSON responses in Rails 3 easy and fun.} s.description = %q{acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.} s.add_dependency('activemodel','>= 3.0.0') s.add_dependency('activesupport','>= 3.0.0') s.add_dependency('rack','>= 1.1.0') s.add_development_dependency('rails', ['>= 3.2.22.2']) s.add_development_dependency('mongoid', ['>= 3.0.1']) s.rdoc_options = ['--charset=UTF-8'] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] end acts_as_api-0.4.3/.gitignore0000644000004100000410000000042012763720301016001 0ustar www-datawww-datanbproject/ pkg/* .bundle Gemfile.lock test acts_as_api.tmproj spec/active_record_dummy/db/*.sqlite3 spec/active_record_dummy/tmp/**/* spec/active_record_dummy/log/*.log spec/mongoid_dummy/tmp/**/* spec/mongoid_dummy/log/*.log .rspec .ruby-version .rvmrc *.sqlite3-journal acts_as_api-0.4.3/README.md0000644000004100000410000001136412763720301015301 0ustar www-datawww-data# acts_as_api ![acts_as_api on travis ci](https://secure.travis-ci.org/fabrik42/acts_as_api.png?branch=master) acts_as_api makes creating XML/JSON responses in Rails 3 easy and fun. It provides a simple interface to determine the representation of your model data, that should be rendered in your API responses. In addition to Rails it theoretically can be used with any ruby app and any database (__ActiveRecord__, __Mongoid__ and __ActiveResource__ are supported out of the box) as it only has few dependencies. The lib is _very_ fast in generating your responses and battle tested in production with platforms like [Diaspora](https://joindiaspora.com) or [flinc](https://flinc.org). ## Introduction acts_as_api enriches the models and controllers of your app in a Rails-like way so you can easily determine how your API responses should look like: ```ruby class User < ActiveRecord::Base acts_as_api api_accessible :public do |template| template.add :first_name template.add :age end # will render json: { "user": { "first_name": "John", "age": 26 } } api_accessible :private, :extend => :public do |template| template.add :last_name template.add :email end # will render json: { "user": { "first_name": "John", "last_name": "Doe", "age": 26, "email": "john@example.org" } } end ``` ## Getting started A nice introduction about acts_as_api with examples can be found here: http://fabrik42.github.com/acts_as_api See the Wiki for a lot of usage examples and features: https://github.com/fabrik42/acts_as_api/wiki There are a lot of how-tos like: * [Extending existing api templates](https://github.com/fabrik42/acts_as_api/wiki/Extending-an-existing-api-template) * [Include attributes and all other kinds of methods of your model](https://github.com/fabrik42/acts_as_api/wiki/Calling-a-method-of-the-model) * [Include child associations (if they also act_as_api this will be considered)](https://github.com/fabrik42/acts_as_api/wiki/Including-a-child-association) * [Rename attributes, methods, associations](https://github.com/fabrik42/acts_as_api/wiki/Renaming-an-attribute) * [Keep your API templates out of your models](https://github.com/fabrik42/acts_as_api/wiki/Keep-your-api-templates-out-of-your-models) * [and much more...](https://github.com/fabrik42/acts_as_api/wiki) ## Features: * DRY templates for your api responses * Ships with support for __ActiveRecord__ and __Mongoid__ * Support for Rails 3 Responders * Plays very well together with client libs like [Backbone.js](http://documentcloud.github.com/backbone), [RestKit](http://restkit.org) (iOS) or [gson](http://code.google.com/p/google-gson) (Android). * Easy but very flexible syntax for defining the templates * XML, JSON and JSON-P support out of the box, easy to extend * Minimal dependecies (you can also use it without Rails) * Supports multiple api rendering templates per model. This is especially useful for API versioning or for example for private vs. public access points to a user’s profile. ### Requirements: * ActiveModel (>= 3.0.0) * ActiveSupport (>= 3.0.0) * Rack (>= 1.1.0) ### Links * Introduction: http://fabrik42.github.com/acts_as_api * Docs: http://rdoc.info/projects/fabrik42/acts_as_api * Found a bug? http://github.com/fabrik42/acts_as_api/issues * Wiki: https://github.com/fabrik42/acts_as_api/wiki * Want to contribute - the spec suite is explained here: https://github.com/fabrik42/acts_as_api/tree/master/spec ### Downwards Compatibility Note that upgrading to 0.3.0 will break code that worked with previous versions due to a complete overhaul of the lib. For a legacy version of this readme file look here: https://github.com/fabrik42/acts_as_api/wiki/legacy-acts_as_api-0.2-readme ### LICENSE: (The MIT License) Copyright (c) 2010 Christian Bäuerlein 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.