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
@@ -1,54 +0,0 @@
1
- require File.expand_path("../test_helper", __FILE__)
2
-
3
- module Namespace
4
- end
5
-
6
- class NamespacedModelsTest < Test::Unit::TestCase
7
- def setup
8
- reset_class("Namespace::Model").tap do |klass|
9
- klass.table_name = 'namespace_models'
10
- klass.has_attached_file :avatar, :storage => :database,
11
- :database_table => :namespace_model_avatars
12
- klass.validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
13
- end
14
-
15
- ActiveRecord::Base.connection.create_table :namespace_models, :force => true do |table|
16
- table.column :avatar_file_name, :string
17
- table.column :avatar_content_type, :string
18
- table.column :avatar_file_size, :integer
19
- table.column :avatar_updated_at, :datetime
20
- table.column :avatar_fingerprint, :string
21
- end
22
- ActiveRecord::Base.connection.create_table :namespace_model_avatars, :force => true do |table|
23
- table.column :namespace_model_id, :integer
24
- table.column :style, :string
25
- table.column :file_contents, :binary
26
- end
27
-
28
- @model = Namespace::Model.new
29
- file = File.open(fixture_file('5k.png'))
30
-
31
- @model.avatar = file
32
- @model.save
33
- end
34
-
35
- def test_namespaced_model_detection
36
- assert_equal(Namespace, @model.avatar.instance_variable_get(:@paperclip_class_module))
37
- end
38
-
39
- def test_class_name_inference
40
- assert_equal('model_avatar_paperclip_files', @model.avatar.instance_variable_get(:@paperclip_files))
41
- end
42
-
43
- def test_class_inference
44
- assert_equal(Namespace::ModelAvatarPaperclipFile, @model.avatar.instance_variable_get(:@paperclip_file))
45
- end
46
-
47
- def test_table_name
48
- assert_equal('namespace_model_avatars', @model.avatar.instance_variable_get(:@database_table))
49
- end
50
-
51
- def test_association
52
- assert(@model.methods.include?(:model_avatar_paperclip_files))
53
- end
54
- end
data/test/test_helper.rb DELETED
@@ -1,101 +0,0 @@
1
- require 'rubygems'
2
- require 'tempfile'
3
- require 'pathname'
4
- require 'test/unit'
5
- require 'active_record'
6
- require 'active_record/version'
7
- require 'active_support'
8
- require 'active_support/core_ext'
9
- require 'mocha/setup'
10
- require 'ostruct'
11
- require 'paperclip'
12
-
13
- ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
14
-
15
- module Rails
16
- module RailsVersion
17
- STRING = Gem.loaded_specs['rails'].version.to_s
18
- end
19
- VERSION = RailsVersion
20
-
21
- def root
22
- Pathname.new(ROOT).join('tmp')
23
- end
24
- def env
25
- 'test'
26
- end
27
- end
28
-
29
- $LOAD_PATH << File.join(ROOT, 'lib')
30
- $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
31
- $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip_database')
32
-
33
- require File.join(ROOT, 'lib', 'paperclip_database.rb')
34
-
35
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
36
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
37
- ActiveRecord::Base.establish_connection(config['test'])
38
- Paperclip.options[:logger] = ActiveRecord::Base.logger
39
-
40
- def reset_class class_name
41
- if class_name.include? '::'
42
- module_name = PaperclipDatabase::deconstantize(class_name)
43
- class_module = module_name.constantize rescue Object
44
- else
45
- class_module = Object
46
- end
47
- class_name = class_name.demodulize
48
-
49
- ActiveRecord::Base.send(:include, Paperclip::Glue)
50
- class_module.send(:remove_const, class_name) rescue nil
51
- klass = class_module.const_set(class_name, Class.new(ActiveRecord::Base))
52
-
53
- klass.class_eval do
54
- include Paperclip::Glue
55
- end
56
-
57
- klass.reset_column_information
58
- klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!)
59
- klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache)
60
- klass
61
- end
62
-
63
- def reset_table table_name, &block
64
- block ||= lambda { |table| true }
65
- ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
66
- end
67
-
68
- def modify_table table_name, &block
69
- ActiveRecord::Base.connection.change_table :dummies, &block
70
- end
71
-
72
- def rebuild_model options = {}
73
- ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
74
- table.column :title, :string
75
- table.column :other, :string
76
- table.column :avatar_file_name, :string
77
- table.column :avatar_content_type, :string
78
- table.column :avatar_file_size, :integer
79
- table.column :avatar_updated_at, :datetime
80
- table.column :avatar_fingerprint, :string
81
- end
82
- rebuild_class options
83
- end
84
-
85
- def rebuild_class options = {}
86
- reset_class("Dummy").tap do |klass|
87
- klass.has_attached_file :avatar, options
88
- Paperclip.reset_duplicate_clash_check!
89
- end
90
- end
91
-
92
- def rebuild_meta_class_of obj, options = {}
93
- (class << obj; self; end).tap do |metaklass|
94
- metaklass.has_attached_file :avatar, options
95
- Paperclip.reset_duplicate_clash_check!
96
- end
97
- end
98
-
99
- def fixture_file(filename)
100
- File.join(File.dirname(__FILE__), 'fixtures', filename)
101
- end