Sha256: fe17cdeafc1091bd97657a82b8bc2483dd9ceefa13b6bd715ca862328403b519
Contents?: true
Size: 1.39 KB
Versions: 6
Compression:
Stored size: 1.39 KB
Contents
require File.expand_path("./helper", File.dirname(__FILE__)) class Post < Ohm::Model list :comments, :Comment end class Comment < Ohm::Model end setup do post = Post.create post.comments.push(c1 = Comment.create) post.comments.push(c2 = Comment.create) post.comments.push(c3 = Comment.create) [post, c1, c2, c3] end test "include?" do |p, c1, c2, c3| assert p.comments.include?(c1) assert p.comments.include?(c2) assert p.comments.include?(c3) end test "first / last / size / empty?" do |p, c1, c2, c3| assert_equal 3, p.comments.size assert_equal c1, p.comments.first assert_equal c3, p.comments.last assert ! p.comments.empty? end test "replace" do |p, c1, c2, c3| c4 = Comment.create p.comments.replace([c4]) assert_equal [c4], p.comments.to_a end test "push / unshift" do |p, c1, c2, c3| c4 = Comment.create c5 = Comment.create p.comments.unshift(c4) p.comments.push(c5) assert_equal c4, p.comments.first assert_equal c5, p.comments.last end test "delete" do |p, c1, c2, c3| p.comments.delete(c1) assert_equal 2, p.comments.size assert ! p.comments.include?(c1) p.comments.delete(c2) assert_equal 1, p.comments.size assert ! p.comments.include?(c2) p.comments.delete(c3) assert p.comments.empty? end test "deleting main model cleans up the collection" do |p, _, _, _| p.delete assert_equal 0, Ohm.redis.call("EXISTS", p.key[:comments]) end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
ohm-2.0.0.rc1 | test/list.rb |
ohm-2.0.0.alpha5 | test/list.rb |
ohm-2.0.0.alpha4 | test/list.rb |
ohm-2.0.0.alpha3 | test/list.rb |
ohm-2.0.0.alpha2 | test/list.rb |
ohm-2.0.0.alpha1 | test/list.rb |