Defect #18875 ยป project_api_include_issue_custom_fields.patch
| app/helpers/custom_fields_helper.rb (working copy) | ||
|---|---|---|
| 180 | 180 |
end |
| 181 | 181 |
form.select :edit_tag_style, select_options, :label => :label_display |
| 182 | 182 |
end |
| 183 | ||
| 184 |
def render_api_issue_custom_field(field, api) |
|
| 185 |
api.custom_field do |
|
| 186 |
api.id field.id |
|
| 187 |
api.name field.name |
|
| 188 |
api.customized_type field.class.customized_class.name.underscore if field.class.customized_class |
|
| 189 |
api.field_format field.field_format |
|
| 190 |
api.regexp field.regexp |
|
| 191 |
api.min_length field.min_length |
|
| 192 |
api.max_length field.max_length |
|
| 193 |
api.is_required field.is_required? |
|
| 194 |
api.is_filter field.is_filter? |
|
| 195 |
api.searchable field.searchable |
|
| 196 |
api.multiple field.multiple? |
|
| 197 |
api.default_value field.default_value |
|
| 198 |
api.visible field.visible? |
|
| 199 | ||
| 200 |
values = field.possible_values_options |
|
| 201 |
if values.present? |
|
| 202 |
api.array :possible_values do |
|
| 203 |
values.each do |label, value| |
|
| 204 |
api.possible_value do |
|
| 205 |
api.value value || label |
|
| 206 |
api.label label |
|
| 207 |
end |
|
| 208 |
end |
|
| 209 |
end |
|
| 210 |
end |
|
| 211 | ||
| 212 |
if field.is_a?(IssueCustomField) |
|
| 213 |
api.array :trackers do |
|
| 214 |
field.trackers.each do |tracker| |
|
| 215 |
api.tracker :id => tracker.id, :name => tracker.name |
|
| 216 |
end |
|
| 217 |
end |
|
| 218 |
api.array :roles do |
|
| 219 |
field.roles.each do |role| |
|
| 220 |
api.role :id => role.id, :name => role.name |
|
| 221 |
end |
|
| 222 |
end |
|
| 223 |
end |
|
| 224 |
end |
|
| 225 |
end |
|
| 226 | ||
| 183 | 227 |
end |
| app/views/custom_fields/index.api.rsb (working copy) | ||
|---|---|---|
| 1 | 1 |
api.array :custom_fields do |
| 2 | 2 |
@custom_fields.each do |field| |
| 3 |
api.custom_field do |
|
| 4 |
api.id field.id |
|
| 5 |
api.name field.name |
|
| 6 |
api.customized_type field.class.customized_class.name.underscore if field.class.customized_class |
|
| 7 |
api.field_format field.field_format |
|
| 8 |
api.regexp field.regexp |
|
| 9 |
api.min_length field.min_length |
|
| 10 |
api.max_length field.max_length |
|
| 11 |
api.is_required field.is_required? |
|
| 12 |
api.is_filter field.is_filter? |
|
| 13 |
api.searchable field.searchable |
|
| 14 |
api.multiple field.multiple? |
|
| 15 |
api.default_value field.default_value |
|
| 16 |
api.visible field.visible? |
|
| 17 | ||
| 18 |
values = field.possible_values_options |
|
| 19 |
if values.present? |
|
| 20 |
api.array :possible_values do |
|
| 21 |
values.each do |label, value| |
|
| 22 |
api.possible_value do |
|
| 23 |
api.value value || label |
|
| 24 |
api.label label |
|
| 25 |
end |
|
| 26 |
end |
|
| 27 |
end |
|
| 28 |
end |
|
| 29 | ||
| 30 |
if field.is_a?(IssueCustomField) |
|
| 31 |
api.array :trackers do |
|
| 32 |
field.trackers.each do |tracker| |
|
| 33 |
api.tracker :id => tracker.id, :name => tracker.name |
|
| 34 |
end |
|
| 35 |
end |
|
| 36 |
api.array :roles do |
|
| 37 |
field.roles.each do |role| |
|
| 38 |
api.role :id => role.id, :name => role.name |
|
| 39 |
end |
|
| 40 |
end |
|
| 41 |
end |
|
| 42 |
end |
|
| 3 |
render_api_issue_custom_field field, api |
|
| 43 | 4 |
end |
| 44 | 5 |
end |
| app/views/projects/show.api.rsb (working copy) | ||
|---|---|---|
| 11 | 11 |
render_api_custom_values @project.visible_custom_field_values, api |
| 12 | 12 |
render_api_includes(@project, api) |
| 13 | 13 | |
| 14 |
api.array :issue_custom_fields do |
|
| 15 |
@project.all_issue_custom_fields.each do |field| |
|
| 16 |
if field.visible_by? @project |
|
| 17 |
render_api_issue_custom_field field, api |
|
| 18 |
end |
|
| 19 |
end |
|
| 20 |
end if include_in_api_response?('issue_custom_fields')
|
|
| 21 | ||
| 14 | 22 |
api.created_on @project.created_on |
| 15 | 23 |
api.updated_on @project.updated_on |
| 16 | 24 |
end |
| test/integration/api_test/projects_test.rb (working copy) | ||
|---|---|---|
| 138 | 138 |
assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]' |
| 139 | 139 |
end |
| 140 | 140 | |
| 141 |
test "GET /projects/:id.xml with include=issue_custom_fields should return issue custom fields" do |
|
| 142 |
get '/projects/1.xml?include=issue_custom_fields' |
|
| 143 |
assert_response :success |
|
| 144 |
assert_equal 'application/xml', @response.content_type |
|
| 145 | ||
| 146 |
assert_select 'issue_custom_fields' do |
|
| 147 |
assert_select 'custom_field' do |
|
| 148 |
assert_select 'name', :text => 'Database' |
|
| 149 |
assert_select 'id', :text => '2' |
|
| 150 |
assert_select 'customized_type', :text => 'issue' |
|
| 151 |
assert_select 'possible_values[type=array]' do |
|
| 152 |
assert_select 'possible_value>value', :text => 'PostgreSQL' |
|
| 153 |
assert_select 'possible_value>label', :text => 'PostgreSQL' |
|
| 154 |
end |
|
| 155 |
assert_select 'trackers[type=array]' |
|
| 156 |
assert_select 'roles[type=array]' |
|
| 157 |
end |
|
| 158 |
end |
|
| 159 |
end |
|
| 160 | ||
| 141 | 161 |
test "POST /projects.xml with valid parameters should create the project" do |
| 142 | 162 |
with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
| 143 | 163 |
assert_difference('Project.count') do
|