ohm-contrib 0.0.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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.markdown +44 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/ohm/contrib/boundaries.rb +17 -0
- data/lib/ohm/contrib/number_validations.rb +9 -0
- data/lib/ohm/contrib/timestamping.rb +21 -0
- data/lib/ohm/contrib/to_hash.rb +11 -0
- data/lib/ohm/contrib/web_validations.rb +35 -0
- data/lib/ohm/contrib.rb +9 -0
- data/test/helper.rb +15 -0
- data/test/test_ohm_boundaries.rb +52 -0
- data/test/test_ohm_contrib.rb +34 -0
- data/test/test_ohm_number_validations.rb +59 -0
- data/test/test_ohm_timestamping.rb +60 -0
- data/test/test_ohm_to_hash.rb +67 -0
- data/test/test_ohm_web_validations.rb +113 -0
- metadata +134 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Cyril David
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
ohm-contrib
|
2
|
+
===========
|
3
|
+
|
4
|
+
A collection of drop-in modules for Ohm.
|
5
|
+
|
6
|
+
List of modules
|
7
|
+
---------------
|
8
|
+
* `Ohm::Boundaries`
|
9
|
+
* `Ohm::Timestamping`
|
10
|
+
* `Ohm::ToHash`
|
11
|
+
|
12
|
+
Example usage
|
13
|
+
-------------
|
14
|
+
|
15
|
+
require 'ohm'
|
16
|
+
require 'ohm/contrib'
|
17
|
+
|
18
|
+
class Post < Ohm::Model
|
19
|
+
include Ohm::Timestamping
|
20
|
+
include Ohm::ToHash
|
21
|
+
include Ohm::Boundaries
|
22
|
+
end
|
23
|
+
|
24
|
+
Post.first
|
25
|
+
Post.last
|
26
|
+
Post.new.to_hash
|
27
|
+
Post.create.to_hash
|
28
|
+
Post.create.created_at
|
29
|
+
Post.create.updated_at
|
30
|
+
|
31
|
+
Note on Patches/Pull Requests
|
32
|
+
-----------------------------
|
33
|
+
* Fork the project.
|
34
|
+
* Make your feature addition or bug fix.
|
35
|
+
* Add tests for it. This is important so I don't break it in a
|
36
|
+
future version unintentionally.
|
37
|
+
* Commit, do not mess with rakefile, version, or history.
|
38
|
+
(if you want to have your own version, that is fine but bump version in a
|
39
|
+
commit by itself I can ignore when I pull)
|
40
|
+
* Send me a pull request. Bonus points for topic branches.
|
41
|
+
|
42
|
+
Copyright
|
43
|
+
---------
|
44
|
+
Copyright (c) 2010 Cyril David. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ohm-contrib"
|
8
|
+
gem.summary = %Q{A collection of ohm related modules}
|
9
|
+
gem.description = %Q{Highly decoupled drop-in functionality for Ohm models}
|
10
|
+
gem.email = "cyx.ucron@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/sinefunc/ohm-contrib"
|
12
|
+
gem.authors = ["Cyril David"]
|
13
|
+
gem.add_development_dependency "contest", ">= 0"
|
14
|
+
gem.add_development_dependency "redis", ">= 0"
|
15
|
+
gem.add_development_dependency "ohm", ">= 0"
|
16
|
+
gem.add_development_dependency "timecop", ">= 0"
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "ohm-contrib #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ohm
|
2
|
+
module Timestamping
|
3
|
+
def self.included(base)
|
4
|
+
base.attribute :created_at
|
5
|
+
base.attribute :updated_at
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
self.created_at ||= Time.now.utc
|
10
|
+
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def write
|
16
|
+
self.updated_at ||= Time.now.utc
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ohm
|
2
|
+
# All credit goes to gnrfan of github
|
3
|
+
# Basically an extraction from http://github.com/gnrfan/ohm_extra_validations
|
4
|
+
module WebValidations
|
5
|
+
|
6
|
+
protected
|
7
|
+
def assert_slug(att, error = [att, :not_slug])
|
8
|
+
if assert_present(att, error) and assert_unique(att)
|
9
|
+
assert_format(att, /^[-\w]+$/, error)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_email(att, error = [att, :not_email])
|
14
|
+
if assert_present(att, error)
|
15
|
+
assert_format(att, /^([^@\s*]+)@((?:[-a-z0-9]+\.)+[a-z]{2,6})$/i, error)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_url(att, error = [att, :not_url])
|
20
|
+
if assert_present(att, error)
|
21
|
+
assert_format(att, /^(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|localhost)(:[0-9]{1,5})?(\/.*)?$/ix, error)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_ipv4(att, error = [att, :not_ipv4])
|
26
|
+
if assert_present(att, error)
|
27
|
+
assert_format(att, /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/, error)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def assert_ipaddr(att, error = [att, :not_ipaddr])
|
32
|
+
assert_ipv4(att, error)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/ohm/contrib.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module Ohm
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
|
4
|
+
autoload :Boundaries, "ohm/contrib/boundaries"
|
5
|
+
autoload :Timestamping, "ohm/contrib/timestamping"
|
6
|
+
autoload :ToHash, "ohm/contrib/to_hash"
|
7
|
+
autoload :WebValidations, "ohm/contrib/web_validations"
|
8
|
+
autoload :NumberValidations, "ohm/contrib/number_validations"
|
9
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'contest'
|
4
|
+
require 'redis'
|
5
|
+
require 'ohm'
|
6
|
+
require 'timecop'
|
7
|
+
|
8
|
+
Ohm.connect :host => "localhost", :port => "6380"
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
+
require 'ohm/contrib'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestOhmBoundaries < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
Ohm.flush
|
6
|
+
end
|
7
|
+
|
8
|
+
class Person < Ohm::Model
|
9
|
+
include Ohm::Boundaries
|
10
|
+
|
11
|
+
attribute :name
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when there are no People" do
|
15
|
+
should "have a nil Person.first" do
|
16
|
+
assert_nil Person.first
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have a nil Person.last" do
|
20
|
+
assert_nil Person.last
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "after creating a single Person named matz" do
|
25
|
+
setup do
|
26
|
+
@matz = Person.create(:name => "matz")
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have matz as the first person" do
|
30
|
+
assert_equal @matz, Person.first
|
31
|
+
end
|
32
|
+
|
33
|
+
should "have matz as the last person" do
|
34
|
+
assert_equal @matz, Person.last
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "after creating matz first then linus next" do
|
39
|
+
setup do
|
40
|
+
@matz = Person.create(:name => "matz")
|
41
|
+
@linus = Person.create(:name => "linus")
|
42
|
+
end
|
43
|
+
|
44
|
+
should "have matz as the first Person" do
|
45
|
+
assert_equal @matz, Person.first
|
46
|
+
end
|
47
|
+
|
48
|
+
should "have linus as the last Person" do
|
49
|
+
assert_equal @linus, Person.last
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestOhmContrib < Test::Unit::TestCase
|
4
|
+
test "autoloading of Boundaries" do
|
5
|
+
assert_nothing_raised NameError, LoadError do
|
6
|
+
Ohm::Boundaries
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "autoloading of timestamping" do
|
11
|
+
assert_nothing_raised NameError, LoadError do
|
12
|
+
Ohm::Timestamping
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test "autoloading of ToHash" do
|
17
|
+
assert_nothing_raised NameError, LoadError do
|
18
|
+
Ohm::ToHash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test "autoloading of WebValidations" do
|
23
|
+
assert_nothing_raised NameError, LoadError do
|
24
|
+
Ohm::WebValidations
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "autoloading of NumberValidations" do
|
29
|
+
assert_nothing_raised NameError, LoadError do
|
30
|
+
Ohm::NumberValidations
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestOhmNumberValidations < Test::Unit::TestCase
|
4
|
+
class Product < Ohm::Model
|
5
|
+
include Ohm::NumberValidations
|
6
|
+
|
7
|
+
attribute :price
|
8
|
+
attribute :optional_price
|
9
|
+
|
10
|
+
def validate
|
11
|
+
assert_decimal :price
|
12
|
+
assert_decimal :optional_price unless optional_price.to_s.empty?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "given no price" do
|
17
|
+
should "still validate as :not_decimal" do
|
18
|
+
product = Product.new(:price => nil)
|
19
|
+
product.valid?
|
20
|
+
|
21
|
+
assert_equal [[:price, :not_decimal]], product.errors
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "given a 0.10 value" do
|
26
|
+
should "validate as a decimal" do
|
27
|
+
product = Product.new(:price => 0.10)
|
28
|
+
|
29
|
+
assert product.valid?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "given 1 as a value" do
|
34
|
+
should "validate as a decimal" do
|
35
|
+
product = Product.new(:price => 1)
|
36
|
+
|
37
|
+
assert product.valid?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "given 1 dot as a value" do
|
42
|
+
should "not validate as a decimal" do
|
43
|
+
product = Product.new(:price => "1.")
|
44
|
+
|
45
|
+
assert ! product.valid?
|
46
|
+
assert_equal [[:price, :not_decimal]], product.errors
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "given no value for optional price" do
|
51
|
+
should "have no validation errors" do
|
52
|
+
product = Product.new(:price => 10.1, :optional_price => nil)
|
53
|
+
assert product.valid?
|
54
|
+
|
55
|
+
product = Product.new(:price => 10.1, :optional_price => '')
|
56
|
+
assert product.valid?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestOhmTimestamping < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
Ohm.flush
|
6
|
+
end
|
7
|
+
|
8
|
+
class Person < Ohm::Model
|
9
|
+
include Ohm::Timestamping
|
10
|
+
end
|
11
|
+
|
12
|
+
context "a new? record" do
|
13
|
+
should "have no created_at" do
|
14
|
+
assert_nil Person.new.created_at
|
15
|
+
end
|
16
|
+
|
17
|
+
should "have no updated_at" do
|
18
|
+
assert_nil Person.new.updated_at
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on create" do
|
23
|
+
setup do
|
24
|
+
@now = Time.utc(2010, 5, 12)
|
25
|
+
Timecop.freeze(@now)
|
26
|
+
@person = Person.create
|
27
|
+
@person = Person[@person.id]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
should "set the created_at equal to the current time" do
|
32
|
+
assert_equal @now.to_s, @person.created_at
|
33
|
+
end
|
34
|
+
|
35
|
+
should "also set the updated_at equal to the current time" do
|
36
|
+
assert_equal @now.to_s, @person.updated_at
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "on update" do
|
41
|
+
setup do
|
42
|
+
@person = Person.create
|
43
|
+
@old_created_at = @person.created_at.to_s
|
44
|
+
|
45
|
+
@now = Time.utc(2010, 10, 31)
|
46
|
+
Timecop.freeze(@now)
|
47
|
+
|
48
|
+
@person.save
|
49
|
+
@person = Person[@person.id]
|
50
|
+
end
|
51
|
+
|
52
|
+
should "leave created_at unchanged" do
|
53
|
+
assert_equal @old_created_at, @person.created_at
|
54
|
+
end
|
55
|
+
|
56
|
+
should "set updated_at to the current Time" do
|
57
|
+
assert_equal @now.to_s, @person.updated_at
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestOhmToHash < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
Ohm.flush
|
6
|
+
end
|
7
|
+
|
8
|
+
context "a Person with name: matz, age: nil, skills: 10" do
|
9
|
+
class Person < Ohm::Model
|
10
|
+
include Ohm::ToHash
|
11
|
+
|
12
|
+
attribute :name
|
13
|
+
attribute :age
|
14
|
+
attribute :skills
|
15
|
+
end
|
16
|
+
|
17
|
+
setup do
|
18
|
+
@person = Person.create(:name => 'matz', :skills => 10)
|
19
|
+
@person = Person[@person.id]
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have a to_hash of { id: 1, name: 'matz', age: nil, skills: 10 }" do
|
23
|
+
assert_equal(
|
24
|
+
{ :id => '1', :name => "matz", :age => nil, :skills => '10' },
|
25
|
+
@person.to_hash
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when a Post has a votes counter" do
|
31
|
+
class Post < Ohm::Model
|
32
|
+
include Ohm::ToHash
|
33
|
+
|
34
|
+
counter :votes
|
35
|
+
end
|
36
|
+
|
37
|
+
setup do
|
38
|
+
@post = Post.create
|
39
|
+
@post.incr :votes
|
40
|
+
@post.incr :votes
|
41
|
+
@post.incr :votes
|
42
|
+
end
|
43
|
+
|
44
|
+
should "include the votes in the hash" do
|
45
|
+
assert_equal({ :id => '1', :votes => 3 }, @post.to_hash)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when a comment has a reference to a person" do
|
50
|
+
Person = Class.new(Ohm::Model)
|
51
|
+
|
52
|
+
class Comment < Ohm::Model
|
53
|
+
include Ohm::ToHash
|
54
|
+
|
55
|
+
reference :person, Person
|
56
|
+
end
|
57
|
+
|
58
|
+
setup do
|
59
|
+
@person = Person.create
|
60
|
+
@comment = Comment.create(:person => @person)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "have the person_id in the hash" do
|
64
|
+
assert_equal({ :id => '1', :person_id => '1' }, @comment.to_hash)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestOhmWebValidations < Test::Unit::TestCase
|
4
|
+
class BlogPost < Ohm::Model
|
5
|
+
include Ohm::WebValidations
|
6
|
+
|
7
|
+
attribute :slug
|
8
|
+
|
9
|
+
index :slug
|
10
|
+
|
11
|
+
def validate
|
12
|
+
assert_slug :slug
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Comment < Ohm::Model
|
17
|
+
include Ohm::WebValidations
|
18
|
+
|
19
|
+
attribute :ip_address
|
20
|
+
attribute :homepage
|
21
|
+
attribute :email
|
22
|
+
|
23
|
+
def validate
|
24
|
+
assert_ipaddr :ip_address
|
25
|
+
assert_url :homepage
|
26
|
+
assert_email :email
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The slug should be valid" do
|
31
|
+
def setup
|
32
|
+
@blog_post_01 = BlogPost.new
|
33
|
+
@blog_post_02 = BlogPost.new
|
34
|
+
end
|
35
|
+
|
36
|
+
should "fail if the slug is not valid" do
|
37
|
+
@blog_post_01.slug = "This is a title, not a SLUG"
|
38
|
+
@blog_post_01.create
|
39
|
+
|
40
|
+
assert @blog_post_01.new?
|
41
|
+
assert_equal [[:slug, :not_slug]], @blog_post_01.errors
|
42
|
+
end
|
43
|
+
|
44
|
+
#should "succeed if the slug is valid" do
|
45
|
+
# @blog_post_02.slug = "this-is-a-valid-slug"
|
46
|
+
# @blog_post_02.create
|
47
|
+
# assert_not_nil @blog_post_02.id
|
48
|
+
#end
|
49
|
+
|
50
|
+
should "fail if the slug is not unique" do
|
51
|
+
|
52
|
+
@blog_post_01.slug = "this-is-a-valid-slug"
|
53
|
+
@blog_post_01.create
|
54
|
+
|
55
|
+
@blog_post_02.slug = "this-is-a-valid-slug"
|
56
|
+
@blog_post_02.create
|
57
|
+
|
58
|
+
assert @blog_post_02.new?
|
59
|
+
assert_equal [[:slug, :not_unique]], @blog_post_02.errors
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "the ip address should be valid" do
|
64
|
+
def setup
|
65
|
+
@comment = Comment.new
|
66
|
+
end
|
67
|
+
|
68
|
+
should "fail if the ip address is not valid" do
|
69
|
+
@comment.ip_address = "400.500.600.700"
|
70
|
+
@comment.create
|
71
|
+
|
72
|
+
assert @comment.new?
|
73
|
+
assert @comment.errors.include? [:ip_address, :not_ipaddr]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "the email address should be valid" do
|
78
|
+
def setup
|
79
|
+
@comment = Comment.new
|
80
|
+
end
|
81
|
+
|
82
|
+
should "fail if the email address is not valid" do
|
83
|
+
@comment.email = "something.com"
|
84
|
+
@comment.create
|
85
|
+
|
86
|
+
assert @comment.new?
|
87
|
+
assert @comment.errors.include? [:email, :not_email]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "the homepage URL should be valid" do
|
92
|
+
def setup
|
93
|
+
@comment = Comment.new
|
94
|
+
end
|
95
|
+
|
96
|
+
should "fail if the homepage URL is not valid" do
|
97
|
+
@comment.homepage = "something"
|
98
|
+
@comment.create
|
99
|
+
|
100
|
+
assert @comment.new?
|
101
|
+
assert @comment.errors.include? [:homepage, :not_url]
|
102
|
+
end
|
103
|
+
|
104
|
+
should "fail if the homepage URL protocol is not http or https" do
|
105
|
+
@comment.homepage = "irc://irc.freenode.net/something"
|
106
|
+
@comment.create
|
107
|
+
|
108
|
+
assert @comment.new?
|
109
|
+
assert @comment.errors.include? [:homepage, :not_url]
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ohm-contrib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Cyril David
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-13 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: contest
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: redis
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: ohm
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: timecop
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
description: Highly decoupled drop-in functionality for Ohm models
|
69
|
+
email: cyx.ucron@gmail.com
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.markdown
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .gitignore
|
80
|
+
- LICENSE
|
81
|
+
- README.markdown
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/ohm/contrib.rb
|
85
|
+
- lib/ohm/contrib/boundaries.rb
|
86
|
+
- lib/ohm/contrib/number_validations.rb
|
87
|
+
- lib/ohm/contrib/timestamping.rb
|
88
|
+
- lib/ohm/contrib/to_hash.rb
|
89
|
+
- lib/ohm/contrib/web_validations.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_ohm_boundaries.rb
|
92
|
+
- test/test_ohm_contrib.rb
|
93
|
+
- test/test_ohm_number_validations.rb
|
94
|
+
- test/test_ohm_timestamping.rb
|
95
|
+
- test/test_ohm_to_hash.rb
|
96
|
+
- test/test_ohm_web_validations.rb
|
97
|
+
has_rdoc: true
|
98
|
+
homepage: http://github.com/sinefunc/ohm-contrib
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: A collection of ohm related modules
|
127
|
+
test_files:
|
128
|
+
- test/helper.rb
|
129
|
+
- test/test_ohm_boundaries.rb
|
130
|
+
- test/test_ohm_contrib.rb
|
131
|
+
- test/test_ohm_number_validations.rb
|
132
|
+
- test/test_ohm_timestamping.rb
|
133
|
+
- test/test_ohm_to_hash.rb
|
134
|
+
- test/test_ohm_web_validations.rb
|