joint 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,14 @@ require 'wand'
5
5
  module Joint
6
6
  autoload :Version, 'joint/version'
7
7
 
8
+ def self.configure(model)
9
+ model.class_inheritable_accessor :attachment_names
10
+ model.attachment_names = Set.new
11
+ end
12
+
8
13
  module ClassMethods
9
14
  def attachment(name)
10
- self.class.class_inheritable_accessor :attachment_names unless self.class.respond_to?(:attachment_names)
11
- self.class.attachment_names ||= Set.new
12
- self.class.attachment_names << name
15
+ self.attachment_names << name
13
16
 
14
17
  after_save :save_attachments
15
18
  after_save :destroy_nil_attachments
@@ -1,3 +1,3 @@
1
1
  module Joint
2
- Version = '0.3'
2
+ Version = '0.3.1'
3
3
  end
@@ -9,6 +9,15 @@ class Asset
9
9
  attachment :file
10
10
  end
11
11
 
12
+ class BaseModel
13
+ include MongoMapper::Document
14
+ plugin Joint
15
+ attachment :file
16
+ end
17
+
18
+ class Image < BaseModel; attachment :image end
19
+ class Video < BaseModel; attachment :video end
20
+
12
21
  module JointTestHelpers
13
22
  def all_files
14
23
  [@file, @image, @image2, @test1, @test2]
@@ -25,6 +34,10 @@ module JointTestHelpers
25
34
  def grid
26
35
  @grid ||= Mongo::Grid.new(MongoMapper.database)
27
36
  end
37
+
38
+ def key_names
39
+ [:id, :name, :type, :size]
40
+ end
28
41
  end
29
42
 
30
43
  class JointTest < Test::Unit::TestCase
@@ -49,9 +62,29 @@ class JointTest < Test::Unit::TestCase
49
62
  end
50
63
 
51
64
  should "add keys for each attachment" do
52
- [:image, :file].each do |attachment|
53
- [:id, :name, :type, :size].each do |key|
54
- Asset.keys.should include("#{attachment}_#{key}")
65
+ key_names.each do |key|
66
+ Asset.keys.should include("image_#{key}")
67
+ Asset.keys.should include("file_#{key}")
68
+ end
69
+ end
70
+
71
+ context "with inheritance" do
72
+ should "add attachment to attachment_names" do
73
+ BaseModel.attachment_names.should == Set.new([:file])
74
+ end
75
+
76
+ should "inherit attachments from superclass, but not share other inherited class attachments" do
77
+ Image.attachment_names.should == Set.new([:file, :image])
78
+ Video.attachment_names.should == Set.new([:file, :video])
79
+ end
80
+
81
+ should "add inherit keys from superclass" do
82
+ key_names.each do |key|
83
+ BaseModel.keys.should include("file_#{key}")
84
+ Image.keys.should include("file_#{key}")
85
+ Image.keys.should include("image_#{key}")
86
+ Video.keys.should include("file_#{key}")
87
+ Video.keys.should include("video_#{key}")
55
88
  end
56
89
  end
57
90
  end
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- version: "0.3"
8
+ - 1
9
+ version: 0.3.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - John Nunemaker
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-04-05 00:00:00 -04:00
17
+ date: 2010-04-07 00:00:00 -04:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency