uses default attribute rendering for custom fields in wp#form

pull/280/head
Jens Ulferts 11 years ago
parent bb85b6bfb0
commit 116b5628fa
  1. 11
      app/helpers/work_packages_helper.rb
  2. 3
      app/views/work_packages/_attributes.html.erb
  3. 24
      app/views/work_packages/_form_custom_fields.html.erb
  4. 12
      features/step_definitions/custom_field_steps.rb
  5. 18
      features/work_packages/editable_fields.feature
  6. 6
      lib/instance_finder.rb
  7. 5
      spec/factories/custom_field_factory.rb
  8. 5
      spec/factories/custom_value_factory.rb
  9. 24
      spec/helpers/work_packages_helper_spec.rb

@ -75,7 +75,8 @@ module WorkPackagesHelper
work_package_form_due_date_attribute(form, work_package, locals),
work_package_form_estimated_hours_attribute(form, work_package, locals),
work_package_form_done_ratio_attribute(form, work_package, locals),
].compact
work_package_form_custom_values_attribute(form, work_package, locals)
].flatten.compact
end
def work_package_form_top_attributes(form, work_package, locals = {})
@ -345,4 +346,12 @@ module WorkPackagesHelper
WorkPackageAttribute.new(:done_ratio, field)
end
end
def work_package_form_custom_values_attribute(form, work_package, locals = {})
work_package.custom_field_values.map do |value|
field = custom_field_tag_with_label :work_package, value
WorkPackageAttribute.new(:"work_package_#{value.id}", field)
end
end
end

@ -36,7 +36,4 @@ See doc/COPYRIGHT.rdoc for more details.
<% end %>
</div>
<div style="clear:both;"> </div>
<%= render :partial => 'form_custom_fields', :locals => { :work_package => work_package } %>
<% end %>

@ -1,24 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2013 the OpenProject Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<div class="splitcontentleft">
<% i = 0 %>
<% split_on = (work_package.custom_field_values.size / 2.0).ceil - 1 %>
<% work_package.custom_field_values.each do |value| %>
<p><%= custom_field_tag_with_label :issue, value %></p>
<% if i == split_on -%>
</div><div class="splitcontentright">
<% end -%>
<% i += 1 -%>
<% end -%>
</div>
<div style="clear:both;"> </div>

@ -14,8 +14,8 @@
RouteMap.register(const, "/custom_fields")
end
Given /^the following (user|issue) custom fields are defined:$/ do |type, table|
type = (type + "_custom_field").to_sym
Given /^the following (user|issue|work package) custom fields are defined:$/ do |type, table|
type = (type.gsub(" ", "_") + "_custom_field").to_sym
as_admin do
table.hashes.each_with_index do |r, i|
@ -43,6 +43,14 @@ Given /^the user "(.+?)" has the user custom field "(.+?)" set to "(.+?)"$/ do |
user.save!
end
Given /^the work package "(.+?)" has the custom field "(.+?)" set to "(.+?)"$/ do |wp_name, field_name, value|
wp = InstanceFinder.find(WorkPackage, wp_name)
custom_field = InstanceFinder.find(WorkPackageCustomField, field_name)
wp.custom_values.build(:custom_field => custom_field, :value => value)
wp.save!
end
Given /^the custom field "(.+)" is( not)? summable$/ do |field_name, negative|
custom_field = WorkPackageCustomField.find_by_name(field_name)

@ -75,3 +75,21 @@ Feature: Fields editable on work package edit
| Activity |
| Comment |
Scenario: Going to the page and viewing custom field fields
Given the role "manager" may have the following rights:
| edit_work_packages |
Given the following work package custom fields are defined:
| name | type |
| cf1 | int |
And there are the following planning elements in project "ecookbook":
| subject |
| pe1 |
And the work package "pe1" has the custom field "cf1" set to "4"
When I go to the edit page of the work package called "pe1"
Then I should see the following fields:
| cf1 | 4 |

@ -17,6 +17,10 @@ class InstanceFinder
end
def self.find(model, identifier)
instance = @model_method_map[model].call(identifier)
if @model_method_map[model].nil?
raise "#{model} is not registerd with InstanceFinder"
end
@model_method_map[model].call(identifier)
end
end

@ -63,6 +63,11 @@ FactoryGirl.define do
end
end
factory :work_package_custom_field do
sequence(:name) { |n| "Work Package Custom Field #{n}" }
type "WorkPackageCustomField"
end
factory :issue_custom_field do
sequence(:name) { |n| "Issue Custom Field #{n}" }
type "WorkPackageCustomField"

@ -23,5 +23,10 @@ FactoryGirl.define do
custom_field :factory => :issue_custom_field
customized :factory => :issue
end
factory :work_package_custom_value do
custom_field :factory => :issue_custom_field
customized :factory => :issue
end
end
end

@ -12,6 +12,9 @@
require 'spec_helper'
describe WorkPackagesHelper do
let(:stub_work_package) { FactoryGirl.build_stubbed(:planning_element) }
let(:form) { double('form', :select => "").as_null_object }
def inside_form &block
ret = ''
@ -60,9 +63,7 @@ describe WorkPackagesHelper do
describe :work_package_form_issue_category_attribute do
let(:stub_project) { FactoryGirl.build_stubbed(:project) }
let(:stub_work_package) { FactoryGirl.build_stubbed(:planning_element) }
let(:stub_category) { FactoryGirl.build_stubbed(:issue_category) }
let(:form) { double('form', :select => "").as_null_object }
before do
# set sensible defaults
@ -112,4 +113,23 @@ describe WorkPackagesHelper do
attribute.field.should have_selector('input#work_package_estimated_hours[@value="3.00"]')
end
end
describe :work_package_form_custom_values_attribute do
let(:stub_custom_value) { FactoryGirl.build_stubbed(:work_package_custom_value) }
let(:expected) { "field contents" }
before do
stub_work_package.stub!(:custom_field_values).and_return([stub_custom_value])
helper.should_receive(:custom_field_tag_with_label).with(:work_package, stub_custom_value).and_return(expected)
end
it "should return an array for an element for every value" do
helper.work_package_form_custom_values_attribute(form, stub_work_package, {}).size.should == 1
end
it "should return the result inside the field" do
helper.work_package_form_custom_values_attribute(form, stub_work_package, {}).first.field.should == expected
end
end
end

Loading…
Cancel
Save