class MoneyRails::TestHelpers::MonetizeMatcher
Public Class Methods
new(attribute)
click to toggle source
# File lib/money-rails/test_helpers.rb, line 10 def initialize(attribute) @attribute = attribute end
Public Instance Methods
allow_nil()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 29 def allow_nil @allow_nil = true self end
as(virt_attr)
click to toggle source
# File lib/money-rails/test_helpers.rb, line 24 def as(virt_attr) @as = virt_attr self end
description()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 52 def description desc = "monetize #{@attribute}" desc << " as #{@as}" if @as desc << " with currency #{@currency_iso}" if @currency_iso desc end
failure_message()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 59 def failure_message # RSpec 3.x msg = "expected that #{@attribute} of #{@actual} would be monetized" msg << " as #{@as}" if @as msg << " with currency #{@currency_iso}" if @currency_iso msg end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 67 def failure_message_when_negated # RSpec 3.x msg = "expected that #{@attribute} of #{@actual} would not be monetized" msg << " as #{@as}" if @as msg << " with currency #{@currency_iso}" if @currency_iso msg end
Also aliased as: failure_message_for_should_not, negative_failure_message
matches?(actual)
click to toggle source
# File lib/money-rails/test_helpers.rb, line 34 def matches?(actual) if actual.is_a?(Class) @actual = actual.new else @actual = actual.class.new end @money_attribute = @as.presence || @attribute.to_s.sub(/_cents$/, "") @money_attribute_setter = "#{@money_attribute}=" object_responds_to_attributes? && test_allow_nil && is_monetized? && test_currency_iso && test_currency_attribute end
with_currency(currency)
click to toggle source
# File lib/money-rails/test_helpers.rb, line 14 def with_currency(currency) @currency_iso = currency self end
with_model_currency(attribute)
click to toggle source
# File lib/money-rails/test_helpers.rb, line 19 def with_model_currency(attribute) @currency_attribute = attribute self end
Private Instance Methods
is_monetized?()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 91 def is_monetized? @actual.public_send(@money_attribute_setter, 1) @actual.public_send(@money_attribute).instance_of?(Money) end
object_responds_to_attributes?()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 78 def object_responds_to_attributes? @actual.respond_to?(@attribute) && @actual.respond_to?(@money_attribute) end
test_allow_nil()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 82 def test_allow_nil if @allow_nil @actual.public_send(@money_attribute_setter, "") @actual.public_send(@money_attribute).nil? else true end end
test_currency_attribute()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 104 def test_currency_attribute if @currency_attribute @actual.public_send(@money_attribute).currency == @actual.public_send(@currency_attribute) else true end end
test_currency_iso()
click to toggle source
# File lib/money-rails/test_helpers.rb, line 96 def test_currency_iso if @currency_iso @actual.public_send(@money_attribute).currency.id == @currency_iso else true end end