Skip to content

Commit

Permalink
Merge pull request #17686 from kbrock/group_role_name
Browse files Browse the repository at this point in the history
fix MiqGroup#miq_user_role_name
  • Loading branch information
bdunne authored Jul 10, 2018
2 parents a9ec5d3 + 850df38 commit e484d1a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/entitlement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Entitlement < ApplicationRecord

validate :one_kind_of_managed_filter

virtual_delegate :name, :to => :miq_user_role, :allow_nil => true, :prefix => true

def self.valid_filters?(filters_hash)
return true unless filters_hash # nil ok
return false unless filters_hash.kind_of?(Hash) # must be Hash
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MiqGroup < ApplicationRecord
has_many :miq_widget_sets, :as => :owner, :dependent => :destroy
has_many :miq_product_features, :through => :miq_user_role

virtual_delegate :name, :to => :miq_user_role, :allow_nil => true, :prefix => true
virtual_delegate :miq_user_role_name, :to => :entitlement, :allow_nil => true
virtual_column :read_only, :type => :boolean
virtual_has_one :sui_product_features, :class_name => "Array"

Expand Down
15 changes: 15 additions & 0 deletions spec/models/miq_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe MiqGroup do
include Spec::Support::ArelHelper

describe "#settings" do
subject { FactoryGirl.create(:miq_group) }

Expand Down Expand Up @@ -568,4 +570,17 @@
expect(subject.sui_product_features).to eq(%w(sui_role_a sui_role_c))
end
end

describe "#miq_user_role_name" do
let(:group) { FactoryGirl.build(:miq_group, :role => "the_role") }

it "calculates in ruby" do
expect(group.miq_user_role_name).to eq("EvmRole-the_role")
end

it "calculates in the database" do
group.save
expect(virtual_column_sql_value(MiqGroup.where(:id => group.id), "miq_user_role_name")).to eq("EvmRole-the_role")
end
end
end

0 comments on commit e484d1a

Please sign in to comment.