Project

General

Profile

Patch #21378 » include_documents_in_projects_api.patch

Helder Manuel Torres Vieira, 2015-11-29 19:06

View differences:

app/helpers/projects_helper.rb (copia de trabajo)
119 119
      end
120 120
    end if include_in_api_response?('enabled_modules')
121 121

  
122
    api.array :documents do
123
      project.documents.each do |document|
124
        api.document do 
125
          api.id document.id
126
          api.title document.title
127
          api.description document.description
128
          api.category(:id => document.category.id, :name => document.category.name)
129
          api.url url_for(:controller => 'documents', :action => 'show', :id => document, :only_path => false)
130
          api.created_on document.created_on
131
        end
132
      end
133
    end if include_in_api_response?('documents')
134

  
122 135
  end
123 136
end
test/integration/api_test/projects_test.rb (copia de trabajo)
20 20
class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
21 21
  fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
22 22
           :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
23
           :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
23
           :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories, :documents
24 24

  
25 25
  def setup
26 26
    super
......
73 73
    assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
74 74
  end
75 75

  
76
  test "GET /projects.xml with include=documents should return documents" do
77
    get '/projects.xml?include=documents'
78
    assert_response :success
79
    assert_equal 'application/xml', @response.content_type
80

  
81
    assert_select 'documents[type=array]>document>id', :text => '1'
82
    assert_select 'documents[type=array]>document>title', :text => 'Test document'
83
    assert_select 'documents[type=array]>document>description', :text => 'Document description'
84
    assert_select 'documents[type=array]>document>category[id="1"]'
85
    assert_select 'documents[type=array]>document>category[name="Uncategorized"]'
86
    assert_select 'documents[type=array]>document>url', :text => 'http://www.example.com/documents/1'
87
  end
88

  
76 89
  test "GET /projects/:id.xml should return the project" do
77 90
    get '/projects/1.xml'
78 91
    assert_response :success
......
130 143
    assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
131 144
  end
132 145

  
146
  test "GET /projects/:id.xml with include=documents should return documents" do
147
    get '/projects/1.xml?include=documents'
148
    assert_response :success
149
    assert_equal 'application/xml', @response.content_type
150

  
151
    assert_select 'documents[type=array]>document>id', :text => '1'
152
    assert_select 'documents[type=array]>document>title', :text => 'Test document'
153
    assert_select 'documents[type=array]>document>description', :text => 'Document description'
154
    assert_select 'documents[type=array]>document>category[id="1"]'
155
    assert_select 'documents[type=array]>document>category[name="Uncategorized"]'
156
    assert_select 'documents[type=array]>document>url', :text => 'http://www.example.com/documents/1'
157
  end
158

  
133 159
  test "POST /projects.xml with valid parameters should create the project" do
134 160
    with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
135 161
      assert_difference('Project.count') do
(1-1/2)