acts_as_api 0.4.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -7
  3. data/History.txt +5 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +0 -25
  6. data/Rakefile +5 -12
  7. data/acts_as_api.gemspec +14 -13
  8. data/{examples/introduction → docs}/docco.css +0 -0
  9. data/{examples/introduction → docs}/index.html +18 -21
  10. data/{examples/introduction → docs}/index.rb +0 -0
  11. data/{examples/introduction → docs}/layout.mustache +0 -0
  12. data/lib/acts_as_api.rb +9 -12
  13. data/lib/acts_as_api/adapters.rb +1 -1
  14. data/lib/acts_as_api/api_template.rb +23 -25
  15. data/lib/acts_as_api/base.rb +11 -20
  16. data/lib/acts_as_api/collection.rb +1 -2
  17. data/lib/acts_as_api/config.rb +0 -5
  18. data/lib/acts_as_api/exceptions.rb +2 -2
  19. data/lib/acts_as_api/rails_renderer.rb +0 -2
  20. data/lib/acts_as_api/rendering.rb +5 -12
  21. data/lib/acts_as_api/responder.rb +8 -13
  22. data/lib/acts_as_api/version.rb +1 -1
  23. data/spec/README.md +15 -6
  24. data/spec/active_record_dummy/Gemfile +2 -10
  25. data/spec/active_record_dummy/app/models/user.rb +31 -32
  26. data/spec/active_record_dummy/config.ru +1 -1
  27. data/spec/active_record_dummy/config/application.rb +2 -2
  28. data/spec/active_record_dummy/config/boot.rb +1 -1
  29. data/spec/active_record_dummy/config/environments/test.rb +2 -2
  30. data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
  31. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
  32. data/spec/active_record_dummy/config/routes.rb +1 -57
  33. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
  34. data/spec/active_record_dummy/db/schema.rb +27 -29
  35. data/spec/active_record_dummy/script/rails +2 -2
  36. data/spec/controllers/plain_objects_controller_spec.rb +11 -12
  37. data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
  38. data/spec/controllers/users_controller_spec.rb +2 -3
  39. data/spec/models/model_spec.rb +17 -19
  40. data/spec/mongoid_dummy/Gemfile +3 -12
  41. data/spec/mongoid_dummy/app/models/profile.rb +6 -6
  42. data/spec/mongoid_dummy/app/models/task.rb +10 -10
  43. data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
  44. data/spec/mongoid_dummy/app/models/user.rb +12 -14
  45. data/spec/mongoid_dummy/config.ru +1 -1
  46. data/spec/mongoid_dummy/config/application.rb +7 -7
  47. data/spec/mongoid_dummy/config/boot.rb +1 -1
  48. data/spec/mongoid_dummy/config/environments/development.rb +0 -1
  49. data/spec/mongoid_dummy/config/environments/production.rb +0 -1
  50. data/spec/mongoid_dummy/config/environments/test.rb +2 -2
  51. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
  52. data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
  53. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
  54. data/spec/mongoid_dummy/config/routes.rb +1 -57
  55. data/spec/mongoid_dummy/script/rails +2 -2
  56. data/spec/shared_engine/Gemfile +1 -1
  57. data/spec/shared_engine/Rakefile +1 -4
  58. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
  59. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
  60. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
  61. data/spec/shared_engine/app/models/plain_object.rb +3 -1
  62. data/spec/shared_engine/app/models/user_template.rb +28 -29
  63. data/spec/shared_engine/lib/shared_engine.rb +1 -1
  64. data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
  65. data/spec/shared_engine/shared_engine.gemspec +10 -12
  66. data/spec/spec_helper.rb +5 -13
  67. data/spec/support/api_test_helpers.rb +0 -2
  68. data/spec/support/controller_examples.rb +128 -173
  69. data/spec/support/it_supports.rb +1 -1
  70. data/spec/support/model_examples/associations.rb +119 -128
  71. data/spec/support/model_examples/callbacks.rb +17 -27
  72. data/spec/support/model_examples/closures.rb +21 -29
  73. data/spec/support/model_examples/conditional_if.rb +71 -103
  74. data/spec/support/model_examples/conditional_unless.rb +71 -103
  75. data/spec/support/model_examples/enabled.rb +5 -6
  76. data/spec/support/model_examples/extending.rb +49 -56
  77. data/spec/support/model_examples/methods.rb +11 -15
  78. data/spec/support/model_examples/options.rb +19 -25
  79. data/spec/support/model_examples/renaming.rb +21 -30
  80. data/spec/support/model_examples/simple.rb +10 -14
  81. data/spec/support/model_examples/sub_nodes.rb +47 -59
  82. data/spec/support/model_examples/undefined.rb +4 -6
  83. data/spec/support/model_examples/untouched.rb +6 -8
  84. data/spec/support/simple_fixtures.rb +11 -38
  85. metadata +22 -159
  86. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  87. data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
  88. data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
  90. data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
  91. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  92. data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
  94. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  95. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  96. data/spec/active_record_dummy/public/404.html +0 -26
  97. data/spec/active_record_dummy/public/422.html +0 -26
  98. data/spec/active_record_dummy/public/500.html +0 -25
  99. data/spec/active_record_dummy/public/favicon.ico +0 -0
  100. data/spec/active_record_dummy/public/index.html +0 -241
  101. data/spec/active_record_dummy/public/robots.txt +0 -5
  102. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  103. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  104. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/README.rdoc +0 -261
  106. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  107. data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
  108. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
  109. data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
  110. data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
  111. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  112. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
  113. data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
  114. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/public/404.html +0 -26
  117. data/spec/mongoid_dummy/public/422.html +0 -26
  118. data/spec/mongoid_dummy/public/500.html +0 -25
  119. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  120. data/spec/mongoid_dummy/public/index.html +0 -241
  121. data/spec/mongoid_dummy/public/robots.txt +0 -5
  122. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  123. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  124. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  125. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  126. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
  127. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
  129. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
  130. data/spec/shared_engine/dummy/README.rdoc +0 -261
  131. data/spec/shared_engine/dummy/Rakefile +0 -7
  132. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
  133. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
  134. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
  135. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
  136. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  137. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  138. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
  139. data/spec/shared_engine/dummy/config.ru +0 -4
  140. data/spec/shared_engine/dummy/config/application.rb +0 -56
  141. data/spec/shared_engine/dummy/config/boot.rb +0 -10
  142. data/spec/shared_engine/dummy/config/database.yml +0 -25
  143. data/spec/shared_engine/dummy/config/environment.rb +0 -5
  144. data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
  145. data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
  146. data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
  147. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
  148. data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
  149. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
  150. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
  151. data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
  152. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
  153. data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
  154. data/spec/shared_engine/dummy/config/routes.rb +0 -4
  155. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  156. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  157. data/spec/shared_engine/dummy/public/404.html +0 -26
  158. data/spec/shared_engine/dummy/public/422.html +0 -26
  159. data/spec/shared_engine/dummy/public/500.html +0 -25
  160. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  161. data/spec/shared_engine/dummy/script/rails +0 -6
@@ -1,22 +1,21 @@
1
1
  module SharedEngine
2
2
  class UsersController < SharedEngine::ApplicationController
3
-
4
3
  def index
5
4
  @users = User.all.sort_by(&:first_name)
6
5
 
7
6
  respond_to do |format|
8
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users }
9
- format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users }
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 }
10
9
  end
11
10
  end
12
11
 
13
12
  def index_meta
14
13
  @users = User.all.to_a
15
- meta_hash = { :page => 1, :total => 999 }
14
+ meta_hash = { page: 1, total: 999 }
16
15
 
17
16
  respond_to do |format|
18
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users, :meta => meta_hash }
19
- format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash }
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 }
20
19
  end
21
20
  end
22
21
 
@@ -28,8 +27,8 @@ module SharedEngine
28
27
  end
29
28
 
30
29
  respond_to do |format|
31
- format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
32
- format.json { render_for_api params[:api_template].to_sym, :json => @users }
30
+ format.xml { render_for_api params[:api_template].to_sym, xml: @users }
31
+ format.json { render_for_api params[:api_template].to_sym, json: @users }
33
32
  end
34
33
  end
35
34
 
@@ -38,38 +37,37 @@ module SharedEngine
38
37
 
39
38
  respond_to do |format|
40
39
  # :root => :user is only used here because we need it for the node name of the MongoUser model
41
- format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
42
- format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user }
40
+ format.xml { render_for_api params[:api_template].to_sym, xml: @user, root: :user }
41
+ format.json { render_for_api params[:api_template].to_sym, json: @user, root: :user }
43
42
  end
44
43
  end
45
44
 
46
45
  def show_meta
47
46
  @user = User.find(params[:id])
48
- meta_hash = { :page => 1, :total => 999 }
47
+ meta_hash = { page: 1, total: 999 }
49
48
  respond_to do |format|
50
49
  # :root => :user is only used here because we need it for the node name of the MongoUser model
51
- format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user }
52
- format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user, :meta => meta_hash }
50
+ format.xml { render_for_api params[:api_template].to_sym, xml: @user, root: :user }
51
+ format.json { render_for_api params[:api_template].to_sym, json: @user, root: :user, meta: meta_hash }
53
52
  end
54
53
  end
55
54
 
56
55
  def show_default
57
56
  @user = User.find(params[:id])
58
57
  respond_to do |format|
59
- format.xml { render :xml => @user }
60
- format.json { render :json => @user }
58
+ format.xml { render xml: @user }
59
+ format.json { render json: @user }
61
60
  end
62
61
  end
63
62
 
64
63
  def show_prefix_postfix
65
64
  @user = User.find(params[:id])
66
- template = {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}
65
+ template = { template: params[:api_template], prefix: params[:api_prefix], postfix: params[:api_postfix] }
67
66
  respond_to do |format|
68
67
  # :root => :user is only used here because we need it for the node name of the MongoUser model
69
- format.xml { render_for_api template, :xml => @user, :root => :user }
70
- format.json { render_for_api template, :json => @user, :root => :user }
68
+ format.xml { render_for_api template, xml: @user, root: :user }
69
+ format.json { render_for_api template, json: @user, root: :user }
71
70
  end
72
71
  end
73
-
74
72
  end
75
73
  end
@@ -1,6 +1,8 @@
1
- class PlainObject < Struct.new(:first_name, :last_name, :age, :active)
1
+ class PlainObject
2
2
  extend ActsAsApi::Base
3
3
 
4
+ attr_accessor :first_name, :last_name, :age, :active
5
+
4
6
  def initialize(opts)
5
7
  opts.each do |k, v|
6
8
  send("#{k}=", v)
@@ -12,11 +12,11 @@ module UserTemplate
12
12
  end
13
13
 
14
14
  api_accessible :rename_last_name do |t|
15
- t.add :last_name, :as => :family_name
15
+ t.add :last_name, as: :family_name
16
16
  end
17
17
 
18
18
  api_accessible :rename_full_name do |t|
19
- t.add :full_name, :as => :other_full_name
19
+ t.add :full_name, as: :other_full_name
20
20
  end
21
21
 
22
22
  api_accessible :with_former_value do |t|
@@ -24,19 +24,19 @@ module UserTemplate
24
24
  t.add :last_name
25
25
  end
26
26
 
27
- api_accessible :age_and_first_name, :extend => :with_former_value do |t|
27
+ api_accessible :age_and_first_name, extend: :with_former_value do |t|
28
28
  t.add :age
29
29
  t.remove :last_name
30
30
  end
31
31
 
32
32
  api_accessible :calling_a_proc do |t|
33
- t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name
34
- t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param
33
+ t.add proc { |model| model.full_name.upcase }, as: :all_caps_name
34
+ t.add proc { |_| Time.now.class.to_s }, as: :without_param
35
35
  end
36
36
 
37
37
  api_accessible :calling_a_lambda do |t|
38
- t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name
39
- t.add lambda{|model| Time.now.class.to_s }, :as => :without_param
38
+ t.add ->(model) { model.full_name.upcase }, as: :all_caps_name
39
+ t.add ->(_) { Time.now.class.to_s }, as: :without_param
40
40
  end
41
41
  api_accessible :include_tasks do |t|
42
42
  t.add :tasks
@@ -48,19 +48,19 @@ module UserTemplate
48
48
 
49
49
  api_accessible :other_sub_template do |t|
50
50
  t.add :first_name
51
- t.add :tasks, :template => :other_template
51
+ t.add :tasks, template: :other_template
52
52
  end
53
53
 
54
54
  api_accessible :include_completed_tasks do |t|
55
- t.add "tasks.completed.all", :as => :completed_tasks
55
+ t.add 'tasks.completed.all', as: :completed_tasks
56
56
  end
57
57
 
58
58
  api_accessible :sub_node do |t|
59
- t.add Hash[:foo => :say_something], :as => :sub_nodes
59
+ t.add Hash[foo: :say_something], as: :sub_nodes
60
60
  end
61
61
 
62
62
  api_accessible :nested_sub_node do |t|
63
- t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes
63
+ t.add Hash[:foo, Hash[:bar, :last_name]], as: :sub_nodes
64
64
  end
65
65
 
66
66
  api_accessible :nested_sub_hash do |t|
@@ -69,46 +69,46 @@ module UserTemplate
69
69
 
70
70
  api_accessible :if_over_thirty do |t|
71
71
  t.add :first_name
72
- t.add :last_name, :if => :over_thirty?
72
+ t.add :last_name, if: :over_thirty?
73
73
  end
74
74
 
75
75
  api_accessible :if_returns_nil do |t|
76
76
  t.add :first_name
77
- t.add :last_name, :if => :return_nil
77
+ t.add :last_name, if: :return_nil
78
78
  end
79
79
 
80
80
  api_accessible :if_over_thirty_proc do |t|
81
81
  t.add :first_name
82
- t.add :last_name, :if => lambda{|u| u.over_thirty? }
82
+ t.add :last_name, if: ->(model) { model.over_thirty? }
83
83
  end
84
84
 
85
85
  api_accessible :if_returns_nil_proc do |t|
86
86
  t.add :first_name
87
- t.add :last_name, :if => lambda{|u| nil }
87
+ t.add :last_name, if: ->(_) { nil }
88
88
  end
89
89
 
90
90
  api_accessible :unless_under_thirty do |t|
91
91
  t.add :first_name
92
- t.add :last_name, :unless => :under_thirty?
92
+ t.add :last_name, unless: :under_thirty?
93
93
  end
94
94
 
95
95
  api_accessible :unless_returns_nil do |t|
96
96
  t.add :first_name
97
- t.add :last_name, :unless => :return_nil
97
+ t.add :last_name, unless: :return_nil
98
98
  end
99
99
 
100
100
  api_accessible :unless_under_thirty_proc do |t|
101
101
  t.add :first_name
102
- t.add :last_name, :unless => lambda{|u| u.under_thirty? }
102
+ t.add :last_name, unless: ->(model) { model.under_thirty? }
103
103
  end
104
104
 
105
105
  api_accessible :unless_returns_nil_proc do |t|
106
106
  t.add :first_name
107
- t.add :last_name, :unless => lambda{|u| nil }
107
+ t.add :last_name, unless: ->(_) { nil }
108
108
  end
109
109
 
110
110
  api_accessible :with_prefix_name_only do |t|
111
- t.add lambda{|model| 'true' }, :as => :prefix
111
+ t.add ->(_) { 'true' }, as: :prefix
112
112
  t.add :first_name
113
113
  t.add :last_name
114
114
  end
@@ -116,17 +116,17 @@ module UserTemplate
116
116
  api_accessible :name_only_with_postfix do |t|
117
117
  t.add :first_name
118
118
  t.add :last_name
119
- t.add lambda{|model| 'true' }, :as => :postfix
119
+ t.add ->(_) { 'true' }, as: :postfix
120
120
  end
121
121
 
122
122
  api_accessible :with_prefix_name_only_with_postfix do |t|
123
- t.add lambda{|model| 'true' }, :as => :prefix
123
+ t.add ->(_) { 'true' }, as: :prefix
124
124
  t.add :first_name
125
125
  t.add :last_name
126
- t.add lambda{|model| 'true' }, :as => :postfix
126
+ t.add ->(_) { 'true' }, as: :postfix
127
127
  end
128
128
 
129
- def before_api_response(api_response)
129
+ def before_api_response(_api_response)
130
130
  @before_api_response_called = true
131
131
  end
132
132
 
@@ -134,7 +134,7 @@ module UserTemplate
134
134
  !!@before_api_response_called
135
135
  end
136
136
 
137
- def after_api_response(api_response)
137
+ def after_api_response(_api_response)
138
138
  @after_api_response_called = true
139
139
  end
140
140
 
@@ -146,9 +146,8 @@ module UserTemplate
146
146
  @skip_api_response = should_skip
147
147
  end
148
148
 
149
- def around_api_response(api_response)
150
- @skip_api_response ? { :skipped => true } : yield
149
+ def around_api_response(_api_response)
150
+ @skip_api_response ? { skipped: true } : yield
151
151
  end
152
-
153
152
  end
154
- end
153
+ end
@@ -1,4 +1,4 @@
1
- require "shared_engine/engine"
1
+ require 'shared_engine/engine'
2
2
 
3
3
  module SharedEngine
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module SharedEngine
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.1'.freeze
3
3
  end
@@ -1,21 +1,19 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  # Maintain your gem's version:
4
- require "shared_engine/version"
4
+ require 'shared_engine/version'
5
5
 
6
6
  # Describe your gem and declare its dependencies:
7
7
  Gem::Specification.new do |s|
8
- s.name = "shared_engine"
8
+ s.name = 'shared_engine'
9
9
  s.version = SharedEngine::VERSION
10
- s.authors = ["Your name"]
11
- s.email = ["Your email"]
12
- s.summary = "Summary of SharedEngine."
13
- s.description = "Description of SharedEngine."
10
+ s.authors = ['Your name']
11
+ s.email = ['Your email']
12
+ s.summary = 'Summary of SharedEngine.'
13
+ s.description = 'Description of SharedEngine.'
14
14
 
15
- s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
15
+ s.files = Dir['{app,config,db,lib}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.rdoc']
16
16
 
17
- s.add_dependency "rails", "~> 5.0.0.1"
18
- # s.add_dependency "jquery-rails"
19
-
20
- s.add_development_dependency "sqlite3"
17
+ s.add_dependency 'rails', '~> 5.0.0.1'
18
+ s.add_development_dependency 'sqlite3'
21
19
  end
@@ -1,24 +1,16 @@
1
- ENV["RAILS_ENV"] = "test"
1
+ ENV['RAILS_ENV'] = 'test'
2
2
 
3
3
  if ENV['ACTS_AS_API_ORM'] == 'active_record'
4
- require "active_record_dummy/config/environment"
4
+ require 'active_record_dummy/config/environment'
5
5
 
6
- load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
6
+ load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
7
7
  # ActiveRecord::Migrator.up('db/migrate') # use migrations
8
-
9
-
10
8
  elsif ENV['ACTS_AS_API_ORM'] == 'mongoid'
11
-
12
- require "mongoid_dummy/config/environment"
13
-
9
+ require 'mongoid_dummy/config/environment'
14
10
  end
15
11
 
16
12
  require 'rspec/rails'
17
13
 
18
14
  # Requires supporting ruby files with custom matchers and macros, etc,
19
15
  # in spec/support/ and its subdirectories.
20
- Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file }
21
-
22
- RSpec.configure do |config|
23
- config.expect_with(:rspec) { |c| c.syntax = :should }
24
- end
16
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |file| require file }
@@ -1,5 +1,4 @@
1
1
  module ApiTestHelpers
2
-
3
2
  def response_body
4
3
  response.body.strip
5
4
  end
@@ -15,7 +14,6 @@ module ApiTestHelpers
15
14
  def jsonp_callback(callback)
16
15
  /\A#{callback}\((.*),\s+\d{3}\)\z/
17
16
  end
18
-
19
17
  end
20
18
 
21
19
  RSpec.configure do |c|
@@ -1,128 +1,115 @@
1
- shared_examples_for "a controller with ActsAsApi responses" do
1
+ shared_examples_for 'a controller with ActsAsApi responses' do
2
2
  include ApiTestHelpers
3
3
  routes { SharedEngine::Engine.routes }
4
4
 
5
5
  describe 'xml responses' do
6
-
7
6
  describe 'get all users' do
8
-
9
7
  before(:each) do
10
8
  get :index, format: 'xml', params: { api_template: :name_only }
11
9
  end
12
10
 
13
- it "should have a root node named users" do
14
- response_body.should have_selector("users")
11
+ it 'should have a root node named users' do
12
+ expect(response_body).to have_selector('users')
15
13
  end
16
14
 
17
- it "should contain all users" do
18
- response_body.should have_selector("users > user") do |users|
19
- users.size.should eql(3)
15
+ it 'should contain all users' do
16
+ expect(response_body).to have_selector('users > user') do |users|
17
+ expect(users.size).to eql(3)
20
18
  end
21
19
  end
22
20
 
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")
21
+ it 'should contain the specified attributes' do
22
+ expect(response_body).to have_selector('users > user > first-name')
23
+ expect(response_body).to have_selector('users > user > last-name')
26
24
  end
27
-
28
25
  end
29
26
 
30
27
  describe 'get a single user' do
31
-
32
28
  before(:each) do
33
29
  get :show, format: 'xml', params: { api_template: :name_only, id: @luke.id }
34
30
  end
35
31
 
36
- it "should have a root node named user" do
37
- response_body.should have_selector("user")
32
+ it 'should have a root node named user' do
33
+ expect(response_body).to have_selector('user')
38
34
  end
39
35
 
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")
36
+ it 'should contain the specified attributes' do
37
+ expect(response_body).to have_selector('user > first-name')
38
+ expect(response_body).to have_selector('user > last-name')
43
39
  end
44
-
45
40
  end
46
41
  end
47
42
 
48
43
  describe 'json responses' do
49
-
50
44
  describe 'get all users' do
51
-
52
45
  before(:each) do
53
46
  get :index, format: 'json', params: { api_template: :name_only }
54
47
  end
55
48
 
56
- it "should have a root node named users" do
57
- response_body_json.should have_key("users")
49
+ it 'should have a root node named users' do
50
+ expect(response_body_json).to have_key('users')
58
51
  end
59
52
 
60
- it "should contain all users" do
61
- response_body_json["users"].should be_a(Array)
53
+ it 'should contain all users' do
54
+ expect(response_body_json['users']).to be_a(Array)
62
55
  end
63
56
 
64
- it "should contain the specified attributes" do
65
- response_body_json["users"].first.should have_key("first_name")
66
- response_body_json["users"].first.should have_key("last_name")
57
+ it 'should contain the specified attributes' do
58
+ expect(response_body_json['users'].first).to have_key('first_name')
59
+ expect(response_body_json['users'].first).to have_key('last_name')
67
60
  end
68
61
 
69
- it "should contain the specified values" do
70
- response_body_json["users"].first["first_name"].should eql("Han")
71
- response_body_json["users"].first["last_name"].should eql("Solo")
62
+ it 'should contain the specified values' do
63
+ expect(response_body_json['users'].first['first_name']).to eql('Han')
64
+ expect(response_body_json['users'].first['last_name']).to eql('Solo')
72
65
  end
73
-
74
66
  end
75
67
 
76
68
  describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do
77
-
78
69
  before(:each) do
79
70
  get :index_relation, format: 'json', params: { api_template: :name_only }
80
71
  end
81
72
 
82
- it "should have a root node named users" do
83
- response_body_json.should have_key("users")
73
+ it 'should have a root node named users' do
74
+ expect(response_body_json).to have_key('users')
84
75
  end
85
76
 
86
- it "should contain all users" do
87
- response_body_json["users"].should be_a(Array)
77
+ it 'should contain all users' do
78
+ expect(response_body_json['users']).to be_a(Array)
88
79
  end
89
80
 
90
- it "should contain the specified attributes" do
91
- response_body_json["users"].first.should have_key("first_name")
92
- response_body_json["users"].first.should have_key("last_name")
81
+ it 'should contain the specified attributes' do
82
+ expect(response_body_json['users'].first).to have_key('first_name')
83
+ expect(response_body_json['users'].first).to have_key('last_name')
93
84
  end
94
85
 
95
- it "should contain the specified values" do
96
- response_body_json["users"].first["first_name"].should eql("Han")
97
- response_body_json["users"].first["last_name"].should eql("Solo")
86
+ it 'should contain the specified values' do
87
+ expect(response_body_json['users'].first['first_name']).to eql('Han')
88
+ expect(response_body_json['users'].first['last_name']).to eql('Solo')
98
89
  end
99
-
100
90
  end
101
91
 
102
92
  describe 'get a single user' do
103
-
104
93
  before(:each) do
105
94
  get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
106
95
  end
107
96
 
108
- it "should have a root node named user" do
109
- response_body_json.should have_key("user")
97
+ it 'should have a root node named user' do
98
+ expect(response_body_json).to have_key('user')
110
99
  end
111
100
 
112
- it "should contain the specified attributes" do
113
- response_body_json["user"].should have_key("first_name")
114
- response_body_json["user"].should have_key("last_name")
101
+ it 'should contain the specified attributes' do
102
+ expect(response_body_json['user']).to have_key('first_name')
103
+ expect(response_body_json['user']).to have_key('last_name')
115
104
  end
116
105
 
117
- it "should contain the specified values" do
118
- response_body_json["user"]["first_name"].should eql("Luke")
119
- response_body_json["user"]["last_name"].should eql("Skywalker")
106
+ it 'should contain the specified values' do
107
+ expect(response_body_json['user']['first_name']).to eql('Luke')
108
+ expect(response_body_json['user']['last_name']).to eql('Skywalker')
120
109
  end
121
-
122
110
  end
123
111
 
124
112
  describe 'get a single user with a nil profile' do
125
-
126
113
  before(:each) do
127
114
  Profile.acts_as_api
128
115
  Profile.api_accessible :include_profile do |t|
@@ -133,41 +120,36 @@ shared_examples_for "a controller with ActsAsApi responses" do
133
120
  get :show, format: 'json', params: { api_template: :include_profile, id: @han.id }
134
121
  end
135
122
 
136
- it "should have a root node named user" do
137
- response_body_json.should have_key("user")
123
+ it 'should have a root node named user' do
124
+ expect(response_body_json).to have_key('user')
138
125
  end
139
126
 
140
- it "should contain the specified attributes" do
141
- response_body_json["user"].should have(1).keys
142
- response_body_json["user"].should have_key("profile")
127
+ it 'should contain the specified attributes' do
128
+ expect(response_body_json['user']).to have(1).keys
129
+ expect(response_body_json['user']).to have_key('profile')
143
130
  end
144
131
 
145
- it "should contain the specified values" do
146
- response_body_json["user"]["profile"].should be_nil
132
+ it 'should contain the specified values' do
133
+ expect(response_body_json['user']['profile']).to be_nil
147
134
  end
148
-
149
135
  end
150
136
 
151
137
  describe 'get a user without specifying an api template' do
152
-
153
138
  before(:each) do
154
139
  get :show_default, format: 'json', params: { id: @luke.id }
155
140
  end
156
141
 
157
- it "should respond with HTTP 200" do
158
- response.code.should == "200"
142
+ it 'should respond with HTTP 200' do
143
+ expect(response.code).to eq('200')
159
144
  end
160
145
 
161
- it "should render the model with to_json" do
162
- response.body.should == @luke.to_json
146
+ it 'should render the model with to_json' do
147
+ expect(response.body).to eq(@luke.to_json)
163
148
  end
164
-
165
149
  end
166
-
167
150
  end
168
151
 
169
152
  describe 'Rails 3 default style json responses' do
170
-
171
153
  before(:each) do
172
154
  @org_include_root_in_json_collections = ActsAsApi::Config.include_root_in_json_collections
173
155
  ActsAsApi::Config.include_root_in_json_collections = true
@@ -178,70 +160,64 @@ shared_examples_for "a controller with ActsAsApi responses" do
178
160
  end
179
161
 
180
162
  describe 'get all users' do
181
-
182
163
  before(:each) do
183
164
  get :index, format: 'json', params: { api_template: :name_only }
184
165
  end
185
166
 
186
- it "should have a root node named users" do
187
- response_body_json.should have_key("users")
167
+ it 'should have a root node named users' do
168
+ expect(response_body_json).to have_key('users')
188
169
  end
189
170
 
190
- it "should contain all users" do
191
- response_body_json["users"].should be_a(Array)
171
+ it 'should contain all users' do
172
+ expect(response_body_json['users']).to be_a(Array)
192
173
  end
193
174
 
194
- it "should contain the specified attributes" do
195
- response_body_json["users"].first["user"].should have_key("first_name")
196
- response_body_json["users"].first["user"].should have_key("last_name")
175
+ it 'should contain the specified attributes' do
176
+ expect(response_body_json['users'].first['user']).to have_key('first_name')
177
+ expect(response_body_json['users'].first['user']).to have_key('last_name')
197
178
  end
198
179
 
199
- it "contains the user root nodes" do
200
- response_body_json["users"].collect(&:keys).flatten.uniq.should eql(["user"])
180
+ it 'contains the user root nodes' do
181
+ expect(response_body_json['users'].collect(&:keys).flatten.uniq).to eql(['user'])
201
182
  end
202
183
 
203
- it "should contain the specified values" do
204
- response_body_json["users"].first["user"]["first_name"].should eql("Han")
205
- response_body_json["users"].first["user"]["last_name"].should eql("Solo")
184
+ it 'should contain the specified values' do
185
+ expect(response_body_json['users'].first['user']['first_name']).to eql('Han')
186
+ expect(response_body_json['users'].first['user']['last_name']).to eql('Solo')
206
187
  end
207
-
208
188
  end
209
189
 
210
190
  describe 'get a single user' do
211
-
212
191
  before(:each) do
213
192
  get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
214
193
  end
215
194
 
216
- it "should have a root node named user" do
217
- response_body_json.should have_key("user")
195
+ it 'should have a root node named user' do
196
+ expect(response_body_json).to have_key('user')
218
197
  end
219
198
 
220
- it "should contain the specified attributes" do
221
- response_body_json["user"].should have_key("first_name")
222
- response_body_json["user"].should have_key("last_name")
199
+ it 'should contain the specified attributes' do
200
+ expect(response_body_json['user']).to have_key('first_name')
201
+ expect(response_body_json['user']).to have_key('last_name')
223
202
  end
224
203
 
225
- it "should contain the specified values" do
226
- response_body_json["user"]["first_name"].should eql("Luke")
227
- response_body_json["user"]["last_name"].should eql("Skywalker")
204
+ it 'should contain the specified values' do
205
+ expect(response_body_json['user']['first_name']).to eql('Luke')
206
+ expect(response_body_json['user']['last_name']).to eql('Skywalker')
228
207
  end
229
208
  end
230
-
231
209
  end
232
210
 
233
211
  describe 'jsonp responses with callback' do
234
-
235
- it "should be disabled by default" do
236
- @callback = "mycallback"
212
+ it 'should be disabled by default' do
213
+ @callback = 'mycallback'
237
214
  get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
238
- response_body_jsonp(@callback).should be_nil
215
+ expect(response_body_jsonp(@callback)).to be_nil
239
216
  end
240
217
 
241
- describe "enabled jsonp callbacks" do
242
-
218
+ describe 'enabled jsonp callbacks' do
243
219
  before(:each) do
244
- @callback = "mycallback"
220
+ @callback = 'mycallback'
245
221
 
246
222
  User.acts_as_api do |config|
247
223
  config.allow_jsonp_callback = true
@@ -256,27 +232,23 @@ shared_examples_for "a controller with ActsAsApi responses" do
256
232
  end
257
233
 
258
234
  describe 'get all users' do
259
-
260
235
  before(:each) do
261
236
  get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
262
237
  end
263
238
 
264
- it "should wrap the response in the callback" do
265
- response_body_jsonp(@callback).should_not be_nil
239
+ it 'should wrap the response in the callback' do
240
+ expect(response_body_jsonp(@callback)).not_to be_nil
266
241
  end
267
-
268
242
  end
269
243
 
270
244
  describe 'get a single user' do
271
-
272
245
  before(:each) do
273
246
  get :show, format: 'json', params: { api_template: :name_only, id: @luke.id, callback: @callback }
274
247
  end
275
248
 
276
- it "should wrap the response in the callback" do
277
- response_body_jsonp(@callback).should_not be_nil
249
+ it 'should wrap the response in the callback' do
250
+ expect(response_body_jsonp(@callback)).not_to be_nil
278
251
  end
279
-
280
252
  end
281
253
 
282
254
  describe 'Requesting the JSONP content as JavaScript' do
@@ -284,8 +256,8 @@ shared_examples_for "a controller with ActsAsApi responses" do
284
256
  get :index, format: :json, params: { api_template: :name_only, callback: @callback }
285
257
  end
286
258
 
287
- it "should set the content type to JavaScript" do
288
- response.content_type.should == Mime[:js]
259
+ it 'should set the content type to JavaScript' do
260
+ expect(response.content_type).to eq(Mime[:js])
289
261
  end
290
262
  end
291
263
  end
@@ -306,8 +278,8 @@ shared_examples_for "a controller with ActsAsApi responses" do
306
278
  get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
307
279
  end
308
280
 
309
- its "response has no named root node" do
310
- response_body_json.should be_an(Array)
281
+ it 'response has no named root node' do
282
+ expect(response_body_json).to be_an(Array)
311
283
  end
312
284
  end
313
285
 
@@ -316,32 +288,31 @@ shared_examples_for "a controller with ActsAsApi responses" do
316
288
  get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
317
289
  end
318
290
 
319
- its "response has no named root node" do
320
- response_body_json.should be_a(Hash)
321
- response_body_json.should have_key("first_name")
291
+ it 'response has no named root node' do
292
+ expect(response_body_json).to be_a(Hash)
293
+ expect(response_body_json.keys).to include('first_name')
322
294
  end
323
295
  end
324
296
  end
325
297
 
326
298
  describe 'pass meta information on rendering' do
327
-
328
299
  describe 'get all users' do
329
300
  before(:each) do
330
301
  get :index_meta, format: 'json', params: { api_template: :name_only }
331
302
  end
332
303
 
333
- it "shows model response fields" do
334
- response_body_json.should be_a(Hash)
335
- response_body_json.should have_key("users")
336
- response_body_json["users"].should be_an(Array)
304
+ it 'shows model response fields' do
305
+ expect(response_body_json).to be_a(Hash)
306
+ expect(response_body_json).to have_key('users')
307
+ expect(response_body_json['users']).to be_an(Array)
337
308
  end
338
309
 
339
- it "shows page field" do
340
- response_body_json.should have_key("page")
310
+ it 'shows page field' do
311
+ expect(response_body_json).to have_key('page')
341
312
  end
342
313
 
343
- it "shows total field" do
344
- response_body_json.should have_key("total")
314
+ it 'shows total field' do
315
+ expect(response_body_json).to have_key('total')
345
316
  end
346
317
  end
347
318
 
@@ -350,97 +321,81 @@ shared_examples_for "a controller with ActsAsApi responses" do
350
321
  get :show_meta, format: 'json', params: { api_template: :name_only, id: @luke.id }
351
322
  end
352
323
 
353
- it "shows model response fields" do
354
- response_body_json.should be_a(Hash)
355
- response_body_json.should have_key("user")
324
+ it 'shows model response fields' do
325
+ expect(response_body_json).to be_a(Hash)
326
+ expect(response_body_json).to have_key('user')
356
327
  end
357
328
 
358
- it "shows page field" do
359
- response_body_json.should have_key("page")
329
+ it 'shows page field' do
330
+ expect(response_body_json).to have_key('page')
360
331
  end
361
332
 
362
- it "shows total field" do
363
- response_body_json.should have_key("total")
333
+ it 'shows total field' do
334
+ expect(response_body_json).to have_key('total')
364
335
  end
365
-
366
336
  end
367
337
  end
368
338
 
369
-
370
339
  describe 'api prefix' do
371
-
372
340
  describe 'get single user' do
373
-
374
341
  before(:each) do
375
342
  get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, id: @luke.id }
376
-
377
343
  end
378
344
 
379
- it "should have a root node named user" do
380
- response_body.should have_selector("user")
345
+ it 'should have a root node named user' do
346
+ expect(response_body).to have_selector('user')
381
347
  end
382
348
 
383
- it "should contain the specified attributes" do
384
- response_body.should have_selector("user > prefix")
385
- response_body.should have_selector("user > first-name")
386
- response_body.should have_selector("user > last-name")
349
+ it 'should contain the specified attributes' do
350
+ expect(response_body).to have_selector('user > prefix')
351
+ expect(response_body).to have_selector('user > first-name')
352
+ expect(response_body).to have_selector('user > last-name')
387
353
  end
388
354
 
389
- it "should not contain the specified attributes" do
390
- response_body.should_not have_selector("user > postfix")
355
+ it 'should not contain the specified attributes' do
356
+ expect(response_body).not_to have_selector('user > postfix')
391
357
  end
392
-
393
358
  end
394
-
395
359
  end
396
360
 
397
361
  describe 'api postfix' do
398
-
399
362
  describe 'get single user' do
400
-
401
363
  before(:each) do
402
364
  get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_postfix: :with_postfix, id: @luke.id }
403
365
  end
404
366
 
405
- it "should have a root node named user" do
406
- response_body.should have_selector("user")
367
+ it 'should have a root node named user' do
368
+ expect(response_body).to have_selector('user')
407
369
  end
408
370
 
409
- it "should contain the specified attributes" do
410
- response_body.should have_selector("user > first-name")
411
- response_body.should have_selector("user > last-name")
412
- response_body.should have_selector("user > postfix")
371
+ it 'should contain the specified attributes' do
372
+ expect(response_body).to have_selector('user > first-name')
373
+ expect(response_body).to have_selector('user > last-name')
374
+ expect(response_body).to have_selector('user > postfix')
413
375
  end
414
376
 
415
- it "should not contain the specified attributes" do
416
- response_body.should_not have_selector("user > prefix")
377
+ it 'should not contain the specified attributes' do
378
+ expect(response_body).not_to have_selector('user > prefix')
417
379
  end
418
-
419
380
  end
420
-
421
381
  end
422
382
 
423
383
  describe 'api prefix and api postfix' do
424
-
425
384
  describe 'get single user' do
426
-
427
385
  before(:each) do
428
- get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, api_postfix: :with_postfix, :id => @luke.id }
386
+ get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, api_postfix: :with_postfix, id: @luke.id }
429
387
  end
430
388
 
431
- it "should have a root node named user" do
432
- response_body.should have_selector("user")
389
+ it 'should have a root node named user' do
390
+ expect(response_body).to have_selector('user')
433
391
  end
434
392
 
435
- it "should contain the specified attributes" do
436
- response_body.should have_selector("user > prefix")
437
- response_body.should have_selector("user > first-name")
438
- response_body.should have_selector("user > last-name")
439
- response_body.should have_selector("user > postfix")
393
+ it 'should contain the specified attributes' do
394
+ expect(response_body).to have_selector('user > prefix')
395
+ expect(response_body).to have_selector('user > first-name')
396
+ expect(response_body).to have_selector('user > last-name')
397
+ expect(response_body).to have_selector('user > postfix')
440
398
  end
441
-
442
399
  end
443
-
444
400
  end
445
-
446
401
  end