Created
December 19, 2011 09:52
-
-
Save leifcr/1496371 to your computer and use it in GitHub Desktop.
Rails 3.1 Helper Issue in production mode with cache_classes=true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#model page.rb | |
class Page < ActiveRecord::Base | |
STATUSES = %w[new published] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Page helper module | |
module PageHelper | |
def possible_statuses(right) | |
statuses = Page::STATUSES | |
statuses.delete("publish") if (right != "can_publish") | |
statuses | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
possible_statuses("no_rights") # Should return ["new"] | |
possible_statuses("can_publish") # Should return ["new", "published"] | |
# if options.cache_classes = true | |
possible_statuses("no_rights") # Returns ["new"] OK | |
possible_statuses("can_publish") # Return ["new"] Not correct... | |
# if options.cache_classes = false | |
possible_statuses("no_rights") # Returns ["new"] OK | |
possible_statuses("can_publish") # Return ["new", "published"] OK | |
# Thought 1: | |
# It seems like the helper method is a bit "smart" and changes | |
# the const STATUSES even though statuses and STATUSES as variables | |
# with different cases shouldn't be equal | |
# What really happens is Ruby Object assignment. | |
# Read: http://stackoverflow.com/questions/2635156/object-assignment-and-pointers | |
# This won't happen i development because of classes beeing reloaded for each request... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment