Output active blocks list
This commit is contained in:
parent
9ec7e8c888
commit
f6572e3712
7 changed files with 37 additions and 14 deletions
|
@ -7,7 +7,10 @@ module Api
|
||||||
|
|
||||||
before_action :set_request_formats
|
before_action :set_request_formats
|
||||||
|
|
||||||
def show; end
|
def show
|
||||||
|
@user_blocks = current_user.blocks.active.order(:id => :desc)
|
||||||
|
@skip_reason = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
json.user_block do
|
json.id user_block.id
|
||||||
json.id user_block.id
|
json.created_at user_block.created_at.xmlschema
|
||||||
json.created_at user_block.created_at.xmlschema
|
json.updated_at user_block.updated_at.xmlschema
|
||||||
json.updated_at user_block.updated_at.xmlschema
|
json.ends_at user_block.ends_at.xmlschema
|
||||||
json.ends_at user_block.ends_at.xmlschema
|
json.needs_view user_block.needs_view
|
||||||
json.needs_view user_block.needs_view
|
|
||||||
|
|
||||||
json.user :uid => user_block.user_id, :user => user_block.user.display_name
|
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.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.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
|
||||||
|
|
||||||
json.reason user_block.reason
|
json.reason user_block.reason unless @skip_reason
|
||||||
end
|
|
||||||
|
|
|
@ -10,5 +10,6 @@ xml.user_block(attrs) do
|
||||||
xml.user :uid => user_block.user_id, :user => user_block.user.display_name
|
xml.user :uid => user_block.user_id, :user => user_block.user.display_name
|
||||||
xml.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
|
xml.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
|
||||||
xml.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
|
xml.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
|
||||||
xml.reason user_block.reason
|
|
||||||
|
xml.reason user_block.reason unless @skip_reason
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
json.partial! "api/root_attributes"
|
||||||
|
|
||||||
|
json.user_blocks do
|
||||||
|
json.array! @user_blocks, :partial => "api/user_blocks/user_block", :as => :user_block
|
||||||
|
end
|
5
app/views/api/user_blocks/active_lists/show.xml.builder
Normal file
5
app/views/api/user_blocks/active_lists/show.xml.builder
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
xml.instruct!
|
||||||
|
|
||||||
|
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||||
|
osm << (render(:partial => "api/user_blocks/user_block", :collection => @user_blocks) || "")
|
||||||
|
end
|
|
@ -1,3 +1,5 @@
|
||||||
json.partial! "api/root_attributes"
|
json.partial! "api/root_attributes"
|
||||||
|
|
||||||
json.partial! @user_block
|
json.user_block do
|
||||||
|
json.partial! @user_block
|
||||||
|
end
|
||||||
|
|
|
@ -50,6 +50,10 @@ module Api
|
||||||
|
|
||||||
get api_user_blocks_active_list_path, :headers => user_auth_header
|
get api_user_blocks_active_list_path, :headers => user_auth_header
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
assert_dom "user_block", :count => 2 do |dom_blocks|
|
||||||
|
assert_dom dom_blocks[0], "> @id", block1.id.to_s
|
||||||
|
assert_dom dom_blocks[1], "> @id", block0.id.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_json
|
def test_show_json
|
||||||
|
@ -63,6 +67,11 @@ module Api
|
||||||
|
|
||||||
get api_user_blocks_active_list_path(:format => "json"), :headers => user_auth_header
|
get api_user_blocks_active_list_path(:format => "json"), :headers => user_auth_header
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
js = ActiveSupport::JSON.decode(@response.body)
|
||||||
|
assert_not_nil js
|
||||||
|
assert_equal 2, js["user_blocks"].count
|
||||||
|
assert_equal block1.id, js["user_blocks"][0]["id"]
|
||||||
|
assert_equal block0.id, js["user_blocks"][1]["id"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue