string_date_accessors 0.0.2 → 0.0.3
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/VERSION +1 -1
- data/lib/string_date_accessors.rb +1 -1
- data/spec/string_date_accessors_spec.rb +60 -21
- data/string_date_accessors.gemspec +3 -3
- metadata +20 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -32,7 +32,7 @@ module StringDateAccessors
|
|
32
32
|
define_method "#{attribute}=" do |input|
|
33
33
|
if input.respond_to?(:strftime)
|
34
34
|
super input
|
35
|
-
elsif input.empty?
|
35
|
+
elsif input.nil? || input.empty?
|
36
36
|
return super(nil) # don't mark as set
|
37
37
|
else
|
38
38
|
super StringDateAccessors.formatted(input)
|
@@ -12,42 +12,81 @@ end
|
|
12
12
|
describe StringDateAccessors do
|
13
13
|
before do
|
14
14
|
StringDateAccessors.format = '%Y/%m/%d'
|
15
|
-
@object = StringDateInheritor.new
|
16
15
|
end
|
17
16
|
|
18
|
-
describe "
|
17
|
+
describe "UK format" do
|
19
18
|
before do
|
20
|
-
|
21
|
-
@object.patched_up_on = '2009/12/25'
|
19
|
+
StringDateAccessors.format = '%d/%m/%y'
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
context "entering strings with slashes" do
|
23
|
+
subject do
|
24
|
+
inheritor = StringDateInheritor.new
|
25
|
+
inheritor.punched_on = '11/12/09'
|
26
|
+
inheritor.punched_on
|
27
|
+
end
|
28
|
+
|
29
|
+
its(:day) { should == 11 }
|
30
|
+
its(:month) { should == 12 }
|
31
|
+
its(:year) { should == 2009 }
|
26
32
|
end
|
33
|
+
end
|
27
34
|
|
28
|
-
|
29
|
-
|
35
|
+
describe "invalid dates" do
|
36
|
+
subject do
|
37
|
+
inheritor = StringDateInheritor.new
|
38
|
+
inheritor.punched_on = 'bad'
|
39
|
+
inheritor.patched_up_on = '2009/12/25'
|
40
|
+
inheritor
|
30
41
|
end
|
42
|
+
|
43
|
+
its(:invalid_date_accessors) { should include(:punched_on) }
|
44
|
+
its(:invalid_date_accessors) { should_not include(:patched_up_on) }
|
31
45
|
end
|
32
46
|
|
33
47
|
describe "date accessor" do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
48
|
+
context "entering strings with slashes" do
|
49
|
+
subject do
|
50
|
+
inheritor = StringDateInheritor.new
|
51
|
+
inheritor.punched_on = '2011/12/11'
|
52
|
+
inheritor.punched_on
|
53
|
+
end
|
54
|
+
|
55
|
+
its(:day) { should == 11 }
|
56
|
+
its(:month) { should == 12 }
|
57
|
+
its(:year) { should == 2011 }
|
39
58
|
end
|
40
59
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
60
|
+
context "entering Date objects" do
|
61
|
+
subject do
|
62
|
+
inheritor = StringDateInheritor.new
|
63
|
+
inheritor.punched_on = Date.new(2011, 12, 11)
|
64
|
+
inheritor.punched_on
|
65
|
+
end
|
66
|
+
|
67
|
+
its(:day) { should == 11 }
|
68
|
+
its(:month) { should == 12 }
|
69
|
+
its(:year) { should == 2011 }
|
46
70
|
end
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
72
|
+
context "entering blank strings" do
|
73
|
+
subject do
|
74
|
+
inheritor = StringDateInheritor.new
|
75
|
+
inheritor.punched_on = ''
|
76
|
+
inheritor.punched_on
|
77
|
+
end
|
78
|
+
|
79
|
+
it { should be_nil }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "entering nil" do
|
83
|
+
subject do
|
84
|
+
inheritor = StringDateInheritor.new
|
85
|
+
inheritor.punched_on = nil
|
86
|
+
inheritor.punched_on
|
87
|
+
end
|
88
|
+
|
89
|
+
it { should be_nil }
|
51
90
|
end
|
52
91
|
end
|
53
92
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{string_date_accessors}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Bruce"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-27}
|
13
13
|
s.description = %q{
|
14
14
|
This gem is useful if you don't want to use Rails' standard date helpers and would rather
|
15
15
|
set a text format for reading and writing dates.
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = %q{http://github.com/camelpunch/string_date_accessors}
|
36
36
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
38
|
+
s.rubygems_version = %q{1.3.6}
|
39
39
|
s.summary = %q{Get and set dates as strings on ActiveRecord-like objects}
|
40
40
|
s.test_files = [
|
41
41
|
"spec/spec_helper.rb",
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_date_accessors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Andrew Bruce
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-27 00:00:00 +00:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
description: "\n This gem is useful if you don't want to use Rails' standard date helpers and would rather\n set a text format for reading and writing dates.\n "
|
26
35
|
email: andrew@camelpunch.com
|
27
36
|
executables: []
|
@@ -56,18 +65,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
65
|
requirements:
|
57
66
|
- - ">="
|
58
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
59
70
|
version: "0"
|
60
|
-
version:
|
61
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
73
|
- - ">="
|
64
74
|
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
65
77
|
version: "0"
|
66
|
-
version:
|
67
78
|
requirements: []
|
68
79
|
|
69
80
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.3.
|
81
|
+
rubygems_version: 1.3.6
|
71
82
|
signing_key:
|
72
83
|
specification_version: 3
|
73
84
|
summary: Get and set dates as strings on ActiveRecord-like objects
|