rabl 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +0 -1
  5. data/fixtures/ashared/NOTES +10 -0
  6. data/fixtures/ashared/views_rails_6/layouts/application.html.erb +13 -0
  7. data/fixtures/ashared/views_rails_6/posts/_show_footer_script.js.erb +1 -0
  8. data/fixtures/ashared/views_rails_6/posts/date.rabl +3 -0
  9. data/fixtures/ashared/views_rails_6/posts/index.html.erb +3 -0
  10. data/fixtures/ashared/views_rails_6/posts/index.rabl +12 -0
  11. data/fixtures/ashared/views_rails_6/posts/renderer.rabl +8 -0
  12. data/fixtures/ashared/views_rails_6/posts/renderer_partial.rabl +4 -0
  13. data/fixtures/ashared/views_rails_6/posts/show.html.erb +3 -0
  14. data/fixtures/ashared/views_rails_6/posts/show.rabl +25 -0
  15. data/fixtures/ashared/views_rails_6/posts/show.rabl_test_v1.rabl +7 -0
  16. data/fixtures/ashared/views_rails_6/users/index.json.rabl +3 -0
  17. data/fixtures/ashared/views_rails_6/users/phone_number.json.rabl +8 -0
  18. data/fixtures/ashared/views_rails_6/users/phone_number.xml.rabl +1 -0
  19. data/fixtures/ashared/views_rails_6/users/show.json.rabl +16 -0
  20. data/fixtures/ashared/views_rails_6/users/show.rabl_test_v1.rabl +3 -0
  21. data/fixtures/padrino_test/app/views +1 -1
  22. data/fixtures/padrino_test/db/migrate +1 -1
  23. data/fixtures/padrino_test/models +1 -1
  24. data/fixtures/padrino_test/test/app/controllers/posts_controller_test.rb +1 -1
  25. data/fixtures/padrino_test/test/app/controllers/users_controller_test.rb +1 -1
  26. data/fixtures/rails2/app/models +1 -1
  27. data/fixtures/rails2/app/views +1 -1
  28. data/fixtures/rails2/db/migrate +1 -1
  29. data/fixtures/rails2/test/functionals/posts_controller_test.rb +1 -1
  30. data/fixtures/rails2/test/functionals/users_controller_test.rb +1 -1
  31. data/fixtures/rails3/app/models +1 -1
  32. data/fixtures/rails3/app/views +1 -1
  33. data/fixtures/rails3/db/migrate +1 -1
  34. data/fixtures/rails3/test/functional/posts_controller_test.rb +1 -1
  35. data/fixtures/rails3/test/functional/users_controller_test.rb +1 -1
  36. data/fixtures/rails3_2/app/models +1 -1
  37. data/fixtures/rails3_2/app/views +1 -1
  38. data/fixtures/rails3_2/db/migrate +1 -1
  39. data/fixtures/rails3_2/test/functional/posts_controller_test.rb +1 -1
  40. data/fixtures/rails3_2/test/functional/users_controller_test.rb +1 -1
  41. data/fixtures/rails4/app/models +1 -1
  42. data/fixtures/rails4/app/views +1 -1
  43. data/fixtures/rails4/db/migrate +1 -1
  44. data/fixtures/rails4/test/functional/posts_controller_test.rb +1 -1
  45. data/fixtures/rails4/test/functional/users_controller_test.rb +1 -1
  46. data/fixtures/rails5/app/controllers/posts_controller.rb +1 -1
  47. data/fixtures/rails5/app/controllers/users_controller.rb +1 -1
  48. data/fixtures/rails5/app/helpers +1 -1
  49. data/fixtures/rails5/app/models +1 -1
  50. data/fixtures/rails5/app/views +1 -1
  51. data/fixtures/rails5/db/migrate +1 -1
  52. data/fixtures/rails5/test/functional/posts_controller_test.rb +1 -1
  53. data/fixtures/rails5/test/functional/users_controller_test.rb +1 -1
  54. data/fixtures/rails5_api/app/controllers/posts_controller.rb +1 -1
  55. data/fixtures/rails5_api/app/controllers/users_controller.rb +1 -1
  56. data/fixtures/rails5_api/app/helpers +1 -1
  57. data/fixtures/rails5_api/app/models +1 -1
  58. data/fixtures/rails5_api/app/views +1 -1
  59. data/fixtures/rails5_api/db/migrate +1 -1
  60. data/fixtures/rails5_api/test/functional/posts_controller_test.rb +1 -1
  61. data/fixtures/rails5_api/test/functional/users_controller_test.rb +1 -1
  62. data/fixtures/rails6/.gitignore +35 -0
  63. data/fixtures/rails6/Gemfile +58 -0
  64. data/fixtures/rails6/README.md +24 -0
  65. data/fixtures/rails6/Rakefile +14 -0
  66. data/fixtures/rails6/app/assets/config/manifest.js +2 -0
  67. data/fixtures/rails6/app/assets/images/.keep +0 -0
  68. data/fixtures/rails6/app/assets/stylesheets/application.css +15 -0
  69. data/fixtures/rails6/app/channels/application_cable/channel.rb +4 -0
  70. data/fixtures/rails6/app/channels/application_cable/connection.rb +4 -0
  71. data/fixtures/rails6/app/controllers/application_controller.rb +2 -0
  72. data/fixtures/rails6/app/controllers/concerns/.keep +0 -0
  73. data/fixtures/rails6/app/controllers/posts_controller.rb +17 -0
  74. data/fixtures/rails6/app/controllers/users_controller.rb +11 -0
  75. data/fixtures/rails6/app/helpers +1 -0
  76. data/fixtures/rails6/app/javascript/channels/consumer.js +6 -0
  77. data/fixtures/rails6/app/javascript/channels/index.js +5 -0
  78. data/fixtures/rails6/app/javascript/packs/application.js +17 -0
  79. data/fixtures/rails6/app/jobs/application_job.rb +7 -0
  80. data/fixtures/rails6/app/mailers/application_mailer.rb +4 -0
  81. data/fixtures/rails6/app/models +1 -0
  82. data/fixtures/rails6/app/views +1 -0
  83. data/fixtures/rails6/babel.config.js +72 -0
  84. data/fixtures/rails6/bin/bundle +105 -0
  85. data/fixtures/rails6/bin/rails +9 -0
  86. data/fixtures/rails6/bin/rake +9 -0
  87. data/fixtures/rails6/bin/setup +36 -0
  88. data/fixtures/rails6/bin/spring +17 -0
  89. data/fixtures/rails6/bin/webpack +19 -0
  90. data/fixtures/rails6/bin/webpack-dev-server +19 -0
  91. data/fixtures/rails6/bin/yarn +11 -0
  92. data/fixtures/rails6/config.ru +5 -0
  93. data/fixtures/rails6/config/application.rb +19 -0
  94. data/fixtures/rails6/config/boot.rb +4 -0
  95. data/fixtures/rails6/config/cable.yml +10 -0
  96. data/fixtures/rails6/config/credentials.yml.enc +1 -0
  97. data/fixtures/rails6/config/database.yml +25 -0
  98. data/fixtures/rails6/config/environment.rb +5 -0
  99. data/fixtures/rails6/config/environments/development.rb +62 -0
  100. data/fixtures/rails6/config/environments/production.rb +112 -0
  101. data/fixtures/rails6/config/environments/test.rb +48 -0
  102. data/fixtures/rails6/config/initializers/application_controller_renderer.rb +8 -0
  103. data/fixtures/rails6/config/initializers/assets.rb +14 -0
  104. data/fixtures/rails6/config/initializers/backtrace_silencers.rb +7 -0
  105. data/fixtures/rails6/config/initializers/content_security_policy.rb +27 -0
  106. data/fixtures/rails6/config/initializers/cookies_serializer.rb +5 -0
  107. data/fixtures/rails6/config/initializers/filter_parameter_logging.rb +4 -0
  108. data/fixtures/rails6/config/initializers/inflections.rb +16 -0
  109. data/fixtures/rails6/config/initializers/mime_types.rb +6 -0
  110. data/fixtures/rails6/config/initializers/wrap_parameters.rb +14 -0
  111. data/fixtures/rails6/config/locales/en.yml +33 -0
  112. data/fixtures/rails6/config/puma.rb +35 -0
  113. data/fixtures/rails6/config/routes.rb +8 -0
  114. data/fixtures/rails6/config/spring.rb +6 -0
  115. data/fixtures/rails6/config/storage.yml +34 -0
  116. data/fixtures/rails6/config/webpack/development.js +5 -0
  117. data/fixtures/rails6/config/webpack/environment.js +3 -0
  118. data/fixtures/rails6/config/webpack/production.js +5 -0
  119. data/fixtures/rails6/config/webpack/test.js +5 -0
  120. data/fixtures/rails6/config/webpacker.yml +95 -0
  121. data/fixtures/rails6/db/migrate/20111002092016_create_users.rb +11 -0
  122. data/fixtures/rails6/db/migrate/20111002092019_create_posts.rb +10 -0
  123. data/fixtures/rails6/db/migrate/20111002092024_create_phone_numbers.rb +12 -0
  124. data/fixtures/rails6/db/schema.rb +41 -0
  125. data/fixtures/rails6/db/seeds.rb +7 -0
  126. data/fixtures/rails6/lib/assets/.keep +0 -0
  127. data/fixtures/rails6/lib/tasks/.keep +0 -0
  128. data/fixtures/rails6/log/.keep +0 -0
  129. data/fixtures/rails6/package.json +15 -0
  130. data/fixtures/rails6/postcss.config.js +12 -0
  131. data/fixtures/rails6/public/404.html +67 -0
  132. data/fixtures/rails6/public/422.html +67 -0
  133. data/fixtures/rails6/public/500.html +66 -0
  134. data/fixtures/rails6/public/apple-touch-icon-precomposed.png +0 -0
  135. data/fixtures/rails6/public/apple-touch-icon.png +0 -0
  136. data/fixtures/rails6/public/favicon.ico +0 -0
  137. data/fixtures/rails6/public/robots.txt +1 -0
  138. data/fixtures/rails6/storage/.keep +0 -0
  139. data/fixtures/rails6/test/application_system_test_case.rb +5 -0
  140. data/fixtures/rails6/test/channels/application_cable/connection_test.rb +11 -0
  141. data/fixtures/rails6/test/controllers/.keep +0 -0
  142. data/fixtures/rails6/test/fixtures/.keep +0 -0
  143. data/fixtures/rails6/test/fixtures/files/.keep +0 -0
  144. data/fixtures/rails6/test/functional/posts_controller_test.rb +1 -0
  145. data/fixtures/rails6/test/functional/users_controller_test.rb +1 -0
  146. data/fixtures/rails6/test/helpers/.keep +0 -0
  147. data/fixtures/rails6/test/integration/.keep +0 -0
  148. data/fixtures/rails6/test/mailers/.keep +0 -0
  149. data/fixtures/rails6/test/models/.keep +0 -0
  150. data/fixtures/rails6/test/system/.keep +0 -0
  151. data/fixtures/rails6/test/test_helper.rb +27 -0
  152. data/fixtures/rails6/tmp/.keep +0 -0
  153. data/fixtures/rails6/vendor/.keep +0 -0
  154. data/fixtures/rails6/yarn.lock +7201 -0
  155. data/fixtures/sinatra_test/db/migrate +1 -1
  156. data/fixtures/sinatra_test/models +1 -1
  157. data/fixtures/sinatra_test/test/functional/posts_controller_test.rb +1 -1
  158. data/fixtures/sinatra_test/test/functional/users_controller_test.rb +1 -1
  159. data/fixtures/sinatra_test/views +1 -1
  160. data/lib/rabl.rb +3 -3
  161. data/lib/rabl/engine.rb +4 -2
  162. data/lib/rabl/railtie.rb +1 -1
  163. data/lib/rabl/template.rb +21 -1
  164. data/lib/rabl/version.rb +1 -1
  165. data/rabl.gemspec +0 -2
  166. data/test/integration/rails6/posts_controller_test.rb +185 -0
  167. data/test/integration/rails6/users_controller_test.rb +87 -0
  168. metadata +113 -4
@@ -1 +1 @@
1
- fixtures/sinatra_test/db/../../ashared/migrate
1
+ ../../ashared/migrate
@@ -1 +1 @@
1
- fixtures/sinatra_test/../ashared/models
1
+ ../ashared/models
@@ -1 +1 @@
1
- fixtures/sinatra_test/test/functional/../../../../test/integration/posts_controller_test.rb
1
+ ../../../../test/integration/posts_controller_test.rb
@@ -1 +1 @@
1
- fixtures/sinatra_test/test/functional/../../../../test/integration/users_controller_test.rb
1
+ ../../../../test/integration/users_controller_test.rb
@@ -1 +1 @@
1
- fixtures/sinatra_test/../ashared/views/
1
+ ../ashared/views/
data/lib/rabl.rb CHANGED
@@ -17,9 +17,9 @@ require 'rabl/renderer'
17
17
  require 'rabl/cache_engine'
18
18
 
19
19
  if defined?(Rails) && Rails.respond_to?(:version)
20
- require 'rabl/tracker' if Rails.version =~ /^[45]/
21
- require 'rabl/digestor' if Rails.version =~ /^[45]/
22
- require 'rabl/railtie' if Rails.version =~ /^[345]/
20
+ require 'rabl/tracker' if Rails.version =~ /^[456]/
21
+ require 'rabl/digestor' if Rails.version =~ /^[456]/
22
+ require 'rabl/railtie' if Rails.version =~ /^[3456]/
23
23
  end
24
24
 
25
25
  # Rabl.register!
data/lib/rabl/engine.rb CHANGED
@@ -61,7 +61,9 @@ module Rabl
61
61
  template = @_options[:template] || @virtual_path
62
62
 
63
63
  digest =
64
- if Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
64
+ if Rails.version.to_s =~ /^[6]/
65
+ Digestor.digest(name: template, finder: lookup_context, format: :rabl)
66
+ elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
65
67
  Digestor.digest(:name => template, :finder => lookup_context)
66
68
  else
67
69
  Digestor.digest(template, :rabl, lookup_context)
@@ -390,7 +392,7 @@ module Rabl
390
392
  end
391
393
 
392
394
  def digestor_available?
393
- defined?(Rails) && Rails.version =~ /^[45]/
395
+ defined?(Rails) && Rails.version =~ /^[456]/
394
396
  end
395
397
 
396
398
  def set_instance_variables!(context_scope, locals)
data/lib/rabl/railtie.rb CHANGED
@@ -22,7 +22,7 @@ module Rabl
22
22
  Rabl.register!
23
23
 
24
24
  # Inject dependency tracker for :rabl
25
- if Rails.version =~ /^[45]/
25
+ if Rails.version =~ /^[456]/
26
26
  require 'action_view/dependency_tracker'
27
27
  ActionView::DependencyTracker.register_tracker :rabl, Rabl::Tracker
28
28
  end
data/lib/rabl/template.rb CHANGED
@@ -40,7 +40,7 @@ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rai
40
40
  ActionView::Template.register_template_handler :rabl, ActionView::TemplateHandlers::RablHandler
41
41
  end
42
42
 
43
- # Rails 3.X / 4.X Template
43
+ # Rails 3.X / 4.X / 5.X Template
44
44
  if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[345]/
45
45
  module ActionView
46
46
  module Template::Handlers
@@ -61,3 +61,23 @@ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rai
61
61
 
62
62
  ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl
63
63
  end
64
+
65
+ # Rails 6.X Template
66
+ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[6]/
67
+ module ActionView
68
+ module Template::Handlers
69
+ class Rabl
70
+ class_attribute :default_format
71
+ self.default_format = :json
72
+
73
+ def self.call(template, source)
74
+ %{ ::Rabl::Engine.new(#{source.inspect}).
75
+ apply(self, assigns.merge(local_assigns)).
76
+ render }
77
+ end # call
78
+ end # rabl class
79
+ end # handlers
80
+ end
81
+
82
+ ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl
83
+ end
data/lib/rabl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.14.1"
2
+ VERSION = "0.14.2"
3
3
  end
data/rabl.gemspec CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{General ruby templating with json, bson, xml and msgpack support}
14
14
  s.license = 'MIT'
15
15
 
16
- s.rubyforge_project = "rabl"
17
-
18
16
  s.files = `git ls-files`.split("\n")
19
17
  s.require_paths = ["lib"]
20
18
 
@@ -0,0 +1,185 @@
1
+ # Lives in <rabl>/test/integration/posts_controller_test.rb
2
+ # Symlinked to fixture applications
3
+
4
+ begin # Padrino
5
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
6
+ rescue LoadError # Rails
7
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
8
+ end
9
+
10
+ require 'rexml/document'
11
+
12
+ context "PostsController" do
13
+ helper(:json_output) { JSON.parse(last_response.body) }
14
+
15
+ setup do
16
+ create_users!
17
+ Post.delete_all
18
+ @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id)
19
+ @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id)
20
+ @post3 = Post.create(:title => "Kaz", :body => "<script>alert('xss & test');</script>", :user_id => @user3.id)
21
+ @posts = [@post1, @post2, @post3]
22
+ end
23
+
24
+ context "for index action" do
25
+ setup do
26
+ get "/posts", format: :json
27
+ end
28
+
29
+ # Attributes (regular)
30
+ asserts("contains post titles") do
31
+ json_output['articles'].map { |o| o["article"]["title"] }
32
+ end.equals { @posts.map(&:title) }
33
+
34
+ asserts("contains post bodies") do
35
+ json_output['articles'].map { |o| o["article"]["body"] }
36
+ end.equals { @posts.map(&:body) }
37
+
38
+ # Attributes (custom name)
39
+ asserts("contains post posted_at") do
40
+ json_output['articles'].map { |o| o["article"]["posted_at"] }
41
+ end.equals { @posts.map(&:created_at).map{ |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } }
42
+
43
+ # Child
44
+ asserts("contains post user child username") do
45
+ json_output['articles'].map { |o| o["article"]["user"]["username"] }
46
+ end.equals { @posts.map(&:user).map(&:username) }
47
+
48
+ asserts("contains post user child role") do
49
+ json_output['articles'].map { |o| o["article"]["user"]["role"] }
50
+ end.equals { ["normal", "normal", "admin"] }
51
+
52
+ # Child Numbers of the Child User
53
+ asserts("contains post user child numbers") do
54
+ json_output['articles'].map { |o| o["article"]["user"]["pnumbers"][0]["pnumber"]["formatted"] }
55
+ end.equals { @posts.map(&:user).map(&:phone_numbers).map(&:first).map(&:formatted) }
56
+
57
+ # Glue (username to article)
58
+ asserts("contains glued usernames") do
59
+ json_output['articles'].map { |o| o["article"]["author_name"] }
60
+ end.equals { @posts.map(&:user).map(&:username) }
61
+
62
+ # Conditional Child (admin)
63
+ asserts("contains admin child only for admins") do
64
+ json_output['articles'].map { |o| o["article"]["admin"]["username"] if o["article"].has_key?("admin") }.compact
65
+ end.equals { [@user3.username] }
66
+
67
+ # Conditional Node (created_by_admin)
68
+ asserts("contains created_by_admin node for admins") do
69
+ json_output['articles'].last['article']['created_by_admin']
70
+ end.equals { true }
71
+
72
+ denies("contains no created_by_admin node for non-admins") do
73
+ json_output['articles'].first['article']
74
+ end.includes(:created_by_admin)
75
+ end # index action, json
76
+
77
+ context "escaping output in index action" do
78
+ context "for first post" do
79
+ setup do
80
+ Rabl.configuration.escape_all_output = true
81
+ get "/posts/#{@post1.id}", format: :json
82
+ json_output['post']
83
+ end
84
+
85
+ # Attributes (regular)
86
+ asserts("contains post title") { topic['title'] }.equals { @post1.title }
87
+ asserts("contains post body") { topic['body'] }.equals { @post1.body }
88
+ end
89
+
90
+ context "for third post with script tags" do
91
+ setup do
92
+ Rabl.configuration.escape_all_output = true
93
+ get "/posts/#{@post3.id}", format: :json
94
+ json_output['post']
95
+ end
96
+
97
+ # Attributes (regular)
98
+ asserts("contains post title") { topic['title'] }.equals { @post3.title }
99
+ asserts("contains escaped post body") { topic['body'] }.equals { ERB::Util.h(@post3.body) }
100
+ end
101
+ end # escaping output
102
+
103
+ context "for show action" do
104
+ setup do
105
+ get "/posts/#{@post1.id}", format: :json
106
+ json_output['post']
107
+ end
108
+
109
+ # Attributes (regular)
110
+ asserts("contains post title") { topic['title'] }.equals { @post1.title }
111
+ asserts("contains post body") { topic['body'] }.equals { @post1.body }
112
+
113
+ # Attributes (custom name)
114
+ asserts("contains post posted_at") { topic['posted_at'] }.equals { @post1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") }
115
+
116
+ # Child
117
+ asserts("contains post user child username") { topic["user"]["username"] }.equals { @post1.user.username }
118
+ asserts("contains post user child role") { topic["user"]["role"] }.equals { "normal" }
119
+
120
+ # Child Numbers of the Child User
121
+ asserts("contains post user child numbers") do
122
+ topic["user"]["pnumbers"][0]["pnumber"]["formatted"]
123
+ end.equals { @post1.user.phone_numbers[0].formatted }
124
+
125
+ # Glue (username to article)
126
+ asserts("contains glued username") { topic["author_name"] }.equals { @post1.user.username }
127
+
128
+ # Non-ORM Date Node Partial
129
+ context "for date node" do
130
+ setup { json_output['post']['created_date'] }
131
+ asserts("contains date partial with day") { topic['day'] }.equals { @post1.created_at.day }
132
+ asserts("contains date partial with hour") { topic['hour'] }.equals { @post1.created_at.hour }
133
+ asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 }
134
+ end # date node
135
+
136
+ asserts("contains helper action") { topic["foo"] }.equals { "BAR!" }
137
+ denies("contains helper action") { topic["created_at_in_words"] }.nil
138
+
139
+ asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] }
140
+ end # show action, json
141
+
142
+ context "renderer" do
143
+ setup do
144
+ mock(ActionController::Base).perform_caching.any_number_of_times { true }
145
+ get "/posts/#{@post1.id}/renderer"
146
+ json_output['post']
147
+ end
148
+
149
+ # Attributes (regular)
150
+ asserts("contains post title") { topic['title'] }.equals { @post1.title }
151
+ asserts("contains post body") { topic['body'] }.equals { @post1.body }
152
+
153
+ # Attributes (partial)
154
+ asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title }
155
+ asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body }
156
+ end # renderer action, json
157
+
158
+ # HTML isn't supported in API mode
159
+ unless Rails.application.config.api_only
160
+ context "for index action rendering JSON within HTML" do
161
+ setup do
162
+ get "/posts", format: :html
163
+ end
164
+
165
+ asserts(:body).includes { "<html>" }
166
+ end # index action, html
167
+
168
+ context "for show action rendering JSON within HTML" do
169
+ setup do
170
+ get "/posts/#{@post1.id}", format: :html
171
+ end
172
+
173
+ asserts(:body).includes { "<html>" }
174
+ end # show action, html
175
+ end
176
+
177
+ context "mime_type" do
178
+ setup do
179
+ get "/posts/#{@post1.id}", format: :rabl_test_v1
180
+ end
181
+
182
+ asserts("contains post title") { json_output['post']['title_v1'] }.equals { @post1.title }
183
+ asserts("contains username") { json_output['post']['user']['username_v1'] }.equals { @post1.user.username }
184
+ end
185
+ end
@@ -0,0 +1,87 @@
1
+ # Lives in <rabl>/test/integration/users_controller_test.rb
2
+ # Symlinked to fixture applications
3
+
4
+ begin # Sinatra
5
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
6
+ rescue LoadError # Rails
7
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
8
+ end
9
+
10
+ context "UsersController" do
11
+ helper(:json_output) { JSON.parse(last_response.body) }
12
+
13
+ setup do
14
+ create_users!
15
+ end
16
+
17
+ context "for index action" do
18
+ # Tests `collection @users` extending from 'show' template
19
+
20
+ setup do
21
+ get "/users", format: :json
22
+ end
23
+
24
+ # Attributes (regular)
25
+ asserts("contains user usernames") do
26
+ json_output.map { |u| u["user"]["username"] }
27
+ end.equals { @users.map(&:username) }
28
+ asserts("contains email") do
29
+ json_output.map { |u| u["user"]["email"] }
30
+ end.equals { @users.map(&:email) }
31
+ asserts("contains location") do
32
+ json_output.map { |u| u["user"]["location"] }
33
+ end.equals { @users.map(&:location) }
34
+
35
+ # Attributes (custom name)
36
+ asserts("contains registered_at") do
37
+ json_output.map { |u| u["user"]["registered_at"] }
38
+ end.equals { @users.map(&:created_at).map { |t| t.strftime("%Y-%m-%d %H:%M:%S %Z") } }
39
+
40
+ # Node (renders based on attribute)
41
+ asserts("contains role") do
42
+ json_output.map { |u| u["user"]["role"] }
43
+ end.equals ['normal', 'normal', 'admin']
44
+
45
+ # Child (custom collection name)
46
+ asserts("contains formatted phone numbers") do
47
+ json_output.map { |u| u["user"]["pnumbers"].map { |n| n["pnumber"]["formatted"] } }
48
+ end.equals { @users.map { |u| u.phone_numbers.map(&:formatted) } }
49
+
50
+ # Node (renders collection partial)
51
+ asserts("contains reversed node numbers") do
52
+ json_output.map { |u| u["user"]["node_numbers"].map { |n| n["reversed"] } }
53
+ end.equals { @users.map { |u| u.phone_numbers.map(&:formatted).map(&:reverse) } }
54
+ end # index
55
+
56
+ context "for show action" do
57
+ # Tests `object :user => :person` custom parent node name
58
+ setup do
59
+ get "/users/#{@user1.id}", format: :json
60
+ end
61
+
62
+ # Attributes (regular)
63
+ asserts("contains username") { json_output["person"]["username"] }.equals { @user1.username }
64
+ asserts("contains email") { json_output["person"]["email"] }.equals { @user1.email }
65
+ asserts("contains location") { json_output["person"]["location"] }.equals { @user1.location }
66
+ # Attributes (custom name)
67
+ asserts("contains registered_at") { json_output["person"]["registered_at"] }.equals { @user1.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") }
68
+ # Node (renders based on attribute)
69
+ asserts("contains role node") { json_output["person"]["role"] }.equals "normal"
70
+
71
+ # Child (custom collection name)
72
+ asserts("contains first phone number") {
73
+ json_output["person"]["pnumbers"][0]["pnumber"]["formatted"]
74
+ }.equals { @user1.phone_numbers[0].formatted }
75
+ asserts("contains second phone number") {
76
+ json_output["person"]["pnumbers"][1]["pnumber"]["formatted"]
77
+ }.equals { @user1.phone_numbers[1].formatted }
78
+
79
+ # Node (renders collection partial)
80
+ asserts("contains first node number") {
81
+ json_output["person"]["node_numbers"][0]["formatted"]
82
+ }.equals { @user1.phone_numbers[0].formatted }
83
+ asserts("contains second node number") {
84
+ json_output["person"]["node_numbers"][1]["formatted"]
85
+ }.equals { @user1.phone_numbers[1].formatted }
86
+ end # show
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-28 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -188,6 +188,21 @@ files:
188
188
  - fixtures/ashared/views_rails_3/users/phone_number.xml.rabl
189
189
  - fixtures/ashared/views_rails_3/users/show.json.rabl
190
190
  - fixtures/ashared/views_rails_3/users/show.rabl_test_v1.rabl
191
+ - fixtures/ashared/views_rails_6/layouts/application.html.erb
192
+ - fixtures/ashared/views_rails_6/posts/_show_footer_script.js.erb
193
+ - fixtures/ashared/views_rails_6/posts/date.rabl
194
+ - fixtures/ashared/views_rails_6/posts/index.html.erb
195
+ - fixtures/ashared/views_rails_6/posts/index.rabl
196
+ - fixtures/ashared/views_rails_6/posts/renderer.rabl
197
+ - fixtures/ashared/views_rails_6/posts/renderer_partial.rabl
198
+ - fixtures/ashared/views_rails_6/posts/show.html.erb
199
+ - fixtures/ashared/views_rails_6/posts/show.rabl
200
+ - fixtures/ashared/views_rails_6/posts/show.rabl_test_v1.rabl
201
+ - fixtures/ashared/views_rails_6/users/index.json.rabl
202
+ - fixtures/ashared/views_rails_6/users/phone_number.json.rabl
203
+ - fixtures/ashared/views_rails_6/users/phone_number.xml.rabl
204
+ - fixtures/ashared/views_rails_6/users/show.json.rabl
205
+ - fixtures/ashared/views_rails_6/users/show.rabl_test_v1.rabl
191
206
  - fixtures/padrino_test/.components
192
207
  - fixtures/padrino_test/.gitignore
193
208
  - fixtures/padrino_test/Gemfile
@@ -556,6 +571,99 @@ files:
556
571
  - fixtures/rails5_api/test/models/.keep
557
572
  - fixtures/rails5_api/test/test_helper.rb
558
573
  - fixtures/rails5_api/tmp/.keep
574
+ - fixtures/rails6/.gitignore
575
+ - fixtures/rails6/Gemfile
576
+ - fixtures/rails6/README.md
577
+ - fixtures/rails6/Rakefile
578
+ - fixtures/rails6/app/assets/config/manifest.js
579
+ - fixtures/rails6/app/assets/images/.keep
580
+ - fixtures/rails6/app/assets/stylesheets/application.css
581
+ - fixtures/rails6/app/channels/application_cable/channel.rb
582
+ - fixtures/rails6/app/channels/application_cable/connection.rb
583
+ - fixtures/rails6/app/controllers/application_controller.rb
584
+ - fixtures/rails6/app/controllers/concerns/.keep
585
+ - fixtures/rails6/app/controllers/posts_controller.rb
586
+ - fixtures/rails6/app/controllers/users_controller.rb
587
+ - fixtures/rails6/app/helpers
588
+ - fixtures/rails6/app/javascript/channels/consumer.js
589
+ - fixtures/rails6/app/javascript/channels/index.js
590
+ - fixtures/rails6/app/javascript/packs/application.js
591
+ - fixtures/rails6/app/jobs/application_job.rb
592
+ - fixtures/rails6/app/mailers/application_mailer.rb
593
+ - fixtures/rails6/app/models
594
+ - fixtures/rails6/app/views
595
+ - fixtures/rails6/babel.config.js
596
+ - fixtures/rails6/bin/bundle
597
+ - fixtures/rails6/bin/rails
598
+ - fixtures/rails6/bin/rake
599
+ - fixtures/rails6/bin/setup
600
+ - fixtures/rails6/bin/spring
601
+ - fixtures/rails6/bin/webpack
602
+ - fixtures/rails6/bin/webpack-dev-server
603
+ - fixtures/rails6/bin/yarn
604
+ - fixtures/rails6/config.ru
605
+ - fixtures/rails6/config/application.rb
606
+ - fixtures/rails6/config/boot.rb
607
+ - fixtures/rails6/config/cable.yml
608
+ - fixtures/rails6/config/credentials.yml.enc
609
+ - fixtures/rails6/config/database.yml
610
+ - fixtures/rails6/config/environment.rb
611
+ - fixtures/rails6/config/environments/development.rb
612
+ - fixtures/rails6/config/environments/production.rb
613
+ - fixtures/rails6/config/environments/test.rb
614
+ - fixtures/rails6/config/initializers/application_controller_renderer.rb
615
+ - fixtures/rails6/config/initializers/assets.rb
616
+ - fixtures/rails6/config/initializers/backtrace_silencers.rb
617
+ - fixtures/rails6/config/initializers/content_security_policy.rb
618
+ - fixtures/rails6/config/initializers/cookies_serializer.rb
619
+ - fixtures/rails6/config/initializers/filter_parameter_logging.rb
620
+ - fixtures/rails6/config/initializers/inflections.rb
621
+ - fixtures/rails6/config/initializers/mime_types.rb
622
+ - fixtures/rails6/config/initializers/wrap_parameters.rb
623
+ - fixtures/rails6/config/locales/en.yml
624
+ - fixtures/rails6/config/puma.rb
625
+ - fixtures/rails6/config/routes.rb
626
+ - fixtures/rails6/config/spring.rb
627
+ - fixtures/rails6/config/storage.yml
628
+ - fixtures/rails6/config/webpack/development.js
629
+ - fixtures/rails6/config/webpack/environment.js
630
+ - fixtures/rails6/config/webpack/production.js
631
+ - fixtures/rails6/config/webpack/test.js
632
+ - fixtures/rails6/config/webpacker.yml
633
+ - fixtures/rails6/db/migrate/20111002092016_create_users.rb
634
+ - fixtures/rails6/db/migrate/20111002092019_create_posts.rb
635
+ - fixtures/rails6/db/migrate/20111002092024_create_phone_numbers.rb
636
+ - fixtures/rails6/db/schema.rb
637
+ - fixtures/rails6/db/seeds.rb
638
+ - fixtures/rails6/lib/assets/.keep
639
+ - fixtures/rails6/lib/tasks/.keep
640
+ - fixtures/rails6/log/.keep
641
+ - fixtures/rails6/package.json
642
+ - fixtures/rails6/postcss.config.js
643
+ - fixtures/rails6/public/404.html
644
+ - fixtures/rails6/public/422.html
645
+ - fixtures/rails6/public/500.html
646
+ - fixtures/rails6/public/apple-touch-icon-precomposed.png
647
+ - fixtures/rails6/public/apple-touch-icon.png
648
+ - fixtures/rails6/public/favicon.ico
649
+ - fixtures/rails6/public/robots.txt
650
+ - fixtures/rails6/storage/.keep
651
+ - fixtures/rails6/test/application_system_test_case.rb
652
+ - fixtures/rails6/test/channels/application_cable/connection_test.rb
653
+ - fixtures/rails6/test/controllers/.keep
654
+ - fixtures/rails6/test/fixtures/.keep
655
+ - fixtures/rails6/test/fixtures/files/.keep
656
+ - fixtures/rails6/test/functional/posts_controller_test.rb
657
+ - fixtures/rails6/test/functional/users_controller_test.rb
658
+ - fixtures/rails6/test/helpers/.keep
659
+ - fixtures/rails6/test/integration/.keep
660
+ - fixtures/rails6/test/mailers/.keep
661
+ - fixtures/rails6/test/models/.keep
662
+ - fixtures/rails6/test/system/.keep
663
+ - fixtures/rails6/test/test_helper.rb
664
+ - fixtures/rails6/tmp/.keep
665
+ - fixtures/rails6/vendor/.keep
666
+ - fixtures/rails6/yarn.lock
559
667
  - fixtures/sinatra_test/Gemfile
560
668
  - fixtures/sinatra_test/Rakefile
561
669
  - fixtures/sinatra_test/app.rb
@@ -598,6 +706,8 @@ files:
598
706
  - test/integration/rails4/users_controller_test.rb
599
707
  - test/integration/rails5/posts_controller_test.rb
600
708
  - test/integration/rails5/users_controller_test.rb
709
+ - test/integration/rails6/posts_controller_test.rb
710
+ - test/integration/rails6/users_controller_test.rb
601
711
  - test/integration/test_init.rb
602
712
  - test/integration/users_controller_test.rb
603
713
  - test/models/ormless.rb
@@ -630,8 +740,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
630
740
  - !ruby/object:Gem::Version
631
741
  version: '0'
632
742
  requirements: []
633
- rubyforge_project: rabl
634
- rubygems_version: 2.6.7
743
+ rubygems_version: 3.0.3
635
744
  signing_key:
636
745
  specification_version: 4
637
746
  summary: General ruby templating with json, bson, xml and msgpack support