acts_as_api 0.3.11 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -4
- data/.travis.yml +5 -1
- data/Gemfile +2 -1
- data/History.txt +4 -0
- data/README.md +9 -4
- data/Rakefile +28 -5
- data/acts_as_api.gemspec +1 -1
- data/lib/acts_as_api/api_template.rb +54 -63
- data/lib/acts_as_api/array.rb +2 -2
- data/lib/acts_as_api/base.rb +19 -13
- data/lib/acts_as_api/config.rb +2 -2
- data/lib/acts_as_api/rendering.rb +4 -4
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/README.md +55 -0
- data/spec/active_record_dummy/.gitignore +15 -0
- data/spec/active_record_dummy/Gemfile +16 -0
- data/spec/active_record_dummy/README.rdoc +261 -0
- data/spec/active_record_dummy/Rakefile +7 -0
- data/spec/{rails_app/public → active_record_dummy/app/assets}/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/{rails_app → active_record_dummy}/app/helpers/application_helper.rb +0 -0
- data/spec/{rails_app/lib/tasks → active_record_dummy/app/mailers}/.gitkeep +0 -0
- data/spec/{rails_app/public/stylesheets → active_record_dummy/app/models}/.gitkeep +0 -0
- data/spec/{rails_app → active_record_dummy}/app/models/profile.rb +1 -0
- data/spec/active_record_dummy/app/models/task.rb +4 -0
- data/spec/{rails_app → active_record_dummy}/app/models/untouched.rb +0 -0
- data/spec/{rails_app → active_record_dummy}/app/models/user.rb +1 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/active_record_dummy/config.ru +4 -0
- data/spec/active_record_dummy/config/application.rb +59 -0
- data/spec/{rails_app → active_record_dummy}/config/boot.rb +0 -0
- data/spec/{rails_app → active_record_dummy}/config/database.yml +5 -3
- data/spec/active_record_dummy/config/environment.rb +5 -0
- data/spec/active_record_dummy/config/environments/development.rb +37 -0
- data/spec/active_record_dummy/config/environments/production.rb +67 -0
- data/spec/active_record_dummy/config/environments/test.rb +37 -0
- data/spec/{rails_app → active_record_dummy}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
- data/spec/{rails_app → active_record_dummy}/config/initializers/inflections.rb +5 -0
- data/spec/{rails_app → active_record_dummy}/config/initializers/mime_types.rb +0 -0
- data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/{rails_app → active_record_dummy}/config/locales/en.yml +1 -1
- data/spec/active_record_dummy/config/routes.rb +59 -0
- data/spec/{rails_app → active_record_dummy}/db/migrate/20110214201640_create_tables.rb +0 -0
- data/spec/{rails_app → active_record_dummy}/db/schema.rb +0 -0
- data/spec/{rails_app → active_record_dummy}/db/seeds.rb +0 -0
- data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
- data/spec/{rails_app/public/favicon.ico → active_record_dummy/lib/assets/.gitkeep} +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/log/.gitkeep +0 -0
- data/spec/{rails_app → active_record_dummy}/public/404.html +0 -0
- data/spec/{rails_app → active_record_dummy}/public/422.html +0 -0
- data/spec/{rails_app → active_record_dummy}/public/500.html +0 -1
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/{rails_app → active_record_dummy}/public/index.html +10 -8
- data/spec/{rails_app → active_record_dummy}/public/robots.txt +0 -0
- data/spec/{rails_app → active_record_dummy}/script/rails +0 -0
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/controllers/respond_with_users_controller_spec.rb +18 -33
- data/spec/controllers/users_controller_spec.rb +8 -25
- data/spec/models/{active_record_spec.rb → model_spec.rb} +5 -3
- data/spec/mongoid_dummy/.gitignore +15 -0
- data/spec/mongoid_dummy/Gemfile +18 -0
- data/spec/mongoid_dummy/README.rdoc +261 -0
- data/spec/mongoid_dummy/Rakefile +7 -0
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/models/.gitkeep +0 -0
- data/spec/{rails_app/app/models/mongo_profile.rb → mongoid_dummy/app/models/profile.rb} +2 -2
- data/spec/{rails_app/app/models/mongo_task.rb → mongoid_dummy/app/models/task.rb} +2 -2
- data/spec/{rails_app/app/models/mongo_untouched.rb → mongoid_dummy/app/models/untouched.rb} +1 -1
- data/spec/mongoid_dummy/app/models/user.rb +48 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/mongoid_dummy/config.ru +4 -0
- data/spec/mongoid_dummy/config/application.rb +65 -0
- data/spec/mongoid_dummy/config/boot.rb +6 -0
- data/spec/mongoid_dummy/config/environment.rb +5 -0
- data/spec/{rails_app → mongoid_dummy}/config/environments/development.rb +10 -4
- data/spec/{rails_app → mongoid_dummy}/config/environments/production.rb +29 -14
- data/spec/{rails_app → mongoid_dummy}/config/environments/test.rb +8 -8
- data/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/generators.rb +2 -0
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +3 -0
- data/spec/mongoid_dummy/config/initializers/inflections.rb +15 -0
- data/spec/mongoid_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/mongoid_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/session_store.rb +8 -0
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/mongoid_dummy/config/locales/en.yml +5 -0
- data/spec/{rails_app → mongoid_dummy}/config/mongoid.yml +8 -3
- data/spec/mongoid_dummy/config/routes.rb +59 -0
- data/spec/mongoid_dummy/db/seeds.rb +7 -0
- data/spec/mongoid_dummy/doc/README_FOR_APP +2 -0
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/log/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +26 -0
- data/spec/mongoid_dummy/public/422.html +26 -0
- data/spec/mongoid_dummy/public/500.html +25 -0
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +241 -0
- data/spec/mongoid_dummy/public/robots.txt +5 -0
- data/spec/mongoid_dummy/script/rails +6 -0
- data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_engine/.gitignore +7 -0
- data/spec/shared_engine/Gemfile +14 -0
- data/spec/shared_engine/MIT-LICENSE +20 -0
- data/spec/shared_engine/README.rdoc +3 -0
- data/spec/shared_engine/Rakefile +29 -0
- data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +15 -0
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +13 -0
- data/spec/shared_engine/app/controllers/shared_engine/application_controller.rb +4 -0
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +59 -0
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +71 -0
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +4 -0
- data/spec/shared_engine/app/models/user_template.rb +154 -0
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +14 -0
- data/spec/{rails_app → shared_engine}/config/routes.rb +2 -4
- data/spec/shared_engine/dummy/README.rdoc +261 -0
- data/spec/{rails_app → shared_engine/dummy}/Rakefile +2 -2
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/{rails_app → shared_engine/dummy}/config.ru +1 -1
- data/spec/{rails_app → shared_engine/dummy}/config/application.rb +30 -10
- data/spec/shared_engine/dummy/config/boot.rb +10 -0
- data/spec/shared_engine/dummy/config/database.yml +25 -0
- data/spec/{rails_app → shared_engine/dummy}/config/environment.rb +1 -1
- data/spec/shared_engine/dummy/config/environments/development.rb +37 -0
- data/spec/shared_engine/dummy/config/environments/production.rb +67 -0
- data/spec/shared_engine/dummy/config/environments/test.rb +37 -0
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +15 -0
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/{rails_app → shared_engine/dummy}/config/initializers/secret_token.rb +1 -1
- data/spec/{rails_app → shared_engine/dummy}/config/initializers/session_store.rb +2 -2
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/shared_engine/dummy/config/locales/en.yml +5 -0
- data/spec/shared_engine/dummy/config/routes.rb +4 -0
- data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
- data/spec/shared_engine/dummy/log/.gitkeep +0 -0
- data/spec/shared_engine/dummy/public/404.html +26 -0
- data/spec/shared_engine/dummy/public/422.html +26 -0
- data/spec/shared_engine/dummy/public/500.html +25 -0
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +6 -0
- data/spec/shared_engine/lib/shared_engine.rb +4 -0
- data/spec/shared_engine/lib/shared_engine/engine.rb +5 -0
- data/spec/shared_engine/lib/shared_engine/version.rb +3 -0
- data/spec/shared_engine/lib/tasks/shared_engine_tasks.rake +4 -0
- data/spec/shared_engine/script/rails +8 -0
- data/spec/shared_engine/shared_engine.gemspec +22 -0
- data/spec/spec_helper.rb +16 -11
- data/spec/support/controller_examples.rb +35 -41
- data/spec/support/model_examples/associations.rb +13 -13
- data/spec/support/model_examples/enabled.rb +2 -2
- data/spec/support/model_examples/extending.rb +6 -6
- data/spec/support/model_examples/options.rb +53 -0
- data/spec/support/model_examples/untouched.rb +2 -2
- data/spec/support/simple_fixtures.rb +31 -59
- metadata +324 -132
- data/spec/models/mongoid_spec.rb +0 -29
- data/spec/models/vanilla_ruby_spec.rb +0 -31
- data/spec/rails_app/.gitignore +0 -4
- data/spec/rails_app/app/controllers/application_controller.rb +0 -11
- data/spec/rails_app/app/controllers/respond_with_users_controller.rb +0 -57
- data/spec/rails_app/app/controllers/users_controller.rb +0 -69
- data/spec/rails_app/app/models/mongo_user.rb +0 -192
- data/spec/rails_app/app/models/task.rb +0 -3
- data/spec/rails_app/app/models/vanilla_profile.rb +0 -16
- data/spec/rails_app/app/models/vanilla_task.rb +0 -16
- data/spec/rails_app/app/models/vanilla_untouched.rb +0 -2
- data/spec/rails_app/app/models/vanilla_user.rb +0 -195
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails_app/config/initializers/acts_as_api_mongoid.rb +0 -6
- data/spec/rails_app/public/javascripts/application.js +0 -2
- data/spec/rails_app/public/javascripts/controls.js +0 -965
- data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
- data/spec/rails_app/public/javascripts/effects.js +0 -1123
- data/spec/rails_app/public/javascripts/prototype.js +0 -6001
- data/spec/rails_app/public/javascripts/rails.js +0 -191
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
+
div.dialog {
|
|
8
|
+
width: 25em;
|
|
9
|
+
padding: 0 4em;
|
|
10
|
+
margin: 4em auto 0 auto;
|
|
11
|
+
border: 1px solid #ccc;
|
|
12
|
+
border-right-color: #999;
|
|
13
|
+
border-bottom-color: #999;
|
|
14
|
+
}
|
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<!-- This file lives in public/422.html -->
|
|
21
|
+
<div class="dialog">
|
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
24
|
+
</div>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
+
div.dialog {
|
|
8
|
+
width: 25em;
|
|
9
|
+
padding: 0 4em;
|
|
10
|
+
margin: 4em auto 0 auto;
|
|
11
|
+
border: 1px solid #ccc;
|
|
12
|
+
border-right-color: #999;
|
|
13
|
+
border-bottom-color: #999;
|
|
14
|
+
}
|
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<!-- This file lives in public/500.html -->
|
|
21
|
+
<div class="dialog">
|
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
23
|
+
</div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/shared_engine/engine', __FILE__)
|
|
6
|
+
|
|
7
|
+
require 'rails/all'
|
|
8
|
+
require 'rails/engine/commands'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
# Maintain your gem's version:
|
|
4
|
+
require "shared_engine/version"
|
|
5
|
+
|
|
6
|
+
# Describe your gem and declare its dependencies:
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = "shared_engine"
|
|
9
|
+
s.version = SharedEngine::VERSION
|
|
10
|
+
s.authors = ["TODO: Your name"]
|
|
11
|
+
s.email = ["TODO: Your email"]
|
|
12
|
+
s.homepage = "TODO"
|
|
13
|
+
s.summary = "TODO: Summary of SharedEngine."
|
|
14
|
+
s.description = "TODO: Description of SharedEngine."
|
|
15
|
+
|
|
16
|
+
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
|
17
|
+
|
|
18
|
+
s.add_dependency "rails", "~> 3.2.3"
|
|
19
|
+
# s.add_dependency "jquery-rails"
|
|
20
|
+
|
|
21
|
+
s.add_development_dependency "sqlite3"
|
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
require 'rspec/rails'
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
require
|
|
3
|
+
if ENV['ACTS_AS_API_ORM'] == 'active_record'
|
|
4
|
+
require "active_record_dummy/config/environment"
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
load_schema = lambda {
|
|
7
|
+
load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
|
|
8
|
+
# ActiveRecord::Migrator.up('db/migrate') # use migrations
|
|
9
|
+
}
|
|
10
|
+
silence_stream(STDOUT, &load_schema)
|
|
11
|
+
|
|
12
|
+
elsif ENV['ACTS_AS_API_ORM'] == 'mongoid'
|
|
13
|
+
|
|
14
|
+
require "mongoid_dummy/config/environment"
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
require 'rspec/rails'
|
|
8
19
|
|
|
9
20
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
10
21
|
# in spec/support/ and its subdirectories.
|
|
11
22
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file }
|
|
12
|
-
|
|
13
|
-
load_schema = lambda {
|
|
14
|
-
load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
|
|
15
|
-
# ActiveRecord::Migrator.up('db/migrate') # use migrations
|
|
16
|
-
}
|
|
17
|
-
silence_stream(STDOUT, &load_schema)
|
|
@@ -7,7 +7,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
7
7
|
describe 'get all users' do
|
|
8
8
|
|
|
9
9
|
before(:each) do
|
|
10
|
-
get :index, :format => 'xml', :api_template => :name_only
|
|
10
|
+
get :index, :format => 'xml', :api_template => :name_only
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "should have a root node named users" do
|
|
@@ -30,7 +30,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
30
30
|
describe 'get a single user' do
|
|
31
31
|
|
|
32
32
|
before(:each) do
|
|
33
|
-
get :show, :format => 'xml', :api_template => :name_only, :id => @luke.id
|
|
33
|
+
get :show, :format => 'xml', :api_template => :name_only, :id => @luke.id
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should have a root node named user" do
|
|
@@ -47,7 +47,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
47
47
|
describe 'get a user without specifying an api template' do
|
|
48
48
|
|
|
49
49
|
before(:each) do
|
|
50
|
-
get :show_default, :format => 'xml', :id => @luke.id
|
|
50
|
+
get :show_default, :format => 'xml', :id => @luke.id
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "should respond with HTTP 200" do
|
|
@@ -72,7 +72,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
72
72
|
describe 'get all users' do
|
|
73
73
|
|
|
74
74
|
before(:each) do
|
|
75
|
-
get :index, :format => 'json', :api_template => :name_only
|
|
75
|
+
get :index, :format => 'json', :api_template => :name_only
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "should have a root node named users" do
|
|
@@ -89,40 +89,34 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it "should contain the specified values" do
|
|
92
|
-
response_body_json["users"].first["first_name"].should eql("
|
|
93
|
-
response_body_json["users"].first["last_name"].should eql("
|
|
92
|
+
response_body_json["users"].first["first_name"].should eql("Han")
|
|
93
|
+
response_body_json["users"].first["last_name"].should eql("Solo")
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
describe 'get all users as a ActiveRecord::Relation object, autodetecting the root node name' do
|
|
98
|
+
describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do
|
|
99
99
|
|
|
100
100
|
before(:each) do
|
|
101
|
-
get :index_relation, :format => 'json', :api_template => :name_only
|
|
102
|
-
|
|
103
|
-
if @orm_for_testing == :active_record
|
|
104
|
-
@root_node = "users"
|
|
105
|
-
elsif @orm_for_testing == :mongoid
|
|
106
|
-
@root_node = "mongo_users"
|
|
107
|
-
end
|
|
101
|
+
get :index_relation, :format => 'json', :api_template => :name_only
|
|
108
102
|
end
|
|
109
103
|
|
|
110
104
|
it "should have a root node named users" do
|
|
111
|
-
response_body_json.should have_key(
|
|
105
|
+
response_body_json.should have_key("users")
|
|
112
106
|
end
|
|
113
107
|
|
|
114
108
|
it "should contain all users" do
|
|
115
|
-
response_body_json[
|
|
109
|
+
response_body_json["users"].should be_a(Array)
|
|
116
110
|
end
|
|
117
111
|
|
|
118
112
|
it "should contain the specified attributes" do
|
|
119
|
-
response_body_json[
|
|
120
|
-
response_body_json[
|
|
113
|
+
response_body_json["users"].first.should have_key("first_name")
|
|
114
|
+
response_body_json["users"].first.should have_key("last_name")
|
|
121
115
|
end
|
|
122
116
|
|
|
123
117
|
it "should contain the specified values" do
|
|
124
|
-
response_body_json[
|
|
125
|
-
response_body_json[
|
|
118
|
+
response_body_json["users"].first["first_name"].should eql("Han")
|
|
119
|
+
response_body_json["users"].first["last_name"].should eql("Solo")
|
|
126
120
|
end
|
|
127
121
|
|
|
128
122
|
end
|
|
@@ -130,7 +124,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
130
124
|
describe 'get a single user' do
|
|
131
125
|
|
|
132
126
|
before(:each) do
|
|
133
|
-
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
127
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
134
128
|
end
|
|
135
129
|
|
|
136
130
|
it "should have a root node named user" do
|
|
@@ -152,13 +146,13 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
152
146
|
describe 'get a single user with a nil profile' do
|
|
153
147
|
|
|
154
148
|
before(:each) do
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
Profile.acts_as_api
|
|
150
|
+
Profile.api_accessible :include_profile do |t|
|
|
157
151
|
t.add :avatar
|
|
158
152
|
t.add :homepage
|
|
159
153
|
end
|
|
160
154
|
|
|
161
|
-
get :show, :format => 'json', :api_template => :include_profile, :id => @han.id
|
|
155
|
+
get :show, :format => 'json', :api_template => :include_profile, :id => @han.id
|
|
162
156
|
end
|
|
163
157
|
|
|
164
158
|
it "should have a root node named user" do
|
|
@@ -179,7 +173,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
179
173
|
describe 'get a user without specifying an api template' do
|
|
180
174
|
|
|
181
175
|
before(:each) do
|
|
182
|
-
get :show_default, :format => 'json', :id => @luke.id
|
|
176
|
+
get :show_default, :format => 'json', :id => @luke.id
|
|
183
177
|
end
|
|
184
178
|
|
|
185
179
|
it "should respond with HTTP 200" do
|
|
@@ -208,7 +202,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
208
202
|
describe 'get all users' do
|
|
209
203
|
|
|
210
204
|
before(:each) do
|
|
211
|
-
get :index, :format => 'json', :api_template => :name_only
|
|
205
|
+
get :index, :format => 'json', :api_template => :name_only
|
|
212
206
|
end
|
|
213
207
|
|
|
214
208
|
it "should have a root node named users" do
|
|
@@ -229,8 +223,8 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
229
223
|
end
|
|
230
224
|
|
|
231
225
|
it "should contain the specified values" do
|
|
232
|
-
response_body_json["users"].first["user"]["first_name"].should eql("
|
|
233
|
-
response_body_json["users"].first["user"]["last_name"].should eql("
|
|
226
|
+
response_body_json["users"].first["user"]["first_name"].should eql("Han")
|
|
227
|
+
response_body_json["users"].first["user"]["last_name"].should eql("Solo")
|
|
234
228
|
end
|
|
235
229
|
|
|
236
230
|
end
|
|
@@ -238,7 +232,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
238
232
|
describe 'get a single user' do
|
|
239
233
|
|
|
240
234
|
before(:each) do
|
|
241
|
-
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
235
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
242
236
|
end
|
|
243
237
|
|
|
244
238
|
it "should have a root node named user" do
|
|
@@ -262,7 +256,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
262
256
|
|
|
263
257
|
it "should be disabled by default" do
|
|
264
258
|
@callback = "mycallback"
|
|
265
|
-
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
259
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
266
260
|
response_body_jsonp(@callback).should be_nil
|
|
267
261
|
end
|
|
268
262
|
|
|
@@ -271,14 +265,14 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
271
265
|
before(:each) do
|
|
272
266
|
@callback = "mycallback"
|
|
273
267
|
|
|
274
|
-
|
|
268
|
+
User.acts_as_api do |config|
|
|
275
269
|
config.allow_jsonp_callback = true
|
|
276
270
|
end
|
|
277
271
|
end
|
|
278
272
|
|
|
279
273
|
after(:each) do
|
|
280
274
|
# put things back to the way they were
|
|
281
|
-
|
|
275
|
+
User.acts_as_api do |config|
|
|
282
276
|
config.allow_jsonp_callback = false
|
|
283
277
|
end
|
|
284
278
|
end
|
|
@@ -286,7 +280,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
286
280
|
describe 'get all users' do
|
|
287
281
|
|
|
288
282
|
before(:each) do
|
|
289
|
-
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
283
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
290
284
|
end
|
|
291
285
|
|
|
292
286
|
it "should wrap the response in the callback" do
|
|
@@ -298,7 +292,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
298
292
|
describe 'get a single user' do
|
|
299
293
|
|
|
300
294
|
before(:each) do
|
|
301
|
-
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id, :callback => @callback
|
|
295
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id, :callback => @callback
|
|
302
296
|
end
|
|
303
297
|
|
|
304
298
|
it "should wrap the response in the callback" do
|
|
@@ -322,7 +316,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
322
316
|
|
|
323
317
|
describe 'get all users' do
|
|
324
318
|
before(:each) do
|
|
325
|
-
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
319
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
|
326
320
|
end
|
|
327
321
|
|
|
328
322
|
its "response has no named root node" do
|
|
@@ -332,7 +326,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
332
326
|
|
|
333
327
|
describe 'get a single user' do
|
|
334
328
|
before(:each) do
|
|
335
|
-
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
329
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
336
330
|
end
|
|
337
331
|
|
|
338
332
|
its "response has no named root node" do
|
|
@@ -346,7 +340,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
346
340
|
|
|
347
341
|
describe 'get all users' do
|
|
348
342
|
before(:each) do
|
|
349
|
-
get :index_meta, :format => 'json', :api_template => :name_only
|
|
343
|
+
get :index_meta, :format => 'json', :api_template => :name_only
|
|
350
344
|
end
|
|
351
345
|
|
|
352
346
|
it "shows model response fields" do
|
|
@@ -366,7 +360,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
366
360
|
|
|
367
361
|
describe 'get a single user' do
|
|
368
362
|
before(:each) do
|
|
369
|
-
get :show_meta, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
363
|
+
get :show_meta, :format => 'json', :api_template => :name_only, :id => @luke.id
|
|
370
364
|
end
|
|
371
365
|
|
|
372
366
|
it "shows model response fields" do
|
|
@@ -391,7 +385,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
391
385
|
describe 'get single user' do
|
|
392
386
|
|
|
393
387
|
before(:each) do
|
|
394
|
-
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :id => @luke.id
|
|
388
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :id => @luke.id
|
|
395
389
|
end
|
|
396
390
|
|
|
397
391
|
it "should have a root node named user" do
|
|
@@ -417,7 +411,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
417
411
|
describe 'get single user' do
|
|
418
412
|
|
|
419
413
|
before(:each) do
|
|
420
|
-
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_postfix => :with_postfix, :id => @luke.id
|
|
414
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_postfix => :with_postfix, :id => @luke.id
|
|
421
415
|
end
|
|
422
416
|
|
|
423
417
|
it "should have a root node named user" do
|
|
@@ -443,7 +437,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
|
443
437
|
describe 'get single user' do
|
|
444
438
|
|
|
445
439
|
before(:each) do
|
|
446
|
-
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :api_postfix => :with_postfix, :id => @luke.id
|
|
440
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :api_postfix => :with_postfix, :id => @luke.id
|
|
447
441
|
end
|
|
448
442
|
|
|
449
443
|
it "should have a root node named user" do
|
|
@@ -33,8 +33,8 @@ shared_examples_for "including an association in the api template" do
|
|
|
33
33
|
context "has_many" do
|
|
34
34
|
|
|
35
35
|
before(:each) do
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
Task.acts_as_api
|
|
37
|
+
Task.api_accessible :include_tasks do |t|
|
|
38
38
|
t.add :heading
|
|
39
39
|
t.add :done
|
|
40
40
|
end
|
|
@@ -74,8 +74,8 @@ shared_examples_for "including an association in the api template" do
|
|
|
74
74
|
context "has_one" do
|
|
75
75
|
|
|
76
76
|
before(:each) do
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
Profile.acts_as_api
|
|
78
|
+
Profile.api_accessible :include_profile do |t|
|
|
79
79
|
t.add :avatar
|
|
80
80
|
t.add :homepage
|
|
81
81
|
end
|
|
@@ -114,8 +114,8 @@ shared_examples_for "including an association in the api template" do
|
|
|
114
114
|
describe "which does acts_as_api, but with using another template name" do
|
|
115
115
|
|
|
116
116
|
before(:each) do
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
Task.acts_as_api
|
|
118
|
+
Task.api_accessible :other_template do |t|
|
|
119
119
|
t.add :description
|
|
120
120
|
t.add :time_spent
|
|
121
121
|
end
|
|
@@ -165,11 +165,11 @@ shared_examples_for "including an association in the api template" do
|
|
|
165
165
|
before(:each) do
|
|
166
166
|
# extend task model with scope
|
|
167
167
|
#class Task < ActiveRecord::Base
|
|
168
|
-
|
|
168
|
+
Task.class_eval do
|
|
169
169
|
scope :completed, where(:done => true)
|
|
170
170
|
end
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
Task.acts_as_api
|
|
172
|
+
Task.api_accessible :include_completed_tasks do |t|
|
|
173
173
|
t.add :heading
|
|
174
174
|
t.add :done
|
|
175
175
|
end
|
|
@@ -212,8 +212,8 @@ shared_examples_for "including an association in the api template" do
|
|
|
212
212
|
context "has_many" do
|
|
213
213
|
|
|
214
214
|
before(:each) do
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
Task.acts_as_api
|
|
216
|
+
Task.api_accessible :include_tasks do |t|
|
|
217
217
|
t.add :heading
|
|
218
218
|
t.add :done
|
|
219
219
|
end
|
|
@@ -244,8 +244,8 @@ shared_examples_for "including an association in the api template" do
|
|
|
244
244
|
|
|
245
245
|
context "has one" do
|
|
246
246
|
before(:each) do
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
Profile.acts_as_api
|
|
248
|
+
Profile.api_accessible :include_profile do |t|
|
|
249
249
|
t.add :avatar
|
|
250
250
|
t.add :homepage
|
|
251
251
|
end
|