Fixed specs to conform to the new schema of generating custom field classes

pull/6827/head
Sebastian Schuster 12 years ago
parent f635e81740
commit b93ad3ba90
  1. 30
      spec/models/cost_query/filter_spec.rb
  2. 18
      spec/models/cost_query/group_by_spec.rb

@ -277,14 +277,20 @@ describe CostQuery, :reporting_query_helper => true do
clear_cache clear_cache
end end
def class_name_for(name)
"CostQuery::Filter::CustomField#{IssueCustomField.find_by_name(name).id}"
end
it "should create classes for custom fields that get added after starting the server" do it "should create classes for custom fields that get added after starting the server" do
clear_cache custom_field
expect { CostQuery::Filter::CustomFieldMyCustomField }.to_not raise_error expect { class_name_for('My custom field').constantize }.to_not raise_error
end end
it "should remove the custom field classes after it is deleted" do it "should remove the custom field classes after it is deleted" do
custom_field
class_name = class_name_for('My custom field')
delete_issue_custom_field("My custom field") delete_issue_custom_field("My custom field")
CostQuery::Filter.all.should_not include CostQuery::Filter::CustomFieldMyCustomField CostQuery::Filter.all.should_not include class_name.constantize
end end
it "should provide the correct available values" do it "should provide the correct available values" do
@ -292,7 +298,7 @@ describe CostQuery, :reporting_query_helper => true do
:field_format => "list", :field_format => "list",
:possible_values => ['value']) :possible_values => ['value'])
clear_cache clear_cache
ao = CostQuery::Filter::CustomFieldDatabase.available_operators.map(&:name) ao = class_name_for('Database').constantize.available_operators.map(&:name)
CostQuery::Operator.null_operators.each do |o| CostQuery::Operator.null_operators.each do |o|
ao.should include o.name ao.should include o.name
end end
@ -303,25 +309,27 @@ describe CostQuery, :reporting_query_helper => true do
:field_format => "list", :field_format => "list",
:possible_values => ['value']) :possible_values => ['value'])
update_issue_custom_field("Database", :field_format => "string") update_issue_custom_field("Database", :field_format => "string")
ao = CostQuery::Filter::CustomFieldDatabase.available_operators.map(&:name) ao = class_name_for('Database').constantize.available_operators.map(&:name)
CostQuery::Operator.string_operators.each do |o| CostQuery::Operator.string_operators.each do |o|
ao.should include o.name ao.should include o.name
end end
update_issue_custom_field("Database", :field_format => "int") update_issue_custom_field("Database", :field_format => "int")
ao = CostQuery::Filter::CustomFieldDatabase.available_operators.map(&:name) ao = class_name_for('Database').constantize.available_operators.map(&:name)
CostQuery::Operator.integer_operators.each do |o| CostQuery::Operator.integer_operators.each do |o|
ao.should include o.name ao.should include o.name
end end
end end
it "includes custom fields classes in CustomFieldEntries.all" do it "includes custom fields classes in CustomFieldEntries.all" do
custom_field
CostQuery::Filter::CustomFieldEntries.all. CostQuery::Filter::CustomFieldEntries.all.
should include(CostQuery::Filter::CustomFieldMyCustomField) should include(class_name_for('My custom field').constantize)
end end
it "includes custom fields classes in Filter.all" do it "includes custom fields classes in Filter.all" do
custom_field
CostQuery::Filter.all. CostQuery::Filter.all.
should include(CostQuery::Filter::CustomFieldMyCustomField) should include(class_name_for('My custom field').constantize)
end end
def create_searchable_fields_and_values def create_searchable_fields_and_values
@ -344,13 +352,15 @@ describe CostQuery, :reporting_query_helper => true do
it "is usable as filter" do it "is usable as filter" do
create_searchable_fields_and_values create_searchable_fields_and_values
@query.filter :custom_field_searchable_field, :operator => '=', :value => "125" id = IssueCustomField.find_by_name("Searchable Field").id
@query.filter "custom_field_#{id}".to_sym, :operator => '=', :value => "125"
@query.result.count.should == 2 @query.result.count.should == 2
end end
it "is usable as filter #2" do it "is usable as filter #2" do
create_searchable_fields_and_values create_searchable_fields_and_values
@query.filter :custom_field_searchable_field, :operator => '=', :value => "finnlabs" id = IssueCustomField.find_by_name("Searchable Field").id
@query.filter "custom_field_#{id}".to_sym, :operator => '=', :value => "finnlabs"
@query.result.count.should == 0 @query.result.count.should == 0
end end
end end

@ -227,37 +227,43 @@ describe CostQuery, :reporting_query_helper => true do
check_cache check_cache
end end
def class_name_for(name)
"CostQuery::GroupBy::CustomField#{IssueCustomField.find_by_name(name).id}"
end
it "should create classes for custom fields" do it "should create classes for custom fields" do
# Would raise a name error # Would raise a name error
CostQuery::GroupBy::CustomFieldSearchableField expect { class_name_for('Searchable Field').constantize }.to_not raise_error
end end
it "should create new classes for custom fields that get added after starting the server" do it "should create new classes for custom fields that get added after starting the server" do
create_issue_custom_field("AFreshCustomField") create_issue_custom_field("AFreshCustomField")
# Would raise a name error # Would raise a name error
CostQuery::GroupBy::CustomFieldAfreshcustomfield expect { class_name_for('AFreshCustomField').constantize }.to_not raise_error
IssueCustomField.find_by_name("AFreshCustomField").destroy IssueCustomField.find_by_name("AFreshCustomField").destroy
end end
it "should remove the custom field classes after it is deleted" do it "should remove the custom field classes after it is deleted" do
create_issue_custom_field("AFreshCustomField") create_issue_custom_field("AFreshCustomField")
name = class_name_for('AFreshCustomField')
delete_issue_custom_field("AFreshCustomField") delete_issue_custom_field("AFreshCustomField")
CostQuery::GroupBy.all.should_not include CostQuery::GroupBy::CustomFieldAfreshcustomfield CostQuery::GroupBy.all.should_not include name.constantize
end end
it "includes custom fields classes in CustomFieldEntries.all" do it "includes custom fields classes in CustomFieldEntries.all" do
CostQuery::GroupBy::CustomFieldEntries.all. CostQuery::GroupBy::CustomFieldEntries.all.
should include(CostQuery::GroupBy::CustomFieldSearchableField) should include(class_name_for('Searchable Field').constantize)
end end
it "includes custom fields classes in GroupBy.all" do it "includes custom fields classes in GroupBy.all" do
CostQuery::GroupBy.all. CostQuery::GroupBy.all.
should include(CostQuery::GroupBy::CustomFieldSearchableField) should include(class_name_for('Searchable Field').constantize)
end end
it "is usable as filter" do it "is usable as filter" do
create_issue_custom_field("Database") create_issue_custom_field("Database")
@query.group_by :custom_field_searchable_field id = IssueCustomField.find_by_name('Database').id
@query.group_by "custom_field_#{id}".to_sym
footprint = @query.result.each_direct_result.map { |c| [c.count, c.units.to_i] }.sort footprint = @query.result.each_direct_result.map { |c| [c.count, c.units.to_i] }.sort
footprint.should == [[8, 8]] footprint.should == [[8, 8]]
end end

Loading…
Cancel
Save