Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct field names for reports #14905

Merged
merged 3 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/miq_expression/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def arel_attribute
target.arel_attribute(column)
end

def report_column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I like this name way better, I'm just thinking that these are used in other parts of the UI than reporting - anywhere there is an expression builder. I wonder if there could be a more generic name for this. @gtanzillo do you have any ideas?

(associations + [column]).join('.')
end

private

def custom_attribute_column_name
Expand Down
7 changes: 6 additions & 1 deletion lib/miq_expression/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def self.parse(field)

def initialize(model, associations, column, managed = true)
super(model, associations, column)
@namespace = "/#{managed ? MANAGED_NAMESPACE : USER_NAMESPACE}/#{column}"
@base_namespace = managed ? MANAGED_NAMESPACE : USER_NAMESPACE
@namespace = "/#{@base_namespace}/#{column}"
end

def contains(value)
Expand All @@ -43,6 +44,10 @@ def attribute_supported_by_sql?
false
end

def report_column
"#{@base_namespace}.#{column}"
end

private

def tag_path
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/miq_expression/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
end
end

describe '#report_column' do
it 'returns the correct format for a field' do
field = MiqExpression::Field.parse('Vm.miq_provision.miq_request-requester_name')
expect(field.report_column).to eq('miq_provision.miq_request.requester_name')
end
end

describe "#parse!" do
it "can parse the model name" do
field = "Vm-name"
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/miq_expression/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
end
end

describe '#report_column' do
it 'returns the correct format for a tag' do
tag = MiqExpression::Tag.parse('Vm.managed-environment')
expect(tag.report_column).to eq('managed.environment')
end
end

describe "#column_type" do
it "is always a string" do
expect(described_class.new(Vm, [], "/host").column_type).to eq(:string)
Expand Down