From b93ad3ba9078b09946727cdd433c60b4f06d0673 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Thu, 20 Jun 2013 16:07:10 +0200 Subject: [PATCH] Fixed specs to conform to the new schema of generating custom field classes --- spec/models/cost_query/filter_spec.rb | 30 ++++++++++++++++--------- spec/models/cost_query/group_by_spec.rb | 18 ++++++++++----- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/spec/models/cost_query/filter_spec.rb b/spec/models/cost_query/filter_spec.rb index 576b3bce8b..0358bae0e2 100644 --- a/spec/models/cost_query/filter_spec.rb +++ b/spec/models/cost_query/filter_spec.rb @@ -277,14 +277,20 @@ describe CostQuery, :reporting_query_helper => true do clear_cache 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 - clear_cache - expect { CostQuery::Filter::CustomFieldMyCustomField }.to_not raise_error + custom_field + expect { class_name_for('My custom field').constantize }.to_not raise_error end 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") - CostQuery::Filter.all.should_not include CostQuery::Filter::CustomFieldMyCustomField + CostQuery::Filter.all.should_not include class_name.constantize end it "should provide the correct available values" do @@ -292,7 +298,7 @@ describe CostQuery, :reporting_query_helper => true do :field_format => "list", :possible_values => ['value']) 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| ao.should include o.name end @@ -303,25 +309,27 @@ describe CostQuery, :reporting_query_helper => true do :field_format => "list", :possible_values => ['value']) 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| ao.should include o.name end 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| ao.should include o.name end end it "includes custom fields classes in CustomFieldEntries.all" do + custom_field CostQuery::Filter::CustomFieldEntries.all. - should include(CostQuery::Filter::CustomFieldMyCustomField) + should include(class_name_for('My custom field').constantize) end it "includes custom fields classes in Filter.all" do + custom_field CostQuery::Filter.all. - should include(CostQuery::Filter::CustomFieldMyCustomField) + should include(class_name_for('My custom field').constantize) end def create_searchable_fields_and_values @@ -344,13 +352,15 @@ describe CostQuery, :reporting_query_helper => true do it "is usable as filter" do 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 end it "is usable as filter #2" do 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 end end diff --git a/spec/models/cost_query/group_by_spec.rb b/spec/models/cost_query/group_by_spec.rb index f0d8067fa7..86dafdb512 100644 --- a/spec/models/cost_query/group_by_spec.rb +++ b/spec/models/cost_query/group_by_spec.rb @@ -227,37 +227,43 @@ describe CostQuery, :reporting_query_helper => true do check_cache end + def class_name_for(name) + "CostQuery::GroupBy::CustomField#{IssueCustomField.find_by_name(name).id}" + end + it "should create classes for custom fields" do # Would raise a name error - CostQuery::GroupBy::CustomFieldSearchableField + expect { class_name_for('Searchable Field').constantize }.to_not raise_error end it "should create new classes for custom fields that get added after starting the server" do create_issue_custom_field("AFreshCustomField") # Would raise a name error - CostQuery::GroupBy::CustomFieldAfreshcustomfield + expect { class_name_for('AFreshCustomField').constantize }.to_not raise_error IssueCustomField.find_by_name("AFreshCustomField").destroy end it "should remove the custom field classes after it is deleted" do create_issue_custom_field("AFreshCustomField") + name = class_name_for('AFreshCustomField') delete_issue_custom_field("AFreshCustomField") - CostQuery::GroupBy.all.should_not include CostQuery::GroupBy::CustomFieldAfreshcustomfield + CostQuery::GroupBy.all.should_not include name.constantize end it "includes custom fields classes in CustomFieldEntries.all" do CostQuery::GroupBy::CustomFieldEntries.all. - should include(CostQuery::GroupBy::CustomFieldSearchableField) + should include(class_name_for('Searchable Field').constantize) end it "includes custom fields classes in GroupBy.all" do CostQuery::GroupBy.all. - should include(CostQuery::GroupBy::CustomFieldSearchableField) + should include(class_name_for('Searchable Field').constantize) end it "is usable as filter" do 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.should == [[8, 8]] end