string_date_accessors 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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 "invalid_date_accessors" do
17
+ describe "UK format" do
19
18
  before do
20
- @object.punched_on = 'bad'
21
- @object.patched_up_on = '2009/12/25'
19
+ StringDateAccessors.format = '%d/%m/%y'
22
20
  end
23
21
 
24
- it "should return the symbols associated with non-dates" do
25
- @object.invalid_date_accessors.should include(:punched_on)
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
- it "should not return the symbols associated with dates" do
29
- @object.invalid_date_accessors.should_not include(:patched_up_on)
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
- it "should accept strings with slashes" do
35
- @object.punched_on = '2011/12/11'
36
- @object.punched_on.day.should == 11
37
- @object.punched_on.month.should == 12
38
- @object.punched_on.year.should == 2011
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
- it "should accept Date objects" do
42
- @object.punched_on = Date.new(2011, 12, 11)
43
- @object.punched_on.day.should == 11
44
- @object.punched_on.month.should == 12
45
- @object.punched_on.year.should == 2011
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
- it "should cope with blank strings" do
49
- @object.punched_on = ''
50
- @object.punched_on.should be_nil
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.2"
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-02-04}
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.5}
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
- version: 0.0.2
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-02-04 00:00:00 +00:00
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
- type: :development
18
- version_requirement:
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
- version:
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.5
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