acts_as_api_sequel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/History.txt +108 -0
- data/README.md +126 -0
- data/Rakefile +48 -0
- data/acts_as_api.gemspec +28 -0
- data/examples/introduction/docco.css +186 -0
- data/examples/introduction/index.html +338 -0
- data/examples/introduction/index.rb +144 -0
- data/examples/introduction/layout.mustache +67 -0
- data/lib/acts_as_api.rb +46 -0
- data/lib/acts_as_api/adapters.rb +5 -0
- data/lib/acts_as_api/adapters/mongoid.rb +11 -0
- data/lib/acts_as_api/api_template.rb +139 -0
- data/lib/acts_as_api/array.rb +21 -0
- data/lib/acts_as_api/base.rb +88 -0
- data/lib/acts_as_api/config.rb +58 -0
- data/lib/acts_as_api/exceptions.rb +4 -0
- data/lib/acts_as_api/rails_renderer.rb +17 -0
- data/lib/acts_as_api/rendering.rb +95 -0
- data/lib/acts_as_api/responder.rb +39 -0
- data/lib/acts_as_api/version.rb +3 -0
- 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/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/active_record_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/profile.rb +4 -0
- data/spec/active_record_dummy/app/models/task.rb +4 -0
- data/spec/active_record_dummy/app/models/untouched.rb +2 -0
- data/spec/active_record_dummy/app/models/user.rb +186 -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/active_record_dummy/config/boot.rb +6 -0
- data/spec/active_record_dummy/config/database.yml +25 -0
- 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/active_record_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
- data/spec/active_record_dummy/config/initializers/inflections.rb +15 -0
- data/spec/active_record_dummy/config/initializers/mime_types.rb +5 -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/active_record_dummy/config/locales/en.yml +5 -0
- data/spec/active_record_dummy/config/routes.rb +59 -0
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +44 -0
- data/spec/active_record_dummy/db/schema.rb +47 -0
- data/spec/active_record_dummy/db/seeds.rb +7 -0
- data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
- data/spec/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/active_record_dummy/public/404.html +26 -0
- data/spec/active_record_dummy/public/422.html +26 -0
- data/spec/active_record_dummy/public/500.html +25 -0
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +241 -0
- data/spec/active_record_dummy/public/robots.txt +5 -0
- data/spec/active_record_dummy/script/rails +6 -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/plain_objects_controller_spec.rb +36 -0
- data/spec/controllers/respond_with_users_controller_spec.rb +142 -0
- data/spec/controllers/users_controller_spec.rb +15 -0
- data/spec/models/model_spec.rb +31 -0
- 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/mongoid_dummy/app/models/profile.rb +10 -0
- data/spec/mongoid_dummy/app/models/task.rb +12 -0
- data/spec/mongoid_dummy/app/models/untouched.rb +7 -0
- 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/mongoid_dummy/config/environments/development.rb +31 -0
- data/spec/mongoid_dummy/config/environments/production.rb +64 -0
- data/spec/mongoid_dummy/config/environments/test.rb +35 -0
- 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/mongoid_dummy/config/mongoid.yml +120 -0
- 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/plain_objects_controller.rb +14 -0
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +64 -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/plain_object.rb +17 -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/shared_engine/config/routes.rb +28 -0
- data/spec/shared_engine/dummy/README.rdoc +261 -0
- data/spec/shared_engine/dummy/Rakefile +7 -0
- 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/shared_engine/dummy/config.ru +4 -0
- data/spec/shared_engine/dummy/config/application.rb +62 -0
- data/spec/shared_engine/dummy/config/boot.rb +10 -0
- data/spec/shared_engine/dummy/config/database.yml +25 -0
- data/spec/shared_engine/dummy/config/environment.rb +5 -0
- 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/shared_engine/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +8 -0
- 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/magic/rails/engine.rb +69 -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.opts +1 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/api_test_helpers.rb +23 -0
- data/spec/support/controller_examples.rb +458 -0
- data/spec/support/it_supports.rb +3 -0
- data/spec/support/model_examples/associations.rb +272 -0
- data/spec/support/model_examples/callbacks.rb +38 -0
- data/spec/support/model_examples/closures.rb +49 -0
- data/spec/support/model_examples/conditional_if.rb +165 -0
- data/spec/support/model_examples/conditional_unless.rb +165 -0
- data/spec/support/model_examples/enabled.rb +10 -0
- data/spec/support/model_examples/extending.rb +112 -0
- data/spec/support/model_examples/methods.rb +23 -0
- data/spec/support/model_examples/options.rb +53 -0
- data/spec/support/model_examples/renaming.rb +50 -0
- data/spec/support/model_examples/simple.rb +23 -0
- data/spec/support/model_examples/sub_nodes.rb +105 -0
- data/spec/support/model_examples/undefined.rb +7 -0
- data/spec/support/model_examples/untouched.rb +13 -0
- data/spec/support/routing.rb +4 -0
- data/spec/support/simple_fixtures.rb +59 -0
- metadata +499 -0
@@ -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.16"
|
19
|
+
# s.add_dependency "jquery-rails"
|
20
|
+
|
21
|
+
s.add_development_dependency "sqlite3"
|
22
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
|
3
|
+
if ENV['ACTS_AS_API_ORM'] == 'active_record'
|
4
|
+
require "active_record_dummy/config/environment"
|
5
|
+
|
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'
|
19
|
+
|
20
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
21
|
+
# in spec/support/ and its subdirectories.
|
22
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ApiTestHelpers
|
2
|
+
|
3
|
+
def response_body
|
4
|
+
response.body.strip
|
5
|
+
end
|
6
|
+
|
7
|
+
def response_body_json
|
8
|
+
ActiveSupport::JSON.decode(response_body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def response_body_jsonp(callback)
|
12
|
+
jsonp_callback(callback).match(response_body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def jsonp_callback(callback)
|
16
|
+
/\A#{callback}\((.*),\s+\d{3}\)\z/
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |c|
|
22
|
+
c.include ApiTestHelpers
|
23
|
+
end
|
@@ -0,0 +1,458 @@
|
|
1
|
+
shared_examples_for "a controller with ActsAsApi responses" do
|
2
|
+
|
3
|
+
include ApiTestHelpers
|
4
|
+
|
5
|
+
describe 'xml responses' do
|
6
|
+
|
7
|
+
describe 'get all users' do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
get :index, :format => 'xml', :api_template => :name_only
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a root node named users" do
|
14
|
+
response_body.should have_selector("users")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should contain all users" do
|
18
|
+
response_body.should have_selector("users > user") do |users|
|
19
|
+
users.size.should eql(3)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should contain the specified attributes" do
|
24
|
+
response_body.should have_selector("users > user > first-name")
|
25
|
+
response_body.should have_selector("users > user > last-name")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'get a single user' do
|
31
|
+
|
32
|
+
before(:each) do
|
33
|
+
get :show, :format => 'xml', :api_template => :name_only, :id => @luke.id
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a root node named user" do
|
37
|
+
response_body.should have_selector("user")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should contain the specified attributes" do
|
41
|
+
response_body.should have_selector("user > first-name")
|
42
|
+
response_body.should have_selector("user > last-name")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'get a user without specifying an api template' do
|
48
|
+
|
49
|
+
before(:each) do
|
50
|
+
get :show_default, :format => 'xml', :id => @luke.id
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should respond with HTTP 200" do
|
54
|
+
response.code.should == "200"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should render the model with standard to_xml" do
|
58
|
+
# TODO: figure out how to compare xml generated by mongo models.
|
59
|
+
|
60
|
+
# This line works fine with ActiveRecord, but not Mongoid:
|
61
|
+
# response.body.should == @luke.to_xml
|
62
|
+
|
63
|
+
response.body.length.should == @luke.to_xml.length
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'json responses' do
|
71
|
+
|
72
|
+
describe 'get all users' do
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
get :index, :format => 'json', :api_template => :name_only
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have a root node named users" do
|
79
|
+
response_body_json.should have_key("users")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should contain all users" do
|
83
|
+
response_body_json["users"].should be_a(Array)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should contain the specified attributes" do
|
87
|
+
response_body_json["users"].first.should have_key("first_name")
|
88
|
+
response_body_json["users"].first.should have_key("last_name")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should contain the specified values" do
|
92
|
+
response_body_json["users"].first["first_name"].should eql("Han")
|
93
|
+
response_body_json["users"].first["last_name"].should eql("Solo")
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do
|
99
|
+
|
100
|
+
before(:each) do
|
101
|
+
get :index_relation, :format => 'json', :api_template => :name_only
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have a root node named users" do
|
105
|
+
response_body_json.should have_key("users")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should contain all users" do
|
109
|
+
response_body_json["users"].should be_a(Array)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should contain the specified attributes" do
|
113
|
+
response_body_json["users"].first.should have_key("first_name")
|
114
|
+
response_body_json["users"].first.should have_key("last_name")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should contain the specified values" do
|
118
|
+
response_body_json["users"].first["first_name"].should eql("Han")
|
119
|
+
response_body_json["users"].first["last_name"].should eql("Solo")
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'get a single user' do
|
125
|
+
|
126
|
+
before(:each) do
|
127
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should have a root node named user" do
|
131
|
+
response_body_json.should have_key("user")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should contain the specified attributes" do
|
135
|
+
response_body_json["user"].should have_key("first_name")
|
136
|
+
response_body_json["user"].should have_key("last_name")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should contain the specified values" do
|
140
|
+
response_body_json["user"]["first_name"].should eql("Luke")
|
141
|
+
response_body_json["user"]["last_name"].should eql("Skywalker")
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'get a single user with a nil profile' do
|
147
|
+
|
148
|
+
before(:each) do
|
149
|
+
Profile.acts_as_api
|
150
|
+
Profile.api_accessible :include_profile do |t|
|
151
|
+
t.add :avatar
|
152
|
+
t.add :homepage
|
153
|
+
end
|
154
|
+
|
155
|
+
get :show, :format => 'json', :api_template => :include_profile, :id => @han.id
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should have a root node named user" do
|
159
|
+
response_body_json.should have_key("user")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should contain the specified attributes" do
|
163
|
+
response_body_json["user"].should have(1).keys
|
164
|
+
response_body_json["user"].should have_key("profile")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should contain the specified values" do
|
168
|
+
response_body_json["user"]["profile"].should be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'get a user without specifying an api template' do
|
174
|
+
|
175
|
+
before(:each) do
|
176
|
+
get :show_default, :format => 'json', :id => @luke.id
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should respond with HTTP 200" do
|
180
|
+
response.code.should == "200"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should render the model with to_json" do
|
184
|
+
response.body.should == @luke.to_json
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe 'Rails 3 default style json responses' do
|
192
|
+
|
193
|
+
before(:each) do
|
194
|
+
@org_include_root_in_json_collections = ActsAsApi::Config.include_root_in_json_collections
|
195
|
+
ActsAsApi::Config.include_root_in_json_collections = true
|
196
|
+
end
|
197
|
+
|
198
|
+
after(:each) do
|
199
|
+
ActsAsApi::Config.include_root_in_json_collections = @org_include_root_in_json_collections
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'get all users' do
|
203
|
+
|
204
|
+
before(:each) do
|
205
|
+
get :index, :format => 'json', :api_template => :name_only
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should have a root node named users" do
|
209
|
+
response_body_json.should have_key("users")
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should contain all users" do
|
213
|
+
response_body_json["users"].should be_a(Array)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should contain the specified attributes" do
|
217
|
+
response_body_json["users"].first["user"].should have_key("first_name")
|
218
|
+
response_body_json["users"].first["user"].should have_key("last_name")
|
219
|
+
end
|
220
|
+
|
221
|
+
it "contains the user root nodes" do
|
222
|
+
response_body_json["users"].collect(&:keys).flatten.uniq.should eql(["user"])
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should contain the specified values" do
|
226
|
+
response_body_json["users"].first["user"]["first_name"].should eql("Han")
|
227
|
+
response_body_json["users"].first["user"]["last_name"].should eql("Solo")
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
describe 'get a single user' do
|
233
|
+
|
234
|
+
before(:each) do
|
235
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should have a root node named user" do
|
239
|
+
response_body_json.should have_key("user")
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should contain the specified attributes" do
|
243
|
+
response_body_json["user"].should have_key("first_name")
|
244
|
+
response_body_json["user"].should have_key("last_name")
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should contain the specified values" do
|
248
|
+
response_body_json["user"]["first_name"].should eql("Luke")
|
249
|
+
response_body_json["user"]["last_name"].should eql("Skywalker")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
describe 'jsonp responses with callback' do
|
256
|
+
|
257
|
+
it "should be disabled by default" do
|
258
|
+
@callback = "mycallback"
|
259
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
260
|
+
response_body_jsonp(@callback).should be_nil
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "enabled jsonp callbacks" do
|
264
|
+
|
265
|
+
before(:each) do
|
266
|
+
@callback = "mycallback"
|
267
|
+
|
268
|
+
User.acts_as_api do |config|
|
269
|
+
config.allow_jsonp_callback = true
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
after(:each) do
|
274
|
+
# put things back to the way they were
|
275
|
+
User.acts_as_api do |config|
|
276
|
+
config.allow_jsonp_callback = false
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe 'get all users' do
|
281
|
+
|
282
|
+
before(:each) do
|
283
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should wrap the response in the callback" do
|
287
|
+
response_body_jsonp(@callback).should_not be_nil
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
describe 'get a single user' do
|
293
|
+
|
294
|
+
before(:each) do
|
295
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id, :callback => @callback
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should wrap the response in the callback" do
|
299
|
+
response_body_jsonp(@callback).should_not be_nil
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
describe 'config.add_root_node_for is empty, so no root node is created' do
|
308
|
+
before(:each) do
|
309
|
+
@org_add_root_node_for_config = ActsAsApi::Config.add_root_node_for.dup
|
310
|
+
ActsAsApi::Config.add_root_node_for = []
|
311
|
+
end
|
312
|
+
|
313
|
+
after(:each) do
|
314
|
+
ActsAsApi::Config.add_root_node_for = @org_add_root_node_for_config
|
315
|
+
end
|
316
|
+
|
317
|
+
describe 'get all users' do
|
318
|
+
before(:each) do
|
319
|
+
get :index, :format => 'json', :api_template => :name_only, :callback => @callback
|
320
|
+
end
|
321
|
+
|
322
|
+
its "response has no named root node" do
|
323
|
+
response_body_json.should be_an(Array)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
describe 'get a single user' do
|
328
|
+
before(:each) do
|
329
|
+
get :show, :format => 'json', :api_template => :name_only, :id => @luke.id
|
330
|
+
end
|
331
|
+
|
332
|
+
its "response has no named root node" do
|
333
|
+
response_body_json.should be_a(Hash)
|
334
|
+
response_body_json.should have_key("first_name")
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
describe 'pass meta information on rendering' do
|
340
|
+
|
341
|
+
describe 'get all users' do
|
342
|
+
before(:each) do
|
343
|
+
get :index_meta, :format => 'json', :api_template => :name_only
|
344
|
+
end
|
345
|
+
|
346
|
+
it "shows model response fields" do
|
347
|
+
response_body_json.should be_a(Hash)
|
348
|
+
response_body_json.should have_key("users")
|
349
|
+
response_body_json["users"].should be_an(Array)
|
350
|
+
end
|
351
|
+
|
352
|
+
it "shows page field" do
|
353
|
+
response_body_json.should have_key("page")
|
354
|
+
end
|
355
|
+
|
356
|
+
it "shows total field" do
|
357
|
+
response_body_json.should have_key("total")
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe 'get a single user' do
|
362
|
+
before(:each) do
|
363
|
+
get :show_meta, :format => 'json', :api_template => :name_only, :id => @luke.id
|
364
|
+
end
|
365
|
+
|
366
|
+
it "shows model response fields" do
|
367
|
+
response_body_json.should be_a(Hash)
|
368
|
+
response_body_json.should have_key("user")
|
369
|
+
end
|
370
|
+
|
371
|
+
it "shows page field" do
|
372
|
+
response_body_json.should have_key("page")
|
373
|
+
end
|
374
|
+
|
375
|
+
it "shows total field" do
|
376
|
+
response_body_json.should have_key("total")
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
describe 'api prefix' do
|
384
|
+
|
385
|
+
describe 'get single user' do
|
386
|
+
|
387
|
+
before(:each) do
|
388
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :id => @luke.id
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should have a root node named user" do
|
392
|
+
response_body.should have_selector("user")
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should contain the specified attributes" do
|
396
|
+
response_body.should have_selector("user > prefix")
|
397
|
+
response_body.should have_selector("user > first-name")
|
398
|
+
response_body.should have_selector("user > last-name")
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should not contain the specified attributes" do
|
402
|
+
response_body.should_not have_selector("user > postfix")
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
end
|
408
|
+
|
409
|
+
describe 'api postfix' do
|
410
|
+
|
411
|
+
describe 'get single user' do
|
412
|
+
|
413
|
+
before(:each) do
|
414
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_postfix => :with_postfix, :id => @luke.id
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should have a root node named user" do
|
418
|
+
response_body.should have_selector("user")
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should contain the specified attributes" do
|
422
|
+
response_body.should have_selector("user > first-name")
|
423
|
+
response_body.should have_selector("user > last-name")
|
424
|
+
response_body.should have_selector("user > postfix")
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should not contain the specified attributes" do
|
428
|
+
response_body.should_not have_selector("user > prefix")
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
end
|
434
|
+
|
435
|
+
describe 'api prefix and api postfix' do
|
436
|
+
|
437
|
+
describe 'get single user' do
|
438
|
+
|
439
|
+
before(:each) do
|
440
|
+
get :show_prefix_postfix, :format => 'xml', :api_template => :name_only, :api_prefix => :with_prefix, :api_postfix => :with_postfix, :id => @luke.id
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should have a root node named user" do
|
444
|
+
response_body.should have_selector("user")
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should contain the specified attributes" do
|
448
|
+
response_body.should have_selector("user > prefix")
|
449
|
+
response_body.should have_selector("user > first-name")
|
450
|
+
response_body.should have_selector("user > last-name")
|
451
|
+
response_body.should have_selector("user > postfix")
|
452
|
+
end
|
453
|
+
|
454
|
+
end
|
455
|
+
|
456
|
+
end
|
457
|
+
|
458
|
+
end
|