test/model.rb in ohm-2.0.0.alpha5 vs test/model.rb in ohm-2.0.0.rc1
- old
+ new
@@ -5,16 +5,16 @@
require "ostruct"
class Post < Ohm::Model
attribute :body
attribute :published
- set :related, Post
+ set :related, :Post
end
class User < Ohm::Model
attribute :email
- set :posts, Post
+ set :posts, :Post
end
class Person < Ohm::Model
attribute :name
counter :logins
@@ -26,11 +26,11 @@
end
class Event < Ohm::Model
attribute :name
counter :votes
- set :attendees, Person
+ set :attendees, :Person
attribute :slug
def save
self.slug = name.to_s.downcase
@@ -49,14 +49,10 @@
end
class Meetup < Ohm::Model
attribute :name
attribute :location
-
- def validate
- assert_present :name
- end
end
test "booleans" do
post = Post.new(body: true, published: false)
@@ -309,12 +305,12 @@
# Delete
test "delete an existing model" do
class ModelToBeDeleted < Ohm::Model
attribute :name
- set :foos, Post
- set :bars, Post
+ set :foos, :Post
+ set :bars, :Post
end
@model = ModelToBeDeleted.create(:name => "Lorem")
@model.foos.add(Post.create)
@@ -772,10 +768,10 @@
assert "hash" == Ohm.redis.call("TYPE", "SomeNamespace::Foo:1")
assert "foo" == SomeNamespace::Foo[1].name
assert "foo" == SomeNamespace::Bar[1].foo.name
-end
+end if RUBY_VERSION >= "2.0.0"
test "typecast attributes" do
class Option < Ohm::Model
attribute :votes, lambda { |x| x.to_i }
end