acts_as_decimal 1.0.6 → 1.1.0
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/Gemfile +2 -12
- data/Gemfile.lock +46 -27
- data/README.rdoc +1 -9
- data/Rakefile +36 -38
- data/acts_as_decimal.gemspec +21 -58
- data/lib/acts_as_decimal/acts_as_decimal.rb +25 -34
- data/lib/acts_as_decimal/version.rb +4 -0
- data/spec/acts_as_decimal_spec.rb +38 -26
- data/spec/spec_helper.rb +11 -9
- metadata +85 -44
- data/VERSION +0 -1
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acts_as_decimal (1.1.0)
|
5
|
+
actionpack (~> 3.0.0)
|
6
|
+
activemodel (~> 3.0.0)
|
7
|
+
activesupport (~> 3.0.0)
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: http://rubygems.org/
|
3
11
|
specs:
|
12
|
+
abstract (1.0.0)
|
13
|
+
actionpack (3.0.0)
|
14
|
+
activemodel (= 3.0.0)
|
15
|
+
activesupport (= 3.0.0)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.4.1)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.12)
|
21
|
+
rack-test (~> 0.5.4)
|
22
|
+
tzinfo (~> 0.3.23)
|
4
23
|
activemodel (3.0.0)
|
5
24
|
activesupport (= 3.0.0)
|
6
25
|
builder (~> 2.1.2)
|
@@ -13,40 +32,40 @@ GEM
|
|
13
32
|
activesupport (3.0.0)
|
14
33
|
arel (1.0.1)
|
15
34
|
activesupport (~> 3.0.0)
|
35
|
+
bluecloth (2.0.11)
|
16
36
|
builder (2.1.2)
|
17
37
|
diff-lcs (1.1.2)
|
18
|
-
|
19
|
-
|
38
|
+
erubis (2.6.6)
|
39
|
+
abstract (>= 1.0.0)
|
20
40
|
i18n (0.4.1)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rspec (2.
|
27
|
-
rspec-core (
|
28
|
-
rspec-expectations (
|
29
|
-
rspec-mocks (
|
30
|
-
rspec-core (2.
|
31
|
-
rspec-expectations (2.
|
32
|
-
diff-lcs (
|
33
|
-
rspec-mocks (2.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
simplecov (0.3.6)
|
39
|
-
simplecov-html (>= 0.3.7)
|
40
|
-
simplecov-html (0.3.8)
|
41
|
-
sqlite3-ruby (1.3.1)
|
41
|
+
rack (1.2.2)
|
42
|
+
rack-mount (0.6.13)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-test (0.5.7)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rspec (2.5.0)
|
47
|
+
rspec-core (~> 2.5.0)
|
48
|
+
rspec-expectations (~> 2.5.0)
|
49
|
+
rspec-mocks (~> 2.5.0)
|
50
|
+
rspec-core (2.5.1)
|
51
|
+
rspec-expectations (2.5.0)
|
52
|
+
diff-lcs (~> 1.1.2)
|
53
|
+
rspec-mocks (2.5.0)
|
54
|
+
simplecov (0.4.1)
|
55
|
+
simplecov-html (~> 0.4.3)
|
56
|
+
simplecov-html (0.4.3)
|
57
|
+
sqlite3 (1.3.3)
|
42
58
|
tzinfo (0.3.23)
|
59
|
+
yard (0.6.4)
|
43
60
|
|
44
61
|
PLATFORMS
|
45
62
|
ruby
|
46
63
|
|
47
64
|
DEPENDENCIES
|
48
|
-
activerecord (
|
49
|
-
|
50
|
-
|
65
|
+
activerecord (~> 3.0.0)
|
66
|
+
acts_as_decimal!
|
67
|
+
bluecloth
|
68
|
+
rspec (~> 2.5.0)
|
51
69
|
simplecov
|
52
|
-
sqlite3
|
70
|
+
sqlite3
|
71
|
+
yard
|
data/README.rdoc
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
= acts_as_decimal
|
2
2
|
|
3
3
|
A simple gem for Rails 3 to make an attribute behave like it is floating point,
|
4
|
-
being stored as an integer in the database. Tested with Ruby 1.8, 1.9 and
|
5
|
-
Rubinius 1.1.
|
4
|
+
being stored as an integer in the database. Tested with Ruby 1.8, 1.9, Rubinius 1.2.2 and JRuby 1.6.
|
6
5
|
|
7
6
|
Add it to your Gemfile:
|
8
7
|
|
@@ -26,13 +25,6 @@ But you still have access to the raw database integer value through :price_raw:
|
|
26
25
|
product.price_raw # => 1230
|
27
26
|
product.price_raw = 4309 # product.price == 43.09
|
28
27
|
|
29
|
-
Furthermore, you get some nice humanizers for free. Note that all humanizers return a string, not a float.
|
30
|
-
|
31
|
-
product = Product.new
|
32
|
-
product.price = 3900400.40
|
33
|
-
product.humanized_price # => "3.900.400,40"
|
34
|
-
product.humanized_price(:thousand_delimiters => false) # => "3900400.40"
|
35
|
-
|
36
28
|
== Note on Patches/Pull Requests
|
37
29
|
|
38
30
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -1,45 +1,43 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "acts_as_decimal"
|
8
|
-
gem.summary = "Treat an attribute as if it were a decimal, storing it as an integer in the database."
|
9
|
-
gem.description = "Rails 3 gem to treat an attribute as a decimal (getting and setting floating-point values) but storing it as an integer in the database (useful for prices and other precision-needed attributes like money)."
|
10
|
-
gem.email = "info@codegram.com"
|
11
|
-
gem.homepage = "http://github.com/codegram/acts_as_decimal"
|
12
|
-
gem.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
|
13
|
-
|
14
|
-
gem.add_dependency 'activemodel', '>= 3.0.0.rc'
|
15
|
-
|
16
|
-
gem.add_development_dependency "rspec", '>= 2.0.0.beta.19'
|
17
|
-
gem.add_development_dependency 'activerecord', '>= 3.0.0.rc'
|
18
|
-
end
|
19
|
-
Jeweler::GemcutterTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
-
end
|
23
|
-
|
24
|
-
# Rake RSpec2 task stuff
|
25
|
-
gem 'rspec', '>= 2.0.0.beta.19'
|
26
|
-
gem 'rspec-expectations'
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
27
3
|
|
28
4
|
require 'rspec/core/rake_task'
|
5
|
+
desc "Run acts_as_decimal specs"
|
6
|
+
RSpec::Core::RakeTask.new
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
|
8
|
+
require 'yard'
|
9
|
+
YARD::Rake::YardocTask.new(:docs) do |t|
|
10
|
+
t.files = ['lib/**/*.rb']
|
11
|
+
t.options = ['-m', 'markdown', '--no-private', '-r', 'Readme.md', '--title', 'Acts as Decimal documentation']
|
33
12
|
end
|
34
13
|
|
35
|
-
|
14
|
+
site = 'doc'
|
15
|
+
source_branch = 'master'
|
16
|
+
deploy_branch = 'gh-pages'
|
17
|
+
|
18
|
+
desc "generate and deploy documentation website to github pages"
|
19
|
+
multitask :pages do
|
20
|
+
puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
|
21
|
+
require 'git'
|
22
|
+
repo = Git.open('.')
|
23
|
+
puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
|
24
|
+
repo.branch("#{deploy_branch}").checkout
|
25
|
+
(Dir["*"] - [site]).each { |f| rm_rf(f) }
|
26
|
+
Dir["#{site}/*"].each {|f| mv(f, "./")}
|
27
|
+
rm_rf(site)
|
28
|
+
puts "\n>>> Moving generated site files <<<\n"
|
29
|
+
Dir["**/*"].each {|f| repo.add(f) }
|
30
|
+
repo.status.deleted.each {|f, s| repo.remove(f)}
|
31
|
+
puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
|
32
|
+
message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
|
33
|
+
repo.commit(message)
|
34
|
+
puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
|
35
|
+
repo.push
|
36
|
+
puts "\n>>> Github Pages deploy complete <<<\n"
|
37
|
+
repo.branch("#{source_branch}").checkout
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
task :doc => [:docs]
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
rdoc.rdoc_files.include('README*')
|
44
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
-
end
|
42
|
+
task :default => :spec
|
43
|
+
task :test => [:spec]
|
data/acts_as_decimal.gemspec
CHANGED
@@ -1,68 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "acts_as_decimal/version"
|
5
3
|
|
6
4
|
Gem::Specification.new do |s|
|
7
5
|
s.name = %q{acts_as_decimal}
|
8
|
-
s.version =
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.version = ActsAsDecimal::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
11
8
|
s.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
|
12
|
-
s.date = %q{2010-10-14}
|
13
|
-
s.description = %q{Rails 3 gem to treat an attribute as a decimal (getting and setting floating-point values) but storing it as an integer in the database (useful for prices and other precision-needed attributes like money).}
|
14
9
|
s.email = %q{info@codegram.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".bundle/config",
|
21
|
-
".document",
|
22
|
-
".gitignore",
|
23
|
-
".rspec",
|
24
|
-
".rvmrc",
|
25
|
-
"Gemfile",
|
26
|
-
"Gemfile.lock",
|
27
|
-
"LICENSE",
|
28
|
-
"README.rdoc",
|
29
|
-
"Rakefile",
|
30
|
-
"VERSION",
|
31
|
-
"acts_as_decimal.gemspec",
|
32
|
-
"lib/acts_as_decimal.rb",
|
33
|
-
"lib/acts_as_decimal/acts_as_decimal.rb",
|
34
|
-
"spec/acts_as_decimal_spec.rb",
|
35
|
-
"spec/model_builder.rb",
|
36
|
-
"spec/spec_helper.rb"
|
37
|
-
]
|
38
10
|
s.homepage = %q{http://github.com/codegram/acts_as_decimal}
|
39
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
-
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.3.7}
|
42
11
|
s.summary = %q{Treat an attribute as if it were a decimal, storing it as an integer in the database.}
|
43
|
-
s.
|
44
|
-
|
45
|
-
"spec/model_builder.rb",
|
46
|
-
"spec/spec_helper.rb"
|
47
|
-
]
|
12
|
+
s.description = %q{Rails 3 gem to treat an attribute as a decimal (getting and setting floating-point values) but storing it as an integer in the database (useful for prices and other precision-needed attributes like money).}
|
13
|
+
s.rubyforge_project = 'acts_as_decimal'
|
48
14
|
|
49
|
-
|
50
|
-
|
51
|
-
|
15
|
+
s.add_runtime_dependency 'activemodel', '~>3.0.0'
|
16
|
+
s.add_runtime_dependency 'activesupport', '~>3.0.0'
|
17
|
+
s.add_runtime_dependency 'actionpack', '~>3.0.0'
|
52
18
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
s.add_dependency(%q<activerecord>, [">= 3.0.0.rc"])
|
61
|
-
end
|
62
|
-
else
|
63
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0.rc"])
|
64
|
-
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
65
|
-
s.add_dependency(%q<activerecord>, [">= 3.0.0.rc"])
|
66
|
-
end
|
67
|
-
end
|
19
|
+
s.add_development_dependency 'rspec', '~> 2.5.0'
|
20
|
+
s.add_development_dependency 'activerecord', '~> 3.0.0'
|
21
|
+
s.add_development_dependency 'sqlite3'
|
22
|
+
|
23
|
+
s.add_development_dependency 'simplecov'
|
24
|
+
s.add_development_dependency 'yard'
|
25
|
+
s.add_development_dependency 'bluecloth'
|
68
26
|
|
27
|
+
s.files = `git ls-files`.split("\n")
|
28
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module ActsAsDecimal
|
3
3
|
require 'bigdecimal'
|
4
|
+
require 'action_view'
|
5
|
+
include ActionView::Helpers::NumberHelper
|
4
6
|
|
5
7
|
def self.included(base)
|
6
8
|
base.extend(ClassMethods)
|
@@ -17,44 +19,33 @@ module ActsAsDecimal
|
|
17
19
|
def acts_as_decimal(attr_name, options = {:decimals => 2})
|
18
20
|
fields = [attr_name] unless attr_name.is_a? Array
|
19
21
|
fields.each do |field|
|
20
|
-
|
21
|
-
|
22
|
-
(self[:#{field}].nil? ? nil : (self[:#{field}] / BigDecimal('10').power(#{options[:decimals]}).to_f))
|
23
|
-
end
|
24
|
-
def human_#{field}(options = {:thousand_delimiters => true})
|
25
|
-
|
26
|
-
return nil if #{field}.blank?
|
27
|
-
|
28
|
-
a = #{field}.to_s.split('.')
|
29
|
-
b = a[1].ljust(2,'0')
|
30
|
-
|
31
|
-
if options[:thousand_delimiters] == false
|
32
|
-
return a[0] + "." + b
|
33
|
-
else
|
34
|
-
groups = a[0].reverse.scan(/\\d{3}/)
|
35
|
-
rest = a[0].gsub(groups.join.reverse, '').reverse
|
36
|
-
groups << rest unless rest.empty?
|
37
|
-
if groups.last == '-'
|
38
|
-
groups.reject!{|x| x == '-'}
|
39
|
-
negative = true
|
40
|
-
end
|
41
|
-
humanized_string = negative ? "-" : ""
|
42
|
-
humanized_string += groups.join('.').reverse + "," + b
|
43
|
-
return humanized_string
|
44
|
-
end
|
22
|
+
define_method "human_#{field}" do |*human_options|
|
23
|
+
ActiveSupport::Deprecation.warn("acts_as_decimal: The human helper has been deprecated. Please use #{field}.number_with_precision, directly in your views. More info: http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precision")
|
45
24
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
25
|
+
human_options = human_options.first || {:thousand_delimiters => true}
|
26
|
+
return number_with_precision(self.send(field), :delimiter => (human_options[:thousand_delimiters] ? '.' : ''), :separator => ',', :precision => 2)
|
27
|
+
end
|
50
28
|
|
51
|
-
|
52
|
-
|
29
|
+
define_method "#{field}" do
|
30
|
+
if value = read_attribute("#{field}")
|
31
|
+
value / BigDecimal('10').power("#{options[:decimals]}".to_i).to_f
|
53
32
|
end
|
54
|
-
|
55
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
define_method "#{field}=" do |decimalnum|
|
36
|
+
value = unless decimalnum.nil?
|
37
|
+
(BigDecimal.new(decimalnum.to_s) * BigDecimal('10').power("#{options[:decimals]}".to_i)).to_i
|
56
38
|
end
|
57
|
-
|
39
|
+
write_attribute("#{field}", value || nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method "#{field}_raw" do
|
43
|
+
read_attribute("#{field}")
|
44
|
+
end
|
45
|
+
|
46
|
+
define_method "#{field}_raw=" do |value|
|
47
|
+
write_attribute("#{field}", value)
|
48
|
+
end
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
@@ -1,13 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Product < ActiveRecord::Base
|
4
|
-
end
|
5
|
-
create_table "products" do end
|
6
|
-
define_model('Product', :name => :string, :price => :integer)
|
7
|
-
|
8
3
|
describe Product do
|
9
|
-
|
10
|
-
|
11
4
|
context "with a price of 10.30" do
|
12
5
|
|
13
6
|
before(:all) do
|
@@ -26,6 +19,11 @@ describe Product do
|
|
26
19
|
subject.price_raw.should == 1030
|
27
20
|
end
|
28
21
|
|
22
|
+
it "sets a price_raw of 2030" do
|
23
|
+
subject.price_raw = 2030
|
24
|
+
subject.price.should == 20.30
|
25
|
+
end
|
26
|
+
|
29
27
|
it "stores 1030 to the database" do
|
30
28
|
subject.attributes["price"].should == 1030
|
31
29
|
end
|
@@ -49,8 +47,8 @@ describe Product do
|
|
49
47
|
subject.human_price.should == "3.900.400,00"
|
50
48
|
end
|
51
49
|
|
52
|
-
it "has a human_price(:thousand_delimiters => false) of 3900400
|
53
|
-
subject.human_price(:thousand_delimiters => false).should == "3900400
|
50
|
+
it "has a human_price(:thousand_delimiters => false) of 3900400,00" do
|
51
|
+
subject.human_price(:thousand_delimiters => false).should == "3900400,00"
|
54
52
|
end
|
55
53
|
|
56
54
|
end
|
@@ -63,8 +61,22 @@ describe Product do
|
|
63
61
|
subject.human_price.should == "20.000,00"
|
64
62
|
end
|
65
63
|
|
66
|
-
it "has a human_price(:thousand_delimiters => false) of 20000
|
67
|
-
subject.human_price(:thousand_delimiters => false).should == "20000
|
64
|
+
it "has a human_price(:thousand_delimiters => false) of 20000,00" do
|
65
|
+
subject.human_price(:thousand_delimiters => false).should == "20000,00"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with a 1234.56 price" do
|
71
|
+
|
72
|
+
subject { Product.new(:price => 1234.56) }
|
73
|
+
|
74
|
+
it "has a human_price of 1.234,56" do
|
75
|
+
subject.human_price.should == "1.234,56"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "has a human_price(:thousand_delimiters => false) of 1234,56" do
|
79
|
+
subject.human_price(:thousand_delimiters => false).should == "1234,56"
|
68
80
|
end
|
69
81
|
|
70
82
|
end
|
@@ -77,23 +89,23 @@ describe Product do
|
|
77
89
|
subject.human_price.should == "900,00"
|
78
90
|
end
|
79
91
|
|
80
|
-
it "has a human_price(:thousand_delimiters => false) of 900
|
81
|
-
subject.human_price(:thousand_delimiters => false).should == "900
|
92
|
+
it "has a human_price(:thousand_delimiters => false) of 900,00" do
|
93
|
+
subject.human_price(:thousand_delimiters => false).should == "900,00"
|
82
94
|
end
|
83
95
|
|
84
96
|
end
|
85
97
|
|
86
98
|
context "with a string price of '900.00'" do
|
87
99
|
|
88
|
-
|
100
|
+
subject { Product.new(:price => "900.00") }
|
89
101
|
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
it "has a human_price of 900,00" do
|
103
|
+
subject.human_price.should == "900,00"
|
104
|
+
end
|
93
105
|
|
94
|
-
|
95
|
-
|
96
|
-
|
106
|
+
it "has a human_price(:thousand_delimiters => false) of 900,00" do
|
107
|
+
subject.human_price(:thousand_delimiters => false).should == "900,00"
|
108
|
+
end
|
97
109
|
|
98
110
|
end
|
99
111
|
|
@@ -105,8 +117,8 @@ describe Product do
|
|
105
117
|
subject.human_price.should == "-900,00"
|
106
118
|
end
|
107
119
|
|
108
|
-
it "has a human_price(:thousand_delimiters => false) of -900
|
109
|
-
subject.human_price(:thousand_delimiters => false).should == "-900
|
120
|
+
it "has a human_price(:thousand_delimiters => false) of -900,00" do
|
121
|
+
subject.human_price(:thousand_delimiters => false).should == "-900,00"
|
110
122
|
end
|
111
123
|
|
112
124
|
end
|
@@ -119,15 +131,15 @@ describe Product do
|
|
119
131
|
subject.human_price.should == "-900,00"
|
120
132
|
end
|
121
133
|
|
122
|
-
it "has a human_price(:thousand_delimiters => false) of -900
|
123
|
-
subject.human_price(:thousand_delimiters => false).should == "-900
|
134
|
+
it "has a human_price(:thousand_delimiters => false) of -900,00" do
|
135
|
+
subject.human_price(:thousand_delimiters => false).should == "-900,00"
|
124
136
|
end
|
125
137
|
|
126
138
|
end
|
127
139
|
end
|
128
140
|
|
129
141
|
context "with a price of 10.30452 and specifying :decimals => 5" do
|
130
|
-
|
142
|
+
|
131
143
|
before(:all) do
|
132
144
|
Product.acts_as_decimal :price, :decimals => 5
|
133
145
|
end
|
@@ -145,7 +157,7 @@ describe Product do
|
|
145
157
|
it "stores 1030452 to the database" do
|
146
158
|
subject.attributes["price"].should == 1030452
|
147
159
|
end
|
148
|
-
|
160
|
+
|
149
161
|
end
|
150
162
|
|
151
163
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,20 +5,22 @@ end
|
|
5
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
7
|
|
8
|
-
require 'rubygems'
|
9
|
-
require 'active_record'
|
10
|
-
|
11
8
|
require 'acts_as_decimal'
|
9
|
+
require 'active_record'
|
12
10
|
require 'rspec'
|
13
|
-
|
14
|
-
RAILS_ENV = "test"
|
15
|
-
RAILS_VERSION = ENV['RAILS_VERSION'] || '3.0.0'
|
11
|
+
ActiveSupport::Deprecation.silenced = true
|
16
12
|
|
17
13
|
ActiveRecord::Base.establish_connection(
|
18
14
|
:adapter => 'sqlite3',
|
19
15
|
:database => ':memory:'
|
20
16
|
)
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
ActiveRecord::Schema.define do
|
19
|
+
create_table :products do |t|
|
20
|
+
t.string :name
|
21
|
+
t.integer :price
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Product < ActiveRecord::Base
|
26
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_decimal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
version: 1.0.6
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Oriol Gual
|
@@ -16,7 +12,7 @@ autorequire:
|
|
16
12
|
bindir: bin
|
17
13
|
cert_chain: []
|
18
14
|
|
19
|
-
date:
|
15
|
+
date: 2011-03-15 00:00:00 +01:00
|
20
16
|
default_executable:
|
21
17
|
dependencies:
|
22
18
|
- !ruby/object:Gem::Dependency
|
@@ -25,58 +21,107 @@ dependencies:
|
|
25
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
22
|
none: false
|
27
23
|
requirements:
|
28
|
-
- -
|
24
|
+
- - ~>
|
29
25
|
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
- 0
|
34
|
-
- rc
|
35
|
-
version: 3.0.0.rc
|
26
|
+
version: 3.0.0
|
36
27
|
type: :runtime
|
37
28
|
version_requirements: *id001
|
38
29
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
30
|
+
name: activesupport
|
40
31
|
prerelease: false
|
41
32
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
33
|
none: false
|
43
34
|
requirements:
|
44
|
-
- -
|
35
|
+
- - ~>
|
45
36
|
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
|
48
|
-
- 0
|
49
|
-
- 0
|
50
|
-
- beta
|
51
|
-
- 19
|
52
|
-
version: 2.0.0.beta.19
|
53
|
-
type: :development
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
54
39
|
version_requirements: *id002
|
55
40
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
41
|
+
name: actionpack
|
57
42
|
prerelease: false
|
58
43
|
requirement: &id003 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id003
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.5.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id004
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activerecord
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.0.0
|
71
|
+
type: :development
|
72
|
+
version_requirements: *id005
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: sqlite3
|
75
|
+
prerelease: false
|
76
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
59
77
|
none: false
|
60
78
|
requirements:
|
61
79
|
- - ">="
|
62
80
|
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
- 3
|
65
|
-
- 0
|
66
|
-
- 0
|
67
|
-
- rc
|
68
|
-
version: 3.0.0.rc
|
81
|
+
version: "0"
|
69
82
|
type: :development
|
70
|
-
version_requirements: *
|
83
|
+
version_requirements: *id006
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id007
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: yard
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
type: :development
|
105
|
+
version_requirements: *id008
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: bluecloth
|
108
|
+
prerelease: false
|
109
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id009
|
71
117
|
description: Rails 3 gem to treat an attribute as a decimal (getting and setting floating-point values) but storing it as an integer in the database (useful for prices and other precision-needed attributes like money).
|
72
118
|
email: info@codegram.com
|
73
119
|
executables: []
|
74
120
|
|
75
121
|
extensions: []
|
76
122
|
|
77
|
-
extra_rdoc_files:
|
78
|
-
|
79
|
-
- README.rdoc
|
123
|
+
extra_rdoc_files: []
|
124
|
+
|
80
125
|
files:
|
81
126
|
- .bundle/config
|
82
127
|
- .document
|
@@ -88,10 +133,10 @@ files:
|
|
88
133
|
- LICENSE
|
89
134
|
- README.rdoc
|
90
135
|
- Rakefile
|
91
|
-
- VERSION
|
92
136
|
- acts_as_decimal.gemspec
|
93
137
|
- lib/acts_as_decimal.rb
|
94
138
|
- lib/acts_as_decimal/acts_as_decimal.rb
|
139
|
+
- lib/acts_as_decimal/version.rb
|
95
140
|
- spec/acts_as_decimal_spec.rb
|
96
141
|
- spec/model_builder.rb
|
97
142
|
- spec/spec_helper.rb
|
@@ -100,8 +145,8 @@ homepage: http://github.com/codegram/acts_as_decimal
|
|
100
145
|
licenses: []
|
101
146
|
|
102
147
|
post_install_message:
|
103
|
-
rdoc_options:
|
104
|
-
|
148
|
+
rdoc_options: []
|
149
|
+
|
105
150
|
require_paths:
|
106
151
|
- lib
|
107
152
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -109,21 +154,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
154
|
requirements:
|
110
155
|
- - ">="
|
111
156
|
- !ruby/object:Gem::Version
|
112
|
-
segments:
|
113
|
-
- 0
|
114
157
|
version: "0"
|
115
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
159
|
none: false
|
117
160
|
requirements:
|
118
161
|
- - ">="
|
119
162
|
- !ruby/object:Gem::Version
|
120
|
-
segments:
|
121
|
-
- 0
|
122
163
|
version: "0"
|
123
164
|
requirements: []
|
124
165
|
|
125
|
-
rubyforge_project:
|
126
|
-
rubygems_version: 1.3
|
166
|
+
rubyforge_project: acts_as_decimal
|
167
|
+
rubygems_version: 1.5.3
|
127
168
|
signing_key:
|
128
169
|
specification_version: 3
|
129
170
|
summary: Treat an attribute as if it were a decimal, storing it as an integer in the database.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.6
|