money-rails 0.6.0 → 0.7.0.pre1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 (coming soon)
4
+ - Added custom validator for Money fields (GH-36)
5
+ TODO: decouple validator from active_record
6
+ - Added mongodb service test support for travis CI
7
+ - Fixed issue with current value assignment in text_field tags (GH-37)
8
+ - Fixed issue related to symbolized keys in Mongoid (GH-40)
9
+
3
10
  ## 0.6.0
4
11
  - Added basic support for Mongoid >= 3.0.
5
12
  - Allow class methods to be monetized (ActiveRecord only - GH-34)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RubyMoney - Money-Rails
1
+ # RubyMoney - Money-Rails [![endorse](http://api.coderwall.com/alup/endorsecount.png)](http://coderwall.com/alup)
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/RubyMoney/money-rails.png?branch=master)](http://travis-ci.org/RubyMoney/money-rails)
4
4
  [![Dependency Status](https://gemnasium.com/RubyMoney/money-rails.png)](https://gemnasium.com/RubyMoney/money-rails)
@@ -342,6 +342,12 @@ without the cents part.
342
342
  * ActiveRecord (>= 3.x)
343
343
  * Mongoid (2.x, 3.x)
344
344
 
345
+ ## Supported Ruby interpreters
346
+
347
+ * MRI Ruby >= 1.9.2
348
+
349
+ You can see a full list of the currently supported interpreters in [travis.yml](http://github.com/RubyMoney/money-rails/blob/master/.travis.yml)
350
+
345
351
  ## Maintainers
346
352
 
347
353
  * Andreas Loupasakis (https://github.com/alup)
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ invalid_currencym: Must be a valid currency (eg. '100', '5%{decimal}24', or '123%{thousands}456%{decimal}78')
5
+
@@ -0,0 +1,5 @@
1
+ es:
2
+ errors:
3
+ messages:
4
+ invalid_currencym: Must be a valid currency (eg. '100', '5%{decimal}24', or '123%{thousands}456%{decimal}78')
5
+
data/lib/money-rails.rb CHANGED
@@ -9,4 +9,5 @@ end
9
9
 
10
10
  if defined? Rails
11
11
  require "money-rails/railtie"
12
+ require "money-rails/engine"
12
13
  end
@@ -0,0 +1,57 @@
1
+ module MoneyRails
2
+ module ActiveModel
3
+ class MoneyValidator < ::ActiveModel::Validations::NumericalityValidator
4
+ def validate_each(record, attr, value)
5
+
6
+ # If subunit is not set then no need to validate as it is an
7
+ # indicator that no assignment has been done onto the virtual
8
+ # money field.
9
+ subunit_attr = record.class.monetized_attributes[attr.to_sym]
10
+ return unless record.changed_attributes.keys.include? subunit_attr
11
+
12
+ # WARNING: Currently this is only defined in ActiveRecord extension!
13
+ before_type_cast = "#{attr}_money_before_type_cast"
14
+ raw_value = record.send(before_type_cast) if record.respond_to?(before_type_cast.to_sym)
15
+
16
+ # Skip it if raw_value is already a Money object
17
+ return if raw_value.is_a?(Money) || raw_value.nil?
18
+
19
+ if !raw_value.blank?
20
+ # remove currency symbol, and negative sign
21
+ currency = record.send("currency_for_#{attr}")
22
+ raw_value = raw_value.to_s.gsub(currency.symbol, "").gsub(/^-/, "")
23
+
24
+ decimal_pieces = raw_value.split(currency.decimal_mark)
25
+
26
+ # check for numbers like 12.23.45
27
+ if decimal_pieces.length > 2
28
+ record.errors.add(attr, I18n.t('errors.messages.invalid_currencym',
29
+ { :thousands => currency.thousands_separator,
30
+ :decimal => currency.decimal_mark }))
31
+ end
32
+
33
+ pieces = decimal_pieces[0].split(currency.thousands_separator)
34
+
35
+ # check for valid thousands separation
36
+ if pieces.length > 1
37
+ record.errors.add(attr, I18n.t('errors.messages.invalid_currencym',
38
+ { :thousands => currency.thousands_separator,
39
+ :decimal => currency.decimal_mark })) if pieces[0].length > 3
40
+ (1..pieces.length-1).each do |index|
41
+ record.errors.add(attr, I18n.t('errors.messages.invalid_currencym',
42
+ { :thousands => currency.thousands_separator,
43
+ :decimal => currency.decimal_mark })) if pieces[index].length != 3
44
+ end
45
+ end
46
+
47
+ # remove thousands separators
48
+ raw_value = raw_value.to_s.gsub(currency.thousands_separator, '')
49
+
50
+ # normalize decimal mark
51
+ raw_value = raw_value.to_s.gsub(currency.decimal_mark, '.')
52
+ end
53
+ super(record, attr, raw_value)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -43,11 +43,25 @@ module MoneyRails
43
43
  name = subunit_name.sub(/_cents$/, "")
44
44
  else
45
45
  # FIXME: provide a better default
46
- name = subunit_name << "_money"
46
+ name = [subunit_name, "money"].join("_")
47
47
  end
48
48
 
49
+ # Create a reverse mapping of the monetized attributes
50
+ @monetized_attributes ||= {}
51
+ @monetized_attributes[name.to_sym] = subunit_name
52
+ class << self
53
+ def monetized_attributes
54
+ @monetized_attributes || superclass.monetized_attributes
55
+ end
56
+ end unless respond_to? :monetized_attributes
57
+
49
58
  # Include numericality validation if needed
50
- validates_numericality_of subunit_name, :allow_nil => options[:allow_nil] if MoneyRails.include_validations
59
+ if MoneyRails.include_validations
60
+ validates_numericality_of subunit_name, :allow_nil => options[:allow_nil]
61
+
62
+ # Allow only Money objects or Numeric values!
63
+ validates name.to_sym, 'money_rails/active_model/money' => { :allow_nil => options[:allow_nil] }
64
+ end
51
65
 
52
66
  define_method name do |*args|
53
67
  amount = send(subunit_name, *args)
@@ -64,10 +78,18 @@ module MoneyRails
64
78
  end
65
79
 
66
80
  define_method "#{name}=" do |value|
81
+
82
+ # Lets keep the before_type_cast value
83
+ instance_variable_set "@#{name}_money_before_type_cast", value
84
+
67
85
  if options[:allow_nil] && value.blank?
68
86
  money = nil
69
87
  else
70
- money = value.is_a?(Money) ? value : value.to_money(send("currency_for_#{name}"))
88
+ begin
89
+ money = value.is_a?(Money) ? value : value.to_money(send("currency_for_#{name}"))
90
+ rescue NoMethodError
91
+ return nil
92
+ end
71
93
  end
72
94
 
73
95
  send("#{subunit_name}=", money.try(:cents))
@@ -87,6 +109,16 @@ module MoneyRails
87
109
  Money.default_currency
88
110
  end
89
111
  end
112
+
113
+ define_method "#{name}_money_before_type_cast" do
114
+ instance_variable_get "@#{name}_money_before_type_cast"
115
+ end
116
+
117
+ # Hook to ensure the reset of before_type_cast attr
118
+ # TODO: think of a better way to avoid this
119
+ after_validation do
120
+ instance_variable_set "@#{name}_money_before_type_cast", nil
121
+ end
90
122
  end
91
123
 
92
124
  def register_currency(currency_name)
@@ -0,0 +1,4 @@
1
+ module MoneyRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -3,6 +3,7 @@ module MoneyRails
3
3
  def self.init
4
4
  # For Active Record
5
5
  ActiveSupport.on_load(:active_record) do
6
+ require 'money-rails/active_model/validator'
6
7
  require 'money-rails/active_record/monetizable'
7
8
  ::ActiveRecord::Base.send :include, MoneyRails::ActiveRecord::Monetizable
8
9
  end
@@ -13,17 +13,24 @@ class Money
13
13
  # Get the object as it was stored in the database, and instantiate
14
14
  # this custom class from it.
15
15
  def demongoize(object)
16
- return nil if object.nil?
17
-
18
- ::Money.new(object[:cents], object[:currency_iso])
16
+ if object.is_a?(Hash)
17
+ object = object.symbolize_keys
18
+ object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil
19
+ else
20
+ nil
21
+ end
19
22
  end
20
23
 
21
24
  # Takes any possible object and converts it to how it would be
22
25
  # stored in the database.
23
26
  def mongoize(object)
24
- case object
25
- when Money then object.mongoize
26
- when Hash then ::Money.new(object[:cents], object[:currency]).mongoize
27
+ case
28
+ when object.is_a?(Money) then object.mongoize
29
+ when object.is_a?(Hash) then
30
+ object.symbolize_keys!
31
+ ::Money.new(object[:cents], object[:currency]).mongoize
32
+ when object.respond_to?(:to_money) then
33
+ object.to_money.mongoize
27
34
  else object
28
35
  end
29
36
  end
@@ -15,11 +15,15 @@ class Money
15
15
 
16
16
  # Money -> Mongo friendly
17
17
  def serialize(object)
18
- return nil unless object.is_a? Money
19
-
20
- {
21
- :cents => object.cents,
22
- :currency_iso => object.currency.iso_code
23
- }
18
+ case
19
+ when object.is_a?(Money)
20
+ {
21
+ :cents => object.cents,
22
+ :currency_iso => object.currency.iso_code
23
+ }
24
+ when object.respond_to?(:to_money)
25
+ serialize(object.to_money)
26
+ else nil
27
+ end
24
28
  end
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module MoneyRails
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0.pre1"
3
3
  end
data/money-rails.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Money gem integration with Rails"
13
13
  s.homepage = "https://github.com/RubyMoney/money-rails"
14
14
 
15
- s.files = Dir.glob("{lib,spec}/**/*")
15
+ s.files = Dir.glob("{lib,spec,config}/**/*")
16
16
  s.files += %w(CHANGELOG.md LICENSE README.md)
17
17
  s.files += %w(Rakefile money-rails.gemspec)
18
18
 
@@ -20,13 +20,11 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.require_path = "lib"
22
22
 
23
- s.add_dependency "money", "~> 5.0.0"
23
+ s.add_dependency "money", "~> 5.1.0"
24
24
  s.add_dependency "activesupport", "~> 3.0"
25
25
  s.add_dependency "railties", "~> 3.0"
26
26
 
27
27
  s.add_development_dependency "rails", "~> 3.0"
28
- s.add_development_dependency "rspec", "~> 2.10"
29
28
  s.add_development_dependency "rspec-rails", "~> 2.10"
30
- s.add_development_dependency "guard-rspec", "~> 1.1"
31
29
  s.add_development_dependency 'database_cleaner', ['>= 0.8.0']
32
30
  end
@@ -1,15 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
+ class Sub < Product; end
4
+
3
5
  if defined? ActiveRecord
4
6
  describe MoneyRails::ActiveRecord::Monetizable do
5
-
6
7
  describe "monetize" do
7
8
  before :each do
8
9
  @product = Product.create(:price_cents => 3000, :discount => 150,
9
- :bonus_cents => 200, :optional_price => 100)
10
+ :bonus_cents => 200, :optional_price => 100,
11
+ :sale_price_amount => 1200)
10
12
  @service = Service.create(:charge_cents => 2000, :discount_cents => 120)
11
13
  end
12
14
 
15
+ it "should be inherited by subclasses" do
16
+ Sub.monetized_attributes.should == Product.monetized_attributes
17
+ end
18
+
13
19
  it "attaches a Money object to model field" do
14
20
  @product.price.should be_an_instance_of(Money)
15
21
  @product.discount_value.should be_an_instance_of(Money)
@@ -26,6 +32,18 @@ if defined? ActiveRecord
26
32
  @product.price_cents.should == 3210
27
33
  end
28
34
 
35
+ it "assigns the correct value from a Money object using create" do
36
+ @product = Product.create(:price => Money.new(3210, "USD"), :discount => 150,
37
+ :bonus_cents => 200, :optional_price => 100)
38
+ @product.valid?.should be_true
39
+ @product.price_cents.should == 3210
40
+ end
41
+
42
+ it "updates correctly from a Money object using update_attributes" do
43
+ @product.update_attributes(:price => Money.new(215, "USD")).should be_true
44
+ @product.price_cents.should == 215
45
+ end
46
+
29
47
  it "respects :as argument" do
30
48
  @product.discount_value.should == Money.new(150, "USD")
31
49
  end
@@ -38,6 +56,45 @@ if defined? ActiveRecord
38
56
  @product.save.should be_true
39
57
  end
40
58
 
59
+ it "respects numericality validation when using update_attributes" do
60
+ @product.update_attributes(:price_cents => "some text").should be_false
61
+ @product.update_attributes(:price_cents => 2000).should be_true
62
+ end
63
+
64
+ it "uses numericality validation on money attribute" do
65
+ @product.price = "some text"
66
+ @product.save.should be_false
67
+
68
+ @product.price = Money.new(320, "USD")
69
+ @product.save.should be_true
70
+
71
+ @product.sale_price = "12,34"
72
+ @product.sale_price_currency_code = 'EUR'
73
+ @product.valid?.should be_true
74
+ end
75
+
76
+ it "fails validation with the proper error message if money value is invalid decimal" do
77
+ @product.price = "12.23.24"
78
+ @product.save.should be_false
79
+ @product.errors[:price].first.should match(/Must be a valid/)
80
+ end
81
+
82
+ it "fails validation with the proper error message if money value has invalid thousands part" do
83
+ @product.price = "12,23.24"
84
+ @product.save.should be_false
85
+ @product.errors[:price].first.should match(/Must be a valid/)
86
+ end
87
+
88
+ it "passes validation if money value has correct format" do
89
+ @product.price = "12,230.24"
90
+ @product.save.should be_true
91
+ end
92
+
93
+ it "respects numericality validation when using update_attributes on money attribute" do
94
+ @product.update_attributes(:price => "some text").should be_false
95
+ @product.update_attributes(:price => Money.new(320, 'USD')).should be_true
96
+ end
97
+
41
98
  it "doesn't allow nil by default" do
42
99
  @product.price_cents = nil
43
100
  @product.save.should be_false
@@ -49,6 +106,32 @@ if defined? ActiveRecord
49
106
  @product.optional_price.should be_nil
50
107
  end
51
108
 
109
+ it "doesn't raise exception if validation is used and nil is not allowed" do
110
+ expect { @product.price = nil }.to_not raise_error
111
+ end
112
+
113
+ it "doesn't save nil values if validation is used and nil is not allowed" do
114
+ @product.price = nil
115
+ @product.save
116
+ @product.price_cents.should_not be_nil
117
+ end
118
+
119
+ it "resets money_before_type_cast attr every time a save operation occurs" do
120
+ v = Money.new(100, :usd)
121
+ @product.price = v
122
+ @product.price_money_before_type_cast.should == v
123
+ @product.save
124
+ @product.price_money_before_type_cast.should be_nil
125
+ @product.price = 10
126
+ @product.price_money_before_type_cast.should == 10
127
+ @product.save
128
+ @product.price_money_before_type_cast.should be_nil
129
+ @product.bonus = ""
130
+ @product.bonus_money_before_type_cast.should == ""
131
+ @product.save.should be_false
132
+ @product.bonus_money_before_type_cast.should be_nil
133
+ end
134
+
52
135
  it "uses Money default currency if :with_currency has not been used" do
53
136
  @service.discount.currency.should == Money::Currency.find(:eur)
54
137
  end
@@ -1,210 +1,68 @@
1
-  (0.1ms) select sqlite_version(*)
2
-  (123.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
3
-  (0.1ms) PRAGMA index_list("schema_migrations")
4
-  (83.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
5
-  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
6
- Migrating to CreateProducts (20120331190108)
7
-  (0.1ms) begin transaction
8
-  (1.0ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
9
-  (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120331190108')
10
-  (176.2ms) commit transaction
11
-  (0.3ms) select sqlite_version(*)
12
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
13
-  (0.0ms) PRAGMA index_list("products")
14
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
15
-  (0.3ms) select sqlite_version(*)
16
-  (127.2ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
17
-  (113.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
18
-  (0.0ms) PRAGMA index_list("schema_migrations")
19
-  (133.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
20
-  (0.1ms) SELECT version FROM "schema_migrations"
21
-  (115.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20120331190108')
22
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
1
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
23
2
  Migrating to CreateProducts (20120331190108)
24
3
  Migrating to AddBonusCentsToProduct (20120402080348)
25
- Migrating to AddCurrencyToProduct (20120402080614)
26
- Migrating to CreateServices (20120524052716)
27
-  (0.1ms) select sqlite_version(*)
4
+  (0.0ms) select sqlite_version(*)
28
5
   (0.0ms) begin transaction
29
-  (0.6ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
30
-  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120524052716')
31
-  (158.1ms) commit transaction
32
-  (0.3ms) select sqlite_version(*)
6
+  (0.2ms) ALTER TABLE "products" ADD "bonus_cents" integer
7
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120402080348')
8
+  (90.4ms) commit transaction
9
+ Migrating to AddCurrencyToProduct (20120402080614)
10
+  (0.1ms) begin transaction
11
+  (0.4ms) ALTER TABLE "products" ADD "currency" varchar(255)
12
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120402080614')
13
+  (69.9ms) commit transaction
14
+  (0.2ms) select sqlite_version(*)
33
15
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
34
16
   (0.0ms) PRAGMA index_list("products")
35
-  (0.0ms) PRAGMA index_list("services")
36
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
37
-  (0.3ms) select sqlite_version(*)
38
-  (156.5ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer, "currency" varchar(255)) 
39
-  (95.7ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
40
-  (127.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
41
-  (0.1ms) PRAGMA index_list("schema_migrations")
42
-  (103.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
43
-  (0.2ms) SELECT version FROM "schema_migrations"
44
-  (87.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20120524052716')
45
-  (88.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20120402080348')
46
-  (110.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20120402080614')
47
-  (99.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20120331190108')
48
-  (0.3ms) SELECT version FROM schema_migrations
49
17
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
50
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
51
- Migrating to CreateServices (20120524052716)
52
-  (0.0ms) select sqlite_version(*)
53
-  (0.0ms) begin transaction
54
-  (0.5ms) DROP TABLE "services"
55
-  (0.1ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20120524052716'
56
-  (113.5ms) commit transaction
57
-  (0.7ms) select sqlite_version(*)
58
-  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
59
-  (0.0ms) PRAGMA index_list("products")
60
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
61
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
18
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
62
19
  Migrating to AddCurrencyToProduct (20120402080614)
63
20
   (0.0ms) select sqlite_version(*)
64
21
   (0.0ms) begin transaction
65
-  (0.6ms) CREATE TEMPORARY TABLE "altered_products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer, "currency" varchar(255)) 
22
+  (0.3ms) CREATE TEMPORARY TABLE "altered_products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer, "currency" varchar(255)) 
66
23
   (0.0ms) PRAGMA index_list("products")
67
24
   (0.1ms) SELECT * FROM "products"
68
-  (0.2ms) DROP TABLE "products"
69
-  (0.2ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer) 
25
+  (0.1ms) DROP TABLE "products"
26
+  (0.1ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer) 
70
27
   (0.0ms) PRAGMA index_list("altered_products")
71
-  (0.1ms) SELECT * FROM "altered_products"
72
-  (0.2ms) DROP TABLE "altered_products"
28
+  (0.0ms) SELECT * FROM "altered_products"
29
+  (0.1ms) DROP TABLE "altered_products"
73
30
   (0.1ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20120402080614'
74
-  (127.3ms) commit transaction
31
+  (147.4ms) commit transaction
75
32
   (0.3ms) select sqlite_version(*)
76
33
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
77
34
   (0.0ms) PRAGMA index_list("products")
78
-  (0.1ms) SELECT version FROM schema_migrations
79
-  (0.1ms) SELECT version FROM schema_migrations
80
35
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
81
- Migrating to CreateProducts (20120331190108)
36
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
82
37
  Migrating to AddBonusCentsToProduct (20120402080348)
83
- Migrating to CreateServices (20120524052716)
84
-  (0.0ms) select sqlite_version(*)
85
-  (0.0ms) begin transaction
86
-  (0.6ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
87
-  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120524052716')
88
-  (194.2ms) commit transaction
89
-  (0.7ms) select sqlite_version(*)
90
-  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
91
-  (0.1ms) PRAGMA index_list("products")
92
-  (0.1ms) PRAGMA index_list("services")
93
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
94
-  (0.3ms) select sqlite_version(*)
95
-  (144.5ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer) 
96
-  (106.8ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
97
-  (127.8ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
98
-  (0.0ms) PRAGMA index_list("schema_migrations")
99
-  (82.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
100
-  (0.2ms) SELECT version FROM "schema_migrations"
101
-  (76.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20120524052716')
102
-  (88.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20120402080348')
103
-  (77.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20120331190108')
104
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
105
- Migrating to CreateProducts (20120331190108)
106
- Migrating to AddBonusCentsToProduct (20120402080348)
107
- Migrating to CreateServices (20120524052716)
108
- Migrating to CreateTransactions (20120528181002)
109
-  (0.1ms) select sqlite_version(*)
110
-  (0.0ms) begin transaction
111
-  (0.6ms) CREATE TABLE "transactions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "amount_cents" integer, "tax_cents" integer, "currency" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
112
-  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120528181002')
113
-  (167.5ms) commit transaction
114
-  (0.4ms) select sqlite_version(*)
115
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
38
+  (0.0ms) select sqlite_version(*)
39
+  (0.0ms) begin transaction
40
+  (0.3ms) CREATE TEMPORARY TABLE "altered_products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer) 
41
+  (0.0ms) PRAGMA index_list("products")
42
+  (0.1ms) SELECT * FROM "products"
43
+  (0.1ms) DROP TABLE "products"
44
+  (0.1ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
45
+  (0.0ms) PRAGMA index_list("altered_products")
46
+  (0.0ms) SELECT * FROM "altered_products"
47
+  (0.1ms) DROP TABLE "altered_products"
48
+  (0.1ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20120402080348'
49
+  (114.1ms) commit transaction
50
+  (0.1ms) select sqlite_version(*)
51
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
116
52
   (0.0ms) PRAGMA index_list("products")
117
-  (0.0ms) PRAGMA index_list("services")
118
-  (0.0ms) PRAGMA index_list("transactions")
119
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
120
-  (0.3ms) select sqlite_version(*)
121
-  (165.3ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer) 
122
-  (91.6ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
123
-  (119.4ms) CREATE TABLE "transactions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "amount_cents" integer, "tax_cents" integer, "currency" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
124
-  (90.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
125
-  (0.0ms) PRAGMA index_list("schema_migrations")
126
-  (134.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
127
-  (0.1ms) SELECT version FROM "schema_migrations"
128
-  (97.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20120528181002')
129
-  (88.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20120524052716')
130
-  (88.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20120402080348')
131
-  (110.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20120331190108')
132
53
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
133
54
  Migrating to CreateProducts (20120331190108)
134
55
  Migrating to AddBonusCentsToProduct (20120402080348)
135
- Migrating to CreateServices (20120524052716)
136
- Migrating to CreateTransactions (20120528181002)
137
- Migrating to CreateDummyProducts (20120528210103)
138
56
   (0.0ms) select sqlite_version(*)
139
57
   (0.0ms) begin transaction
140
-  (0.6ms) CREATE TABLE "dummy_products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "currency" varchar(255), "price_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
141
-  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120528210103')
142
-  (140.3ms) commit transaction
143
-  (0.8ms) select sqlite_version(*)
144
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
145
-  (0.0ms) PRAGMA index_list("dummy_products")
146
-  (0.0ms) PRAGMA index_list("products")
147
-  (0.0ms) PRAGMA index_list("services")
148
-  (0.0ms) PRAGMA index_list("transactions")
149
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
150
-  (0.3ms) select sqlite_version(*)
151
-  (157.0ms) CREATE TABLE "dummy_products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "currency" varchar(255), "price_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
152
-  (122.6ms) CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "price_cents" integer, "discount" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "bonus_cents" integer)
153
-  (123.4ms) CREATE TABLE "services" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "charge_cents" integer, "discount_cents" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
154
-  (95.8ms) CREATE TABLE "transactions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "amount_cents" integer, "tax_cents" integer, "currency" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
155
-  (128.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
156
-  (0.1ms) PRAGMA index_list("schema_migrations")
157
-  (102.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
158
-  (0.2ms) SELECT version FROM "schema_migrations"
159
-  (109.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20120528210103')
160
-  (110.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20120524052716')
161
-  (121.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20120402080348')
162
-  (99.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20120528181002')
163
-  (99.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20120331190108')
164
- Connecting to database specified by database.yml
165
- Connecting to database specified by database.yml
166
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
167
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
168
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
169
- Connecting to database specified by database.yml
170
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
171
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
172
- Connecting to database specified by database.yml
173
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
174
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
175
- Connecting to database specified by database.yml
176
- MONGODB (0ms) dummy_development['system.namespaces'].find({})
177
- MONGODB (36ms) dummy_development['$cmd'].find({:create=>"priceables"}).limit(-1)
178
- MONGODB (0ms) dummy_development['priceables'].insert([{"_id"=>BSON::ObjectId('4fe8d4c2eac0741caf000001'), "price"=>{:cents=>100, :currency_iso=>"EUR"}}])
179
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
180
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
181
- Connecting to database specified by database.yml
182
- MONGODB (60ms) dummy_development['system.namespaces'].find({})
183
- MONGODB (0ms) dummy_development['$cmd'].find({"count"=>"priceables", "query"=>{}, "fields"=>nil}).limit(-1)
184
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
185
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
186
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
187
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
188
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
189
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
190
- MONGODB (0ms) dummy_development['priceables'].find({}).limit(-1).sort([[:_id, :asc]])
191
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
192
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
193
- Connecting to database specified by database.yml
194
- MONGODB (0ms) dummy_development['system.namespaces'].find({})
195
- MONGODB (0ms) dummy_development['$cmd'].find({"count"=>"priceables", "query"=>{}, "fields"=>nil}).limit(-1)
196
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
197
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
198
- Connecting to database specified by database.yml
199
- MONGODB (7ms) dummy_development['system.namespaces'].find({})
200
- MONGODB (0ms) dummy_development['$cmd'].find({"count"=>"priceables", "query"=>{}, "fields"=>nil}).limit(-1)
201
- MONGODB (0ms) dummy_development['priceables'].insert([{"_id"=>BSON::ObjectId('4feb6f8feac07427a9000001'), "price"=>{:cents=>245, :currency_iso=>"EUR"}}])
202
- MONGODB (0ms) dummy_development['$cmd'].find({"count"=>"priceables", "query"=>{}, "fields"=>nil}).limit(-1)
203
- MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
204
- MONGODB (0ms) admin['$cmd'].find({:ismaster=>1}).limit(-1)
205
- Connecting to database specified by database.yml
206
- MONGODB (0ms) dummy_development['system.namespaces'].find({})
207
- MONGODB (0ms) dummy_development['$cmd'].find({"count"=>"priceables", "query"=>{}, "fields"=>nil}).limit(-1)
208
- Connecting to database specified by database.yml
209
- Connecting to database specified by database.yml
210
- Connecting to database specified by database.yml
58
+  (0.2ms) ALTER TABLE "products" ADD "bonus_cents" integer
59
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120402080348')
60
+  (108.4ms) commit transaction
61
+ Migrating to AddCurrencyToProduct (20120402080614)
62
+  (0.0ms) begin transaction
63
+  (0.2ms) ALTER TABLE "products" ADD "currency" varchar(255)
64
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120402080614')
65
+  (76.9ms) commit transaction
66
+  (0.4ms) select sqlite_version(*)
67
+  (0.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
68
+  (0.0ms) PRAGMA index_list("products")