Project

General

Profile

Defect #32769 » 0001-Fix-sort-projects-table-by-custom-field.patch

Marius BĂLTEANU, 2020-01-09 19:10

View differences:

app/models/project_query.rb
70 70
    return @available_columns if @available_columns
71 71
    @available_columns = self.class.available_columns.dup
72 72
    @available_columns += ProjectCustomField.visible.
73
                            map {|cf| QueryAssociationCustomFieldColumn.new(:project, cf) }
73
                            map {|cf| QueryCustomFieldColumn.new(cf) }
74 74
    @available_columns
75 75
  end
76 76

  
test/functional/projects_controller_test.rb
96 96

  
97 97
  def test_index_as_list_should_format_column_value
98 98
    get :index, :params => {
99
      :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'project.cf_3'],
99
      :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'],
100 100
      :display_type => 'list'
101 101
    }
102 102
    assert_response :success
......
111 111
        assert_select 'td.identifier', :text => 'ecookbook'
112 112
        assert_select 'td.is_public', :text => 'Yes'
113 113
        assert_select 'td.created_on', :text => format_time(project.created_on)
114
        assert_select 'td.project_cf_3.list', :text => 'Stable'
114
        assert_select 'td.cf_3.list', :text => 'Stable'
115 115
      end
116 116
      assert_select 'tr[id=?]', 'project-4' do
117 117
        assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
......
207 207
    end
208 208
  end
209 209

  
210
  def test_index_sort_by_custom_field
211
    @request.session[:user_id] = 1
212

  
213
    cf = ProjectCustomField.find(3)
214
    CustomValue.create!(:custom_field => cf, :customized => Project.find(2), :value => 'Beta')
215

  
216
    get(
217
      :index,
218
      :params => {
219
        :display_type => 'list',
220
        :c => ['name', 'identifier', 'cf_3'],
221
        :set_filter => 1,
222
        :sort => "cf_#{cf.id}:asc"
223
      }
224
    )
225
    assert_response :success
226

  
227
    assert_equal(
228
      ['Beta', 'Stable'],
229
      columns_values_in_list('cf_3').reject {|p| p.empty?}
230
    )
231
  end
232

  
210 233
  def test_autocomplete_js
211 234
    get(
212 235
      :autocomplete,
test/unit/project_query_test.rb
58 58

  
59 59
  def test_available_columns_should_include_project_custom_fields
60 60
    query = ProjectQuery.new
61
    assert_include :"project.cf_3", query.available_columns.map(&:name)
61
    assert_include :cf_3, query.available_columns.map(&:name)
62 62
  end
63 63
end
    (1-1/1)