fileclip 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/fileclip.rb +9 -2
- data/lib/fileclip/version.rb +1 -1
- data/spec/fileclip/validators_spec.rb +30 -0
- data/spec/fileclip_spec.rb +20 -0
- data/spec/schema.rb +20 -0
- data/spec/spec_helper.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d40924bf65cf039c91bcceead4b1cf7c74eb45b
|
4
|
+
data.tar.gz: f611297bd1576eba94220544c3b3657a92b0b1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc984b5f899557d9fcf6ba87d799cfe094dd8fa2a04e8c12ec92338a63cb87f4445e71ebb2009d08c3190bacc17a45d7b0f1cb994be6f564158ffb29311020f9
|
7
|
+
data.tar.gz: 88cde2cfabb89d4738540c0a2bb4d1e0b09f10495a2e43ccdeee86071fa2bdac9a95b8addf43b8053d05771ec99a59a51febcc121554822e23fcf7c4459818e4
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fileclip (0.2.
|
4
|
+
fileclip (0.2.3)
|
5
5
|
paperclip
|
6
6
|
paperclip (>= 3.5.1)
|
7
7
|
railties (>= 3.0)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
builder (3.0.4)
|
42
42
|
climate_control (0.0.3)
|
43
43
|
activesupport (>= 3.0)
|
44
|
-
cocaine (0.5.
|
44
|
+
cocaine (0.5.2)
|
45
45
|
climate_control (>= 0.0.3, < 1.0)
|
46
46
|
diff-lcs (1.2.4)
|
47
47
|
erubis (2.7.0)
|
data/lib/fileclip.rb
CHANGED
@@ -6,6 +6,8 @@ require 'fileclip/railtie'
|
|
6
6
|
require 'fileclip/jobs/resque'
|
7
7
|
require 'rest-client'
|
8
8
|
|
9
|
+
# TODO: make fileclip methods only load on fileclipped models
|
10
|
+
|
9
11
|
module FileClip
|
10
12
|
mattr_accessor :change_keys
|
11
13
|
|
@@ -79,7 +81,7 @@ module FileClip
|
|
79
81
|
|
80
82
|
def delay_process!
|
81
83
|
update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
|
82
|
-
Resque.enqueue(FileClip::Jobs::Resque, self.class.name, self.id)
|
84
|
+
::Resque.enqueue(FileClip::Jobs::Resque, self.class.name, self.id)
|
83
85
|
end
|
84
86
|
|
85
87
|
def process_from_filepicker
|
@@ -96,7 +98,11 @@ module FileClip
|
|
96
98
|
metadata = JSON.parse(::RestClient.get filepicker_url + "/metadata")
|
97
99
|
|
98
100
|
self.send(:"#{attachment_name}_content_type=", metadata["mimetype"])
|
99
|
-
|
101
|
+
|
102
|
+
# Delegate to paperclips filename cleaner
|
103
|
+
filename = self.attachment_object.send(:cleanup_filename, metadata["filename"])
|
104
|
+
self.send(:"#{attachment_name}_file_name=", filename)
|
105
|
+
|
100
106
|
self.send(:"#{attachment_name}_file_size=", metadata["size"])
|
101
107
|
end
|
102
108
|
|
@@ -107,6 +113,7 @@ module FileClip
|
|
107
113
|
end
|
108
114
|
|
109
115
|
def filepicker_url_not_present?
|
116
|
+
return true unless self.class.column_names.include? "filepicker_url"
|
110
117
|
!filepicker_url.present?
|
111
118
|
end
|
112
119
|
|
data/lib/fileclip/version.rb
CHANGED
@@ -32,6 +32,7 @@ describe FileClip::Validators do
|
|
32
32
|
describe "with filepicker url" do
|
33
33
|
before :each do
|
34
34
|
image.filepicker_url = "image.com"
|
35
|
+
image.filepicker_url_not_present?.should be_false
|
35
36
|
end
|
36
37
|
|
37
38
|
it "observes attachment presence" do
|
@@ -53,5 +54,34 @@ describe FileClip::Validators do
|
|
53
54
|
image.errors.should be_empty
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
describe "for non fileclipped asset" do
|
59
|
+
let(:asset) { Asset.new }
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
Asset.reset_callbacks(:validate)
|
63
|
+
Asset._validators.clear
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "if no filepicker_url" do
|
67
|
+
it "observes attachment presence" do
|
68
|
+
Asset.validates :attachment, :attachment_presence => true
|
69
|
+
asset.save.should be_false
|
70
|
+
asset.errors.first.last.should == "can't be blank"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "observes attachment size" do
|
74
|
+
Asset.validates_attachment :attachment, :size => { :in => 0..1000 }, :presence => true
|
75
|
+
asset.save.should be_false
|
76
|
+
asset.errors.should_not be_empty
|
77
|
+
end
|
78
|
+
|
79
|
+
it "observes attachment content" do
|
80
|
+
Asset.validates_attachment :attachment, :content_type => { :content_type => "image/jpg" }, :presence => true
|
81
|
+
asset.save.should be_false
|
82
|
+
asset.errors.should_not be_empty
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
56
86
|
end
|
57
87
|
end
|
data/spec/fileclip_spec.rb
CHANGED
@@ -108,6 +108,26 @@ describe FileClip do
|
|
108
108
|
image.update_from_filepicker!
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
context "with delayed paperclip" do
|
113
|
+
let(:delayed_image) { DelayedImage.create }
|
114
|
+
|
115
|
+
before :each do
|
116
|
+
FileClip.stub(:delayed?).and_return true
|
117
|
+
FileClip.stub(:resque_enabled?).and_return true
|
118
|
+
stub_const "Resque", Class.new
|
119
|
+
|
120
|
+
delayed_image.filepicker_url = filepicker_url
|
121
|
+
delayed_image.stub_chain(:previous_changes, :keys).and_return ["filepicker_url"]
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should update processing column" do
|
125
|
+
delayed_image.attachment_processing.should be_false
|
126
|
+
Resque.should_receive(:enqueue).with(FileClip::Jobs::Resque, "DelayedImage", delayed_image.id)
|
127
|
+
delayed_image.update_from_filepicker!
|
128
|
+
delayed_image.attachment_processing.should be_true
|
129
|
+
end
|
130
|
+
end
|
111
131
|
end
|
112
132
|
|
113
133
|
context "#update_from_filepicker?" do
|
data/spec/schema.rb
CHANGED
@@ -8,3 +8,23 @@ ActiveRecord::Schema.define :version => 0 do
|
|
8
8
|
t.string :filepicker_url
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define :version => 0 do
|
13
|
+
create_table "delayed_images", :force => true do |t|
|
14
|
+
t.string :attachment_file_name
|
15
|
+
t.string :attachment_content_type
|
16
|
+
t.integer :attachment_updated_at
|
17
|
+
t.integer :attachment_file_size
|
18
|
+
t.boolean :attachment_processing, default: false
|
19
|
+
t.string :filepicker_url
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveRecord::Schema.define :version => 0 do
|
24
|
+
create_table "assets", :force => true do |t|
|
25
|
+
t.string :attachment_file_name
|
26
|
+
t.string :attachment_content_type
|
27
|
+
t.integer :attachment_updated_at
|
28
|
+
t.integer :attachment_file_size
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -32,3 +32,28 @@ class Image < ActiveRecord::Base
|
|
32
32
|
fileclip :attachment
|
33
33
|
|
34
34
|
end
|
35
|
+
|
36
|
+
class DelayedImage < ActiveRecord::Base
|
37
|
+
|
38
|
+
has_attached_file :attachment,
|
39
|
+
:storage => :filesystem,
|
40
|
+
:path => "./spec/tmp/:style/:id.:extension",
|
41
|
+
:url => "./spec/tmp/:style/:id.extension"
|
42
|
+
|
43
|
+
# Not testing DelayedPaperclip directly yet
|
44
|
+
# process_in_background :attachment,
|
45
|
+
# if: :filepicker_url_not_present?
|
46
|
+
|
47
|
+
fileclip :attachment
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class Asset < ActiveRecord::Base
|
53
|
+
|
54
|
+
has_attached_file :attachment,
|
55
|
+
:storage => :filesystem,
|
56
|
+
:path => "./spec/tmp/:style/:id.:extension",
|
57
|
+
:url => "./spec/tmp/:style/:id.extension"
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fileclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Carleton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paperclip
|