From 9442829d310ef1444203f1b3f3dd4b08b75e2cc9 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 9 Sep 2023 16:41:10 +0300 Subject: [PATCH 1/1] Add json output for show user block api --- app/views/api/user_blocks/_user_block.json.jbuilder | 13 +++++++++++++ app/views/api/user_blocks/show.json.jbuilder | 3 +++ test/controllers/api/user_blocks_controller_test.rb | 10 ++++++++++ 3 files changed, 26 insertions(+) create mode 100644 app/views/api/user_blocks/_user_block.json.jbuilder create mode 100644 app/views/api/user_blocks/show.json.jbuilder diff --git a/app/views/api/user_blocks/_user_block.json.jbuilder b/app/views/api/user_blocks/_user_block.json.jbuilder new file mode 100644 index 000000000..3288dd6ad --- /dev/null +++ b/app/views/api/user_blocks/_user_block.json.jbuilder @@ -0,0 +1,13 @@ +json.user_block do + json.id user_block.id + json.created_at user_block.created_at.xmlschema + json.updated_at user_block.updated_at.xmlschema + json.ends_at user_block.ends_at.xmlschema + json.needs_view user_block.needs_view + + json.user :uid => user_block.user_id, :user => user_block.user.display_name + json.creator :uid => user_block.creator_id, :user => user_block.creator.display_name + json.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker + + json.reason user_block.reason +end diff --git a/app/views/api/user_blocks/show.json.jbuilder b/app/views/api/user_blocks/show.json.jbuilder new file mode 100644 index 000000000..6cfc0ded5 --- /dev/null +++ b/app/views/api/user_blocks/show.json.jbuilder @@ -0,0 +1,3 @@ +json.partial! "api/root_attributes" + +json.partial! @user_block diff --git a/test/controllers/api/user_blocks_controller_test.rb b/test/controllers/api/user_blocks_controller_test.rb index eef54e931..c8bdc1d57 100644 --- a/test/controllers/api/user_blocks_controller_test.rb +++ b/test/controllers/api/user_blocks_controller_test.rb @@ -7,6 +7,10 @@ module Api { :path => "/api/0.6/user_blocks/1", :method => :get }, { :controller => "api/user_blocks", :action => "show", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/user_blocks/1.json", :method => :get }, + { :controller => "api/user_blocks", :action => "show", :id => "1", :format => "json" } + ) end def test_show @@ -15,6 +19,12 @@ module Api get api_user_block_path(:id => block) assert_response :success assert_select "user_block[id='#{block.id}']", 1 + + get api_user_block_path(:id => block, :format => "json") + assert_response :success + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal block.id, js["user_block"]["id"] end def test_show_not_found -- 2.39.5