counterfeit 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/lib/counterfeit/active_record.rb +14 -3
- data/lib/counterfeit/version.rb +1 -1
- data/spec/counterfeit_spec.rb +17 -5
- data/spec/spec_helper.rb +1 -1
- metadata +54 -62
- data/counterfeit.sqlite3 +0 -0
- data/spec/debug.log +0 -63
data/.gitignore
CHANGED
@@ -8,20 +8,31 @@ module Counterfeit
|
|
8
8
|
options = options.with_indifferent_access
|
9
9
|
|
10
10
|
default_currency = options.delete(:currency).try(:to_s).try(:upcase)
|
11
|
+
|
11
12
|
amount_attr = options.delete(:amount_attribute) || "#{attr}_in_cents"
|
12
13
|
currency_attr = options.delete(:currency_attribute) || "#{attr}_currency"
|
13
14
|
|
14
15
|
mapping = [[ amount_attr, 'cents' ], [ currency_attr, 'currency_as_string' ]]
|
15
16
|
|
16
17
|
after_initialize do
|
17
|
-
self[currency_attr]
|
18
|
+
self[currency_attr] ||= default_currency || Money.default_currency.iso_code
|
19
|
+
end
|
20
|
+
|
21
|
+
constructor = lambda { |cents, currency| Money.new(cents || 0, currency) }
|
22
|
+
|
23
|
+
converter = lambda do |value|
|
24
|
+
if value.respond_to?(:to_money)
|
25
|
+
value.to_money(default_currency)
|
26
|
+
else
|
27
|
+
raise ArgumentError, "Can't convert #{value.class} to Money"
|
28
|
+
end
|
18
29
|
end
|
19
30
|
|
20
31
|
composed_of attr.to_sym,
|
21
32
|
:class_name => 'Money',
|
22
33
|
:mapping => mapping,
|
23
|
-
:constructor =>
|
24
|
-
:converter =>
|
34
|
+
:constructor => constructor,
|
35
|
+
:converter => converter
|
25
36
|
|
26
37
|
end
|
27
38
|
|
data/lib/counterfeit/version.rb
CHANGED
data/spec/counterfeit_spec.rb
CHANGED
@@ -19,9 +19,11 @@ describe Item do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should handle custom attribute names' do
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
Item.new(:money => 500).custom_money_amount.should == 500_00
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should respect default currency attribute' do
|
26
|
+
Item.new.custom_money_currency.should == 'EUR'
|
25
27
|
end
|
26
28
|
|
27
29
|
it 'should work witn has_money alias' do
|
@@ -36,7 +38,7 @@ describe Item do
|
|
36
38
|
it 'should automatically turn on google exchange on fail' do
|
37
39
|
Money.google_saved_the_day = false
|
38
40
|
Money.default_bank = Money::Bank::VariableExchange.instance
|
39
|
-
money = Money.new(
|
41
|
+
money = Money.new(500_00, 'USD')
|
40
42
|
lambda do
|
41
43
|
money.exchange_to('EUR')
|
42
44
|
end.should_not raise_error
|
@@ -46,10 +48,20 @@ describe Item do
|
|
46
48
|
|
47
49
|
it 'should use the google hack only once' do
|
48
50
|
Money.default_bank = Money::Bank::VariableExchange.instance
|
49
|
-
money = Money.new(
|
51
|
+
money = Money.new(500_00, 'USD')
|
50
52
|
money.bank.should be_kind_of(Money::Bank::VariableExchange)
|
51
53
|
lambda do
|
52
54
|
money.exchange_to('EUR')
|
53
55
|
end.should raise_error(Money::Bank::UnknownRate)
|
54
56
|
end
|
57
|
+
|
58
|
+
it 'should allow currency change' do
|
59
|
+
Money.default_currency = Money::Currency.new('USD')
|
60
|
+
item = Item.create
|
61
|
+
item.price_currency.should == 'USD'
|
62
|
+
item.update_attributes(:price => '100', :price_currency => 'RUB')
|
63
|
+
item.reload.price.should == Money.new(100_00, 'RUB')
|
64
|
+
item.save
|
65
|
+
item.reload.price_currency.should == 'RUB'
|
66
|
+
end
|
55
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -23,7 +23,7 @@ require File.expand_path('../../lib/counterfeit', __FILE__)
|
|
23
23
|
|
24
24
|
db_filename = 'counterfeit.sqlite3'
|
25
25
|
|
26
|
-
File.delete(db_filename)
|
26
|
+
File.delete(db_filename) if File.exists?(db_filename)
|
27
27
|
|
28
28
|
active_record_configuration = { :adapter => 'sqlite3', :database => db_filename }
|
29
29
|
|
metadata
CHANGED
@@ -1,128 +1,120 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: counterfeit
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Pavel Pravosud
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-07-25 00:00:00.000000000 +07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2158214320 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
|
-
requirements:
|
19
|
+
requirements:
|
21
20
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
24
23
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: money
|
28
24
|
prerelease: false
|
29
|
-
|
25
|
+
version_requirements: *2158214320
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: money
|
28
|
+
requirement: &2158213820 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
|
-
requirements:
|
30
|
+
requirements:
|
32
31
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
32
|
+
- !ruby/object:Gem::Version
|
34
33
|
version: 3.7.1
|
35
34
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: google_currency
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
version_requirements: *2158213820
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: google_currency
|
39
|
+
requirement: &2158213360 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
|
-
requirements:
|
41
|
+
requirements:
|
43
42
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
43
|
+
- !ruby/object:Gem::Version
|
45
44
|
version: 1.2.0
|
46
45
|
type: :runtime
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: sqlite3
|
50
46
|
prerelease: false
|
51
|
-
|
47
|
+
version_requirements: *2158213360
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: sqlite3
|
50
|
+
requirement: &2158212900 !ruby/object:Gem::Requirement
|
52
51
|
none: false
|
53
|
-
requirements:
|
52
|
+
requirements:
|
54
53
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
54
|
+
- !ruby/object:Gem::Version
|
56
55
|
version: 1.3.3
|
57
56
|
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: rspec
|
61
57
|
prerelease: false
|
62
|
-
|
58
|
+
version_requirements: *2158212900
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: &2158212440 !ruby/object:Gem::Requirement
|
63
62
|
none: false
|
64
|
-
requirements:
|
63
|
+
requirements:
|
65
64
|
- - ~>
|
66
|
-
- !ruby/object:Gem::Version
|
65
|
+
- !ruby/object:Gem::Version
|
67
66
|
version: 2.6.0
|
68
67
|
type: :development
|
69
|
-
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2158212440
|
70
70
|
description: Easy Money gem integration for rails 3.
|
71
|
-
email:
|
71
|
+
email:
|
72
72
|
- rwz@duckroll.ru
|
73
73
|
executables: []
|
74
|
-
|
75
74
|
extensions: []
|
76
|
-
|
77
75
|
extra_rdoc_files: []
|
78
|
-
|
79
|
-
files:
|
76
|
+
files:
|
80
77
|
- .gitignore
|
81
78
|
- Gemfile
|
82
79
|
- README.md
|
83
80
|
- Rakefile
|
84
81
|
- counterfeit.gemspec
|
85
|
-
- counterfeit.sqlite3
|
86
82
|
- lib/counterfeit.rb
|
87
83
|
- lib/counterfeit/active_record.rb
|
88
84
|
- lib/counterfeit/money.rb
|
89
85
|
- lib/counterfeit/schema.rb
|
90
86
|
- lib/counterfeit/version.rb
|
91
87
|
- spec/counterfeit_spec.rb
|
92
|
-
- spec/debug.log
|
93
88
|
- spec/models.rb
|
94
89
|
- spec/schema.rb
|
95
90
|
- spec/spec_helper.rb
|
91
|
+
has_rdoc: true
|
96
92
|
homepage: https://github.com/rwz/counterfeit
|
97
93
|
licenses: []
|
98
|
-
|
99
94
|
post_install_message:
|
100
95
|
rdoc_options: []
|
101
|
-
|
102
|
-
require_paths:
|
96
|
+
require_paths:
|
103
97
|
- lib
|
104
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
99
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
105
|
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version:
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
116
110
|
requirements: []
|
117
|
-
|
118
111
|
rubyforge_project: counterfeit
|
119
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.6.2
|
120
113
|
signing_key:
|
121
114
|
specification_version: 3
|
122
115
|
summary: Easy Money gem integration for rails 3.
|
123
|
-
test_files:
|
116
|
+
test_files:
|
124
117
|
- spec/counterfeit_spec.rb
|
125
|
-
- spec/debug.log
|
126
118
|
- spec/models.rb
|
127
119
|
- spec/schema.rb
|
128
120
|
- spec/spec_helper.rb
|
data/counterfeit.sqlite3
DELETED
Binary file
|
data/spec/debug.log
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# Logfile created on 2011-06-16 20:34:50 +0700 by logger.rb/25413
|
2
|
-
[1m[36mSQL (0.2ms)[0m [1m SELECT name
|
3
|
-
FROM sqlite_master
|
4
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
5
|
-
[0m
|
6
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'RUB', 0, 'RUB')
|
7
|
-
[1m[36mAREL (0.2ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'RUB', 0, 'RUB')[0m
|
8
|
-
[1m[36mSQL (0.2ms)[0m [1m SELECT name
|
9
|
-
FROM sqlite_master
|
10
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
11
|
-
[0m
|
12
|
-
[1m[35mAREL (0.4ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'RUB', 0, 'RUB')
|
13
|
-
[1m[36mAREL (0.4ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'RUB', 0, 'RUB')[0m
|
14
|
-
[1m[36mSQL (0.1ms)[0m [1m SELECT name
|
15
|
-
FROM sqlite_master
|
16
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
17
|
-
[0m
|
18
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')
|
19
|
-
[1m[36mAREL (0.2ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')[0m
|
20
|
-
[1m[36mSQL (0.2ms)[0m [1m SELECT name
|
21
|
-
FROM sqlite_master
|
22
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
23
|
-
[0m
|
24
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')
|
25
|
-
[1m[36mAREL (0.3ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')[0m
|
26
|
-
[1m[36mSQL (0.2ms)[0m [1m SELECT name
|
27
|
-
FROM sqlite_master
|
28
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
29
|
-
[0m
|
30
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')
|
31
|
-
[1m[36mAREL (0.3ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "money_in_cents", "money_currency") VALUES (0, 'RUB', 0, 'THB', 0, 'RUB')[0m
|
32
|
-
[1m[36mSQL (0.2ms)[0m [1m SELECT name
|
33
|
-
FROM sqlite_master
|
34
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
35
|
-
[0m
|
36
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)
|
37
|
-
[1m[36mAREL (0.3ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)[0m
|
38
|
-
[1m[36mSQL (0.1ms)[0m [1m SELECT name
|
39
|
-
FROM sqlite_master
|
40
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
41
|
-
[0m
|
42
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)
|
43
|
-
[1m[36mAREL (0.3ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)[0m
|
44
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', 50000, 'RUB')
|
45
|
-
[1m[36mSQL (0.1ms)[0m [1m SELECT name
|
46
|
-
FROM sqlite_master
|
47
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
48
|
-
[0m
|
49
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)
|
50
|
-
[1m[36mAREL (0.2ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)[0m
|
51
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', 50000, 'RUB')
|
52
|
-
[1m[36mSQL (0.1ms)[0m [1m SELECT name
|
53
|
-
FROM sqlite_master
|
54
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
55
|
-
[0m
|
56
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)
|
57
|
-
[1m[36mAREL (0.2ms)[0m [1mINSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', NULL, NULL)[0m
|
58
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', 50000, 'RUB')
|
59
|
-
[1m[36mSQL (0.1ms)[0m [1m SELECT name
|
60
|
-
FROM sqlite_master
|
61
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
62
|
-
[0m
|
63
|
-
[1m[35mAREL (0.3ms)[0m INSERT INTO "items" ("price_in_cents", "price_currency", "balance_in_cents", "balance_currency", "custom_money_amount", "custom_money_currency") VALUES (0, 'RUB', 0, 'THB', 50000, 'RUB')
|