rfc-3339-attributes 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/VERSION.yml +1 -1
- data/lib/active_record/rfc_3339_attributes.rb +6 -6
- data/rfc-3339-attributes.gemspec +51 -0
- data/test/rfc_3339_attributes_test.rb +11 -0
- metadata +6 -4
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/VERSION.yml
CHANGED
@@ -28,12 +28,12 @@ module ActiveRecord
|
|
28
28
|
|
29
29
|
send(validation_method(configuration[:on] || :save), configuration) do |record|
|
30
30
|
attr_names.each do |attr_name|
|
31
|
-
|
32
|
-
next if
|
33
|
-
if
|
34
|
-
record.errors.add(attr_name, :invalid, :default => "can't be blank", :value =>
|
35
|
-
elsif
|
36
|
-
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value =>
|
31
|
+
value = record.send(:instance_variable_get, "@#{attr_name}_before_type_cast") || record.send(attr_name)
|
32
|
+
next if value.acts_like?(:time)
|
33
|
+
if value.blank? and !configuration[:allow_blank]
|
34
|
+
record.errors.add(attr_name, :invalid, :default => "can't be blank", :value => value)
|
35
|
+
elsif value.to_s !~ configuration[:with]
|
36
|
+
record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rfc-3339-attributes}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Manfred Stienstra"]
|
12
|
+
s.date = %q{2010-07-20}
|
13
|
+
s.description = %q{A tiny Rails plugin to allow validation on RFC-3339 datetime attributes.}
|
14
|
+
s.email = %q{manfred@fngtps.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"lib/active_record/rfc_3339_attributes.rb",
|
26
|
+
"rails/init.rb",
|
27
|
+
"rfc-3339-attributes.gemspec",
|
28
|
+
"test/rfc_3339_attributes_test.rb",
|
29
|
+
"test/test_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://fingertips.github.com}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
|
+
s.summary = %q{A tiny Rails plugin to allow validation on RFC-3339 datetime attributes.}
|
36
|
+
s.test_files = [
|
37
|
+
"test/rfc_3339_attributes_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -24,6 +24,12 @@ class RFC3339AttributesValidationTest < ActiveSupport::TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
test "accepts valid timestamps when read from the database" do
|
28
|
+
@member.write_attribute(:measured_at, Time.now)
|
29
|
+
@member.valid?
|
30
|
+
assert @member.errors.on(:measured_at).blank?
|
31
|
+
end
|
32
|
+
|
27
33
|
test "rejects invalid timestamps" do
|
28
34
|
%w{
|
29
35
|
invalid
|
@@ -32,6 +38,11 @@ class RFC3339AttributesValidationTest < ActiveSupport::TestCase
|
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
41
|
+
test "rejects invalid timestamps when read from the database" do
|
42
|
+
@member.valid?
|
43
|
+
assert !@member.errors.on(:measured_at).blank?
|
44
|
+
end
|
45
|
+
|
35
46
|
private
|
36
47
|
|
37
48
|
def assert_valid_timestamp(timestamp)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfc-3339-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Manfred Stienstra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,12 +29,14 @@ extra_rdoc_files:
|
|
29
29
|
- LICENSE
|
30
30
|
- README.rdoc
|
31
31
|
files:
|
32
|
+
- .gitignore
|
32
33
|
- LICENSE
|
33
34
|
- README.rdoc
|
34
35
|
- Rakefile
|
35
36
|
- VERSION.yml
|
36
37
|
- lib/active_record/rfc_3339_attributes.rb
|
37
38
|
- rails/init.rb
|
39
|
+
- rfc-3339-attributes.gemspec
|
38
40
|
- test/rfc_3339_attributes_test.rb
|
39
41
|
- test/test_helper.rb
|
40
42
|
has_rdoc: true
|