Skip to content

Commit aa86548

Browse files
committed
Move monetized attributes tests to a new spec file for better organization
1 parent 628f321 commit aa86548

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

spec/active_record/monetizable/monetize_spec.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ def update_product(*attributes)
2626
end
2727
end
2828

29-
context ".monetized_attributes" do
30-
31-
class InheritedMonetizeProduct < Product
32-
monetize :special_price_cents
33-
end
34-
35-
it "should be inherited by subclasses" do
36-
assert_monetized_attributes(Sub.monetized_attributes, Product.monetized_attributes)
37-
end
38-
39-
it "should be inherited by subclasses with new monetized attribute" do
40-
assert_monetized_attributes(InheritedMonetizeProduct.monetized_attributes, Product.monetized_attributes.merge(special_price: "special_price_cents"))
41-
end
42-
43-
def assert_monetized_attributes(monetized_attributes, expected_attributes)
44-
expect(monetized_attributes).to include expected_attributes
45-
expect(expected_attributes).to include monetized_attributes
46-
expect(monetized_attributes.size).to eql expected_attributes.size
47-
monetized_attributes.keys.each do |key|
48-
expect(key.is_a? String).to be_truthy
49-
end
50-
end
51-
end
52-
5329
it "attaches a Money object to model field" do
5430
expect_to_have_money_attributes(product, :price, :discount_value, :bonus)
5531
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
require_relative 'money_helpers'
6+
7+
if defined? ActiveRecord
8+
describe MoneyRails::ActiveRecord::Monetizable do
9+
include MoneyHelpers
10+
11+
describe ".monetized_attributes" do
12+
13+
class InheritedMonetizeProduct < Product
14+
monetize :special_price_cents
15+
end
16+
17+
it "should be inherited by subclasses" do
18+
assert_monetized_attributes(Sub.monetized_attributes, Product.monetized_attributes)
19+
end
20+
21+
it "should be inherited by subclasses with new monetized attribute" do
22+
assert_monetized_attributes(InheritedMonetizeProduct.monetized_attributes, Product.monetized_attributes.merge(special_price: "special_price_cents"))
23+
end
24+
25+
def assert_monetized_attributes(monetized_attributes, expected_attributes)
26+
expect(monetized_attributes).to include expected_attributes
27+
expect(expected_attributes).to include monetized_attributes
28+
expect(monetized_attributes.size).to eql expected_attributes.size
29+
monetized_attributes.keys.each do |key|
30+
expect(key.is_a? String).to be_truthy
31+
end
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)