Prefer #map over #collect

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/6827/head
Alex Coles 10 years ago
parent e239e72b1a
commit 4c617f5fc1
  1. 2
      app/models/cost_query/filter/work_package_id.rb
  2. 2
      lib/widget/entry_table.rb
  3. 2
      lib/widget/simple_table.rb
  4. 6
      spec/models/cost_query/chaining_spec.rb
  5. 4
      spec/models/cost_query/result_spec.rb

@ -23,7 +23,7 @@ class CostQuery::Filter::WorkPackageId < Report::Filter::Base
end
def self.available_values(*)
work_packages = Project.visible.collect { |p| p.work_packages }.flatten.uniq.sort_by { |i| i.id }
work_packages = Project.visible.map { |p| p.work_packages }.flatten.uniq.sort_by { |i| i.id }
work_packages.map { |i| [text_for_work_package(i), i.id] }
end

@ -36,7 +36,7 @@ class Widget::Table::EntryTable < Widget::Table
def head
content_tag :thead do
content_tag :tr do
Fields.collect { |field| concat content_tag(:th) { label_for(field) } }
Fields.map { |field| concat content_tag(:th) { label_for(field) } }
concat content_tag(:th, class: 'right') { cost_type.try(:unit_plural) || l(:units) }
concat content_tag(:th, class: 'right') { CostEntry.human_attribute_name(:costs) }
hit = false

@ -21,7 +21,7 @@ class Widget::Table::SimpleTable < Widget::Table
simple_table self
def render
@list = @subject.collect {|r| r.important_fields }.flatten.uniq
@list = @subject.map {|r| r.important_fields }.flatten.uniq
@show_units = @list.include? "cost_type_id"
content = content_tag :table, { class: "report", id: "sortable-table" } do

@ -107,14 +107,14 @@ describe CostQuery, type: :model, reporting_query_helper: true do
@query.filter :project_id
@query.group_by :project_id
expect(@query.filters.size).to eq(2)
expect(@query.filters.collect {|f| f.class.underscore_name}).to include "project_id"
expect(@query.filters.map {|f| f.class.underscore_name}).to include "project_id"
end
it "should return all group_bys" do
@query.filter :project_id
@query.group_by :project_id
expect(@query.group_bys.size).to eq(1)
expect(@query.group_bys.collect {|g| g.class.underscore_name}).to include "project_id"
expect(@query.group_bys.map {|g| g.class.underscore_name}).to include "project_id"
end
it "should initialize the chain through a block" do
@ -125,7 +125,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do
end
TestFilter.send(:initialize_query_with) {|query| query.filter(:project_id, value: project.id)}
@query.build_new_chain
expect(@query.filters.collect {|f| f.class.underscore_name}).to include "project_id"
expect(@query.filters.map {|f| f.class.underscore_name}).to include "project_id"
expect(@query.filters.detect {|f| f.class.underscore_name == "project_id"}.values).to eq(Array(project.id))
end

@ -32,11 +32,11 @@ describe CostQuery, type: :model, reporting_query_helper: true do
describe CostQuery::Result do
def direct_results(quantity = 0)
(1..quantity).collect {|i| CostQuery::Result.new real_costs:i.to_f, count:1 ,units:i.to_f}
(1..quantity).map {|i| CostQuery::Result.new real_costs:i.to_f, count:1 ,units:i.to_f}
end
def wrapped_result(source, quantity=1)
CostQuery::Result.new((1..quantity).collect { |i| source})
CostQuery::Result.new((1..quantity).map { |i| source})
end
it "should travel recursively depth-first" do

Loading…
Cancel
Save