paperclip_database 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.rspec +1 -1
  4. data/.travis.yml +4 -3
  5. data/Appraisals +14 -10
  6. data/README.md +7 -5
  7. data/Rakefile +6 -10
  8. data/features/basic_integration.feature +2 -2
  9. data/features/step_definitions/html_steps.rb +2 -2
  10. data/features/step_definitions/rails_steps.rb +2 -2
  11. data/features/step_definitions/web_steps.rb +4 -98
  12. data/gemfiles/rails30_paperclip23.gemfile +2 -2
  13. data/gemfiles/rails30_paperclip2x.gemfile +2 -2
  14. data/gemfiles/rails30_paperclip30.gemfile +2 -2
  15. data/gemfiles/rails30_paperclip3x.gemfile +2 -2
  16. data/gemfiles/rails31_paperclip23.gemfile +2 -2
  17. data/gemfiles/rails31_paperclip2x.gemfile +2 -2
  18. data/gemfiles/rails31_paperclip30.gemfile +2 -2
  19. data/gemfiles/rails31_paperclip3x.gemfile +2 -2
  20. data/gemfiles/rails32_paperclip23.gemfile +2 -2
  21. data/gemfiles/rails32_paperclip2x.gemfile +2 -2
  22. data/gemfiles/rails32_paperclip30.gemfile +2 -2
  23. data/gemfiles/rails32_paperclip3x.gemfile +2 -2
  24. data/gemfiles/rails32_paperclip40.gemfile +2 -2
  25. data/gemfiles/rails32_paperclip4x.gemfile +2 -2
  26. data/gemfiles/rails40_paperclip42.gemfile +10 -0
  27. data/gemfiles/rails40_paperclip4x.gemfile +4 -3
  28. data/gemfiles/rails41_paperclip42.gemfile +9 -0
  29. data/gemfiles/rails41_paperclip4x.gemfile +9 -0
  30. data/lib/generators/paperclip_database/migration/migration_generator.rb +0 -2
  31. data/lib/paperclip/storage/database.rb +47 -32
  32. data/lib/paperclip_database/version.rb +1 -1
  33. data/lib/paperclip_database.rb +0 -1
  34. data/paperclip_database.gemspec +4 -3
  35. data/{test → spec}/database.yml +0 -0
  36. data/spec/default_options_spec.rb +74 -0
  37. data/{test → spec}/fixtures/5k.png +0 -0
  38. data/spec/major_version_API_spec.rb +85 -0
  39. data/spec/namespaced_models_spec.rb +39 -0
  40. data/spec/single_table_inheritance_spec.rb +39 -0
  41. data/spec/spec_helper.rb +81 -1
  42. metadata +22 -22
  43. data/gemfiles/rails40_paperclip34.gemfile +0 -9
  44. data/gemfiles/rails40_paperclip3x.gemfile +0 -9
  45. data/gemfiles/rails40_paperclip40.gemfile +0 -9
  46. data/lib/paperclip_database/deconstantize.rb +0 -11
  47. data/spec/paperclip_database_spec.rb +0 -7
  48. data/test/namespaced_models_test.rb +0 -54
  49. data/test/test_helper.rb +0 -101
@@ -58,7 +58,9 @@ module Paperclip
58
58
 
59
59
  def self.extended(base)
60
60
  base.instance_eval do
61
- setup_paperclip_files_model
61
+ setup_attachment_class
62
+ setup_paperclip_file_model
63
+ setup_paperclip_files_association
62
64
  override_default_options base
63
65
  end
64
66
  Paperclip.interpolates(:database_path) do |attachment, style|
@@ -79,30 +81,42 @@ module Paperclip
79
81
  ActiveRecord::Base.logger.info("[paperclip] Database Storage Initalized.")
80
82
  end
81
83
 
82
- def setup_paperclip_files_model
83
- # If the model is in a namespace, look up that module
84
- if instance.class.name.include?('::')
85
- module_name = PaperclipDatabase::deconstantize(instance.class.name)
86
- @paperclip_class_module = module_name.constantize rescue Object
87
- else
88
- @paperclip_class_module = Object
89
- end
84
+ def setup_paperclip_files_association
85
+ @paperclip_files_association_name = 'paperclip_files'
86
+ @database_table = @paperclip_file_model.table_name
87
+ #FIXME: This fails when using set_table_name "<myname>" in your model
88
+ #FIXME: This should be fixed in ActiveRecord...
89
+ instance.class.has_many(@paperclip_files_association_name.to_sym,
90
+ :class_name => @paperclip_file_model.name,
91
+ :foreign_key => instance.class.table_name.classify.underscore + '_id'
92
+ )
93
+ end
94
+ private :setup_paperclip_files_association
90
95
 
91
- @paperclip_files = "#{instance.class.name.demodulize.underscore}_#{name.to_s}_paperclip_files"
92
- if !@paperclip_class_module.const_defined?(@paperclip_files.classify)
93
- @paperclip_file = @paperclip_class_module.const_set(@paperclip_files.classify, Class.new(::ActiveRecord::Base))
94
- @paperclip_file.table_name = @options[:database_table] || name.to_s.pluralize
95
- @paperclip_file.validates_uniqueness_of :style, :scope => instance.class.table_name.classify.underscore + '_id'
96
- @paperclip_file.scope :file_for, lambda {|style| @paperclip_file.where('style = ?', style) }
96
+ def setup_paperclip_file_model
97
+ class_name = "#{instance.class.table_name.singularize}_#{name.to_s}_paperclip_file".classify
98
+ if @attachment_class.const_defined?(class_name, false)
99
+ @paperclip_file_model = @attachment_class.const_get(class_name, false)
97
100
  else
98
- @paperclip_file = @paperclip_class_module.const_get(@paperclip_files.classify)
101
+ @paperclip_file_model = @attachment_class.const_set(class_name, Class.new(::ActiveRecord::Base))
102
+ @paperclip_file_model.table_name = @options[:database_table] || name.to_s.pluralize
103
+ @paperclip_file_model.validates_uniqueness_of :style, :scope => instance.class.table_name.classify.underscore + '_id'
104
+ @paperclip_file_model.scope :file_for, lambda {|style| @paperclip_file_model.where('style = ?', style) }
105
+ end
106
+ end
107
+ private :setup_paperclip_file_model
108
+
109
+ def setup_attachment_class
110
+ instance.class.ancestors.each do |ancestor|
111
+ # Pick the top-most definition like
112
+ # Paperclip::AttachmentRegistry#definitions_for
113
+ names_for_ancestor = ancestor.attachment_definitions.keys rescue []
114
+ if names_for_ancestor.member?(name)
115
+ @attachment_class = ancestor
116
+ end
99
117
  end
100
- @database_table = @paperclip_file.table_name
101
- #FIXME: This fails when using set_table_name "<myname>" in your model
102
- #FIXME: This should be fixed in ActiveRecord...
103
- instance.class.has_many @paperclip_files.to_sym, :class_name => @paperclip_file.name, :foreign_key => instance.class.table_name.classify.underscore + '_id'
104
118
  end
105
- private :setup_paperclip_files_model
119
+ private :setup_attachment_class
106
120
 
107
121
  def copy_to_local_file(style, dest_path)
108
122
  File.open(dest_path, 'wb+'){|df| to_file(style).tap{|sf| File.copy_stream(sf, df); sf.close;sf.unlink} }
@@ -131,7 +145,7 @@ module Paperclip
131
145
 
132
146
  def exists?(style = default_style)
133
147
  if original_filename
134
- instance.send("#{@paperclip_files}").where(:style => style).exists?
148
+ instance.send("#{@paperclip_files_association_name}").where(:style => style).exists?
135
149
  else
136
150
  false
137
151
  end
@@ -157,7 +171,7 @@ module Paperclip
157
171
  alias_method :to_io, :to_file
158
172
 
159
173
  def file_for(style)
160
- db_result = instance.send("#{@paperclip_files}").send(:file_for, style.to_s)
174
+ db_result = instance.send("#{@paperclip_files_association_name}").send(:file_for, style.to_s)
161
175
  raise RuntimeError, "More than one result for #{style}" if db_result.size > 1
162
176
  db_result.first
163
177
  end
@@ -169,13 +183,13 @@ module Paperclip
169
183
  def flush_writes
170
184
  ActiveRecord::Base.logger.info("[paperclip] Writing files for #{name}")
171
185
  @queued_for_write.each do |style, file|
172
- case Rails::VERSION::STRING
173
- when /^3/
174
- paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by_style, style.to_s)
175
- when /^4/
176
- paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by, style: style.to_s)
186
+ case ActiveModel::VERSION::MAJOR
187
+ when 3
188
+ paperclip_file = instance.send(@paperclip_files_association_name).send(:find_or_create_by_style, style.to_s)
189
+ when 4
190
+ paperclip_file = instance.send(@paperclip_files_association_name).send(:find_or_create_by, style: style.to_s)
177
191
  else
178
- raise "Rails version #{Rails::VERSION::STRING} is not supported (yet)"
192
+ raise "ActiveModel version #{ActiveModel::VERSION::STRING} is not supported (yet)"
179
193
  end
180
194
  paperclip_file.file_contents = file.read
181
195
  paperclip_file.save!
@@ -190,9 +204,9 @@ module Paperclip
190
204
  @queued_for_delete.each do |path|
191
205
  /id=([0-9]+)/.match(path)
192
206
  if @options[:cascade_deletion] && !instance.class.exists?(instance.id)
193
- raise RuntimeError, "Deletion has not been done by through cascading." if @paperclip_file.exists?($1)
207
+ raise RuntimeError, "Deletion has not been done by through cascading." if @paperclip_file_model.exists?($1)
194
208
  else
195
- @paperclip_file.destroy $1
209
+ @paperclip_file_model.destroy $1
196
210
  end
197
211
  end
198
212
  @queued_for_delete = []
@@ -204,7 +218,8 @@ module Paperclip
204
218
  end
205
219
  def downloads_files_for(model, attachment, options = {})
206
220
  define_method("#{attachment.to_s.pluralize}") do
207
- model_record = Object.const_get(model.to_s.camelize.to_sym).find(params[:id])
221
+ #FIXME: Handling Namespaces
222
+ model_record = Object.const_get(model.to_s.camelize.to_sym, false).find(params[:id])
208
223
  style = params[:style] ? params[:style] : 'original'
209
224
  send_data model_record.send(attachment).file_contents(style),
210
225
  :filename => model_record.send("#{attachment}_file_name".to_sym),
@@ -1,3 +1,3 @@
1
1
  module PaperclipDatabase
2
- VERSION = "2.2.2" unless defined? PaperclipDatabase::VERSION
2
+ VERSION = "2.3.0" unless defined? PaperclipDatabase::VERSION
3
3
  end
@@ -1,4 +1,3 @@
1
1
  require 'paperclip'
2
2
  require 'paperclip/storage/database'
3
3
  require 'paperclip_database/version'
4
- require 'paperclip_database/deconstantize'
@@ -15,16 +15,17 @@ Gem::Specification.new do |s|
15
15
  s.license = 'MIT'
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.requirements << "ImageMagick"
23
23
 
24
- s.add_dependency('rails', '>= 3.0.0')
25
24
  s.add_dependency('paperclip', '>= 2.3.0')
26
25
 
27
- s.add_development_dependency('appraisal', '~> 0.4')
26
+ s.add_development_dependency('rspec', '~> 3.1')
27
+ s.add_development_dependency('appraisal', '~> 1.0')
28
+ # s.add_development_dependency('rails', '>= 3.0.0') # Appraisal
28
29
  s.add_development_dependency('mocha')
29
30
  s.add_development_dependency('sqlite3', '~> 1.3')
30
31
  s.add_development_dependency('cucumber', '~> 1.1')
File without changes
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PaperclipDatabase" do
4
+ describe "default options" do
5
+ before(:context) do
6
+ create_model_tables :users, :avatars
7
+ build_model 'User', nil, :avatar, {}
8
+
9
+ @model = User.new
10
+ file = File.open(fixture_file('5k.png'))
11
+
12
+ @model.avatar = file
13
+ @model.save
14
+
15
+ end
16
+
17
+ after(:context) do
18
+ reset_activerecord
19
+ reset_database :users, :avatars
20
+ end
21
+
22
+ it "has backward compatible table name" do
23
+ expect(@model.avatar.instance_variable_get(:@database_table)).to eq 'avatars'
24
+ end
25
+
26
+ it "has association name" do
27
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
28
+ end
29
+
30
+ it "has model constant" do
31
+ expect(@model.avatar.instance_variable_get(:@paperclip_file_model).to_s).to eq 'User::UserAvatarPaperclipFile'
32
+ end
33
+
34
+ it "has association" do
35
+ expect(@model.methods.include?(:paperclip_files)).to be_truthy
36
+ end
37
+ end
38
+ describe "Namespaced model" do
39
+ describe "default options" do
40
+ before(:context) do
41
+ Object.const_set('Namespace', Module.new())
42
+ create_model_tables :users, :avatars
43
+ build_model 'Namespace::User', nil, :avatar, {}
44
+
45
+ @model = Namespace::User.new
46
+ file = File.open(fixture_file('5k.png'))
47
+
48
+ @model.avatar = file
49
+ @model.save
50
+ end
51
+ after(:context) do
52
+ reset_activerecord
53
+ reset_database :users, :avatars
54
+ Object.send(:remove_const, 'Namespace')
55
+ end
56
+
57
+ it "has backward compatible table name" do
58
+ expect(@model.avatar.instance_variable_get(:@database_table)).to eq 'avatars'
59
+ end
60
+
61
+ it "has association name" do
62
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
63
+ end
64
+
65
+ it "has model constant" do
66
+ expect(@model.avatar.instance_variable_get(:@paperclip_file_model).to_s).to eq 'Namespace::User::UserAvatarPaperclipFile'
67
+ end
68
+
69
+ it "has association" do
70
+ expect(@model.methods.include?(:paperclip_files)).to be_truthy
71
+ end
72
+ end
73
+ end
74
+ end
File without changes
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ ##
4
+ ## named subject 'association' is the SUT
5
+ # args can be
6
+ # [:table_name] The table name
7
+ #
8
+ shared_examples_for "major version API compatible" do |args|
9
+ table_name = args[:table_name]
10
+ describe "Major version compatible with table name '#{table_name}'" do
11
+ it "has table name '#{table_name}'" do
12
+ expect(association.instance_variable_get(:@database_table)).to eq table_name
13
+ end
14
+ end
15
+ end
16
+
17
+ ## named subject 'namespace' is the SUT
18
+ shared_examples_for "model in namespace" do |args|
19
+ describe "with default options" do
20
+ let!(:model_name){"#{namespace}User"}
21
+ let!(:attachment_name){'avatar'}
22
+ it_behaves_like "major version API compatible", :table_name => 'avatars'
23
+ end
24
+ describe "with custom model table_name" do
25
+ let(:model_name){"#{namespace}CUser"}
26
+ let(:model_table_name){'custom_users'}
27
+ let(:attachment_name){'avatar'}
28
+ it_behaves_like "major version API compatible", :table_name => 'avatars'
29
+ end
30
+ describe "with custom attachment table_name" do
31
+ let(:model_name){"#{namespace}AUser"}
32
+ let(:attachment_name){'avatar'}
33
+ let(:attachment_table_name){'custom_avatars'}
34
+ it_behaves_like "major version API compatible", :table_name => 'custom_avatars'
35
+ end
36
+ describe "with custom model table_name and custom attachment table_name" do
37
+ let(:model_name){"#{namespace}SUser"}
38
+ let(:model_table_name){'special_users'}
39
+ let(:attachment_name){'avatar'}
40
+ let(:attachment_table_name){'custom_avatars'}
41
+ it_behaves_like "major version API compatible", :table_name => 'custom_avatars'
42
+ end
43
+ end
44
+
45
+ describe "PaperclipDatabase" do
46
+ describe "backward compatibility" do
47
+ before(:example) do
48
+ @attachment_table_name = defined?(attachment_table_name) ? attachment_table_name : attachment_name.tableize
49
+ extra_paperclip_options = defined?(attachment_table_name)? {:database_table => attachment_table_name.to_sym} : {}
50
+
51
+ build_model model_name, (defined?(model_table_name)? model_table_name: nil), attachment_name.to_sym, extra_paperclip_options
52
+ @model_table_name = model_name.constantize.table_name
53
+ create_model_tables @model_table_name, @attachment_table_name, attachment_name
54
+ @model = model_name.constantize.new
55
+ file = File.open(fixture_file('5k.png'))
56
+
57
+ @model.send(:"#{attachment_name}=",file)
58
+ @model.save
59
+ end
60
+ subject(:association){@model.avatar}
61
+ after(:example) do
62
+ reset_activerecord
63
+ reset_database @model_table_name, @attachment_table_name
64
+ end
65
+
66
+ describe "no namespace" do
67
+ subject(:namespace){''}
68
+ it_behaves_like "model in namespace"
69
+ end
70
+ describe "namespace '::'" do
71
+ subject(:namespace){'::'}
72
+ it_behaves_like "model in namespace"
73
+ end
74
+ describe "namespace 'Object::'" do
75
+ subject(:namespace){'Object::'}
76
+ it_behaves_like "model in namespace"
77
+ end
78
+ describe "namespace 'Namespace::'" do
79
+ before(:context) { Object.const_set('Namespace', Module.new()) }
80
+ after(:context) { Object.send(:remove_const, 'Namespace') }
81
+ subject(:namespace){'Namespace::'}
82
+ it_behaves_like "model in namespace"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PaperclipDatabase" do
4
+ describe "Namespaced model" do
5
+ before(:context) do
6
+ Object.const_set('Namespace', Module.new())
7
+ create_model_tables :namespace_models, :namespace_model_avatars, 'avatar'
8
+ build_model 'Namespace::Model', 'namespace_models', :avatar, {:database_table => :namespace_model_avatars}
9
+
10
+ @model = Namespace::Model.new
11
+ file = File.open(fixture_file('5k.png'))
12
+
13
+ @model.avatar = file
14
+ @model.save
15
+
16
+ end
17
+ after(:context) do
18
+ reset_activerecord
19
+ reset_database :namespace_models, :namespace_model_avatars
20
+ Object.send(:remove_const, 'Namespace')
21
+ end
22
+
23
+ it "has correct association name" do
24
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
25
+ end
26
+
27
+ it "has correct model constant" do
28
+ expect(@model.avatar.instance_variable_get(:@paperclip_file_model).to_s).to eq 'Namespace::Model::NamespaceModelAvatarPaperclipFile'
29
+ end
30
+
31
+ it "has correct table name" do
32
+ expect(@model.avatar.instance_variable_get(:@database_table)).to eq 'namespace_model_avatars'
33
+ end
34
+
35
+ it "has association" do
36
+ expect(@model.methods.include?(:paperclip_files)).to be_truthy
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PaperclipDatabase" do
4
+ describe "Single table inheritance" do
5
+ before(:example) do
6
+ create_model_tables :users, :avatars
7
+ build_model 'User', nil, :avatar, {}
8
+
9
+ Object.const_set('SuperUser', Class.new(User))
10
+
11
+ @model = SuperUser.new
12
+ file = File.open(fixture_file('5k.png'))
13
+
14
+ @model.avatar = file
15
+ @model.save
16
+ end
17
+ after(:example) do
18
+ reset_activerecord
19
+ reset_database :users, :avatars
20
+ Object.send(:remove_const, 'SuperUser')
21
+ end
22
+
23
+ it "has correct association name" do
24
+ expect(@model.avatar.instance_variable_get(:@paperclip_files_association_name)).to eq 'paperclip_files'
25
+ end
26
+
27
+ it "has correct model constant" do
28
+ expect(@model.avatar.instance_variable_get(:@paperclip_file_model).to_s).to eq 'User::UserAvatarPaperclipFile'
29
+ end
30
+
31
+ it "has correct table name" do
32
+ expect(@model.avatar.instance_variable_get(:@database_table)).to eq 'avatars'
33
+ end
34
+
35
+ it "has association" do
36
+ expect(@model.methods.include?(:paperclip_files)).to be_truthy
37
+ end
38
+ end
39
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,91 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'paperclip_database'
5
+ require 'active_record'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+ require 'yaml'
9
+
10
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
11
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
12
+ ActiveRecord::Base.establish_connection(config['test'])
13
+ Paperclip.options[:logger] = ActiveRecord::Base.logger
14
+
5
15
 
6
16
  # Requires supporting files with custom matchers and macros, etc,
7
17
  # in ./support/ and its subdirectories.
8
18
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
19
 
10
20
  RSpec.configure do |config|
11
-
21
+
22
+ end
23
+
24
+ def reset_activerecord
25
+ if Gem::Version.new(::ActiveModel::VERSION::STRING) < Gem::Version.new('3.1.0')
26
+ ActiveRecord::Base.descendants.each do |model|
27
+ model.reset_column_information
28
+ end
29
+ else
30
+ ActiveRecord::Base.clear_cache!
31
+ end
32
+ end
33
+
34
+ def reset_database(*tables)
35
+ tables.each do |table|
36
+ ActiveRecord::Base.connection.drop_table table
37
+ end
38
+ end
39
+
40
+ def create_model_tables(model_table_name, attachment_table_name, association_name = nil)
41
+ association_name ||= attachment_table_name.to_s.singularize
42
+ ActiveRecord::Base.connection.create_table model_table_name, :force => true do |table|
43
+ table.column :"#{association_name}_file_name", :string
44
+ table.column :"#{association_name}_content_type", :string
45
+ table.column :"#{association_name}_file_size", :integer
46
+ table.column :"#{association_name}_updated_at", :datetime
47
+ table.column :"#{association_name}_fingerprint", :string
48
+ end
49
+ single_model = model_table_name.to_s.singularize
50
+ ActiveRecord::Base.connection.create_table attachment_table_name, :force => true do |table|
51
+ table.column :"#{single_model}_id", :integer
52
+ table.column :style, :string
53
+ table.column :file_contents, :binary
54
+ end
55
+ end
56
+
57
+ def build_model(name, table_name, attachment_name, paperclip_options)
58
+ reset_class(name, attachment_name).tap do |klass|
59
+ klass.table_name = table_name if table_name
60
+ klass.has_attached_file attachment_name, {:storage => :database}.merge(paperclip_options)
61
+ klass.validates_attachment_content_type attachment_name, :content_type => /\Aimage\/.*\Z/
62
+ end
63
+ end
64
+
65
+ def reset_class class_name, attachment_name
66
+ if class_name.include? '::'
67
+ module_name = class_name[0...(class_name.rindex('::') || 0)]
68
+ class_module = module_name.constantize rescue Object
69
+ else
70
+ class_module = Object
71
+ end
72
+ class_name = class_name.demodulize
73
+
74
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
75
+ if class_module.const_defined?(class_name)
76
+ old_klass = class_module.const_get(class_name)
77
+ paperclip_class_name = "#{old_klass.table_name.singularize}_#{attachment_name.to_s}_paperclip_file".classify
78
+ class_module.send(:remove_const, paperclip_class_name) rescue nil
79
+ class_module.send(:remove_const, class_name) rescue nil
80
+ end
81
+ klass = class_module.const_set(class_name, Class.new(ActiveRecord::Base))
82
+
83
+ klass.class_eval do
84
+ include Paperclip::Glue
85
+ end
86
+
87
+ klass
88
+ end
89
+
90
+ def fixture_file(filename)
91
+ File.join(File.dirname(__FILE__), 'fixtures', filename)
12
92
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarl Friis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: paperclip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 2.3.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: paperclip
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.0
34
- type: :runtime
33
+ version: '3.1'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.3.0
40
+ version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.4'
47
+ version: '1.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.4'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -225,25 +225,25 @@ files:
225
225
  - gemfiles/rails32_paperclip3x.gemfile
226
226
  - gemfiles/rails32_paperclip40.gemfile
227
227
  - gemfiles/rails32_paperclip4x.gemfile
228
- - gemfiles/rails40_paperclip34.gemfile
229
- - gemfiles/rails40_paperclip3x.gemfile
230
- - gemfiles/rails40_paperclip40.gemfile
228
+ - gemfiles/rails40_paperclip42.gemfile
231
229
  - gemfiles/rails40_paperclip4x.gemfile
230
+ - gemfiles/rails41_paperclip42.gemfile
231
+ - gemfiles/rails41_paperclip4x.gemfile
232
232
  - lib/generators/paperclip_database/migration/USAGE
233
233
  - lib/generators/paperclip_database/migration/migration_generator.rb
234
234
  - lib/generators/paperclip_database/migration/templates/migration.rb.erb
235
235
  - lib/paperclip/storage/database.rb
236
236
  - lib/paperclip_database.rb
237
- - lib/paperclip_database/deconstantize.rb
238
237
  - lib/paperclip_database/version.rb
239
238
  - paperclip_database.gemspec
240
239
  - rails/init.rb
241
- - spec/paperclip_database_spec.rb
240
+ - spec/database.yml
241
+ - spec/default_options_spec.rb
242
+ - spec/fixtures/5k.png
243
+ - spec/major_version_API_spec.rb
244
+ - spec/namespaced_models_spec.rb
245
+ - spec/single_table_inheritance_spec.rb
242
246
  - spec/spec_helper.rb
243
- - test/database.yml
244
- - test/fixtures/5k.png
245
- - test/namespaced_models_test.rb
246
- - test/test_helper.rb
247
247
  homepage: https://github.com/softace/paperclip_database
248
248
  licenses:
249
249
  - MIT
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 4.0.0"
6
- gem "paperclip", "~> 3.4.0"
7
- gem "paperclip_database", :path=>"../"
8
-
9
- gemspec :path=>"../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 4.0.0"
6
- gem "paperclip", "~> 3.0"
7
- gem "paperclip_database", :path=>"../"
8
-
9
- gemspec :path=>"../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 4.0.0"
6
- gem "paperclip", "~> 4.0.0"
7
- gem "paperclip_database", :path=>"../"
8
-
9
- gemspec :path=>"../"
@@ -1,11 +0,0 @@
1
-
2
- module PaperclipDatabase
3
- # This function only appears in Rails >= 3.2.1, so define our own copy here
4
- def self.deconstantize(path)
5
- if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new('3.2.1')
6
- path.deconstantize
7
- else
8
- path.to_s[0...(path.rindex('::') || 0)]
9
- end
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "PaperclipDatabase" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
- end