Project

General

Profile

Patch #17602 ยป include_issue_categories_trackers_enabled_modules_in_projects_api.patch

Jan from Planio www.plan.io, 2014-08-03 18:26

View differences:

app/helpers/projects_helper.rb
91 91
    sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
92 92
    l("label_version_sharing_#{sharing}")
93 93
  end
94

  
95
  def render_api_includes(project, api)
96
    api.array :trackers do
97
      project.trackers.each do |tracker|
98
        api.tracker(:id => tracker.id, :name => tracker.name)
99
      end
100
    end if include_in_api_response?('trackers')
101

  
102
    api.array :issue_categories do
103
      project.issue_categories.each do |category|
104
        api.issue_category(:id => category.id, :name => category.name)
105
      end
106
    end if include_in_api_response?('issue_categories')
107

  
108
    api.array :enabled_modules do
109
      project.enabled_modules.each do |enabled_module|
110
        api.enabled_module(:id => enabled_module.id, :name => enabled_module.name)
111
      end
112
    end if include_in_api_response?('enabled_modules')
113

  
114
  end
94 115
end
app/views/projects/index.api.rsb
9 9
      api.status      project.status
10 10

  
11 11
      render_api_custom_values project.visible_custom_field_values, api
12
      render_api_includes(project, api)
12 13

  
13 14
      api.created_on  project.created_on
14 15
      api.updated_on  project.updated_on
app/views/projects/show.api.rsb
8 8
  api.status      @project.status
9 9

  
10 10
  render_api_custom_values @project.visible_custom_field_values, api
11
  render_api_includes(@project, api)
11 12

  
12 13
  api.created_on @project.created_on
13 14
  api.updated_on @project.updated_on
14

  
15
  api.array :trackers do
16
    @project.trackers.each do |tracker|
17
      api.tracker(:id => tracker.id, :name => tracker.name)
18
    end
19
  end if include_in_api_response?('trackers')
20

  
21
  api.array :issue_categories do
22
    @project.issue_categories.each do |category|
23
      api.issue_category(:id => category.id, :name => category.name)
24
    end
25
  end if include_in_api_response?('issue_categories')
26 15
end
test/integration/api_test/projects_test.rb
65 65
    assert json['projects'].first.has_key?('id')
66 66
  end
67 67

  
68
  test "GET /projects.xml with include=issue_categories should return categories" do
69
    get '/projects.xml?include=issue_categories'
70
    assert_response :success
71
    assert_equal 'application/xml', @response.content_type
72

  
73
    assert_tag 'issue_categories',
74
      :attributes => {:type => 'array'},
75
      :child => {
76
        :tag => 'issue_category',
77
        :attributes => {
78
          :id => '2',
79
          :name => 'Recipes'
80
        }
81
      }
82
  end
83

  
84
  test "GET /projects.xml with include=trackers should return trackers" do
85
    get '/projects.xml?include=trackers'
86
    assert_response :success
87
    assert_equal 'application/xml', @response.content_type
88

  
89
    assert_tag 'trackers',
90
      :attributes => {:type => 'array'},
91
      :child => {
92
        :tag => 'tracker',
93
        :attributes => {
94
          :id => '2',
95
          :name => 'Feature request'
96
        }
97
      }
98
  end
99

  
100
  test "GET /projects.xml with include=enabled_modules should return enabled modules" do
101
    get '/projects.xml?include=enabled_modules'
102
    assert_response :success
103
    assert_equal 'application/xml', @response.content_type
104

  
105
    assert_tag 'enabled_modules',
106
      :attributes => {:type => 'array'},
107
      :child => {
108
        :tag => 'enabled_module',
109
        :attributes => {
110
          :name => 'issue_tracking'
111
        }
112
      }
113
  end
114

  
68 115
  test "GET /projects/:id.xml should return the project" do
69 116
    get '/projects/1.xml'
70 117
    assert_response :success
......
130 177
      }
131 178
  end
132 179

  
180
  test "GET /projects/:id.xml with include=enabled_modules should return enabled modules" do
181
    get '/projects/1.xml?include=enabled_modules'
182
    assert_response :success
183
    assert_equal 'application/xml', @response.content_type
184

  
185
    assert_tag 'enabled_modules',
186
      :attributes => {:type => 'array'},
187
      :child => {
188
        :tag => 'enabled_module',
189
        :attributes => {
190
          :name => 'issue_tracking'
191
        }
192
      }
193
  end
194

  
133 195
  test "POST /projects.xml with valid parameters should create the project" do
134 196
    Setting.default_projects_modules = ['issue_tracking', 'repository']
135 197

  
    (1-1/1)