From: Go MAEDA Date: Sat, 3 Nov 2018 08:11:22 +0000 (+0000) Subject: Removes request and response accessors from Structure class (#28564). X-Git-Tag: 4.0.0~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c99d5071328fe0df594d153f7dcb3736b29667b;p=redmine.git Removes request and response accessors from Structure class (#28564). Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@17617 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/views/builders/json.rb b/lib/redmine/views/builders/json.rb index 97ac1250a..299fd9255 100644 --- a/lib/redmine/views/builders/json.rb +++ b/lib/redmine/views/builders/json.rb @@ -35,7 +35,7 @@ module Redmine json = @struct.first.to_json if jsonp.present? json = "#{jsonp}(#{json})" - response.content_type = 'application/javascript' + @response.content_type = 'application/javascript' end json end diff --git a/lib/redmine/views/builders/structure.rb b/lib/redmine/views/builders/structure.rb index 5e59f8978..3f4468b8e 100644 --- a/lib/redmine/views/builders/structure.rb +++ b/lib/redmine/views/builders/structure.rb @@ -21,12 +21,11 @@ module Redmine module Views module Builders class Structure < BlankSlate - attr_accessor :request, :response def initialize(request, response) @struct = [{}] - self.request = request - self.response = response + @request = request + @response = response end def array(tag, options={}, &block) diff --git a/test/unit/lib/redmine/views/builders/json_test.rb b/test/unit/lib/redmine/views/builders/json_test.rb index b1b50b80a..8ffb71fa7 100644 --- a/test/unit/lib/redmine/views/builders/json_test.rb +++ b/test/unit/lib/redmine/views/builders/json_test.rb @@ -86,6 +86,17 @@ class Redmine::Views::Builders::JsonTest < ActiveSupport::TestCase end end + def test_request_response + assert_json_output({'request' => { 'get' => 'book' }, 'response' => { 'book' => { 'title' => 'Book 1' } }}) do |b| + b.request do + b.get 'book' + end + b.response do + b.book title: 'Book 1' + end + end + end + def assert_json_output(expected, &block) builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create) block.call(builder)