Skip to content

Commit

Permalink
Don’t memoize root_tenant in validation method
Browse files Browse the repository at this point in the history
Validation validate_only_one_root
was using memoized method  Tenant#root_tenant
which is called before after_save hook
which is creating default group (Tenant#create_tenant_group)

and thanks to this fact in variable (@root_tenant) was filled
without created default group created in (Tenant#create_tenant_group)
and it was causing problems for specs.
(then tests were working with instance of root tenant without default group )
  • Loading branch information
lpichler committed May 30, 2017
1 parent 937efa8 commit 0ea303b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ def self.default_tenant
#
# @return [Tenant] the root tenant
def self.root_tenant
@root_tenant ||= in_my_region.roots.first
@root_tenant ||= root_tenant_without_cache
end

def self.root_tenant_without_cache
in_my_region.roots.first
end

# NOTE: returns the root tenant
Expand Down Expand Up @@ -303,7 +307,7 @@ def nil_blanks
# validates that there is only one tree
def validate_only_one_root
unless parent_id || parent
root = self.class.root_tenant
root = self.class.root_tenant_without_cache
errors.add(:parent, "required") if root && root != self
end
end
Expand Down

0 comments on commit 0ea303b

Please sign in to comment.