@@ -47,7 +47,8 class Version < ActiveRecord::Base | |||
|
47 | 47 | 'wiki_page_title', |
|
48 | 48 | 'status', |
|
49 | 49 | 'sharing', |
|
50 | 'custom_field_values' | |
|
50 | 'custom_field_values', | |
|
51 | 'custom_fields' | |
|
51 | 52 | |
|
52 | 53 | # Returns true if +user+ or current user is allowed to view the version |
|
53 | 54 | def visible?(user=User.current) |
@@ -82,6 +82,29 class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base | |||
|
82 | 82 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | should "create the version with custom fields" do | |
|
86 | field = VersionCustomField.generate! | |
|
87 | ||
|
88 | assert_difference 'Version.count' do | |
|
89 | post '/projects/1/versions.xml', { | |
|
90 | :version => { | |
|
91 | :name => 'API test', | |
|
92 | :custom_fields => [ | |
|
93 | {'id' => field.id.to_s, 'value' => 'Some value'} | |
|
94 | ] | |
|
95 | } | |
|
96 | }, credentials('jsmith') | |
|
97 | end | |
|
98 | ||
|
99 | version = Version.first(:order => 'id DESC') | |
|
100 | assert_equal 'API test', version.name | |
|
101 | assert_equal 'Some value', version.custom_field_value(field) | |
|
102 | ||
|
103 | assert_response :created | |
|
104 | assert_equal 'application/xml', @response.content_type | |
|
105 | assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value' | |
|
106 | end | |
|
107 | ||
|
85 | 108 | context "with failure" do |
|
86 | 109 | should "return the errors" do |
|
87 | 110 | assert_no_difference('Version.count') do |
@@ -148,4 +148,15 module ObjectHelpers | |||
|
148 | 148 | attachment.save! |
|
149 | 149 | attachment |
|
150 | 150 | end |
|
151 | ||
|
152 | def CustomField.generate!(attributes={}) | |
|
153 | @generated_custom_field_name ||= 'Custom field 0' | |
|
154 | @generated_custom_field_name.succ! | |
|
155 | field = new(attributes) | |
|
156 | field.name = @generated_custom_field_name.dup if field.name.blank? | |
|
157 | field.field_format = 'string' if field.field_format.blank? | |
|
158 | yield field if block_given? | |
|
159 | field.save! | |
|
160 | field | |
|
161 | end | |
|
151 | 162 | end |
General Comments 0
You need to be logged in to leave comments.
Login now