test/test_joint.rb in joint-0.3 vs test/test_joint.rb in joint-0.3.1

- old
+ new

@@ -7,10 +7,19 @@ key :title, String attachment :image attachment :file end +class BaseModel + include MongoMapper::Document + plugin Joint + attachment :file +end + +class Image < BaseModel; attachment :image end +class Video < BaseModel; attachment :video end + module JointTestHelpers def all_files [@file, @image, @image2, @test1, @test2] end @@ -23,10 +32,14 @@ end def grid @grid ||= Mongo::Grid.new(MongoMapper.database) end + + def key_names + [:id, :name, :type, :size] + end end class JointTest < Test::Unit::TestCase include JointTestHelpers @@ -47,12 +60,32 @@ should "add each attachment to attachment_names" do Asset.attachment_names.should == Set.new([:image, :file]) end should "add keys for each attachment" do - [:image, :file].each do |attachment| - [:id, :name, :type, :size].each do |key| - Asset.keys.should include("#{attachment}_#{key}") + key_names.each do |key| + Asset.keys.should include("image_#{key}") + Asset.keys.should include("file_#{key}") + end + end + + context "with inheritance" do + should "add attachment to attachment_names" do + BaseModel.attachment_names.should == Set.new([:file]) + end + + should "inherit attachments from superclass, but not share other inherited class attachments" do + Image.attachment_names.should == Set.new([:file, :image]) + Video.attachment_names.should == Set.new([:file, :video]) + end + + should "add inherit keys from superclass" do + key_names.each do |key| + BaseModel.keys.should include("file_#{key}") + Image.keys.should include("file_#{key}") + Image.keys.should include("image_#{key}") + Video.keys.should include("file_#{key}") + Video.keys.should include("video_#{key}") end end end end \ No newline at end of file