/
test_helpers_spec.rb
64 lines (49 loc) · 1.85 KB
/
test_helpers_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- encoding : utf-8 -*-
require 'spec_helper'
if defined? ActiveRecord
describe 'TestHelpers' do
require "money-rails/test_helpers"
include MoneyRails::TestHelpers
let(:product) do
Product.create(:price_cents => 3000, :discount => 150,
:bonus_cents => 200,
:sale_price_amount => 1200)
end
describe "monetize matcher" do
shared_context "monetize matcher" do
it "matches model attribute without a '_cents' suffix by default" do
is_expected.to monetize(:price)
end
it "matches model attribute specified by :as chain" do
is_expected.to monetize(:discount).as(:discount_value)
end
it "matches model attribute with nil value specified by :allow_nil chain" do
is_expected.to monetize(:optional_price).allow_nil
end
it "matches nullable model attribute when tested instance has a non-nil value" do
is_expected.to monetize(:optional_price).allow_nil
end
it "matches model attribute with currency specified by :with_currency chain" do
is_expected.to monetize(:bonus).with_currency(:gbp)
end
it "does not match non existed attribute" do
is_expected.not_to monetize(:price_fake)
end
it "does not match wrong currency iso" do
is_expected.not_to monetize(:bonus).with_currency(:usd)
end
it "does not match wrong money attribute name" do
is_expected.not_to monetize(:bonus).as(:bonussss)
end
end
describe "testing against an instance of the model class" do
subject { product }
include_context "monetize matcher"
end
describe "testing against the model class itself" do
subject { Product }
include_context "monetize matcher"
end
end
end
end