easy_rails_money 0.0.4 → 0.0.5

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
@@ -19,6 +19,10 @@ _yardoc
19
19
  doc/
20
20
  rdoc
21
21
 
22
+ # temporary emacs files
23
+ \#*
24
+ \.\#*
25
+
22
26
  .rvmrc
23
27
  .ruby-version
24
28
  .ruby-gemset
data/CHANGELOG.md CHANGED
@@ -21,3 +21,12 @@
21
21
 
22
22
  ## 0.0.4
23
23
  - add dsl with_currency for defining a single currency on the model
24
+
25
+ ## 0.0.5
26
+ - bugfix: defining a model before the table is created throws an error
27
+ see spec tagged with `migration`.
28
+ if we define a ActiveRecord object with a money column
29
+ "before" the table is defined. Then it will throw
30
+ an error and we will assume that a single
31
+ currency is defined. So always restart the app after the
32
+ migrations are run.
data/README.md CHANGED
@@ -361,3 +361,10 @@ loan_usd.currency # equals Money::Currency.new(:usd)
361
361
  11. the column names are suffixed with ```_money``` and ```_currency```
362
362
  We need this for now, to reflect on the database scheme.
363
363
  Ideally should be able to read the metadata from rails scheme cache.
364
+ 12. see spec tagged with `migration`.
365
+ if we define a ActiveRecord object with a money column
366
+ "before" the table is defined. Then it will throw
367
+ an error and we will assume that a single
368
+ currency is defined. So always restart the app after the
369
+ migrations are run.
370
+ Any better way ?
@@ -10,7 +10,17 @@ module EasyRailsMoney
10
10
  attr_accessor :single_currency
11
11
 
12
12
  def single_currency?
13
+ # if we define a ActiveRecord object with a money column
14
+ # "before" the table is defined. Then it will throw an error
15
+ # and we will assume that a single currency is defined
16
+ # So always restart the app after the migrations are run
13
17
  self.columns_hash.has_key? "currency"
18
+ rescue ::ActiveRecord::StatementInvalid => err
19
+ if err.message =~ /Could not find table/
20
+ return true
21
+ else
22
+ raise
23
+ end
14
24
  end
15
25
 
16
26
  def with_currency currency, &block
@@ -1,3 +1,3 @@
1
1
  module EasyRailsMoney
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'active_record_spec_helper'
3
- require 'tempfile'
4
3
  require 'active_record/schema_dumper'
5
4
 
6
5
  # migrations used in tests. our factories/fixtures
@@ -233,7 +232,7 @@ EOF
233
232
  end
234
233
  EOF
235
234
  end
236
-
235
+
237
236
  context "and testing schema statements", :schema_statements do
238
237
  context "which have one currency column for each money column" do
239
238
  before(:each) do
@@ -26,6 +26,22 @@ describe "Money DSL" do
26
26
  describe "#money" do
27
27
  # validations
28
28
 
29
+ # the #money dsl queries the database schema to find out if a
30
+ # single-currency column is defined. or does every money column
31
+ # have its own currency column. If no table exists we assume that
32
+ # a single currency column exists (so that no error is thrown).
33
+ # for this to work, the app has to be reloaded after the migration
34
+ # is run
35
+ it "does not throw an error if a model is defined without the table being created ie. before the migration runs", :fixme, :migration do
36
+ expect(dump_schema).to be_blank
37
+ expect {
38
+ class Loan < ActiveRecord::Base
39
+ attr_accessible :name
40
+ money :principal
41
+ end
42
+ }.to_not raise_error
43
+ end
44
+
29
45
  context "individual currency columns" do
30
46
  before(:each) do
31
47
  migrate CreateTableDefinition::CreateLoanWithoutCurrency
@@ -1,3 +1,5 @@
1
+ require 'tempfile'
2
+
1
3
  module CreateTableDefinition
2
4
  class CreateLoanWithCurrency < ActiveRecord::Migration
3
5
  def change
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_rails_money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: money
@@ -242,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
242
  version: '0'
243
243
  segments:
244
244
  - 0
245
- hash: -2090962941235077945
245
+ hash: 539753263843198908
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  none: false
248
248
  requirements:
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  version: '0'
252
252
  segments:
253
253
  - 0
254
- hash: -2090962941235077945
254
+ hash: 539753263843198908
255
255
  requirements: []
256
256
  rubyforge_project:
257
257
  rubygems_version: 1.8.24