From 9c99d5071328fe0df594d153f7dcb3736b29667b Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 3 Nov 2018 08:11:22 +0000 Subject: [PATCH] Removes request and response accessors from Structure class (#28564). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@17617 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/views/builders/json.rb | 2 +- lib/redmine/views/builders/structure.rb | 5 ++--- test/unit/lib/redmine/views/builders/json_test.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) 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) -- 2.39.5