paperclip_database 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +6 -0
- data/Gemfile.lock +2 -2
- data/features/basic_integration.feature +14 -3
- data/features/step_definitions/rails_steps.rb +9 -1
- data/features/support/rails.rb +12 -0
- data/gemfiles/rails2_legacy.gemfile +9 -0
- data/lib/paperclip/storage/database.rb +3 -3
- data/lib/paperclip_database/version.rb +1 -1
- data/paperclip_database.gemspec +1 -1
- metadata +26 -25
data/Appraisals
CHANGED
data/Gemfile.lock
CHANGED
@@ -14,6 +14,18 @@ Feature: Rails integration
|
|
14
14
|
has_attached_file :attachment,
|
15
15
|
:storage => :database,
|
16
16
|
:database_table => :user_attachments,
|
17
|
+
:url => '/user_attachment_views/:id?style=:style'
|
18
|
+
"""
|
19
|
+
And I run a rails generator to generate a "UserAttachmentView" scaffold with ""
|
20
|
+
Given I add this snippet to the "user_attachment_views" controller:
|
21
|
+
"""
|
22
|
+
def show
|
23
|
+
style = params[:style] ? params[:style] : 'original'
|
24
|
+
record = User.find(params[:id])
|
25
|
+
send_data record.attachment.file_contents(style),
|
26
|
+
:filename => record.attachment_file_name,
|
27
|
+
:type => record.attachment_content_type
|
28
|
+
end
|
17
29
|
"""
|
18
30
|
And I run a paperclip_database generator to create storage for paperclip "attachment" to the "User" model
|
19
31
|
And I run a migration
|
@@ -23,7 +35,6 @@ Feature: Rails integration
|
|
23
35
|
And I attach the file "test/fixtures/5k.png" to "Attachment"
|
24
36
|
And I press "Submit"
|
25
37
|
Then I should see "Name: something"
|
26
|
-
And I should see an image with a path of "/
|
27
|
-
|
28
|
-
And the result of "User.first.attachment.file_for(:original).file_contents" should be the same as "test/fixtures/5k.png"
|
38
|
+
And I should see an image with a path of "/user_attachment_views/1?style=original"
|
39
|
+
And the file at "/user_attachment_views/1?style=original" should be the same as "test/fixtures/5k.png"
|
29
40
|
|
@@ -11,7 +11,7 @@ Given /^I generate a new rails application$/ do
|
|
11
11
|
gem "capybara"
|
12
12
|
gem "gherkin"
|
13
13
|
gem "aws-sdk"
|
14
|
-
gem "paperclip"
|
14
|
+
gem "paperclip", "#{paperclip_version}"
|
15
15
|
"""
|
16
16
|
And I configure the application to use "paperclip_database" from this project
|
17
17
|
And I reset Bundler environment variable
|
@@ -83,6 +83,14 @@ Given /^I add this snippet to the User model:$/ do |snippet|
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
Given /^I add this snippet to the "(.*?)" controller:$/ do |controller_name, snippet|
|
87
|
+
file_name = "app/controllers/#{controller_name}_controller.rb"
|
88
|
+
in_current_dir do
|
89
|
+
content = File.read(file_name)
|
90
|
+
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
86
94
|
Given /^I start the rails application$/ do
|
87
95
|
in_current_dir do
|
88
96
|
require "./config/environment"
|
data/features/support/rails.rb
CHANGED
@@ -43,4 +43,16 @@ module RailsCommandHelpers
|
|
43
43
|
framework_version?("3") ? "script/rails runner" : "script/runner"
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
module PaperclipGemHelpers
|
48
|
+
def paperclip_version?(version_string)
|
49
|
+
paperclip_version =~ /^#{version_string}/
|
50
|
+
end
|
51
|
+
|
52
|
+
def paperclip_version
|
53
|
+
@paperclip_version = Gem::Specification.find_by_name('paperclip').version.to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
46
57
|
World(RailsCommandHelpers)
|
58
|
+
World(PaperclipGemHelpers)
|
@@ -89,6 +89,7 @@ module Paperclip
|
|
89
89
|
end
|
90
90
|
@database_table = @options[:database_table] || name.to_s.pluralize
|
91
91
|
@paperclip_file.set_table_name @database_table
|
92
|
+
@paperclip_file.validates_uniqueness_of :style, :scope => instance.class.table_name.classify.underscore + '_id'
|
92
93
|
case Rails::VERSION::STRING
|
93
94
|
when /^2/
|
94
95
|
@paperclip_file.named_scope :file_for, lambda {|style| { :conditions => ['style = ?', style] }}
|
@@ -162,10 +163,9 @@ module Paperclip
|
|
162
163
|
def flush_writes
|
163
164
|
ActiveRecord::Base.logger.info("[paperclip] Writing files for #{name}")
|
164
165
|
@queued_for_write.each do |style, file|
|
165
|
-
paperclip_file = @
|
166
|
+
paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by_style, style.to_s)
|
166
167
|
paperclip_file.file_contents = file.read
|
167
|
-
paperclip_file.
|
168
|
-
instance.send(@paperclip_files) << paperclip_file
|
168
|
+
paperclip_file.save!
|
169
169
|
end
|
170
170
|
@queued_for_write = {}
|
171
171
|
end
|
data/paperclip_database.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip_database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
16
|
-
requirement: &
|
16
|
+
requirement: &17068180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17068180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: appraisal
|
27
|
-
requirement: &
|
27
|
+
requirement: &17067180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.4.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17067180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mocha
|
38
|
-
requirement: &
|
38
|
+
requirement: &17065840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17065840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &17065100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.3.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *17065100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: cucumber
|
60
|
-
requirement: &
|
60
|
+
requirement: &17064220 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.1.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *17064220
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: aruba
|
71
|
-
requirement: &
|
71
|
+
requirement: &17063360 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *17063360
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: capybara
|
82
|
-
requirement: &
|
82
|
+
requirement: &17062760 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *17062760
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: bundler
|
93
|
-
requirement: &
|
93
|
+
requirement: &17062000 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *17062000
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rake
|
104
|
-
requirement: &
|
104
|
+
requirement: &17060980 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *17060980
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: fakeweb
|
115
|
-
requirement: &
|
115
|
+
requirement: &17060500 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *17060500
|
124
124
|
description: ! 'To have all your data i one place: the database'
|
125
125
|
email:
|
126
126
|
- jarl@softace.dk
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- features/support/rails.rb
|
149
149
|
- features/support/selectors.rb
|
150
150
|
- gemfiles/rails2.gemfile
|
151
|
+
- gemfiles/rails2_legacy.gemfile
|
151
152
|
- gemfiles/rails3.gemfile
|
152
153
|
- gemfiles/rails3_1.gemfile
|
153
154
|
- generators/paperclip_database/USAGE
|
@@ -179,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
segments:
|
181
182
|
- 0
|
182
|
-
hash:
|
183
|
+
hash: 2952639071527051601
|
183
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
185
|
none: false
|
185
186
|
requirements:
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
version: '0'
|
189
190
|
segments:
|
190
191
|
- 0
|
191
|
-
hash:
|
192
|
+
hash: 2952639071527051601
|
192
193
|
requirements:
|
193
194
|
- ImageMagick
|
194
195
|
rubyforge_project: paperclip_database
|