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.
Files changed (198) hide show
  1. data/.gitignore +7 -4
  2. data/.travis.yml +5 -1
  3. data/Gemfile +2 -1
  4. data/History.txt +4 -0
  5. data/README.md +9 -4
  6. data/Rakefile +28 -5
  7. data/acts_as_api.gemspec +1 -1
  8. data/lib/acts_as_api/api_template.rb +54 -63
  9. data/lib/acts_as_api/array.rb +2 -2
  10. data/lib/acts_as_api/base.rb +19 -13
  11. data/lib/acts_as_api/config.rb +2 -2
  12. data/lib/acts_as_api/rendering.rb +4 -4
  13. data/lib/acts_as_api/version.rb +1 -1
  14. data/spec/README.md +55 -0
  15. data/spec/active_record_dummy/.gitignore +15 -0
  16. data/spec/active_record_dummy/Gemfile +16 -0
  17. data/spec/active_record_dummy/README.rdoc +261 -0
  18. data/spec/active_record_dummy/Rakefile +7 -0
  19. data/spec/{rails_app/public → active_record_dummy/app/assets}/images/rails.png +0 -0
  20. data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
  21. data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/{rails_app → active_record_dummy}/app/helpers/application_helper.rb +0 -0
  24. data/spec/{rails_app/lib/tasks → active_record_dummy/app/mailers}/.gitkeep +0 -0
  25. data/spec/{rails_app/public/stylesheets → active_record_dummy/app/models}/.gitkeep +0 -0
  26. data/spec/{rails_app → active_record_dummy}/app/models/profile.rb +1 -0
  27. data/spec/active_record_dummy/app/models/task.rb +4 -0
  28. data/spec/{rails_app → active_record_dummy}/app/models/untouched.rb +0 -0
  29. data/spec/{rails_app → active_record_dummy}/app/models/user.rb +1 -0
  30. data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/active_record_dummy/config.ru +4 -0
  32. data/spec/active_record_dummy/config/application.rb +59 -0
  33. data/spec/{rails_app → active_record_dummy}/config/boot.rb +0 -0
  34. data/spec/{rails_app → active_record_dummy}/config/database.yml +5 -3
  35. data/spec/active_record_dummy/config/environment.rb +5 -0
  36. data/spec/active_record_dummy/config/environments/development.rb +37 -0
  37. data/spec/active_record_dummy/config/environments/production.rb +67 -0
  38. data/spec/active_record_dummy/config/environments/test.rb +37 -0
  39. data/spec/{rails_app → active_record_dummy}/config/initializers/backtrace_silencers.rb +0 -0
  40. data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
  41. data/spec/{rails_app → active_record_dummy}/config/initializers/inflections.rb +5 -0
  42. data/spec/{rails_app → active_record_dummy}/config/initializers/mime_types.rb +0 -0
  43. data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
  44. data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
  45. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/{rails_app → active_record_dummy}/config/locales/en.yml +1 -1
  47. data/spec/active_record_dummy/config/routes.rb +59 -0
  48. data/spec/{rails_app → active_record_dummy}/db/migrate/20110214201640_create_tables.rb +0 -0
  49. data/spec/{rails_app → active_record_dummy}/db/schema.rb +0 -0
  50. data/spec/{rails_app → active_record_dummy}/db/seeds.rb +0 -0
  51. data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
  52. data/spec/{rails_app/public/favicon.ico → active_record_dummy/lib/assets/.gitkeep} +0 -0
  53. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  54. data/spec/active_record_dummy/log/.gitkeep +0 -0
  55. data/spec/{rails_app → active_record_dummy}/public/404.html +0 -0
  56. data/spec/{rails_app → active_record_dummy}/public/422.html +0 -0
  57. data/spec/{rails_app → active_record_dummy}/public/500.html +0 -1
  58. data/spec/active_record_dummy/public/favicon.ico +0 -0
  59. data/spec/{rails_app → active_record_dummy}/public/index.html +10 -8
  60. data/spec/{rails_app → active_record_dummy}/public/robots.txt +0 -0
  61. data/spec/{rails_app → active_record_dummy}/script/rails +0 -0
  62. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  63. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  64. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  65. data/spec/controllers/respond_with_users_controller_spec.rb +18 -33
  66. data/spec/controllers/users_controller_spec.rb +8 -25
  67. data/spec/models/{active_record_spec.rb → model_spec.rb} +5 -3
  68. data/spec/mongoid_dummy/.gitignore +15 -0
  69. data/spec/mongoid_dummy/Gemfile +18 -0
  70. data/spec/mongoid_dummy/README.rdoc +261 -0
  71. data/spec/mongoid_dummy/Rakefile +7 -0
  72. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  73. data/spec/mongoid_dummy/app/assets/javascripts/application.js +15 -0
  74. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +13 -0
  75. data/spec/mongoid_dummy/app/controllers/application_controller.rb +3 -0
  76. data/spec/mongoid_dummy/app/helpers/application_helper.rb +2 -0
  77. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  78. data/spec/mongoid_dummy/app/models/.gitkeep +0 -0
  79. data/spec/{rails_app/app/models/mongo_profile.rb → mongoid_dummy/app/models/profile.rb} +2 -2
  80. data/spec/{rails_app/app/models/mongo_task.rb → mongoid_dummy/app/models/task.rb} +2 -2
  81. data/spec/{rails_app/app/models/mongo_untouched.rb → mongoid_dummy/app/models/untouched.rb} +1 -1
  82. data/spec/mongoid_dummy/app/models/user.rb +48 -0
  83. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +14 -0
  84. data/spec/mongoid_dummy/config.ru +4 -0
  85. data/spec/mongoid_dummy/config/application.rb +65 -0
  86. data/spec/mongoid_dummy/config/boot.rb +6 -0
  87. data/spec/mongoid_dummy/config/environment.rb +5 -0
  88. data/spec/{rails_app → mongoid_dummy}/config/environments/development.rb +10 -4
  89. data/spec/{rails_app → mongoid_dummy}/config/environments/production.rb +29 -14
  90. data/spec/{rails_app → mongoid_dummy}/config/environments/test.rb +8 -8
  91. data/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb +7 -0
  92. data/spec/mongoid_dummy/config/initializers/generators.rb +2 -0
  93. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +3 -0
  94. data/spec/mongoid_dummy/config/initializers/inflections.rb +15 -0
  95. data/spec/mongoid_dummy/config/initializers/mime_types.rb +5 -0
  96. data/spec/mongoid_dummy/config/initializers/secret_token.rb +7 -0
  97. data/spec/mongoid_dummy/config/initializers/session_store.rb +8 -0
  98. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +10 -0
  99. data/spec/mongoid_dummy/config/locales/en.yml +5 -0
  100. data/spec/{rails_app → mongoid_dummy}/config/mongoid.yml +8 -3
  101. data/spec/mongoid_dummy/config/routes.rb +59 -0
  102. data/spec/mongoid_dummy/db/seeds.rb +7 -0
  103. data/spec/mongoid_dummy/doc/README_FOR_APP +2 -0
  104. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  106. data/spec/mongoid_dummy/log/.gitkeep +0 -0
  107. data/spec/mongoid_dummy/public/404.html +26 -0
  108. data/spec/mongoid_dummy/public/422.html +26 -0
  109. data/spec/mongoid_dummy/public/500.html +25 -0
  110. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  111. data/spec/mongoid_dummy/public/index.html +241 -0
  112. data/spec/mongoid_dummy/public/robots.txt +5 -0
  113. data/spec/mongoid_dummy/script/rails +6 -0
  114. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  117. data/spec/shared_engine/.gitignore +7 -0
  118. data/spec/shared_engine/Gemfile +14 -0
  119. data/spec/shared_engine/MIT-LICENSE +20 -0
  120. data/spec/shared_engine/README.rdoc +3 -0
  121. data/spec/shared_engine/Rakefile +29 -0
  122. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  123. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +15 -0
  124. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +13 -0
  125. data/spec/shared_engine/app/controllers/shared_engine/application_controller.rb +4 -0
  126. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +59 -0
  127. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +71 -0
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +4 -0
  129. data/spec/shared_engine/app/models/user_template.rb +154 -0
  130. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +14 -0
  131. data/spec/{rails_app → shared_engine}/config/routes.rb +2 -4
  132. data/spec/shared_engine/dummy/README.rdoc +261 -0
  133. data/spec/{rails_app → shared_engine/dummy}/Rakefile +2 -2
  134. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +15 -0
  135. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +13 -0
  136. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +3 -0
  137. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +2 -0
  138. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  139. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  140. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +14 -0
  141. data/spec/{rails_app → shared_engine/dummy}/config.ru +1 -1
  142. data/spec/{rails_app → shared_engine/dummy}/config/application.rb +30 -10
  143. data/spec/shared_engine/dummy/config/boot.rb +10 -0
  144. data/spec/shared_engine/dummy/config/database.yml +25 -0
  145. data/spec/{rails_app → shared_engine/dummy}/config/environment.rb +1 -1
  146. data/spec/shared_engine/dummy/config/environments/development.rb +37 -0
  147. data/spec/shared_engine/dummy/config/environments/production.rb +67 -0
  148. data/spec/shared_engine/dummy/config/environments/test.rb +37 -0
  149. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +7 -0
  150. data/spec/shared_engine/dummy/config/initializers/inflections.rb +15 -0
  151. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +5 -0
  152. data/spec/{rails_app → shared_engine/dummy}/config/initializers/secret_token.rb +1 -1
  153. data/spec/{rails_app → shared_engine/dummy}/config/initializers/session_store.rb +2 -2
  154. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +14 -0
  155. data/spec/shared_engine/dummy/config/locales/en.yml +5 -0
  156. data/spec/shared_engine/dummy/config/routes.rb +4 -0
  157. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  158. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  159. data/spec/shared_engine/dummy/public/404.html +26 -0
  160. data/spec/shared_engine/dummy/public/422.html +26 -0
  161. data/spec/shared_engine/dummy/public/500.html +25 -0
  162. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  163. data/spec/shared_engine/dummy/script/rails +6 -0
  164. data/spec/shared_engine/lib/shared_engine.rb +4 -0
  165. data/spec/shared_engine/lib/shared_engine/engine.rb +5 -0
  166. data/spec/shared_engine/lib/shared_engine/version.rb +3 -0
  167. data/spec/shared_engine/lib/tasks/shared_engine_tasks.rake +4 -0
  168. data/spec/shared_engine/script/rails +8 -0
  169. data/spec/shared_engine/shared_engine.gemspec +22 -0
  170. data/spec/spec_helper.rb +16 -11
  171. data/spec/support/controller_examples.rb +35 -41
  172. data/spec/support/model_examples/associations.rb +13 -13
  173. data/spec/support/model_examples/enabled.rb +2 -2
  174. data/spec/support/model_examples/extending.rb +6 -6
  175. data/spec/support/model_examples/options.rb +53 -0
  176. data/spec/support/model_examples/untouched.rb +2 -2
  177. data/spec/support/simple_fixtures.rb +31 -59
  178. metadata +324 -132
  179. data/spec/models/mongoid_spec.rb +0 -29
  180. data/spec/models/vanilla_ruby_spec.rb +0 -31
  181. data/spec/rails_app/.gitignore +0 -4
  182. data/spec/rails_app/app/controllers/application_controller.rb +0 -11
  183. data/spec/rails_app/app/controllers/respond_with_users_controller.rb +0 -57
  184. data/spec/rails_app/app/controllers/users_controller.rb +0 -69
  185. data/spec/rails_app/app/models/mongo_user.rb +0 -192
  186. data/spec/rails_app/app/models/task.rb +0 -3
  187. data/spec/rails_app/app/models/vanilla_profile.rb +0 -16
  188. data/spec/rails_app/app/models/vanilla_task.rb +0 -16
  189. data/spec/rails_app/app/models/vanilla_untouched.rb +0 -2
  190. data/spec/rails_app/app/models/vanilla_user.rb +0 -195
  191. data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
  192. data/spec/rails_app/config/initializers/acts_as_api_mongoid.rb +0 -6
  193. data/spec/rails_app/public/javascripts/application.js +0 -2
  194. data/spec/rails_app/public/javascripts/controls.js +0 -965
  195. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  196. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  197. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
  198. 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,4 @@
1
+ require "shared_engine/engine"
2
+
3
+ module SharedEngine
4
+ end
@@ -0,0 +1,5 @@
1
+ module SharedEngine
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SharedEngine
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SharedEngine
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :shared_engine do
3
+ # # Task goes here
4
+ # end
@@ -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
- require "rails_app/config/environment"
2
- require 'rspec/rails'
1
+ ENV["RAILS_ENV"] = "test"
3
2
 
4
- $:.unshift(File.dirname(__FILE__) + '/../lib')
5
- require 'acts_as_api'
3
+ if ENV['ACTS_AS_API_ORM'] == 'active_record'
4
+ require "active_record_dummy/config/environment"
6
5
 
7
- ENV["RAILS_ENV"] = "test"
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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("Luke")
93
- response_body_json["users"].first["last_name"].should eql("Skywalker")
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, :orm => @orm_for_testing
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(@root_node)
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[@root_node].should be_a(Array)
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[@root_node].first.should have_key("first_name")
120
- response_body_json[@root_node].first.should have_key("last_name")
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[@root_node].first["first_name"].should eql("Luke")
125
- response_body_json[@root_node].first["last_name"].should eql("Skywalker")
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, :orm => @orm_for_testing
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
- @profile_model.acts_as_api
156
- @profile_model.api_accessible :include_profile do |t|
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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("Luke")
233
- response_body_json["users"].first["user"]["last_name"].should eql("Skywalker")
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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
- @user_model.acts_as_api do |config|
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
- @user_model.acts_as_api do |config|
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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, :orm => @orm_for_testing
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
- @task_model.acts_as_api
37
- @task_model.api_accessible :include_tasks do |t|
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
- @profile_model.acts_as_api
78
- @profile_model.api_accessible :include_profile do |t|
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
- @task_model.acts_as_api
118
- @task_model.api_accessible :other_template do |t|
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
- @task_model.class_eval do
168
+ Task.class_eval do
169
169
  scope :completed, where(:done => true)
170
170
  end
171
- @task_model.acts_as_api
172
- @task_model.api_accessible :include_completed_tasks do |t|
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
- @task_model.acts_as_api
216
- @task_model.api_accessible :include_tasks do |t|
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
- @profile_model.acts_as_api
248
- @profile_model.api_accessible :include_profile do |t|
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