versions 0.2.0 → 0.2.1
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/History.txt +8 -3
- data/README.rdoc +11 -0
- data/lib/versions/attachment.rb +5 -0
- data/lib/versions/shared_attachment.rb +9 -1
- data/lib/versions/version.rb +1 -1
- data/test/fixtures.rb +0 -1
- data/test/unit/attachment_test.rb +14 -0
- data/test/unit/auto_test.rb +1 -1
- data/versions.gemspec +2 -2
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
== 0.2.1 2010-02-16
|
2
|
+
|
3
|
+
* 1 major enhancement
|
4
|
+
* Attachment was not creating the 'file' method
|
5
|
+
|
1
6
|
== 0.2.0 2010-02-15
|
2
7
|
|
3
8
|
* 1 major enhancement
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
9
|
+
* changed inverse option from 'as' to 'inverse' in Multi
|
10
|
+
* implemented the Attachment module
|
11
|
+
* added AfterCommit module
|
7
12
|
|
8
13
|
== 0.1.0 2010-02-14
|
9
14
|
|
data/README.rdoc
CHANGED
@@ -77,3 +77,14 @@ and deleted when no more versions are using them. Example:
|
|
77
77
|
store_attachments_in :version, :attachment_class => 'Attachment'
|
78
78
|
end
|
79
79
|
|
80
|
+
== Testing Gotcha
|
81
|
+
|
82
|
+
If you are testing your application with AfterCommit, you should note that the 'after_commit' code will
|
83
|
+
*NEVER BE EXECUTED* if you have enabled transactional fixtures. You can fix this by disabling transactional
|
84
|
+
fixtures in the tests where you need the after_commit code to execute (save file).
|
85
|
+
|
86
|
+
class DocumentTest < Test::Unit::TestCase
|
87
|
+
self.use_transactional_fixtures = false
|
88
|
+
|
89
|
+
# ...
|
90
|
+
end
|
data/lib/versions/attachment.rb
CHANGED
@@ -67,9 +67,14 @@ module Versions
|
|
67
67
|
self.attachment = nil
|
68
68
|
end
|
69
69
|
@attachment_need_save = true
|
70
|
+
@file = file
|
70
71
|
self.build_attachment(:file => file)
|
71
72
|
end
|
72
73
|
|
74
|
+
def file
|
75
|
+
@file ||= attachment ? attachment.file : nil
|
76
|
+
end
|
77
|
+
|
73
78
|
def filepath
|
74
79
|
attachment ? attachment.filepath : nil
|
75
80
|
end
|
@@ -18,6 +18,10 @@ module Versions
|
|
18
18
|
self[:filename] = get_filename(file)
|
19
19
|
end
|
20
20
|
|
21
|
+
def file
|
22
|
+
File.new(filepath)
|
23
|
+
end
|
24
|
+
|
21
25
|
def filepath
|
22
26
|
@filepath ||= begin digest = ::Digest::SHA1.hexdigest(self[:id].to_s)
|
23
27
|
"#{digest[0..0]}/#{digest[1..1]}/#{filename}"
|
@@ -42,7 +46,11 @@ module Versions
|
|
42
46
|
if data.respond_to?(:rewind)
|
43
47
|
data.rewind
|
44
48
|
end
|
45
|
-
File.open(path, "wb")
|
49
|
+
File.open(path, "wb") do |file|
|
50
|
+
while buffer = data.read(2_024_000)
|
51
|
+
file.syswrite(buffer)
|
52
|
+
end
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
56
|
def remove_file
|
data/lib/versions/version.rb
CHANGED
data/test/fixtures.rb
CHANGED
@@ -53,6 +53,11 @@ class AttachmentTest < Test::Unit::TestCase
|
|
53
53
|
assert_equal @owner.filepath, attachment.filepath
|
54
54
|
end
|
55
55
|
|
56
|
+
should 'restore the file with the database' do
|
57
|
+
attachment = Attachment.find(@owner.attachment_id)
|
58
|
+
assert_equal uploaded_jpg('bird.jpg').read, attachment.file.read
|
59
|
+
end
|
60
|
+
|
56
61
|
should 'rename file on bad original_filename' do
|
57
62
|
file = uploaded_jpg('bird.jpg')
|
58
63
|
class << file
|
@@ -118,6 +123,15 @@ class AttachmentTest < Test::Unit::TestCase
|
|
118
123
|
assert_equal uploaded_jpg('lake.jpg').read, File.read(@owner.filepath)
|
119
124
|
assert !File.exist?(old_filepath)
|
120
125
|
end
|
126
|
+
|
127
|
+
should 'get file when sent :file' do
|
128
|
+
assert_equal uploaded_jpg('bird.jpg').read, @owner.file.read
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'get file before save when sent :file' do
|
132
|
+
@owner = Version.new(:file => uploaded_jpg('bird.jpg'))
|
133
|
+
assert_equal uploaded_jpg('bird.jpg').read, @owner.file.read
|
134
|
+
end
|
121
135
|
end
|
122
136
|
|
123
137
|
context 'Updating document' do
|
data/test/unit/auto_test.rb
CHANGED
data/versions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{versions}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gaspard Bucher"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-22}
|
13
13
|
s.description = %q{A list of libraries to work with ActiveRecord model versioning: Auto (duplicate on save), Multi (hide many versions behind a single one), Transparent (hide versions from outside world), Property (define properties on model, store them in versions)}
|
14
14
|
s.email = %q{gaspard@teti.ch}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaspard Bucher
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|