bulldog 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/lib/bulldog/attachment/maybe.rb +7 -0
- data/lib/bulldog/has_attachment.rb +1 -0
- data/lib/bulldog/version.rb +1 -1
- data/spec/unit/has_attachment_spec.rb +20 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -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)
|
data/lib/bulldog/version.rb
CHANGED
@@ -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
|
-
-
|
9
|
-
version: 0.2.
|
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-
|
17
|
+
date: 2010-07-26 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|