activerecord-time 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9191c5f543363446595ac56995e20183695cc689
4
+ data.tar.gz: 2a9480f6e1ef46a9df53ecb51b1d09f7cb7531c3
5
+ SHA512:
6
+ metadata.gz: b8190c77ed345a716ca0f9426d1f3d6b57488c9c757a6e5d3ffa966f4cc41f6c9a56de71b36a2c5aa9f09d50bf9a2cb9c9a902a1d6c45d5981420382aa721299
7
+ data.tar.gz: 6fad7c2cc20029685ad15ff4fccfdb8e490fe6c63ec65a7223bd7aa4630a7b3948f6ecef0a0fc2514ebe12b104c50542119e985371765f9b14b32f59765993f0
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ :memory:
2
+ debug.log
1
3
  *.gem
2
4
  *.rbc
3
5
  .bundle
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'rubygems'
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
@@ -4,16 +4,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'activerecord-time/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "activerecord-time"
7
+ gem.name = 'activerecord-time'
8
8
  gem.version = Activerecord::Time::VERSION
9
- gem.authors = ["Uwe Kubosch"]
10
- gem.email = ["uwe@kubosch.no"]
9
+ gem.authors = ['Uwe Kubosch']
10
+ gem.email = %w(uwe@kubosch.no)
11
11
  gem.description = %q{A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.}
12
12
  gem.summary = %q{A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.}
13
- gem.homepage = ""
13
+ gem.homepage = 'https://github.com/donv/activerecord-time'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = %w(lib)
19
+
20
+ gem.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
19
21
  end
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module Time
3
- VERSION = "0.0.1"
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
data/lib/time_of_day.rb CHANGED
@@ -38,13 +38,18 @@ class TimeOfDay
38
38
  Time.local(date.year, date.month, date.day, hour, minute, second)
39
39
  end
40
40
 
41
- def -(seconds)
41
+ def +(seconds)
42
42
  raise "Illegal argument: #{seconds.inspect}" unless seconds.is_a? Numeric
43
43
  t = Time.local(0, 1, 1, hour, minute, second)
44
- t -= seconds
44
+ t += seconds
45
45
  self.class.new(t.hour, t.min, t.sec)
46
46
  end
47
47
 
48
+ def -(seconds)
49
+ raise "Illegal argument: #{seconds.inspect}" unless seconds.is_a? Numeric
50
+ self.+(-seconds)
51
+ end
52
+
48
53
  def <=>(other)
49
54
  [@hour, @minute, @second] <=> [other.hour, other.minute, other.second]
50
55
  end
data/test/database.yml CHANGED
@@ -2,7 +2,7 @@ sqlite:
2
2
  :adapter: sqlite
3
3
  :dbfile: plugin.sqlite.db
4
4
  sqlite3:
5
- :adapter: sqlite3
5
+ :adapter: jdbcsqlite3
6
6
  :dbfile: ":memory:"
7
7
  postgresql:
8
8
  :adapter: postgresql
@@ -4,7 +4,7 @@ class Thing < ActiveRecord::Base
4
4
  end
5
5
 
6
6
  def thing
7
- Thing.new(:name => "Thing One",:price_in_cents=> 125)
7
+ Thing.new(:name => 'Thing One',:price_in_cents=> 125)
8
8
  end
9
9
 
10
10
  class RailsMoneyTest < Test::Unit::TestCase
@@ -84,39 +84,4 @@ class MoneyTest < Test::Unit::TestCase
84
84
  assert Money.new(0) == Money.new(0)
85
85
  end
86
86
 
87
- def test_should_add_money
88
- assert_equal Money.new(20.95), Money.new(10) + Money.new(10.95)
89
- assert_equal Money.new(2000), Money.new(1000) + 1000
90
- assert_equal Money.new(20.06), Money.new(10.00) + 10.056
91
- end
92
-
93
- def test_should_subtract_money
94
- assert_equal Money.new(500), Money.new(1000) - Money.new(500)
95
- assert_equal Money.new(500), Money.new(1000) - 500
96
- assert_equal Money.new(4.60), Money.new(10) - 5.40
97
- end
98
-
99
- def test_should_multiply_money
100
- assert_equal Money.new(500), Money.new(100) * 5
101
- assert_equal Money.new(9.99), Money.new(3.33) * 3
102
- assert_equal Money.new(11.99), Money.new(3.33) * 3.6 # 1198.9
103
- end
104
-
105
- def test_should_divide_money_and_retur_array_of_monies
106
- money_array = [Money.new(3.34), Money.new(3.33), Money.new(3.33)]
107
- assert_equal money_array, Money.new(10.00) / 3
108
- assert_equal [Money.new(2.00), Money.new(2.00)], Money.new(4.00) / 2
109
- assert_raises(MoneyError) { Money.new(4.00) / 2.2 }
110
- end
111
-
112
- def test_should_implement_to_money
113
- assert_equal Money.new(10), Money.new(10).to_money
114
- assert_equal Money.new(100.00), 100.00.to_money
115
- assert_equal Money.new(100.96), 100.956.to_money
116
- end
117
-
118
- def test_should_create_from_cents
119
- assert_equal Money.new(1.50), Money.create_from_cents(150)
120
- end
121
-
122
87
  end
data/test/test_helper.rb CHANGED
@@ -4,14 +4,12 @@ RAILS_ROOT = File.dirname(__FILE__)
4
4
  require 'rubygems'
5
5
  require 'test/unit'
6
6
  require 'active_record'
7
- require "#{File.dirname(__FILE__)}/../init"
7
+ require 'activerecord-time'
8
+ require 'logger'
9
+ require 'fileutils'
8
10
 
11
+ FileUtils.rm_rf File.expand_path(':memory:', File.dirname(__FILE__))
9
12
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
10
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
13
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
11
14
  ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
12
-
13
- load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")
14
-
15
-
16
-
17
-
15
+ load(File.dirname(__FILE__) + '/schema.rb') if File.exist?(File.dirname(__FILE__) + '/schema.rb')
@@ -0,0 +1,23 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+
3
+ class TimeOfDayTest < Test::Unit::TestCase
4
+ def setup
5
+ @twelve_o_clock = TimeOfDay.parse '12:00:00'
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_parse_full
12
+ assert_equal @twelve_o_clock, TimeOfDay.parse('12:00:00')
13
+ end
14
+
15
+ def test_parse_hour_and_minute
16
+ assert_equal @twelve_o_clock, TimeOfDay.parse('12:00')
17
+ end
18
+
19
+ def test_parse_hour_only
20
+ assert_equal @twelve_o_clock, TimeOfDay.parse('12')
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -1,33 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activerecord-time
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Uwe Kubosch
14
- autorequire:
8
+ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-01-04 00:00:00 Z
19
- dependencies: []
20
-
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord-jdbcsqlite3-adapter
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :development
21
27
  description: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
22
- email:
28
+ email:
23
29
  - uwe@kubosch.no
24
30
  executables: []
25
-
26
31
  extensions: []
27
-
28
32
  extra_rdoc_files: []
29
-
30
- files:
33
+ files:
31
34
  - .gitignore
32
35
  - Gemfile
33
36
  - LICENSE.txt
@@ -42,41 +45,33 @@ files:
42
45
  - test/rails_time_test.rb
43
46
  - test/schema.rb
44
47
  - test/test_helper.rb
45
- homepage: ""
48
+ - test/time_of_day_test.rb
49
+ homepage: https://github.com/donv/activerecord-time
46
50
  licenses: []
47
-
48
- post_install_message:
51
+ metadata: {}
52
+ post_install_message:
49
53
  rdoc_options: []
50
-
51
- require_paths:
54
+ require_paths:
52
55
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
71
66
  requirements: []
72
-
73
- rubyforge_project:
74
- rubygems_version: 1.8.24
75
- signing_key:
76
- specification_version: 3
67
+ rubyforge_project:
68
+ rubygems_version: 2.1.9
69
+ signing_key:
70
+ specification_version: 4
77
71
  summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
78
- test_files:
72
+ test_files:
79
73
  - test/database.yml
80
74
  - test/rails_time_test.rb
81
75
  - test/schema.rb
82
76
  - test/test_helper.rb
77
+ - test/time_of_day_test.rb