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
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mongoid", :orm => "mongoid" do
4
-
5
- before(:each) do
6
- setup_mongoid_models
7
- end
8
-
9
- after(:each) do
10
- clean_up_mongoid_models
11
- end
12
-
13
- describe :act_as_api do
14
- it_supports "including an association in the api template"
15
- it_supports "calling a closure in the api template"
16
- it_supports "conditional if statements"
17
- it_supports "conditional unless statements"
18
- it_supports "acts_as_api is enabled"
19
- it_supports "extending a given api template"
20
- it_supports "calling a method in the api template"
21
- it_supports "renaming"
22
- it_supports "listing attributes in the api template"
23
- it_supports "creating a sub hash in the api template"
24
- it_supports "trying to render an api template that is not defined"
25
- it_supports "untouched models"
26
- it_supports "defining a model callback"
27
- end
28
-
29
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Class, :orm => "vanilla" do
4
-
5
- before(:each) do
6
- setup_roflscale_models
7
- end
8
-
9
- after(:each) do
10
- clean_up_roflscale_models
11
- end
12
-
13
- describe :act_as_api do
14
- # deactivated as I won't implement a fake association model just for specs ;)
15
- # it_supports "including an association in the api template"
16
- it_supports "calling a closure in the api template"
17
- it_supports "conditional if statements"
18
- it_supports "conditional unless statements"
19
- it_supports "acts_as_api is enabled"
20
- it_supports "extending a given api template"
21
- it_supports "calling a method in the api template"
22
- it_supports "renaming"
23
- it_supports "listing attributes in the api template"
24
- it_supports "creating a sub hash in the api template"
25
- it_supports "trying to render an api template that is not defined"
26
- # deactivated as acts_as_api won't get mixed into any class
27
- # it_supports "untouched models"
28
- it_supports "defining a model callback"
29
- end
30
-
31
- end
@@ -1,4 +0,0 @@
1
- .bundle
2
- db/*.sqlite3
3
- log/*.log
4
- tmp/
@@ -1,11 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
-
4
- before_filter do
5
- if params[:orm] == 'active_record'
6
- @user_model = User
7
- elsif params[:orm] == 'mongoid'
8
- @user_model = MongoUser
9
- end
10
- end
11
- end
@@ -1,57 +0,0 @@
1
- class RespondWithUsersController < ApplicationController
2
-
3
- respond_to :json, :xml
4
-
5
- self.responder = ActsAsApi::Responder
6
-
7
- def index
8
- @users = @user_model.all
9
- respond_with @users, :api_template => params[:api_template].to_sym, :root => :users
10
- end
11
-
12
- def index_meta
13
- @users = @user_model.all
14
- meta_hash = { :page => 1, :total => 999 }
15
- respond_with @users, :api_template => params[:api_template].to_sym, :root => :users, :meta => meta_hash
16
- end
17
-
18
- def index_relation
19
- @users = @user_model.limit(100)
20
- respond_with @users, :api_template => params[:api_template].to_sym
21
- end
22
-
23
- def show
24
- @user = @user_model.find(params[:id])
25
- # :root => :user is only used here because we need it for the node name of the MongoUser model
26
- respond_with @user, :api_template => params[:api_template].to_sym, :root => :user
27
- end
28
-
29
- def show_meta
30
- @user = @user_model.find(params[:id])
31
- meta_hash = { :page => 1, :total => 999 }
32
- # :root => :user is only used here because we need it for the node name of the MongoUser model
33
- respond_with @user, :api_template => params[:api_template].to_sym, :root => :user, :meta => meta_hash
34
- end
35
-
36
- def show_default
37
- @user = @user_model.find(params[:id])
38
- respond_with @user
39
- end
40
-
41
- def show_prefix_postfix
42
- @user = @user_model.find(params[:id])
43
- # :root => :user is only used here because we need it for the node name of the MongoUser model
44
- respond_with @user, :api_template => {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}, :root => :user
45
- end
46
-
47
- def create
48
- @user = @user_model.new(params[:user])
49
-
50
- if @user.save
51
- respond_with @user, :api_template => params[:api_template]
52
- else
53
- respond_with @user
54
- end
55
- end
56
-
57
- end
@@ -1,69 +0,0 @@
1
- class UsersController < ApplicationController
2
-
3
- def index
4
- @users = @user_model.all
5
-
6
- respond_to do |format|
7
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users }
8
- format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users }
9
- end
10
- end
11
-
12
- def index_meta
13
- @users = @user_model.all
14
- meta_hash = { :page => 1, :total => 999 }
15
-
16
- respond_to do |format|
17
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users, :meta => meta_hash }
18
- format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash }
19
- end
20
- end
21
-
22
- def index_relation
23
- @users = @user_model.limit(100)
24
-
25
- respond_to do |format|
26
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
27
- format.json { render_for_api params[:api_template].to_sym, :json => @users }
28
- end
29
- end
30
-
31
- def show
32
- @user = @user_model.find(params[:id])
33
-
34
- respond_to do |format|
35
- # :root => :user is only used here because we need it for the node name of the MongoUser model
36
- format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
37
- format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user }
38
- end
39
- end
40
-
41
- def show_meta
42
- @user = @user_model.find(params[:id])
43
- meta_hash = { :page => 1, :total => 999 }
44
- respond_to do |format|
45
- # :root => :user is only used here because we need it for the node name of the MongoUser model
46
- format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
47
- format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user, :meta => meta_hash }
48
- end
49
- end
50
-
51
- def show_default
52
- @user = @user_model.find(params[:id])
53
- respond_to do |format|
54
- format.xml { render :xml => @user }
55
- format.json { render :json => @user }
56
- end
57
- end
58
-
59
- def show_prefix_postfix
60
- @user = @user_model.find(params[:id])
61
- template = {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}
62
- respond_to do |format|
63
- # :root => :user is only used here because we need it for the node name of the MongoUser model
64
- format.xml { render_for_api template, :xml => @user, :root => :user }
65
- format.json { render_for_api template, :json => @user, :root => :user }
66
- end
67
- end
68
-
69
- end
@@ -1,192 +0,0 @@
1
- class MongoUser
2
-
3
- include Mongoid::Document
4
-
5
- field :first_name, :type => String
6
- field :last_name, :type => String
7
- field :age, :type => Integer
8
- field :active, :type => Boolean
9
- field :created_at, :type => DateTime
10
- field :updated_at, :type => DateTime
11
-
12
- embeds_one :profile, :class_name => "MongoProfile", :inverse_of => :user
13
- embeds_many :tasks, :class_name => "MongoTask", :inverse_of => :user
14
-
15
- acts_as_api
16
-
17
- api_accessible :name_only do |t|
18
- t.add :first_name
19
- t.add :last_name
20
- end
21
-
22
- api_accessible :only_full_name do |t|
23
- t.add :full_name
24
- end
25
-
26
- api_accessible :rename_last_name do |t|
27
- t.add :last_name, :as => :family_name
28
- end
29
-
30
- api_accessible :rename_full_name do |t|
31
- t.add :full_name, :as => :other_full_name
32
- end
33
-
34
- api_accessible :with_former_value do |t|
35
- t.add :first_name
36
- t.add :last_name
37
- end
38
-
39
- api_accessible :age_and_first_name, :extend => :with_former_value do |t|
40
- t.add :age
41
- t.remove :last_name
42
- end
43
-
44
- api_accessible :calling_a_proc do |t|
45
- t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name
46
- t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param
47
- end
48
-
49
- api_accessible :calling_a_lambda do |t|
50
- t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name
51
- t.add lambda{|model| Time.now.class.to_s }, :as => :without_param
52
- end
53
- api_accessible :include_tasks do |t|
54
- t.add :tasks
55
- end
56
-
57
- api_accessible :include_profile do |t|
58
- t.add :profile
59
- end
60
-
61
- api_accessible :other_sub_template do |t|
62
- t.add :first_name
63
- t.add :tasks, :template => :other_template
64
- end
65
-
66
- api_accessible :include_completed_tasks do |t|
67
- t.add "tasks.completed.all", :as => :completed_tasks
68
- end
69
-
70
- api_accessible :sub_node do |t|
71
- t.add Hash[:foo => :say_something], :as => :sub_nodes
72
- end
73
-
74
- api_accessible :nested_sub_node do |t|
75
- t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes
76
- end
77
-
78
- api_accessible :nested_sub_hash do |t|
79
- t.add :sub_hash
80
- end
81
-
82
- api_accessible :if_over_thirty do |t|
83
- t.add :first_name
84
- t.add :last_name, :if => :over_thirty?
85
- end
86
-
87
- api_accessible :if_returns_nil do |t|
88
- t.add :first_name
89
- t.add :last_name, :if => :return_nil
90
- end
91
-
92
- api_accessible :if_over_thirty_proc do |t|
93
- t.add :first_name
94
- t.add :last_name, :if => lambda{|u| u.over_thirty? }
95
- end
96
-
97
- api_accessible :if_returns_nil_proc do |t|
98
- t.add :first_name
99
- t.add :last_name, :if => lambda{|u| nil }
100
- end
101
-
102
- api_accessible :unless_under_thirty do |t|
103
- t.add :first_name
104
- t.add :last_name, :unless => :under_thirty?
105
- end
106
-
107
- api_accessible :unless_returns_nil do |t|
108
- t.add :first_name
109
- t.add :last_name, :unless => :return_nil
110
- end
111
-
112
- api_accessible :unless_under_thirty_proc do |t|
113
- t.add :first_name
114
- t.add :last_name, :unless => lambda{|u| u.under_thirty? }
115
- end
116
-
117
- api_accessible :unless_returns_nil_proc do |t|
118
- t.add :first_name
119
- t.add :last_name, :unless => lambda{|u| nil }
120
- end
121
-
122
- api_accessible :with_prefix_name_only do |t|
123
- t.add lambda{|model| 'true' }, :as => :prefix
124
- t.add :first_name
125
- t.add :last_name
126
- end
127
-
128
- api_accessible :name_only_with_postfix do |t|
129
- t.add :first_name
130
- t.add :last_name
131
- t.add lambda{|model| 'true' }, :as => :postfix
132
- end
133
-
134
- api_accessible :with_prefix_name_only_with_postfix do |t|
135
- t.add lambda{|model| 'true' }, :as => :prefix
136
- t.add :first_name
137
- t.add :last_name
138
- t.add lambda{|model| 'true' }, :as => :postfix
139
- end
140
-
141
- def before_api_response(api_response)
142
- @before_api_response_called = true
143
- end
144
-
145
- def before_api_response_called?
146
- !!@before_api_response_called
147
- end
148
-
149
- def after_api_response(api_response)
150
- @after_api_response_called = true
151
- end
152
-
153
- def after_api_response_called?
154
- !!@after_api_response_called
155
- end
156
-
157
- def skip_api_response=(should_skip)
158
- @skip_api_response = should_skip
159
- end
160
-
161
- def around_api_response(api_response)
162
- @skip_api_response ? { :skipped => true } : yield
163
- end
164
-
165
- def over_thirty?
166
- age > 30
167
- end
168
-
169
- def under_thirty?
170
- age < 30
171
- end
172
-
173
- def return_nil
174
- nil
175
- end
176
-
177
- def full_name
178
- '' << first_name.to_s << ' ' << last_name.to_s
179
- end
180
-
181
- def say_something
182
- "something"
183
- end
184
-
185
- def sub_hash
186
- {
187
- :foo => "bar",
188
- :hello => "world"
189
- }
190
- end
191
-
192
- end
@@ -1,3 +0,0 @@
1
- class Task < ActiveRecord::Base
2
- belongs_to :user
3
- end
@@ -1,16 +0,0 @@
1
- class VanillaProfile
2
- extend ActsAsApi::Base
3
-
4
- attr_accessor :user, :avatar, :homepage, :created_at, :updated_at
5
-
6
- def initialize(opts)
7
- opts.each do |k,v|
8
- self.send :"#{k}=", v
9
- end
10
- end
11
-
12
- def model_name
13
- 'profile'
14
- end
15
-
16
- end
@@ -1,16 +0,0 @@
1
- class VanillaTask
2
- extend ActsAsApi::Base
3
-
4
- attr_accessor :user, :heading, :description, :time_spent, :done, :created_at, :updated_at
5
-
6
- def initialize(opts)
7
- opts.each do |k,v|
8
- self.send :"#{k}=", v
9
- end
10
- end
11
-
12
- def model_name
13
- 'task'
14
- end
15
-
16
- end
@@ -1,2 +0,0 @@
1
- class VanillaUntouched
2
- end