bulldog 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.2 2010-07-26
2
+
3
+ * Support for assigning one attachment to another.
4
+
1
5
  == 0.2.1 2010-07-15
2
6
 
3
7
  * Path/URL templates may be symbols specifying methods to call to
@@ -12,6 +12,13 @@ module Bulldog
12
12
  @saved = @value.is_a?(SavedFile) || @value.is_a?(MissingFile)
13
13
  end
14
14
 
15
+ #
16
+ # Return a copy of this attachment for the given record.
17
+ #
18
+ def copy_for(record)
19
+ self.class.new(record, name, stream)
20
+ end
21
+
15
22
  attr_reader :record, :name, :stream, :value
16
23
 
17
24
  #
@@ -126,6 +126,7 @@ module Bulldog
126
126
 
127
127
  def make_attachment_for(name, value)
128
128
  return Attachment.none(self, name) if value.nil?
129
+ return value.copy_for(self) if value.is_a?(Attachment::Maybe)
129
130
  stream = Stream.new(value)
130
131
  reflection = attachment_reflection_for(name)
131
132
  type = reflection.detect_attachment_type(self, stream)
@@ -1,5 +1,5 @@
1
1
  module Bulldog
2
- VERSION = [0, 2, 1]
2
+ VERSION = [0, 2, 2]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -51,6 +51,26 @@ describe HasAttachment do
51
51
  end
52
52
  end
53
53
 
54
+ describe "assigning to an attachment" do
55
+ use_model_class(:Thing)
56
+
57
+ describe "when assigning an existing attachment" do
58
+ before do
59
+ Thing.has_attachment :photo
60
+ @existing_thing = Thing.new(:photo => uploaded_file('test.jpg'))
61
+ @thing = Thing.new(:photo => @existing_thing.photo)
62
+ end
63
+
64
+ it "should make a copy of the attachment" do
65
+ @thing.photo.value.should == @existing_thing.photo.value
66
+ end
67
+
68
+ it "should ensure the copy points to the new record" do
69
+ @thing.photo.record.should equal(@thing)
70
+ end
71
+ end
72
+ end
73
+
54
74
  describe ".attachment_reflections" do
55
75
  use_model_class(:Thing)
56
76
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - George Ogata
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-15 00:00:00 -04:00
17
+ date: 2010-07-26 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency