Folks,

I was just burned by this when tests/code started failing when god was
rolled out -- god redefines kilobytes, megabytes, and gigabytes in lib/
sugar.rb. This is a problem for calculations involving diskspace for
us -- file_size > 1.megabyte behavior changes pretty significantly for
example :)

So my question is what to do about it -- in my perfect world the tests
below would pass :) But god's not rails-specific so I totally get how
one library's sugar isn't really relevant to another library's sugar
-- in this case, Rails counts bytes and God counts kb for the same
methods and both make sense (personally I prefer god's base of kb, but
I digress)

Our original method looked like this

MAX_FILE_STORAGE = 1.gigabyte

def filespace_available
    MAX_FILE_STORAGE - files.sum('item_file_size').to_i # filesize
from paperclip upload in bytes
end

For now, going to simply do this

MAX_FILE_STORAGE = 1 *
ActiveSupport::CoreExtensions::Numeric::Bytes::GIGABYTE

which ensures our bases match up and the math is right.

How are other people handling this or am I the only one?

--------- tests ------------

  def test_god_did_not_redefine_kilobyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::KILOBYTE, 1.kilobyte,
"kilobyte was redefined"
  end

  def test_god_did_not_redefine_megabyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::MEGABYTE, 1.megabyte,
"megabyte was redefined"
  end

  def test_god_did_not_redefine_gigabyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::GIGABYTE, 1.gigabyte,
"gigabyte was redefined"
  end

  def test_god_did_not_redefine_terabyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::TERABYTE, 1.terabyte,
"terabyte was redefined"
  end

  def test_god_did_not_redefine_petabyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::PETABYTE, 1.petabyte,
"petabyte was redefined"
  end

  def test_god_did_not_redefine_exabyte
    assert_equal
ActiveSupport::CoreExtensions::Numeric::Bytes::EXABYTE, 1.exabyte,
"exabyte was redefined"
  end


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"god.rb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/god-rb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to