mm-money 0.1.0 → 0.1.1

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 CHANGED
@@ -2,4 +2,4 @@ announcement.txt
2
2
  coverage
3
3
  doc
4
4
  pkg
5
-
5
+ spec/log/*
@@ -3,30 +3,21 @@ require 'money'
3
3
 
4
4
  class Money
5
5
  def self.to_mongo(value)
6
- value = if value.instance_of? Money
6
+ if value.kind_of?(Array)
7
7
  value
8
- elsif value.kind_of? Numeric
9
- value.to_money
10
- elsif value.kind_of? String
11
- value.to_money
12
- end
13
-
14
- unless value.nil?
15
- value.format(:with_currency => true)
16
- else
8
+ elsif value.nil? || !value.respond_to?(:to_money)
17
9
  nil
10
+ else
11
+ value = value.to_money
12
+ [value.cents, value.currency.iso_code]
18
13
  end
19
14
  end
20
15
 
21
16
  def self.from_mongo(value)
22
- if value.instance_of? Money
23
- value
24
- elsif value.kind_of? Numeric
25
- value.to_money
26
- elsif value.kind_of? String
27
- value.to_money
28
- else
17
+ if value.nil?
29
18
  nil
19
+ else
20
+ Money.new(value.first, value.second)
30
21
  end
31
22
  end
32
23
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mm-money}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Toni Tuominen"]
9
- s.date = %q{2010-07-04}
9
+ s.date = %q{2010-07-12}
10
10
  s.description = %q{Handle money keys with MongoMapper.}
11
11
  s.email = %q{toni@piranhadigital.fi}
12
12
  s.extra_rdoc_files = ["History.txt", "README.txt", "version.txt"]
13
- s.files = [".gitignore", "History.txt", "README.txt", "Rakefile", "lib/mm-money.rb", "spec/log/spec.log", "spec/mm-money_spec.rb", "spec/spec_helper.rb", "version.txt"]
13
+ s.files = [".gitignore", "History.txt", "README.txt", "Rakefile", "lib/mm-money.rb", "mm-money.gemspec", "spec/mm-money_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "version.txt"]
14
14
  s.homepage = %q{http://github.com/tjtuom/mm-money}
15
15
  s.rdoc_options = ["--main", "README.txt"]
16
16
  s.require_paths = ["lib"]
@@ -22,6 +22,10 @@ describe "Money key" do
22
22
  Product.new(:price => 10).price.should be_kind_of(Money)
23
23
  end
24
24
 
25
+ it 'handles nils correctly' do
26
+ Product.new().price.should be_nil
27
+ end
28
+
25
29
  it 'handles integers correctly' do
26
30
  Product.new(:price => 10).price.should == Money.new(1000, 'EUR')
27
31
  end
@@ -34,6 +38,10 @@ describe "Money key" do
34
38
  Product.new(:price => '10').price.should == Money.new(1000, 'EUR')
35
39
  end
36
40
 
41
+ it 'handles money objects correctly' do
42
+ Product.new(:price => Money.new(1000, 'EUR')).price.should == Money.new(1000, 'EUR')
43
+ end
44
+
37
45
  it 'handles strings with currency in them correctly' do
38
46
  Product.new(:price => '10 USD').price.should == Money.new(1000, 'USD')
39
47
  end
@@ -44,10 +52,11 @@ describe "Money key" do
44
52
  end
45
53
 
46
54
  it 'handles sorting in the db properly' do
47
- first = Product.create!(:price => 10)
48
- third = Product.create!(:price => 30)
49
- second = Product.create!(:price => 20)
55
+ first = Product.create!(:price => 0)
56
+ third = Product.create!(:price => 35)
57
+ second = Product.create!(:price => 5)
50
58
 
51
59
  Product.sort(:price.asc).all.should == [first, second, third]
60
+ Product.sort(:price.desc).all.should == [third, second, first]
52
61
  end
53
62
  end
@@ -0,0 +1 @@
1
+ --color
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Toni Tuominen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-04 00:00:00 +03:00
17
+ date: 2010-07-12 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -90,8 +90,8 @@ files:
90
90
  - Rakefile
91
91
  - lib/mm-money.rb
92
92
  - mm-money.gemspec
93
- - spec/log/spec.log
94
93
  - spec/mm-money_spec.rb
94
+ - spec/spec.opts
95
95
  - spec/spec_helper.rb
96
96
  - version.txt
97
97
  has_rdoc: true
@@ -1,69 +0,0 @@
1
- # Logfile created on Sun Jul 04 10:28:58 +0300 2010 by logger.rb/22285
2
- MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
3
- MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
4
- MONGODB mm-money-test-1-8-7['products'].remove({})
5
- MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
6
- MONGODB mm-money-test-1-8-7['products'].remove({})
7
- MONGODB mm-money-test-1-8-7['products'].remove({})
8
- MONGODB mm-money-test-1-8-7['products'].remove({})
9
- MONGODB mm-money-test-1-8-7['products'].remove({})
10
- MONGODB mm-money-test-1-8-7['products'].remove({})
11
- MONGODB mm-money-test-1-8-7['products'].remove({})
12
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000006')})
13
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
14
- MONGODB mm-money-test-1-8-7['products'].remove({})
15
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000007')})
16
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000008')})
17
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000009')})
18
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
19
- MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
20
- MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
21
- MONGODB mm-money-test-1-8-7['products'].remove({})
22
- MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
23
- MONGODB mm-money-test-1-8-7['products'].remove({})
24
- MONGODB mm-money-test-1-8-7['products'].remove({})
25
- MONGODB mm-money-test-1-8-7['products'].remove({})
26
- MONGODB mm-money-test-1-8-7['products'].remove({})
27
- MONGODB mm-money-test-1-8-7['products'].remove({})
28
- MONGODB mm-money-test-1-8-7['products'].remove({})
29
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000006')})
30
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
31
- MONGODB mm-money-test-1-8-7['products'].remove({})
32
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000007')})
33
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000008')})
34
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000009')})
35
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
36
- MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
37
- MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
38
- MONGODB mm-money-test-1-8-7['products'].remove({})
39
- MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
40
- MONGODB mm-money-test-1-8-7['products'].remove({})
41
- MONGODB mm-money-test-1-8-7['products'].remove({})
42
- MONGODB mm-money-test-1-8-7['products'].remove({})
43
- MONGODB mm-money-test-1-8-7['products'].remove({})
44
- MONGODB mm-money-test-1-8-7['products'].remove({})
45
- MONGODB mm-money-test-1-8-7['products'].remove({})
46
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000006')})
47
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
48
- MONGODB mm-money-test-1-8-7['products'].remove({})
49
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000007')})
50
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000008')})
51
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000009')})
52
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
53
- MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
54
- MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
55
- MONGODB mm-money-test-1-8-7['products'].remove({})
56
- MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
57
- MONGODB mm-money-test-1-8-7['products'].remove({})
58
- MONGODB mm-money-test-1-8-7['products'].remove({})
59
- MONGODB mm-money-test-1-8-7['products'].remove({})
60
- MONGODB mm-money-test-1-8-7['products'].remove({})
61
- MONGODB mm-money-test-1-8-7['products'].remove({})
62
- MONGODB mm-money-test-1-8-7['products'].remove({})
63
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000006')})
64
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
65
- MONGODB mm-money-test-1-8-7['products'].remove({})
66
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000007')})
67
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000008')})
68
- MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000009')})
69
- MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])