acts_as_duration 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d965eddb71dcd43ad4306d6427bc954ef532968f
4
- data.tar.gz: 78f95706c14c1c5de28ae595274d5c43870c8149
3
+ metadata.gz: 26d548368dd2f852f56c9d78f6551fd9fe4e1f76
4
+ data.tar.gz: 3a89a824fd3ed56c3c64d6a9ceffcf2cb96f4aba
5
5
  SHA512:
6
- metadata.gz: 6198490f2967dea650574367a75d2092346ef883fb34f19e56e8a2ee8e804e949b3ed8b3a60160b7d8ffacc0411e9fb00ea4bc93a748bfb070a3dcfcbd9fa697
7
- data.tar.gz: 3d665f3d07fc90e238dbc6ee4cce16de3f3ea073578e8c58d8144cfc6e0d9915bb51ac8a440ca98ca777d38d486a58a8581b008ee188f5e7160e39348f0af220
6
+ metadata.gz: 87af822b4eec97f6b82922cd8b502a0ce1bc278a8997aea46a641ffeb54464d7441ceda95b553bdaa2a7ac798b947129101c4d4955fab1303c33fb71a9a47010
7
+ data.tar.gz: b7b5d91827ae60df31fdf294f187a7dd252de2828de535727273344bc703e412976387b87d29e25e1661190ff0301d750f768259f5616825424569b3c0b7ad71
@@ -7,15 +7,17 @@ module ActsAsDuration
7
7
 
8
8
 
9
9
  module ClassMethods
10
- def acts_as_duration(base_attr, options = {})
10
+ def acts_as_duration(*base_attrs, **options)
11
11
  valid_units = [:seconds, :minutes, :hours, :days]
12
- base_unit = options[:attr_unit] || base_attr[/(#{valid_units.join('|')})/,1].to_sym
12
+ base_attrs.each do |base_attr|
13
+ base_unit = options[:attr_unit] || base_attr[/(#{valid_units.join('|')})/,1].to_sym
13
14
 
14
- (valid_units - [base_unit]).each do |new_unit|
15
- name = base_attr.to_s.gsub!(base_unit.to_s, new_unit.to_s)
16
- options_hash = {name: name, base_attr: base_attr, base_unit: base_unit, new_unit: new_unit}
17
- define_reader_method(options_hash)
18
- define_writer_method(options_hash) unless options[:read_only]
15
+ (valid_units - [base_unit]).each do |new_unit|
16
+ name = base_attr.to_s.gsub!(base_unit.to_s, new_unit.to_s)
17
+ options_hash = {name: name, base_attr: base_attr, base_unit: base_unit, new_unit: new_unit}
18
+ define_reader_method(options_hash)
19
+ define_writer_method(options_hash) unless options[:read_only]
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsDuration
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -49,4 +49,19 @@ class ActsAsDurationTest < ActiveSupport::TestCase
49
49
  assert_equal 2.03, foo.barfoo_hours
50
50
  end
51
51
 
52
+ test 'accepts multiple attributs as well as hash arguments' do
53
+ Foobar.class_eval do
54
+ attr_accessor :a_seconds, :b_minutes, :c_hours
55
+ acts_as_duration :a_seconds, :b_minutes, :c_hours, read_only: true
56
+ end
57
+
58
+ expected_methods = [:a_minutes, :a_hours, :b_seconds, :b_hours, :c_seconds, :c_minutes]
59
+ assert (expected_methods - Foobar.instance_methods).empty?
60
+
61
+ unexpected_methods = [:a_minutes=, :a_hours=, :b_seconds=, :b_hours=, :c_seconds=, :c_minutes=]
62
+ assert_equal 6, (unexpected_methods - Foobar.instance_methods).count
63
+
64
+
65
+ end
66
+
52
67
  end
@@ -846,3 +846,61 @@ ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
846
846
   (0.1ms) RELEASE SAVEPOINT active_record_1
847
847
  Foobar Load (0.2ms) SELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1 [["id", 1]]
848
848
   (0.6ms) rollback transaction
849
+  (0.7ms) begin transaction
850
+ -----------------------------------------------------------------------------
851
+ ActsAsDurationTest: test_accepts_multiple_attributs_as_well_as_hash_arguments
852
+ -----------------------------------------------------------------------------
853
+  (0.1ms) rollback transaction
854
+  (0.1ms) begin transaction
855
+ --------------------------------------------------------------------
856
+ ActsAsDurationTest: test_adds_additional_conversion_methods_to_model
857
+ --------------------------------------------------------------------
858
+  (0.1ms) rollback transaction
859
+  (0.1ms) begin transaction
860
+ ---------------------------------------------------------
861
+ ActsAsDurationTest: test_adds_conversion_methods_to_model
862
+ ---------------------------------------------------------
863
+  (0.1ms) rollback transaction
864
+  (0.1ms) begin transaction
865
+ -------------------------------------------------------------------
866
+ ActsAsDurationTest: test_converts_from_minutes_to_seconds_and_hours
867
+ -------------------------------------------------------------------
868
+  (0.1ms) rollback transaction
869
+  (0.0ms) begin transaction
870
+ --------------------------------------------------------------------------
871
+ ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
872
+ --------------------------------------------------------------------------
873
+  (0.1ms) SAVEPOINT active_record_1
874
+ SQL (37.2ms) INSERT INTO "foobars" ("created_at", "test_seconds", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 25 Apr 2014 17:17:26 UTC +00:00], ["test_seconds", 7380], ["updated_at", Fri, 25 Apr 2014 17:17:26 UTC +00:00]]
875
+  (0.1ms) RELEASE SAVEPOINT active_record_1
876
+ Foobar Load (0.2ms) SELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1 [["id", 1]]
877
+  (0.6ms) rollback transaction
878
+  (0.4ms) begin transaction
879
+ -----------------------------------------------------------------------------
880
+ ActsAsDurationTest: test_accepts_multiple_attributs_as_well_as_hash_arguments
881
+ -----------------------------------------------------------------------------
882
+  (0.1ms) rollback transaction
883
+  (0.1ms) begin transaction
884
+ --------------------------------------------------------------------
885
+ ActsAsDurationTest: test_adds_additional_conversion_methods_to_model
886
+ --------------------------------------------------------------------
887
+  (0.1ms) rollback transaction
888
+  (0.1ms) begin transaction
889
+ ---------------------------------------------------------
890
+ ActsAsDurationTest: test_adds_conversion_methods_to_model
891
+ ---------------------------------------------------------
892
+  (0.1ms) rollback transaction
893
+  (0.1ms) begin transaction
894
+ -------------------------------------------------------------------
895
+ ActsAsDurationTest: test_converts_from_minutes_to_seconds_and_hours
896
+ -------------------------------------------------------------------
897
+  (0.0ms) rollback transaction
898
+  (0.1ms) begin transaction
899
+ --------------------------------------------------------------------------
900
+ ActsAsDurationTest: test_converts_from_seconds_to_minutes,_hours_and_saves
901
+ --------------------------------------------------------------------------
902
+  (0.1ms) SAVEPOINT active_record_1
903
+ SQL (2.6ms) INSERT INTO "foobars" ("created_at", "test_seconds", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 25 Apr 2014 17:17:57 UTC +00:00], ["test_seconds", 7380], ["updated_at", Fri, 25 Apr 2014 17:17:57 UTC +00:00]]
904
+  (0.1ms) RELEASE SAVEPOINT active_record_1
905
+ Foobar Load (0.1ms) SELECT "foobars".* FROM "foobars" WHERE "foobars"."id" = ? LIMIT 1 [["id", 1]]
906
+  (0.7ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_duration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yonah Forst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails