paperclip_database 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/features/basic_integration.feature +7 -7
- data/features/step_definitions/rails_steps.rb +0 -27
- data/features/support/rails.rb +3 -11
- data/lib/generators/paperclip_database/migration/templates/migration.rb.erb +5 -2
- data/lib/paperclip/storage/database.rb +4 -9
- data/lib/paperclip_database/version.rb +1 -1
- metadata +4 -8
- data/generators/paperclip_database/USAGE +0 -5
- data/generators/paperclip_database/paperclip_database_generator.rb +0 -28
- data/generators/paperclip_database/templates/paperclip_database_migration.rb.erb +0 -17
- data/generators/templates/paperclip_database_migration.rb.erb +0 -17
@@ -14,21 +14,21 @@ Feature: Rails integration
|
|
14
14
|
"""
|
15
15
|
has_attached_file :avatar,
|
16
16
|
:storage => :database,
|
17
|
-
:
|
18
|
-
:url => '/user_avatar_views/:id?style=:style'
|
17
|
+
:url => '/avatar_views/:id?style=:style'
|
19
18
|
"""
|
20
|
-
And I run a "scaffold" generator to generate a "
|
21
|
-
Given I replace /^ def show$.*?^ end$/ with this snippet in the "
|
19
|
+
And I run a "scaffold" generator to generate a "AvatarView" scaffold with ""
|
20
|
+
Given I replace /^ def show$.*?^ end$/ with this snippet in the "avatar_views" controller:
|
22
21
|
"""
|
23
22
|
def show
|
24
23
|
style = params[:style] ? params[:style] : 'original'
|
25
24
|
record = User.find(params[:id])
|
25
|
+
raise 'Error' unless record.avatar.exists?(style)
|
26
26
|
send_data record.avatar.file_contents(style),
|
27
27
|
:filename => record.avatar_file_name,
|
28
28
|
:type => record.avatar_content_type
|
29
29
|
end
|
30
30
|
"""
|
31
|
-
Given I replace /before_action :
|
31
|
+
Given I replace /before_action :set_avatar_view.*?$/ with this snippet in the "avatar_views" controller:
|
32
32
|
"""
|
33
33
|
"""
|
34
34
|
|
@@ -40,6 +40,6 @@ Feature: Rails integration
|
|
40
40
|
And I attach the file "test/fixtures/5k.png" to "Avatar"
|
41
41
|
And I press "Submit"
|
42
42
|
Then I should see "Name: something"
|
43
|
-
And I should see an image with a path of "/
|
44
|
-
And the file at "/
|
43
|
+
And I should see an image with a path of "/avatar_views/1?style=original"
|
44
|
+
And the file at "/avatar_views/1?style=original" should be the same as "test/fixtures/5k.png"
|
45
45
|
|
@@ -74,9 +74,6 @@ Given /^I run a "(.*?)" generator to add a paperclip "(.*?)" to the "(.*?)" mode
|
|
74
74
|
end
|
75
75
|
|
76
76
|
Given /^I run a "(.*?)" generator to create storage for paperclip "(.*?)" to the "(.*?)" model$/ do |generator_name, attachment_name, model_name|
|
77
|
-
if framework_version?("2")
|
78
|
-
generator_name = rails2_generator_name(generator_name)
|
79
|
-
end
|
80
77
|
step %[I successfully run `bundle exec #{generator_command} #{generator_name} #{model_name} #{attachment_name}`]
|
81
78
|
end
|
82
79
|
|
@@ -146,30 +143,6 @@ When %r{I turn off class caching} do
|
|
146
143
|
end
|
147
144
|
end
|
148
145
|
|
149
|
-
Given /^I update my application to use Bundler$/ do
|
150
|
-
if framework_version?("2")
|
151
|
-
boot_config_template = File.read('features/support/fixtures/boot_config.txt')
|
152
|
-
preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
|
153
|
-
gemfile_template = File.read('features/support/fixtures/gemfile.txt')
|
154
|
-
in_current_dir do
|
155
|
-
content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
|
156
|
-
File.open("config/boot.rb", "w") { |file| file.write(content) }
|
157
|
-
File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
|
158
|
-
File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
|
164
|
-
if framework_version?("2.3")
|
165
|
-
require 'fileutils'
|
166
|
-
source = File.expand_path('lib/tasks/paperclip.rake')
|
167
|
-
destination = in_current_dir { File.expand_path("lib/tasks") }
|
168
|
-
FileUtils.cp source, destination
|
169
|
-
append_to "Rakefile", "require 'paperclip'"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
146
|
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
174
147
|
expected = IO.binread(path)
|
175
148
|
actual = if web_file.match %r{^https?://}
|
data/features/support/rails.rb
CHANGED
@@ -36,24 +36,16 @@ module RailsCommandHelpers
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def new_application_command(app_name)
|
39
|
-
|
39
|
+
"rails new #{app_name} --skip-sprockets --skip-javascript --skip-bundle"
|
40
40
|
end
|
41
41
|
|
42
42
|
def generator_command
|
43
|
-
|
43
|
+
"rails generate"
|
44
44
|
end
|
45
45
|
|
46
46
|
def runner_command
|
47
|
-
|
47
|
+
"rails runner"
|
48
48
|
end
|
49
|
-
|
50
|
-
def rails2_generator_name(rails3_generator_name)
|
51
|
-
case rails3_generator_name
|
52
|
-
when "paperclip_database:migration" then "paperclip_database"
|
53
|
-
else rails3_generator_name
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
49
|
end
|
58
50
|
|
59
51
|
module PaperclipGemHelpers
|
@@ -1,7 +1,10 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
+
<%
|
4
|
+
module_names = class_name.underscore.split('/')[0...-1]
|
5
|
+
-%>
|
3
6
|
<% attachment_names.each do |attachment| -%>
|
4
|
-
create_table :<%=
|
7
|
+
create_table :<%= (module_names +[attachment.pluralize]).join("_") %> do |t|
|
5
8
|
t.integer :<%= class_name.underscore.tr('/', '_') %>_id
|
6
9
|
t.string :style
|
7
10
|
t.binary :file_contents
|
@@ -11,7 +14,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
11
14
|
|
12
15
|
def self.down
|
13
16
|
<% attachment_names.each do |attachment| -%>
|
14
|
-
drop_table :<%=
|
17
|
+
drop_table :<%= (module_names +[attachment.pluralize]).join("_") %>
|
15
18
|
<% end -%>
|
16
19
|
end
|
17
20
|
end
|
@@ -93,12 +93,7 @@ module Paperclip
|
|
93
93
|
@paperclip_file = @paperclip_class_module.const_set(@paperclip_files.classify, Class.new(::ActiveRecord::Base))
|
94
94
|
@paperclip_file.table_name = @options[:database_table] || name.to_s.pluralize
|
95
95
|
@paperclip_file.validates_uniqueness_of :style, :scope => instance.class.table_name.classify.underscore + '_id'
|
96
|
-
|
97
|
-
when /^2/
|
98
|
-
@paperclip_file.named_scope :file_for, lambda {|style| { :conditions => ['style = ?', style] }}
|
99
|
-
else # 3.x
|
100
|
-
@paperclip_file.scope :file_for, lambda {|style| @paperclip_file.where('style = ?', style) }
|
101
|
-
end
|
96
|
+
@paperclip_file.scope :file_for, lambda {|style| @paperclip_file.where('style = ?', style) }
|
102
97
|
else
|
103
98
|
@paperclip_file = @paperclip_class_module.const_get(@paperclip_files.classify)
|
104
99
|
end
|
@@ -136,7 +131,7 @@ module Paperclip
|
|
136
131
|
|
137
132
|
def exists?(style = default_style)
|
138
133
|
if original_filename
|
139
|
-
|
134
|
+
instance.send("#{@paperclip_files}").where(:style => style).exists?
|
140
135
|
else
|
141
136
|
false
|
142
137
|
end
|
@@ -175,11 +170,11 @@ module Paperclip
|
|
175
170
|
ActiveRecord::Base.logger.info("[paperclip] Writing files for #{name}")
|
176
171
|
@queued_for_write.each do |style, file|
|
177
172
|
case Rails::VERSION::STRING
|
178
|
-
when /^
|
173
|
+
when /^3/
|
179
174
|
paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by_style, style.to_s)
|
180
175
|
when /^4/
|
181
176
|
paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by, style: style.to_s)
|
182
|
-
else
|
177
|
+
else
|
183
178
|
raise "Rails version #{Rails::VERSION::STRING} is not supported (yet)"
|
184
179
|
end
|
185
180
|
paperclip_file.file_contents = file.read
|
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: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -250,10 +250,6 @@ files:
|
|
250
250
|
- gemfiles/rails32_paperclip3x.gemfile
|
251
251
|
- gemfiles/rails40_paperclip34.gemfile
|
252
252
|
- gemfiles/rails40_paperclip3x.gemfile
|
253
|
-
- generators/paperclip_database/USAGE
|
254
|
-
- generators/paperclip_database/paperclip_database_generator.rb
|
255
|
-
- generators/paperclip_database/templates/paperclip_database_migration.rb.erb
|
256
|
-
- generators/templates/paperclip_database_migration.rb.erb
|
257
253
|
- lib/generators/paperclip_database/migration/USAGE
|
258
254
|
- lib/generators/paperclip_database/migration/migration_generator.rb
|
259
255
|
- lib/generators/paperclip_database/migration/templates/migration.rb.erb
|
@@ -284,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
284
280
|
version: '0'
|
285
281
|
segments:
|
286
282
|
- 0
|
287
|
-
hash: -
|
283
|
+
hash: -2980498353163651834
|
288
284
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
289
285
|
none: false
|
290
286
|
requirements:
|
@@ -293,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
289
|
version: '0'
|
294
290
|
segments:
|
295
291
|
- 0
|
296
|
-
hash: -
|
292
|
+
hash: -2980498353163651834
|
297
293
|
requirements:
|
298
294
|
- ImageMagick
|
299
295
|
rubyforge_project:
|
@@ -1,28 +0,0 @@
|
|
1
|
-
class PaperclipDatabaseGenerator < Rails::Generator::NamedBase
|
2
|
-
attr_accessor :attachments, :migration_name
|
3
|
-
|
4
|
-
def initialize(args, options = {})
|
5
|
-
super
|
6
|
-
@class_name, @attachments = args[0], args[1..-1]
|
7
|
-
end
|
8
|
-
|
9
|
-
def manifest
|
10
|
-
file_name = generate_file_name
|
11
|
-
@migration_name = file_name.camelize
|
12
|
-
record do |m|
|
13
|
-
m.migration_template "paperclip_database_migration.rb.erb",
|
14
|
-
File.join('db', 'migrate'),
|
15
|
-
:migration_file_name => file_name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def generate_file_name
|
22
|
-
debugger
|
23
|
-
names = attachments.map{|a| "#{class_name.underscore.tr('/', '_')}_#{a.pluralize}" }
|
24
|
-
names = names[0..-2] + ["and", names[-1]] if names.length > 1
|
25
|
-
"create_#{names.join('_')}"
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
<% attachments.each do |attachment| -%>
|
4
|
-
create_table :<%= class_name.underscore.tr('/', '_') %>_<%= attachment.pluralize %> do |t|
|
5
|
-
t.integer :<%= class_name.underscore.tr('/', '_') %>_id
|
6
|
-
t.string :style
|
7
|
-
t.binary :file_contents
|
8
|
-
end
|
9
|
-
<% end -%>
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.down
|
13
|
-
<% attachments.each do |attachment| -%>
|
14
|
-
drop_table :<%= class_name.underscore.tr('/', '_') %>_<%= attachment.pluralize %>
|
15
|
-
<% end -%>
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
<% attachments.each do |attachment| -%>
|
4
|
-
create_table :<%= name.underscore.camelize.tableize.tr('/', '_') %>_<%= attachment.pluralize %> do |t|
|
5
|
-
t.integer :<%= name.underscore.camelize.tableize.tr('/', '_') %>_id
|
6
|
-
t.string :style
|
7
|
-
t.binary :file_contents
|
8
|
-
end
|
9
|
-
end
|
10
|
-
<% end -%>
|
11
|
-
|
12
|
-
def self.down
|
13
|
-
<% attachments.each do |attachment| -%>
|
14
|
-
drop_table :<%= name.underscore.camelize.tableize.tr('/', '_') %>_<%= attachment.pluralize %>
|
15
|
-
<% end -%>
|
16
|
-
end
|
17
|
-
end
|