acts-as-api-0.4.2/0000755000076400007640000000000012326165355012663 5ustar pravipraviacts-as-api-0.4.2/spec/0000755000076400007640000000000012326165355013615 5ustar pravipraviacts-as-api-0.4.2/spec/spec_helper.rb0000644000076400007640000000120312326165355016427 0ustar pravipraviENV["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.2/spec/spec.opts0000644000076400007640000000001112326165355015446 0ustar pravipravi--colour acts-as-api-0.4.2/spec/active_record_dummy/0000755000076400007640000000000012326165355017641 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/README.rdoc0000644000076400007640000002177012326165355021456 0ustar pravipravi== 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.2/spec/active_record_dummy/vendor/0000755000076400007640000000000012326165355021136 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/assets/0000755000076400007640000000000012326165355022440 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/assets/stylesheets/0000755000076400007640000000000012326165355025014 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep0000644000076400007640000000000012326165355026433 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/assets/javascripts/0000755000076400007640000000000012326165355024771 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep0000644000076400007640000000000012326165355026410 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/plugins/0000755000076400007640000000000012326165355022617 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/vendor/plugins/.gitkeep0000644000076400007640000000000012326165355024236 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/db/0000755000076400007640000000000012326165355020226 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/db/schema.rb0000644000076400007640000000276312326165355022023 0ustar pravipravi# 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.2/spec/active_record_dummy/db/migrate/0000755000076400007640000000000012326165355021656 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb0000644000076400007640000000172212326165355026431 0ustar pravipraviclass 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.2/spec/active_record_dummy/db/seeds.rb0000644000076400007640000000054112326165355021656 0ustar pravipravi# 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.2/spec/active_record_dummy/log/0000755000076400007640000000000012326165355020422 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/log/.gitkeep0000644000076400007640000000000012326165355022041 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/config/0000755000076400007640000000000012326165355021106 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/config/environment.rb0000644000076400007640000000024112326165355023774 0ustar pravipravi# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application ActiveRecordDummy::Application.initialize! acts-as-api-0.4.2/spec/active_record_dummy/config/locales/0000755000076400007640000000000012326165355022530 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/config/locales/en.yml0000644000076400007640000000032612326165355023656 0ustar pravipravi# 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.2/spec/active_record_dummy/config/environments/0000755000076400007640000000000012326165355023635 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/config/environments/test.rb0000644000076400007640000000300112326165355025133 0ustar pravipraviActiveRecordDummy::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.2/spec/active_record_dummy/config/environments/production.rb0000644000076400007640000000464012326165355026354 0ustar pravipraviActiveRecordDummy::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.2/spec/active_record_dummy/config/environments/development.rb0000644000076400007640000000255012326165355026506 0ustar pravipraviActiveRecordDummy::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.2/spec/active_record_dummy/config/boot.rb0000644000076400007640000000027712326165355022404 0ustar pravipravirequire '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.2/spec/active_record_dummy/config/initializers/0000755000076400007640000000000012326165355023614 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/config/initializers/session_store.rb0000644000076400007640000000070012326165355027035 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/mime_types.rb0000644000076400007640000000031512326165355026313 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/secret_token.rb0000644000076400007640000000077412326165355026636 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/inflections.rb0000644000076400007640000000102512326165355026454 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/wrap_parameters.rb0000644000076400007640000000072412326165355027340 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/backtrace_silencers.rb0000644000076400007640000000062412326165355030131 0ustar pravipravi# 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.2/spec/active_record_dummy/config/initializers/generators.rb0000644000076400007640000000005712326165355026314 0ustar pravipraviRails.application.config.generators do |g| end acts-as-api-0.4.2/spec/active_record_dummy/config/database.yml0000644000076400007640000000110012326165355023365 0ustar pravipravi# 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.2/spec/active_record_dummy/config/routes.rb0000644000076400007640000000350412326165355022756 0ustar pravipraviActiveRecordDummy::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.2/spec/active_record_dummy/config/application.rb0000644000076400007640000000524312326165355023742 0ustar pravipravirequire 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.2/spec/active_record_dummy/script/0000755000076400007640000000000012326165355021145 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/script/rails0000755000076400007640000000044712326165355022212 0ustar pravipravi#!/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.2/spec/active_record_dummy/public/0000755000076400007640000000000012326165355021117 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/public/422.html0000644000076400007640000000130712326165355022315 0ustar pravipravi 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.2/spec/active_record_dummy/public/500.html0000644000076400007640000000120312326165355022305 0ustar pravipravi We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts-as-api-0.4.2/spec/active_record_dummy/public/index.html0000644000076400007640000001342212326165355023116 0ustar pravipravi 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.2/spec/active_record_dummy/public/favicon.ico0000644000076400007640000000000012326165355023226 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/public/404.html0000644000076400007640000000133012326165355022311 0ustar pravipravi 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.2/spec/active_record_dummy/public/robots.txt0000644000076400007640000000031412326165355023166 0ustar pravipravi# 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.2/spec/active_record_dummy/doc/0000755000076400007640000000000012326165355020406 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/doc/README_FOR_APP0000644000076400007640000000032312326165355022472 0ustar pravipraviUse 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.2/spec/active_record_dummy/config.ru0000644000076400007640000000024712326165355021461 0ustar pravipravi# 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.2/spec/active_record_dummy/app/0000755000076400007640000000000012326165355020421 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/assets/0000755000076400007640000000000012326165355021723 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/assets/stylesheets/0000755000076400007640000000000012326165355024277 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/assets/stylesheets/application.css0000644000076400007640000000104112326165355027310 0ustar pravipravi/* * 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.2/spec/active_record_dummy/app/assets/javascripts/0000755000076400007640000000000012326165355024254 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/assets/javascripts/application.js0000644000076400007640000000120112326165355027107 0ustar pravipravi// 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.2/spec/active_record_dummy/app/assets/images/0000755000076400007640000000000012326165355023170 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/assets/images/rails.png0000644000076400007640000001476612326165355025026 0ustar pravipraviPNG  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.2/spec/active_record_dummy/app/models/.gitkeep0000644000076400007640000000000012326165355023323 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/models/untouched.rb0000644000076400007640000000005112326165355024223 0ustar pravipraviclass Untouched < ActiveRecord::Base end acts-as-api-0.4.2/spec/active_record_dummy/app/models/profile.rb0000644000076400007640000000014212326165355023666 0ustar pravipraviclass Profile < ActiveRecord::Base attr_accessible :avatar, :homepage belongs_to :user endacts-as-api-0.4.2/spec/active_record_dummy/app/models/task.rb0000644000076400007640000000016712326165355023177 0ustar pravipraviclass Task < ActiveRecord::Base attr_accessible :heading, :description, :time_spent, :done belongs_to :user endacts-as-api-0.4.2/spec/active_record_dummy/app/views/0000755000076400007640000000000012326165355021556 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/views/layouts/0000755000076400007640000000000012326165355023256 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/views/layouts/application.html.erb0000644000076400007640000000036412326165355027221 0ustar pravipravi ActiveRecordDummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts-as-api-0.4.2/spec/active_record_dummy/app/controllers/0000755000076400007640000000000012326165355022767 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/app/controllers/application_controller.rb0000644000076400007640000000012012326165355030053 0ustar pravipraviclass ApplicationController < ActionController::Base protect_from_forgery end acts-as-api-0.4.2/spec/active_record_dummy/Gemfile0000644000076400007640000000046712326165355021143 0ustar pravipravisource '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.2/spec/active_record_dummy/lib/0000755000076400007640000000000012326165355020407 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/lib/assets/0000755000076400007640000000000012326165355021711 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/lib/assets/.gitkeep0000644000076400007640000000000012326165355023330 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/lib/tasks/0000755000076400007640000000000012326165355021534 5ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/lib/tasks/.gitkeep0000644000076400007640000000000012326165355023153 0ustar pravipraviacts-as-api-0.4.2/spec/active_record_dummy/Rakefile0000644000076400007640000000043212326165355021305 0ustar pravipravi#!/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.2/spec/active_record_dummy/.gitignore0000644000076400007640000000065612326165355021640 0ustar pravipravi# 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.2/spec/models/0000755000076400007640000000000012326165355015100 5ustar pravipraviacts-as-api-0.4.2/spec/models/model_spec.rb0000644000076400007640000000164412326165355017544 0ustar pravipravirequire '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.2/spec/README.md0000644000076400007640000000413112326165355015073 0ustar pravipravi# 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.2/spec/shared_engine/0000755000076400007640000000000012326165355016410 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/shared_engine.gemspec0000644000076400007640000000125512326165355022553 0ustar pravipravi$:.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 = ["TODO: Your name"] s.email = ["TODO: Your email"] s.homepage = "TODO" s.summary = "TODO: Summary of SharedEngine." s.description = "TODO: Description of SharedEngine." s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] s.add_dependency "rails", "~> 3.2.16" # s.add_dependency "jquery-rails" s.add_development_dependency "sqlite3" end acts-as-api-0.4.2/spec/shared_engine/README.rdoc0000644000076400007640000000007012326165355020213 0ustar pravipravi= SharedEngine This project rocks and uses MIT-LICENSE.acts-as-api-0.4.2/spec/shared_engine/config/0000755000076400007640000000000012326165355017655 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/config/routes.rb0000644000076400007640000000101712326165355021522 0ustar pravipraviSharedEngine::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.2/spec/shared_engine/script/0000755000076400007640000000000012326165355017714 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/script/rails0000755000076400007640000000050412326165355020753 0ustar pravipravi#!/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.2/spec/shared_engine/dummy/0000755000076400007640000000000012326165355017543 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/README.rdoc0000644000076400007640000002177012326165355021360 0ustar pravipravi== 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.2/spec/shared_engine/dummy/log/0000755000076400007640000000000012326165355020324 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/log/.gitkeep0000644000076400007640000000000012326165355021743 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/config/0000755000076400007640000000000012326165355021010 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/config/environment.rb0000644000076400007640000000022512326165355023700 0ustar pravipravi# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize! acts-as-api-0.4.2/spec/shared_engine/dummy/config/locales/0000755000076400007640000000000012326165355022432 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/config/locales/en.yml0000644000076400007640000000032612326165355023560 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/environments/0000755000076400007640000000000012326165355023537 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/config/environments/test.rb0000644000076400007640000000276512326165355025055 0ustar pravipraviDummy::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.2/spec/shared_engine/dummy/config/environments/production.rb0000644000076400007640000000462412326165355026260 0ustar pravipraviDummy::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.2/spec/shared_engine/dummy/config/environments/development.rb0000644000076400007640000000253412326165355026412 0ustar pravipraviDummy::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.2/spec/shared_engine/dummy/config/boot.rb0000644000076400007640000000035312326165355022301 0ustar pravipravirequire '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.2/spec/shared_engine/dummy/config/initializers/0000755000076400007640000000000012326165355023516 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/config/initializers/session_store.rb0000644000076400007640000000063212326165355026743 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/initializers/mime_types.rb0000644000076400007640000000031512326165355026215 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/initializers/secret_token.rb0000644000076400007640000000076012326165355026533 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/initializers/inflections.rb0000644000076400007640000000102512326165355026356 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb0000644000076400007640000000072412326165355027242 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb0000644000076400007640000000062412326165355030033 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/database.yml0000644000076400007640000000110012326165355023267 0ustar pravipravi# 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.2/spec/shared_engine/dummy/config/routes.rb0000644000076400007640000000012712326165355022656 0ustar pravipraviRails.application.routes.draw do mount SharedEngine::Engine => "/shared_engine" end acts-as-api-0.4.2/spec/shared_engine/dummy/config/application.rb0000644000076400007640000000516112326165355023643 0ustar pravipravirequire 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.2/spec/shared_engine/dummy/script/0000755000076400007640000000000012326165355021047 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/script/rails0000755000076400007640000000044712326165355022114 0ustar pravipravi#!/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.2/spec/shared_engine/dummy/public/0000755000076400007640000000000012326165355021021 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/public/422.html0000644000076400007640000000130712326165355022217 0ustar pravipravi 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.2/spec/shared_engine/dummy/public/500.html0000644000076400007640000000120312326165355022207 0ustar pravipravi We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts-as-api-0.4.2/spec/shared_engine/dummy/public/favicon.ico0000644000076400007640000000000012326165355023130 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/public/404.html0000644000076400007640000000133012326165355022213 0ustar pravipravi 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.2/spec/shared_engine/dummy/config.ru0000644000076400007640000000023312326165355021356 0ustar pravipravi# 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.2/spec/shared_engine/dummy/app/0000755000076400007640000000000012326165355020323 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/assets/0000755000076400007640000000000012326165355021625 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/assets/stylesheets/0000755000076400007640000000000012326165355024201 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/assets/stylesheets/application.css0000644000076400007640000000104112326165355027212 0ustar pravipravi/* * 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.2/spec/shared_engine/dummy/app/assets/javascripts/0000755000076400007640000000000012326165355024156 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/assets/javascripts/application.js0000644000076400007640000000120112326165355027011 0ustar pravipravi// 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.2/spec/shared_engine/dummy/app/helpers/0000755000076400007640000000000012326165355021765 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/helpers/application_helper.rb0000644000076400007640000000003512326165355026152 0ustar pravipravimodule ApplicationHelper end acts-as-api-0.4.2/spec/shared_engine/dummy/app/mailers/0000755000076400007640000000000012326165355021757 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/mailers/.gitkeep0000644000076400007640000000000012326165355023376 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/models/0000755000076400007640000000000012326165355021606 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/models/.gitkeep0000644000076400007640000000000012326165355023225 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/views/0000755000076400007640000000000012326165355021460 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/views/layouts/0000755000076400007640000000000012326165355023160 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/views/layouts/application.html.erb0000644000076400007640000000035012326165355027116 0ustar pravipravi Dummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts-as-api-0.4.2/spec/shared_engine/dummy/app/controllers/0000755000076400007640000000000012326165355022671 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/app/controllers/application_controller.rb0000644000076400007640000000012012326165355027755 0ustar pravipraviclass ApplicationController < ActionController::Base protect_from_forgery end acts-as-api-0.4.2/spec/shared_engine/dummy/lib/0000755000076400007640000000000012326165355020311 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/lib/assets/0000755000076400007640000000000012326165355021613 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/lib/assets/.gitkeep0000644000076400007640000000000012326165355023232 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/dummy/Rakefile0000644000076400007640000000041612326165355021211 0ustar pravipravi#!/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.2/spec/shared_engine/app/0000755000076400007640000000000012326165355017170 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/0000755000076400007640000000000012326165355020472 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/stylesheets/0000755000076400007640000000000012326165355023046 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/stylesheets/shared_engine/0000755000076400007640000000000012326165355025641 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css0000644000076400007640000000104112326165355030652 0ustar pravipravi/* * 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.2/spec/shared_engine/app/assets/javascripts/0000755000076400007640000000000012326165355023023 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/javascripts/shared_engine/0000755000076400007640000000000012326165355025616 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/javascripts/shared_engine/application.js0000644000076400007640000000120112326165355030451 0ustar pravipravi// 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.2/spec/shared_engine/app/assets/images/0000755000076400007640000000000012326165355021737 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/images/shared_engine/0000755000076400007640000000000012326165355024532 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/assets/images/shared_engine/.gitkeep0000644000076400007640000000000012326165355026151 0ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/helpers/0000755000076400007640000000000012326165355020632 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/helpers/shared_engine/0000755000076400007640000000000012326165355023425 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/helpers/shared_engine/application_helper.rb0000644000076400007640000000007112326165355027612 0ustar pravipravimodule SharedEngine module ApplicationHelper end end acts-as-api-0.4.2/spec/shared_engine/app/models/0000755000076400007640000000000012326165355020453 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/models/plain_object.rb0000644000076400007640000000043112326165355023427 0ustar pravipraviclass 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.2/spec/shared_engine/app/models/user_template.rb0000644000076400007640000000745412326165355023663 0ustar pravipravimodule 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.2/spec/shared_engine/app/views/0000755000076400007640000000000012326165355020325 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/views/layouts/0000755000076400007640000000000012326165355022025 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/views/layouts/shared_engine/0000755000076400007640000000000012326165355024620 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb0000644000076400007640000000041312326165355030556 0ustar pravipravi SharedEngine <%= stylesheet_link_tag "shared_engine/application", :media => "all" %> <%= javascript_include_tag "shared_engine/application" %> <%= csrf_meta_tags %> <%= yield %> acts-as-api-0.4.2/spec/shared_engine/app/controllers/0000755000076400007640000000000012326165355021536 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/controllers/shared_engine/0000755000076400007640000000000012326165355024331 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/app/controllers/shared_engine/users_controller.rb0000644000076400007640000000513512326165355030266 0ustar pravipravimodule 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.2/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb0000644000076400007640000000377312326165355033061 0ustar pravipravimodule 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.2/spec/shared_engine/app/controllers/shared_engine/application_controller.rb0000644000076400007640000000012512326165355031422 0ustar pravipravimodule SharedEngine class ApplicationController < ActionController::Base end end acts-as-api-0.4.2/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb0000644000076400007640000000062012326165355031733 0ustar pravipravimodule 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.2/spec/shared_engine/Gemfile0000644000076400007640000000106712326165355017707 0ustar pravipravisource "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.2/spec/shared_engine/lib/0000755000076400007640000000000012326165355017156 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/lib/tasks/0000755000076400007640000000000012326165355020303 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/lib/tasks/shared_engine_tasks.rake0000644000076400007640000000013312326165355025144 0ustar pravipravi# desc "Explaining what the task does" # task :shared_engine do # # Task goes here # end acts-as-api-0.4.2/spec/shared_engine/lib/shared_engine.rb0000644000076400007640000000007012326165355022273 0ustar pravipravirequire "shared_engine/engine" module SharedEngine end acts-as-api-0.4.2/spec/shared_engine/lib/shared_engine/0000755000076400007640000000000012326165355021751 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/lib/shared_engine/version.rb0000644000076400007640000000005412326165355023762 0ustar pravipravimodule SharedEngine VERSION = "0.0.1" end acts-as-api-0.4.2/spec/shared_engine/lib/shared_engine/engine.rb0000644000076400007640000000014212326165355023540 0ustar pravipravimodule SharedEngine class Engine < ::Rails::Engine isolate_namespace SharedEngine end end acts-as-api-0.4.2/spec/shared_engine/lib/magic/0000755000076400007640000000000012326165355020236 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/lib/magic/rails/0000755000076400007640000000000012326165355021350 5ustar pravipraviacts-as-api-0.4.2/spec/shared_engine/lib/magic/rails/engine.rb0000644000076400007640000000561312326165355023147 0ustar pravipravimodule 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.2/spec/shared_engine/Rakefile0000644000076400007640000000117512326165355020061 0ustar pravipravi#!/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.2/spec/shared_engine/MIT-LICENSE0000644000076400007640000000203012326165355020037 0ustar pravipraviCopyright 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.2/spec/shared_engine/.gitignore0000644000076400007640000000013012326165355020372 0ustar pravipravi.bundle/ log/*.log pkg/ dummy/db/*.sqlite3 dummy/log/*.log dummy/tmp/ dummy/.sass-cache acts-as-api-0.4.2/spec/support/0000755000076400007640000000000012326165355015331 5ustar pravipraviacts-as-api-0.4.2/spec/support/it_supports.rb0000644000076400007640000000012712326165355020251 0ustar pravipraviRSpec.configure do |c| c.alias_it_should_behave_like_to :it_supports, 'supports:' endacts-as-api-0.4.2/spec/support/controller_examples.rb0000644000076400007640000003100712326165355021740 0ustar pravipravishared_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 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.2/spec/support/routing.rb0000644000076400007640000000020212326165355017337 0ustar pravipravirequire 'magic/rails/engine' # Replace RspecRouting by the namespace used by your engine SharedEngine::Engine.load_engine_routes acts-as-api-0.4.2/spec/support/api_test_helpers.rb0000644000076400007640000000060612326165355021212 0ustar pravipravimodule 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 endacts-as-api-0.4.2/spec/support/model_examples/0000755000076400007640000000000012326165355020327 5ustar pravipraviacts-as-api-0.4.2/spec/support/model_examples/callbacks.rb0000644000076400007640000000153612326165355022600 0ustar pravipravishared_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.2/spec/support/model_examples/enabled.rb0000644000076400007640000000035312326165355022247 0ustar pravipravishared_examples_for "acts_as_api is enabled" do it "indicates that acts_as_api is enabled" do User.acts_as_api?.should be_true end it "does respond to api_accessible" do User.should respond_to :api_accessible end end acts-as-api-0.4.2/spec/support/model_examples/methods.rb0000644000076400007640000000101712326165355022316 0ustar pravipravishared_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.2/spec/support/model_examples/simple.rb0000644000076400007640000000104112326165355022141 0ustar pravipravishared_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.2/spec/support/model_examples/extending.rb0000644000076400007640000000607412326165355022650 0ustar pravipravishared_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.2/spec/support/model_examples/associations.rb0000644000076400007640000001665212326165355023365 0ustar pravipravishared_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.2/spec/support/model_examples/options.rb0000644000076400007640000000310412326165355022345 0ustar pravipravishared_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.2/spec/support/model_examples/conditional_if.rb0000644000076400007640000001002212326165355023630 0ustar pravipravishared_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.2/spec/support/model_examples/undefined.rb0000644000076400007640000000035112326165355022614 0ustar pravipravishared_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.2/spec/support/model_examples/sub_nodes.rb0000644000076400007640000000477212326165355022647 0ustar pravipravishared_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.2/spec/support/model_examples/untouched.rb0000644000076400007640000000047712326165355022662 0ustar pravipravishared_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 be_false end it "does not respond to api_accessible" do Untouched.should_not respond_to :api_accessible end end endacts-as-api-0.4.2/spec/support/model_examples/conditional_unless.rb0000644000076400007640000001007712326165355024555 0ustar pravipravishared_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.2/spec/support/model_examples/closures.rb0000644000076400007640000000240212326165355022511 0ustar pravipravishared_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.2/spec/support/model_examples/renaming.rb0000644000076400007640000000216612326165355022461 0ustar pravipravishared_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.2/spec/support/simple_fixtures.rb0000644000076400007640000000552512326165355021107 0ustar pravipravimodule 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.2/spec/mongoid_dummy/0000755000076400007640000000000012326165355016464 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/README.rdoc0000644000076400007640000002177012326165355020301 0ustar pravipravi== 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.2/spec/mongoid_dummy/vendor/0000755000076400007640000000000012326165355017761 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/assets/0000755000076400007640000000000012326165355021263 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/assets/stylesheets/0000755000076400007640000000000012326165355023637 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep0000644000076400007640000000000012326165355025256 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/assets/javascripts/0000755000076400007640000000000012326165355023614 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep0000644000076400007640000000000012326165355025233 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/plugins/0000755000076400007640000000000012326165355021442 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/vendor/plugins/.gitkeep0000644000076400007640000000000012326165355023061 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/db/0000755000076400007640000000000012326165355017051 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/db/seeds.rb0000644000076400007640000000052712326165355020505 0ustar pravipravi# 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.2/spec/mongoid_dummy/log/0000755000076400007640000000000012326165355017245 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/log/.gitkeep0000644000076400007640000000000012326165355020664 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/config/0000755000076400007640000000000012326165355017731 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/config/environment.rb0000644000076400007640000000023412326165355022621 0ustar pravipravi# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application MongoidDummy::Application.initialize! acts-as-api-0.4.2/spec/mongoid_dummy/config/locales/0000755000076400007640000000000012326165355021353 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/config/locales/en.yml0000644000076400007640000000032612326165355022501 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/environments/0000755000076400007640000000000012326165355022460 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/config/environments/test.rb0000644000076400007640000000256612326165355023775 0ustar pravipraviMongoidDummy::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.2/spec/mongoid_dummy/config/environments/production.rb0000644000076400007640000000436212326165355025200 0ustar pravipraviMongoidDummy::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.2/spec/mongoid_dummy/config/environments/development.rb0000644000076400007640000000206512326165355025332 0ustar pravipraviMongoidDummy::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.2/spec/mongoid_dummy/config/boot.rb0000644000076400007640000000027712326165355021227 0ustar pravipravirequire '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.2/spec/mongoid_dummy/config/initializers/0000755000076400007640000000000012326165355022437 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/config/initializers/session_store.rb0000644000076400007640000000066012326165355025665 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/mime_types.rb0000644000076400007640000000031512326165355025136 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/secret_token.rb0000644000076400007640000000076712326165355025463 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/inflections.rb0000644000076400007640000000102512326165355025277 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/wrap_parameters.rb0000644000076400007640000000053012326165355026156 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb0000644000076400007640000000062412326165355026754 0ustar pravipravi# 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.2/spec/mongoid_dummy/config/initializers/generators.rb0000644000076400007640000000005712326165355025137 0ustar pravipraviRails.application.config.generators do |g| end acts-as-api-0.4.2/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb0000644000076400007640000000014212326165355026732 0ustar pravipraviif defined?(Mongoid::Document) Mongoid::Document.send :include, ActsAsApi::Adapters::Mongoid endacts-as-api-0.4.2/spec/mongoid_dummy/config/routes.rb0000644000076400007640000000347612326165355021611 0ustar pravipraviMongoidDummy::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.2/spec/mongoid_dummy/config/mongoid.yml0000644000076400007640000001046212326165355022113 0ustar pravipravidevelopment: # 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.2/spec/mongoid_dummy/config/application.rb0000644000076400007640000000556212326165355022571 0ustar pravipravirequire 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.2/spec/mongoid_dummy/script/0000755000076400007640000000000012326165355017770 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/script/rails0000755000076400007640000000044712326165355021035 0ustar pravipravi#!/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.2/spec/mongoid_dummy/public/0000755000076400007640000000000012326165355017742 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/public/422.html0000644000076400007640000000130712326165355021140 0ustar pravipravi 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.2/spec/mongoid_dummy/public/500.html0000644000076400007640000000120312326165355021130 0ustar pravipravi We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

acts-as-api-0.4.2/spec/mongoid_dummy/public/index.html0000644000076400007640000001342212326165355021741 0ustar pravipravi 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.2/spec/mongoid_dummy/public/favicon.ico0000644000076400007640000000000012326165355022051 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/public/404.html0000644000076400007640000000133012326165355021134 0ustar pravipravi 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.2/spec/mongoid_dummy/public/robots.txt0000644000076400007640000000031412326165355022011 0ustar pravipravi# 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.2/spec/mongoid_dummy/doc/0000755000076400007640000000000012326165355017231 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/doc/README_FOR_APP0000644000076400007640000000032312326165355021315 0ustar pravipraviUse 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.2/spec/mongoid_dummy/config.ru0000644000076400007640000000024212326165355020277 0ustar pravipravi# 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.2/spec/mongoid_dummy/app/0000755000076400007640000000000012326165355017244 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/assets/0000755000076400007640000000000012326165355020546 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/assets/stylesheets/0000755000076400007640000000000012326165355023122 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/assets/stylesheets/application.css0000644000076400007640000000104112326165355026133 0ustar pravipravi/* * 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.2/spec/mongoid_dummy/app/assets/javascripts/0000755000076400007640000000000012326165355023077 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/assets/javascripts/application.js0000644000076400007640000000120112326165355025732 0ustar pravipravi// 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.2/spec/mongoid_dummy/app/assets/images/0000755000076400007640000000000012326165355022013 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/assets/images/rails.png0000644000076400007640000001476612326165355023651 0ustar pravipraviPNG  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 :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.2/spec/mongoid_dummy/app/models/.gitkeep0000644000076400007640000000000012326165355022146 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/models/untouched.rb0000644000076400007640000000024512326165355023053 0ustar pravipraviclass Untouched include Mongoid::Document field :nothing, :type => String field :created_at, :type => DateTime field :updated_at, :type => DateTime end acts-as-api-0.4.2/spec/mongoid_dummy/app/models/profile.rb0000644000076400007640000000040512326165355022513 0ustar pravipraviclass 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.2/spec/mongoid_dummy/app/models/task.rb0000644000076400007640000000051712326165355022021 0ustar pravipraviclass Task include Mongoid::Document field :heading, :type => 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.2/spec/mongoid_dummy/app/views/0000755000076400007640000000000012326165355020401 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/views/layouts/0000755000076400007640000000000012326165355022101 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/views/layouts/application.html.erb0000644000076400007640000000035712326165355026046 0ustar pravipravi MongoidDummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> acts-as-api-0.4.2/spec/mongoid_dummy/app/controllers/0000755000076400007640000000000012326165355021612 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/app/controllers/application_controller.rb0000644000076400007640000000012012326165355026676 0ustar pravipraviclass ApplicationController < ActionController::Base protect_from_forgery end acts-as-api-0.4.2/spec/mongoid_dummy/Gemfile0000644000076400007640000000052612326165355017762 0ustar pravipravisource 'https://rubygems.org' gem 'rails', '3.2.3' # 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.2/spec/mongoid_dummy/lib/0000755000076400007640000000000012326165355017232 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/lib/assets/0000755000076400007640000000000012326165355020534 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/lib/assets/.gitkeep0000644000076400007640000000000012326165355022153 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/lib/tasks/0000755000076400007640000000000012326165355020357 5ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/lib/tasks/.gitkeep0000644000076400007640000000000012326165355021776 0ustar pravipraviacts-as-api-0.4.2/spec/mongoid_dummy/Rakefile0000644000076400007640000000042512326165355020132 0ustar pravipravi#!/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.2/spec/mongoid_dummy/.gitignore0000644000076400007640000000065612326165355020463 0ustar pravipravi# 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.2/spec/controllers/0000755000076400007640000000000012326165355016163 5ustar pravipraviacts-as-api-0.4.2/spec/controllers/respond_with_users_controller_spec.rb0000644000076400007640000000752712326165355025726 0ustar pravipravirequire 'spec_helper' # # RSpec.configure do |config| # config.include SharedEngine::Engine.routes.url_helpers # end describe SharedEngine::RespondWithUsersController 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.2/spec/controllers/plain_objects_controller_spec.rb0000644000076400007640000000204712326165355024604 0ustar pravipravirequire 'spec_helper' describe SharedEngine::PlainObjectsController 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.2/spec/controllers/users_controller_spec.rb0000644000076400007640000000040512326165355023125 0ustar pravipravirequire 'spec_helper' describe SharedEngine::UsersController 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.2/.travis.yml0000644000076400007640000000010712326165355014772 0ustar pravipraviscript: bundle exec rake spec:all services: - mongodb rvm: - 1.9.3 acts-as-api-0.4.2/acts_as_api.gemspec0000644000076400007640000000220712326165355016477 0ustar pravipravi# 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.16']) 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.2/History.txt0000644000076400007640000000437312326165355015074 0ustar pravipravi=== 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.2/examples/0000755000076400007640000000000012326165355014501 5ustar pravipraviacts-as-api-0.4.2/examples/introduction/0000755000076400007640000000000012326165355017222 5ustar pravipraviacts-as-api-0.4.2/examples/introduction/index.rb0000644000076400007640000001075712326165355020670 0ustar pravipravi# 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.2/examples/introduction/index.html0000644000076400007640000003500312326165355021220 0ustar pravipravi 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.2/examples/introduction/docco.css0000644000076400007640000001567512326165355021041 0ustar pravipravi/*--------------------- 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.2/examples/introduction/layout.mustache0000644000076400007640000000375512326165355022304 0ustar pravipravi 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.2/checksums.yaml.gz0000444000076400007640000000064712326165355016160 0ustar pravipraviRO@ t節!\V!hF!h|n{XE"XFcgFA?wF_2v͘>סN@CA/~dL.7 ؃Z{( Vۡz~rZxacts-as-api-0.4.2/README.md0000644000076400007640000001233312326165355014144 0ustar pravipravi# 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__ and __Mongoid__ 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 ### Travis CI build status ![acts_as_api on travis ci](https://secure.travis-ci.org/fabrik42/acts_as_api.png?branch=master) Specs run with 1.9.3: http://travis-ci.org/#!/fabrik42/acts_as_api ### Tested with: It has been used in production with the following ruby versions. They are not integrated in Travis, because optional dependencies (like Mongoid 3) don't support these Ruby versions. * MRI 1.9.3-p125 * MRI 1.9.2-p290 * MRI 1.8.7-p358 * But it just should work fine with other versions too... :) ### 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.acts-as-api-0.4.2/Gemfile0000644000076400007640000000044412326165355014160 0ustar pravipravisource "http://rubygems.org" # Specify your gem's dependencies in acts_as_api.gemspec gemspec group :test do gem 'sqlite3-ruby' gem 'mongoid', '>= 3.0.1' gem 'rspec', '>= 2.9.0' gem 'rspec-rails', '>= 2.5.0' gem 'webrat' gem 'shared_engine', :path => './spec/shared_engine' end acts-as-api-0.4.2/metadata.yml0000644000076400007640000005111412326165355015170 0ustar pravipravi--- !ruby/object:Gem::Specification name: acts_as_api version: !ruby/object:Gem::Version version: 0.4.2 platform: ruby authors: - Christian Bäuerlein autorequire: bindir: bin cert_chain: [] date: 2013-12-28 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activemodel requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.0 - !ruby/object:Gem::Dependency name: activesupport requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.0 - !ruby/object:Gem::Dependency name: rack requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.1.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.1.0 - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.2.16 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.2.16 - !ruby/object:Gem::Dependency name: mongoid requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.1 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.1 description: 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. email: - christian@ffwdme.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .travis.yml - Gemfile - History.txt - README.md - Rakefile - acts_as_api.gemspec - examples/introduction/docco.css - examples/introduction/index.html - examples/introduction/index.rb - examples/introduction/layout.mustache - lib/acts_as_api.rb - lib/acts_as_api/adapters.rb - lib/acts_as_api/adapters/mongoid.rb - lib/acts_as_api/api_template.rb - lib/acts_as_api/array.rb - lib/acts_as_api/base.rb - lib/acts_as_api/config.rb - lib/acts_as_api/exceptions.rb - lib/acts_as_api/rails_renderer.rb - lib/acts_as_api/rendering.rb - lib/acts_as_api/responder.rb - lib/acts_as_api/version.rb - spec/README.md - spec/active_record_dummy/.gitignore - spec/active_record_dummy/Gemfile - spec/active_record_dummy/README.rdoc - spec/active_record_dummy/Rakefile - spec/active_record_dummy/app/assets/images/rails.png - spec/active_record_dummy/app/assets/javascripts/application.js - spec/active_record_dummy/app/assets/stylesheets/application.css - spec/active_record_dummy/app/controllers/application_controller.rb - spec/active_record_dummy/app/helpers/application_helper.rb - spec/active_record_dummy/app/mailers/.gitkeep - spec/active_record_dummy/app/models/.gitkeep - spec/active_record_dummy/app/models/profile.rb - spec/active_record_dummy/app/models/task.rb - spec/active_record_dummy/app/models/untouched.rb - spec/active_record_dummy/app/models/user.rb - spec/active_record_dummy/app/views/layouts/application.html.erb - spec/active_record_dummy/config.ru - spec/active_record_dummy/config/application.rb - spec/active_record_dummy/config/boot.rb - spec/active_record_dummy/config/database.yml - spec/active_record_dummy/config/environment.rb - spec/active_record_dummy/config/environments/development.rb - spec/active_record_dummy/config/environments/production.rb - spec/active_record_dummy/config/environments/test.rb - spec/active_record_dummy/config/initializers/backtrace_silencers.rb - spec/active_record_dummy/config/initializers/generators.rb - spec/active_record_dummy/config/initializers/inflections.rb - spec/active_record_dummy/config/initializers/mime_types.rb - spec/active_record_dummy/config/initializers/secret_token.rb - spec/active_record_dummy/config/initializers/session_store.rb - spec/active_record_dummy/config/initializers/wrap_parameters.rb - spec/active_record_dummy/config/locales/en.yml - spec/active_record_dummy/config/routes.rb - spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb - spec/active_record_dummy/db/schema.rb - spec/active_record_dummy/db/seeds.rb - spec/active_record_dummy/doc/README_FOR_APP - spec/active_record_dummy/lib/assets/.gitkeep - spec/active_record_dummy/lib/tasks/.gitkeep - spec/active_record_dummy/log/.gitkeep - spec/active_record_dummy/public/404.html - spec/active_record_dummy/public/422.html - spec/active_record_dummy/public/500.html - spec/active_record_dummy/public/favicon.ico - spec/active_record_dummy/public/index.html - spec/active_record_dummy/public/robots.txt - spec/active_record_dummy/script/rails - spec/active_record_dummy/vendor/assets/javascripts/.gitkeep - spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep - spec/active_record_dummy/vendor/plugins/.gitkeep - spec/controllers/plain_objects_controller_spec.rb - spec/controllers/respond_with_users_controller_spec.rb - spec/controllers/users_controller_spec.rb - spec/models/model_spec.rb - spec/mongoid_dummy/.gitignore - spec/mongoid_dummy/Gemfile - spec/mongoid_dummy/README.rdoc - spec/mongoid_dummy/Rakefile - spec/mongoid_dummy/app/assets/images/rails.png - spec/mongoid_dummy/app/assets/javascripts/application.js - spec/mongoid_dummy/app/assets/stylesheets/application.css - spec/mongoid_dummy/app/controllers/application_controller.rb - spec/mongoid_dummy/app/helpers/application_helper.rb - spec/mongoid_dummy/app/mailers/.gitkeep - spec/mongoid_dummy/app/models/.gitkeep - spec/mongoid_dummy/app/models/profile.rb - spec/mongoid_dummy/app/models/task.rb - spec/mongoid_dummy/app/models/untouched.rb - spec/mongoid_dummy/app/models/user.rb - spec/mongoid_dummy/app/views/layouts/application.html.erb - spec/mongoid_dummy/config.ru - spec/mongoid_dummy/config/application.rb - spec/mongoid_dummy/config/boot.rb - spec/mongoid_dummy/config/environment.rb - spec/mongoid_dummy/config/environments/development.rb - spec/mongoid_dummy/config/environments/production.rb - spec/mongoid_dummy/config/environments/test.rb - spec/mongoid_dummy/config/initializers/backtrace_silencers.rb - spec/mongoid_dummy/config/initializers/generators.rb - spec/mongoid_dummy/config/initializers/include_acts_as_api.rb - spec/mongoid_dummy/config/initializers/inflections.rb - spec/mongoid_dummy/config/initializers/mime_types.rb - spec/mongoid_dummy/config/initializers/secret_token.rb - spec/mongoid_dummy/config/initializers/session_store.rb - spec/mongoid_dummy/config/initializers/wrap_parameters.rb - spec/mongoid_dummy/config/locales/en.yml - spec/mongoid_dummy/config/mongoid.yml - spec/mongoid_dummy/config/routes.rb - spec/mongoid_dummy/db/seeds.rb - spec/mongoid_dummy/doc/README_FOR_APP - spec/mongoid_dummy/lib/assets/.gitkeep - spec/mongoid_dummy/lib/tasks/.gitkeep - spec/mongoid_dummy/log/.gitkeep - spec/mongoid_dummy/public/404.html - spec/mongoid_dummy/public/422.html - spec/mongoid_dummy/public/500.html - spec/mongoid_dummy/public/favicon.ico - spec/mongoid_dummy/public/index.html - spec/mongoid_dummy/public/robots.txt - spec/mongoid_dummy/script/rails - spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep - spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep - spec/mongoid_dummy/vendor/plugins/.gitkeep - spec/shared_engine/.gitignore - spec/shared_engine/Gemfile - spec/shared_engine/MIT-LICENSE - spec/shared_engine/README.rdoc - spec/shared_engine/Rakefile - spec/shared_engine/app/assets/images/shared_engine/.gitkeep - spec/shared_engine/app/assets/javascripts/shared_engine/application.js - spec/shared_engine/app/assets/stylesheets/shared_engine/application.css - spec/shared_engine/app/controllers/shared_engine/application_controller.rb - spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb - spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb - spec/shared_engine/app/controllers/shared_engine/users_controller.rb - spec/shared_engine/app/helpers/shared_engine/application_helper.rb - spec/shared_engine/app/models/plain_object.rb - spec/shared_engine/app/models/user_template.rb - spec/shared_engine/app/views/layouts/shared_engine/application.html.erb - spec/shared_engine/config/routes.rb - spec/shared_engine/dummy/README.rdoc - spec/shared_engine/dummy/Rakefile - spec/shared_engine/dummy/app/assets/javascripts/application.js - spec/shared_engine/dummy/app/assets/stylesheets/application.css - spec/shared_engine/dummy/app/controllers/application_controller.rb - spec/shared_engine/dummy/app/helpers/application_helper.rb - spec/shared_engine/dummy/app/mailers/.gitkeep - spec/shared_engine/dummy/app/models/.gitkeep - spec/shared_engine/dummy/app/views/layouts/application.html.erb - spec/shared_engine/dummy/config.ru - spec/shared_engine/dummy/config/application.rb - spec/shared_engine/dummy/config/boot.rb - spec/shared_engine/dummy/config/database.yml - spec/shared_engine/dummy/config/environment.rb - spec/shared_engine/dummy/config/environments/development.rb - spec/shared_engine/dummy/config/environments/production.rb - spec/shared_engine/dummy/config/environments/test.rb - spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb - spec/shared_engine/dummy/config/initializers/inflections.rb - spec/shared_engine/dummy/config/initializers/mime_types.rb - spec/shared_engine/dummy/config/initializers/secret_token.rb - spec/shared_engine/dummy/config/initializers/session_store.rb - spec/shared_engine/dummy/config/initializers/wrap_parameters.rb - spec/shared_engine/dummy/config/locales/en.yml - spec/shared_engine/dummy/config/routes.rb - spec/shared_engine/dummy/lib/assets/.gitkeep - spec/shared_engine/dummy/log/.gitkeep - spec/shared_engine/dummy/public/404.html - spec/shared_engine/dummy/public/422.html - spec/shared_engine/dummy/public/500.html - spec/shared_engine/dummy/public/favicon.ico - spec/shared_engine/dummy/script/rails - spec/shared_engine/lib/magic/rails/engine.rb - spec/shared_engine/lib/shared_engine.rb - spec/shared_engine/lib/shared_engine/engine.rb - spec/shared_engine/lib/shared_engine/version.rb - spec/shared_engine/lib/tasks/shared_engine_tasks.rake - spec/shared_engine/script/rails - spec/shared_engine/shared_engine.gemspec - spec/spec.opts - spec/spec_helper.rb - spec/support/api_test_helpers.rb - spec/support/controller_examples.rb - spec/support/it_supports.rb - spec/support/model_examples/associations.rb - spec/support/model_examples/callbacks.rb - spec/support/model_examples/closures.rb - spec/support/model_examples/conditional_if.rb - spec/support/model_examples/conditional_unless.rb - spec/support/model_examples/enabled.rb - spec/support/model_examples/extending.rb - spec/support/model_examples/methods.rb - spec/support/model_examples/options.rb - spec/support/model_examples/renaming.rb - spec/support/model_examples/simple.rb - spec/support/model_examples/sub_nodes.rb - spec/support/model_examples/undefined.rb - spec/support/model_examples/untouched.rb - spec/support/routing.rb - spec/support/simple_fixtures.rb homepage: https://github.com/fabrik42/acts_as_api licenses: [] metadata: {} post_install_message: rdoc_options: - --charset=UTF-8 require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.1.11 signing_key: specification_version: 4 summary: Makes creating XML/JSON responses in Rails 3 easy and fun. test_files: - spec/README.md - spec/active_record_dummy/.gitignore - spec/active_record_dummy/Gemfile - spec/active_record_dummy/README.rdoc - spec/active_record_dummy/Rakefile - spec/active_record_dummy/app/assets/images/rails.png - spec/active_record_dummy/app/assets/javascripts/application.js - spec/active_record_dummy/app/assets/stylesheets/application.css - spec/active_record_dummy/app/controllers/application_controller.rb - spec/active_record_dummy/app/helpers/application_helper.rb - spec/active_record_dummy/app/mailers/.gitkeep - spec/active_record_dummy/app/models/.gitkeep - spec/active_record_dummy/app/models/profile.rb - spec/active_record_dummy/app/models/task.rb - spec/active_record_dummy/app/models/untouched.rb - spec/active_record_dummy/app/models/user.rb - spec/active_record_dummy/app/views/layouts/application.html.erb - spec/active_record_dummy/config.ru - spec/active_record_dummy/config/application.rb - spec/active_record_dummy/config/boot.rb - spec/active_record_dummy/config/database.yml - spec/active_record_dummy/config/environment.rb - spec/active_record_dummy/config/environments/development.rb - spec/active_record_dummy/config/environments/production.rb - spec/active_record_dummy/config/environments/test.rb - spec/active_record_dummy/config/initializers/backtrace_silencers.rb - spec/active_record_dummy/config/initializers/generators.rb - spec/active_record_dummy/config/initializers/inflections.rb - spec/active_record_dummy/config/initializers/mime_types.rb - spec/active_record_dummy/config/initializers/secret_token.rb - spec/active_record_dummy/config/initializers/session_store.rb - spec/active_record_dummy/config/initializers/wrap_parameters.rb - spec/active_record_dummy/config/locales/en.yml - spec/active_record_dummy/config/routes.rb - spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb - spec/active_record_dummy/db/schema.rb - spec/active_record_dummy/db/seeds.rb - spec/active_record_dummy/doc/README_FOR_APP - spec/active_record_dummy/lib/assets/.gitkeep - spec/active_record_dummy/lib/tasks/.gitkeep - spec/active_record_dummy/log/.gitkeep - spec/active_record_dummy/public/404.html - spec/active_record_dummy/public/422.html - spec/active_record_dummy/public/500.html - spec/active_record_dummy/public/favicon.ico - spec/active_record_dummy/public/index.html - spec/active_record_dummy/public/robots.txt - spec/active_record_dummy/script/rails - spec/active_record_dummy/vendor/assets/javascripts/.gitkeep - spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep - spec/active_record_dummy/vendor/plugins/.gitkeep - spec/controllers/plain_objects_controller_spec.rb - spec/controllers/respond_with_users_controller_spec.rb - spec/controllers/users_controller_spec.rb - spec/models/model_spec.rb - spec/mongoid_dummy/.gitignore - spec/mongoid_dummy/Gemfile - spec/mongoid_dummy/README.rdoc - spec/mongoid_dummy/Rakefile - spec/mongoid_dummy/app/assets/images/rails.png - spec/mongoid_dummy/app/assets/javascripts/application.js - spec/mongoid_dummy/app/assets/stylesheets/application.css - spec/mongoid_dummy/app/controllers/application_controller.rb - spec/mongoid_dummy/app/helpers/application_helper.rb - spec/mongoid_dummy/app/mailers/.gitkeep - spec/mongoid_dummy/app/models/.gitkeep - spec/mongoid_dummy/app/models/profile.rb - spec/mongoid_dummy/app/models/task.rb - spec/mongoid_dummy/app/models/untouched.rb - spec/mongoid_dummy/app/models/user.rb - spec/mongoid_dummy/app/views/layouts/application.html.erb - spec/mongoid_dummy/config.ru - spec/mongoid_dummy/config/application.rb - spec/mongoid_dummy/config/boot.rb - spec/mongoid_dummy/config/environment.rb - spec/mongoid_dummy/config/environments/development.rb - spec/mongoid_dummy/config/environments/production.rb - spec/mongoid_dummy/config/environments/test.rb - spec/mongoid_dummy/config/initializers/backtrace_silencers.rb - spec/mongoid_dummy/config/initializers/generators.rb - spec/mongoid_dummy/config/initializers/include_acts_as_api.rb - spec/mongoid_dummy/config/initializers/inflections.rb - spec/mongoid_dummy/config/initializers/mime_types.rb - spec/mongoid_dummy/config/initializers/secret_token.rb - spec/mongoid_dummy/config/initializers/session_store.rb - spec/mongoid_dummy/config/initializers/wrap_parameters.rb - spec/mongoid_dummy/config/locales/en.yml - spec/mongoid_dummy/config/mongoid.yml - spec/mongoid_dummy/config/routes.rb - spec/mongoid_dummy/db/seeds.rb - spec/mongoid_dummy/doc/README_FOR_APP - spec/mongoid_dummy/lib/assets/.gitkeep - spec/mongoid_dummy/lib/tasks/.gitkeep - spec/mongoid_dummy/log/.gitkeep - spec/mongoid_dummy/public/404.html - spec/mongoid_dummy/public/422.html - spec/mongoid_dummy/public/500.html - spec/mongoid_dummy/public/favicon.ico - spec/mongoid_dummy/public/index.html - spec/mongoid_dummy/public/robots.txt - spec/mongoid_dummy/script/rails - spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep - spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep - spec/mongoid_dummy/vendor/plugins/.gitkeep - spec/shared_engine/.gitignore - spec/shared_engine/Gemfile - spec/shared_engine/MIT-LICENSE - spec/shared_engine/README.rdoc - spec/shared_engine/Rakefile - spec/shared_engine/app/assets/images/shared_engine/.gitkeep - spec/shared_engine/app/assets/javascripts/shared_engine/application.js - spec/shared_engine/app/assets/stylesheets/shared_engine/application.css - spec/shared_engine/app/controllers/shared_engine/application_controller.rb - spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb - spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb - spec/shared_engine/app/controllers/shared_engine/users_controller.rb - spec/shared_engine/app/helpers/shared_engine/application_helper.rb - spec/shared_engine/app/models/plain_object.rb - spec/shared_engine/app/models/user_template.rb - spec/shared_engine/app/views/layouts/shared_engine/application.html.erb - spec/shared_engine/config/routes.rb - spec/shared_engine/dummy/README.rdoc - spec/shared_engine/dummy/Rakefile - spec/shared_engine/dummy/app/assets/javascripts/application.js - spec/shared_engine/dummy/app/assets/stylesheets/application.css - spec/shared_engine/dummy/app/controllers/application_controller.rb - spec/shared_engine/dummy/app/helpers/application_helper.rb - spec/shared_engine/dummy/app/mailers/.gitkeep - spec/shared_engine/dummy/app/models/.gitkeep - spec/shared_engine/dummy/app/views/layouts/application.html.erb - spec/shared_engine/dummy/config.ru - spec/shared_engine/dummy/config/application.rb - spec/shared_engine/dummy/config/boot.rb - spec/shared_engine/dummy/config/database.yml - spec/shared_engine/dummy/config/environment.rb - spec/shared_engine/dummy/config/environments/development.rb - spec/shared_engine/dummy/config/environments/production.rb - spec/shared_engine/dummy/config/environments/test.rb - spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb - spec/shared_engine/dummy/config/initializers/inflections.rb - spec/shared_engine/dummy/config/initializers/mime_types.rb - spec/shared_engine/dummy/config/initializers/secret_token.rb - spec/shared_engine/dummy/config/initializers/session_store.rb - spec/shared_engine/dummy/config/initializers/wrap_parameters.rb - spec/shared_engine/dummy/config/locales/en.yml - spec/shared_engine/dummy/config/routes.rb - spec/shared_engine/dummy/lib/assets/.gitkeep - spec/shared_engine/dummy/log/.gitkeep - spec/shared_engine/dummy/public/404.html - spec/shared_engine/dummy/public/422.html - spec/shared_engine/dummy/public/500.html - spec/shared_engine/dummy/public/favicon.ico - spec/shared_engine/dummy/script/rails - spec/shared_engine/lib/magic/rails/engine.rb - spec/shared_engine/lib/shared_engine.rb - spec/shared_engine/lib/shared_engine/engine.rb - spec/shared_engine/lib/shared_engine/version.rb - spec/shared_engine/lib/tasks/shared_engine_tasks.rake - spec/shared_engine/script/rails - spec/shared_engine/shared_engine.gemspec - spec/spec.opts - spec/spec_helper.rb - spec/support/api_test_helpers.rb - spec/support/controller_examples.rb - spec/support/it_supports.rb - spec/support/model_examples/associations.rb - spec/support/model_examples/callbacks.rb - spec/support/model_examples/closures.rb - spec/support/model_examples/conditional_if.rb - spec/support/model_examples/conditional_unless.rb - spec/support/model_examples/enabled.rb - spec/support/model_examples/extending.rb - spec/support/model_examples/methods.rb - spec/support/model_examples/options.rb - spec/support/model_examples/renaming.rb - spec/support/model_examples/simple.rb - spec/support/model_examples/sub_nodes.rb - spec/support/model_examples/undefined.rb - spec/support/model_examples/untouched.rb - spec/support/routing.rb - spec/support/simple_fixtures.rb acts-as-api-0.4.2/lib/0000755000076400007640000000000012326165355013431 5ustar pravipraviacts-as-api-0.4.2/lib/acts_as_api.rb0000644000076400007640000000255012326165355016226 0ustar pravipravirequire '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 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.2/lib/acts_as_api/0000755000076400007640000000000012326165355015677 5ustar pravipraviacts-as-api-0.4.2/lib/acts_as_api/adapters/0000755000076400007640000000000012326165355017502 5ustar pravipraviacts-as-api-0.4.2/lib/acts_as_api/adapters/mongoid.rb0000644000076400007640000000025012326165355021460 0ustar pravipravimodule ActsAsApi module Adapters module Mongoid extend ActiveSupport::Concern included do extend ActsAsApi::Base end end end end acts-as-api-0.4.2/lib/acts_as_api/rails_renderer.rb0000644000076400007640000000107112326165355021223 0ustar pravipravimodule 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 ||= Mime::JSON self.response_body = json end end end end acts-as-api-0.4.2/lib/acts_as_api/api_template.rb0000644000076400007640000001002612326165355020667 0ustar pravipravimodule 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.2/lib/acts_as_api/version.rb0000644000076400007640000000005112326165355017705 0ustar pravipravimodule ActsAsApi VERSION = "0.4.2" end acts-as-api-0.4.2/lib/acts_as_api/config.rb0000644000076400007640000000345312326165355017476 0ustar pravipravimodule 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.2/lib/acts_as_api/base.rb0000644000076400007640000000507512326165355017145 0ustar pravipravimodule 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.2/lib/acts_as_api/responder.rb0000644000076400007640000000302012326165355020220 0ustar pravipravimodule 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 # Should be specified as an option to the `respond_with` call attr_reader :api_template # Grabs the required :api_template parameter, then hands control back to # the base ActionController::Responder initializer. def initialize(controller, resources, options={}) @api_template = options.delete(:api_template) super(controller, resources, options) end # Overrides the base implementation of display, replacing it with # the render_for_api method whenever api_template is specified. def display(resource, given_options={}) 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 end acts-as-api-0.4.2/lib/acts_as_api/adapters.rb0000644000076400007640000000014312326165355020025 0ustar pravipravimodule ActsAsApi module Adapters autoload :Mongoid, "acts_as_api/adapters/mongoid" end end acts-as-api-0.4.2/lib/acts_as_api/array.rb0000644000076400007640000000110412326165355017336 0ustar pravipravi# 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.2/lib/acts_as_api/exceptions.rb0000644000076400007640000000016512326165355020407 0ustar pravipravimodule ActsAsApi class ActsAsApiError < RuntimeError; end class TemplateNotFoundError < ActsAsApiError; end endacts-as-api-0.4.2/lib/acts_as_api/rendering.rb0000644000076400007640000000711012326165355020200 0ustar pravipravimodule 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.2/Rakefile0000644000076400007640000000206412326165355014332 0ustar pravipravirequire '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.2/.gitignore0000644000076400007640000000040112326165355014646 0ustar pravipravinbproject/ 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 .rvmrc *.sqlite3-journal