-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Input
<p>I ran into a weird situation today. Active Record objects stored in vars are removed when I switched from one tenant
to another on the fly. This will create a weird test-failing scenario and you never know why its happening.</p>
<pre>
def switch(name)
yield(name)
end
@customers = [1,2,3]
switch('shiva') do |name|
puts name
puts @customers
end
# Gives output
# shiva
# 1
# 2
# 3
</pre>
<p> </p>
<p>but when I do this</p>
<pre>
@roles = Role.all
@customers = org.branches
@list = [1, 2]
puts 'Role count' + @roles.count.to_s
puts 'Customer count' + @customers.count.to_s
puts 'list count' + @list.count.to_s
Apartment::Tenant.switch!(org.database_name)
puts '-------'
puts 'Role count' + @roles.count.to_s
puts 'Customer count' + @customers.count.to_s
puts 'list count' + @list.count.to_s
</pre>
<p>output is</p>
<pre>
Role count2
Customer count2
list count2
-------
Role count0
Customer count0
list count2
</pre>
<p> </p>
<h2>Reason</h2>
<pre>
# apartment-2.2.0/lib/apartment/adapters/abstract_adapter.rb
# Switch to a new tenant
#
# @param {String} tenant name
#
def switch!(tenant = nil)
run_callbacks :switch do
return reset if tenant.nil?
connect_to_new(tenant).tap do
<strong>Apartment.connection.clear_query_cache</strong>
end
end
end
</pre>is rendered into
I ran into a weird situation today. Active Record objects stored in vars are removed when I switched from one tenant to another on the fly. This will create a weird test-failing scenario and you never know why its happening.
def switch(name) yield(name) end @customers = [1,2,3] switch('shiva') do |name| puts name puts @customers end # Gives output # shiva # 1 # 2 # 3
but when I do this
@roles = Role.all @customers = org.branches @list = [1, 2] puts 'Role count' + @roles.count.to\_s puts 'Customer count' + @customers.count.to\_s puts 'list count' + @list.count.to\_s Apartment::Tenant.switch!(org.database\_name) puts '-------' puts 'Role count' + @roles.count.to\_s puts 'Customer count' + @customers.count.to\_s puts 'list count' + @list.count.to\_s
output is
Role count2 Customer count2 list count2 ------- Role count0 Customer count0 list count2
## Reason
# apartment-2.2.0/lib/apartment/adapters/abstract\_adapter.rb # Switch to a new tenant # # @param {String} tenant name # def switch!(tenant = nil) run\_callbacks :switch do return reset if tenant.nil? connect\_to\_new(tenant).tap do **Apartment.connection.clear\_query\_cache** end end end
Expected
It should have rendered newline chars \n inside <pre> tag where there is no <code> tag inside.
The HTML is extracted from by blog at https://cbabhusal.wordpress.com . Wordpress does not put <code> tag inside <pre> tag.
Code
ReverseMarkdown.convert(post['content'])Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels