carrierwave-serializable 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 82365049a37fc90c0cdf9e0ac27e35a86556c275
4
- data.tar.gz: 30037ac9507ba6cb2551566f3db61353d99361d0
2
+ SHA256:
3
+ metadata.gz: 705005ed9d28d521d499fe829da9b35d085b1fc73a48040b63441a36674b4d60
4
+ data.tar.gz: 96d2e100737e15ca6ec83a37b59eea0c809d2fbcdb0280e5cca56fb1c867358a
5
5
  SHA512:
6
- metadata.gz: d227f799b2f810b6736ad0208e51bde94a499432e8bc5160ad7b3d0a4b756e0bd8166a2a2754063528d4cf8599a1f14b9a380c3b6ceb70ab3970ca128f3c93ee
7
- data.tar.gz: 2345d755b69a02df0ce3255f3a55f5145dd5e979d0b9f8f28531668d9cae68740f86351c971130a3b874c2482c91992236089da24cac1e74e9652d2096d2c175
6
+ metadata.gz: deef3d01ef6cf03e2a8df75578860e0f12b6e9fd1cf2cb028d1287774bdc569689b3af67fcfc6bea5daf60cd1beff06486a7f0668626852440c8088a63c9bfae
7
+ data.tar.gz: 69ec95ecbcc7ebda4e616f3296a21196627e1e7b3a74b866ff3da25bc7095c3238d2d32c1a773455279e99923792cab65725093df248ad90e6c09fb5fb413893
@@ -0,0 +1,23 @@
1
+ name: CI RSpec Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: ['**']
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest]
15
+ ruby: [2.6, 2.7, 3.0, 'head']
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v1
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
23
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ uploads
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in carrierwave-serializable.gemspec
4
4
  gemspec
5
+
6
+ gem 'activerecord'
7
+ gem 'sqlite3'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Tima Maslyuchenko
1
+ Copyright (c) 2013 Tim Masliuchenko
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Carrierwave::Serializable
1
+ # Carrierwave::Serializable ![Build Status](https://github.com/timfjord/carrierwave-serializable/actions/workflows/test.yml/badge.svg)
2
2
 
3
3
  Carrierwave plugin that allow mount uploader to serialized field
4
4
 
@@ -14,13 +14,15 @@ Or install it yourself as:
14
14
 
15
15
  ## Usage
16
16
 
17
- If you need mount uploader to serialized field, set `serialize_to` option
18
- to serialized field where you want to store your uplaoder.
17
+ To mount an uploader to the serialized field, set the `serialize_to` option
18
+ to the serialized field where you want to store the uploader.
19
19
 
20
- class User < ActiveRecord::Base
21
- serialize :documents, Hash
22
- mount_uploader :document1, DocumentUploader, serialize_to: :documents
23
- end
20
+ ```ruby
21
+ class User < ActiveRecord::Base
22
+ serialize :documents, Hash
23
+ mount_uploader :document1, DocumentUploader, serialize_to: :documents
24
+ end
25
+ ```
24
26
 
25
27
  ## Contributing
26
28
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -4,19 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'carrierwave-serializable/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "carrierwave-serializable"
7
+ gem.name = 'carrierwave-serializable'
8
8
  gem.version = CarrierWave::Serializable::VERSION
9
- gem.authors = ["Tima Maslyuchenko"]
10
- gem.email = ["insside@gmail.com"]
9
+ gem.authors = ['Tim Masliuchenko']
10
+ gem.email = ['timfjord@hey.com']
11
11
  gem.description = %q{Carrierwave plugin that allow mount uploader to serialized field}
12
12
  gem.summary = %q{Carrierwave plugin that allow mount uploader to serialized field}
13
- gem.homepage = "https://github.com/timsly/carrierwave-serializable"
13
+ gem.homepage = 'https://github.com/timfjord/carrierwave-serializable'
14
14
  gem.licenses = 'MIT'
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
20
-
19
+ gem.require_paths = ['lib']
20
+
21
21
  gem.add_dependency 'carrierwave'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'rake'
22
25
  end
@@ -1,5 +1,5 @@
1
- require "carrierwave"
2
- require "carrierwave-serializable/version"
3
- require "carrierwave-serializable/orm/activerecord"
1
+ require 'carrierwave'
2
+ require 'carrierwave-serializable/version'
3
+ require 'carrierwave-serializable/orm/activerecord'
4
4
 
5
- ActiveRecord::Base.extend CarrierWave::ActiveRecord::Serializable if defined?(Rails)
5
+ ActiveRecord::Base.extend CarrierWave::ActiveRecord::Serializable if defined?(ActiveRecord)
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "carrierwave/orm/activerecord"
3
+ require 'carrierwave/orm/activerecord'
4
4
 
5
5
  module CarrierWave
6
6
  module ActiveRecord
7
7
  module Serializable
8
8
  def serialized_uploaders
9
- @serialized_uploaders ||= read_from_superclass? ? superclass.serialized_uploaders : {}
9
+ @serialized_uploaders ||= read_from_superclass? ? superclass.serialized_uploaders.dup : {}
10
10
  end
11
11
 
12
12
  def serialized_uploader?(column)
@@ -16,7 +16,7 @@ module CarrierWave
16
16
  ##
17
17
  # See +CarrierWave::Mount#mount_uploader+ for documentation
18
18
  #
19
- def mount_uploader(column, uploader=nil, options={}, &block)
19
+ def mount_uploader(column, uploader = nil, options = {}, &block)
20
20
  super
21
21
 
22
22
  serialize_to = options.delete :serialize_to
@@ -34,7 +34,8 @@ module CarrierWave
34
34
  end
35
35
  RUBY
36
36
  end
37
- class_eval <<-RUBY, __FILE__, __LINE__+1
37
+
38
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
38
39
  def write_uploader(column, identifier)
39
40
  if self.class.serialized_uploader?(column)
40
41
  serialized_field_name = self.class.serialized_uploaders[column].to_s
@@ -42,7 +43,7 @@ module CarrierWave
42
43
  if serialized_field = self.send(serialized_field_name)
43
44
  serialized_field[column.to_s] = identifier
44
45
  else
45
- self.send "\#{serialized_field_name}=", column.to_s => identifier
46
+ self.send("\#{serialized_field_name}=", column.to_s => identifier)
46
47
  end
47
48
  else
48
49
  write_attribute(column, identifier)
@@ -66,6 +67,6 @@ module CarrierWave
66
67
  def read_from_superclass?
67
68
  superclass != ::ActiveRecord::Base && superclass.respond_to?(:serialized_uploaders)
68
69
  end
69
- end # Serializable
70
- end # ActiveRecord
71
- end # CarrierWave
70
+ end
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Serializable
3
- VERSION = '0.0.6'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
Binary file
@@ -0,0 +1,82 @@
1
+ RSpec.describe 'Integration' do
2
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
3
+ ActiveRecord::Migration.verbose = false
4
+
5
+ class TestMigration < ActiveRecord::Migration[4.2]
6
+ def self.up
7
+ create_table :avatars, force: true do |t|
8
+ t.column :image1, :text
9
+ end
10
+
11
+ create_table :images, force: true do |t|
12
+ t.column :data, :text
13
+ end
14
+ end
15
+
16
+ def self.down
17
+ drop_table :avatars
18
+ drop_table :images
19
+ end
20
+ end
21
+
22
+ class ImageUploader < CarrierWave::Uploader::Base; end
23
+
24
+ class ApplicationRecord < ActiveRecord::Base
25
+ self.abstract_class = true
26
+
27
+ mount_uploader :base_image, ImageUploader, serialize_to: :data
28
+ end
29
+
30
+ class Avatar < ApplicationRecord
31
+ mount_uploader :image1, ImageUploader
32
+ end
33
+
34
+ class Image < ApplicationRecord
35
+ serialize :data, Hash
36
+ mount_uploader :image1, ImageUploader, serialize_to: :data
37
+ end
38
+
39
+ before(:all) { TestMigration.up }
40
+ after(:all) { TestMigration.down }
41
+
42
+ after do
43
+ Avatar.destroy_all
44
+ Image.destroy_all
45
+ end
46
+
47
+ let(:image) { Image.new }
48
+
49
+ it 'should mount uploader to serialized field' do
50
+ expect(image.image1).to be_instance_of ImageUploader
51
+ end
52
+
53
+ it 'should upload image and store it to the serialized field' do
54
+ with_image do |file|
55
+ image.image1 = file
56
+ image.save!
57
+
58
+ expect(image.data['image1']).to be_present
59
+ end
60
+ end
61
+
62
+ it 'inherits superclass uploaders' do
63
+ with_image do |file|
64
+ image.base_image = file
65
+ image.save!
66
+
67
+ expect(image.data['base_image']).to be_present
68
+ end
69
+ end
70
+
71
+ describe 'model with the regular uploader and same name as serialized uploader' do
72
+ before do
73
+ Image.new
74
+ end
75
+
76
+ it 'mounts uploader to regular field' do
77
+ avatar = Avatar.new
78
+
79
+ expect(avatar.image1).to be_instance_of ImageUploader
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'carrierwave-serializable'
5
+
6
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
7
+
8
+ RSpec.configure do |config|
9
+ config.include FileHelper
10
+
11
+ config.expect_with :rspec do |expectations|
12
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13
+ end
14
+
15
+ config.mock_with :rspec do |mocks|
16
+ mocks.verify_partial_doubles = true
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module FileHelper
2
+ def with_image(name = 'blank.gif', &block)
3
+ File.open File.expand_path("../../fixtures/#{name}", __FILE__), &block
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-serializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Tima Maslyuchenko
8
- autorequire:
7
+ - Tim Masliuchenko
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -24,14 +24,44 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description: Carrierwave plugin that allow mount uploader to serialized field
28
56
  email:
29
- - insside@gmail.com
57
+ - timfjord@hey.com
30
58
  executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
62
+ - ".github/workflows/test.yml"
34
63
  - ".gitignore"
64
+ - ".rspec"
35
65
  - Gemfile
36
66
  - LICENSE.txt
37
67
  - README.md
@@ -40,11 +70,15 @@ files:
40
70
  - lib/carrierwave-serializable.rb
41
71
  - lib/carrierwave-serializable/orm/activerecord.rb
42
72
  - lib/carrierwave-serializable/version.rb
43
- homepage: https://github.com/timsly/carrierwave-serializable
73
+ - spec/fixtures/blank.gif
74
+ - spec/integration_spec.rb
75
+ - spec/spec_helper.rb
76
+ - spec/support/file_helpder.rb
77
+ homepage: https://github.com/timfjord/carrierwave-serializable
44
78
  licenses:
45
79
  - MIT
46
80
  metadata: {}
47
- post_install_message:
81
+ post_install_message:
48
82
  rdoc_options: []
49
83
  require_paths:
50
84
  - lib
@@ -59,10 +93,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
93
  - !ruby/object:Gem::Version
60
94
  version: '0'
61
95
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.2.2
64
- signing_key:
96
+ rubygems_version: 3.1.4
97
+ signing_key:
65
98
  specification_version: 4
66
99
  summary: Carrierwave plugin that allow mount uploader to serialized field
67
- test_files: []
68
- has_rdoc:
100
+ test_files:
101
+ - spec/fixtures/blank.gif
102
+ - spec/integration_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/file_helpder.rb