administrate-field-carrierwave 0.3.0 → 0.3.2

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
2
  SHA256:
3
- metadata.gz: '0785bcefc7b18191135609c7c948db105ed2196fd32b5c174ee4aa22c5ddf474'
4
- data.tar.gz: 73d8f9701de8c05b1eedadf77bebd7fca865763a15591e1220216dc0f440ae72
3
+ metadata.gz: 505ff07bb8b8dc13a7926c9a327bf73068de8564d6fe89b7cc84f5236e7c1bde
4
+ data.tar.gz: 19bc883f883ecdb2f70156c58083f0067fed395259e148b1e000a42a41321223
5
5
  SHA512:
6
- metadata.gz: fe1612084d140a5d5cd047a8279360d08afbb60bd2381b620b16beb24ef87cb9f4e2774640055769aefc627f05cc759adb508162602ff4385e34ee0138e70501
7
- data.tar.gz: 1eab103c7a587e173bed291ce4c7accc0b0849198d35aaeecd80082a213b917eb659c1b7ae305d3bfa8b069e5749083fe6e2071caa2cd65798163a0cb7bddab3
6
+ metadata.gz: 7ffbfa4ac815083b73c806a26089d8f43499a8022a52c2cf3650b844c5f566d7a33514cf4c4b8ba3ec8f4fd3c32cd078d5546076caefcdac6e3cc03d66801180
7
+ data.tar.gz: e11d1584a89a28f1dbffe2030696c9061e426b5c8538e5d18fe377f979c381fc7f80ed2693cf9d32d6b660442aa72fe89545a12d9ba9495a95bee7269191e115
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.3.0](https://github.com/zooppa/administrate-field-carrierwave/tree/v0.2.0) (2018-01-29)
3
+ ## [v0.3.2](https://github.com/zooppa/administrate-field-carrierwave/tree/v0.3.2) (2018-03-06)
4
+
5
+ [Full Changelog](https://github.com/zooppa/administrate-field-carrierwave/compare/v0.3.1...v0.3.2)
6
+
7
+ * Fix bug in view
8
+
9
+ ## [v0.3.1](https://github.com/zooppa/administrate-field-carrierwave/tree/v0.3.1) (2018-03-06)
10
+
11
+ [Full Changelog](https://github.com/zooppa/administrate-field-carrierwave/compare/v0.3.0...v0.3.1)
12
+
13
+ * Fix errors when no uploaded image exists (thanks @evrimfeyyaz)
14
+
15
+ ## [v0.3.0](https://github.com/zooppa/administrate-field-carrierwave/tree/v0.3.0) (2018-01-29)
4
16
 
5
17
  [Full Changelog](https://github.com/zooppa/administrate-field-carrierwave/compare/v0.2.0...v0.3.0)
6
18
 
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2015-2016 Zooppa.com Inc.
3
+ Copyright (c) 2018 Zooppa
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Administrate::Field::Carrierwave
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/zooppa/administrate-field-carrierwave/badges/gpa.svg)](https://codeclimate.com/github/zooppa/administrate-field-carrierwave)
4
+ [![Build Status](https://semaphoreci.com/api/v1/zooppa/administrate-field-carrierwave/branches/master/badge.svg)](https://semaphoreci.com/zooppa/administrate-field-carrierwave)
4
5
 
5
6
  A plugin to upload and preview Carrierwave attachments in [Administrate].
6
7
 
@@ -9,7 +10,7 @@ A plugin to upload and preview Carrierwave attachments in [Administrate].
9
10
  Add it to your `Gemfile`:
10
11
 
11
12
  ```ruby
12
- gem 'administrate-field-carrierwave', '~> 0.3.0'
13
+ gem 'administrate-field-carrierwave', '~> 0.3.2'
13
14
  ```
14
15
 
15
16
  Run:
@@ -51,10 +52,10 @@ end
51
52
 
52
53
  ## About
53
54
 
54
- `Administrate::Field::Carrierwave` is maintained by [z.productions].
55
+ `Administrate::Field::Carrierwave` is maintained by [zooppa].
55
56
 
56
57
  See also the list of [contributors](https://github.com/zooppa/administrate-field-carrierwave/contributors) who participated in this project.
57
58
 
58
59
  [administrate]: https://github.com/thoughtbot/administrate
59
60
  [version]: https://github.com/carrierwaveuploader/carrierwave#adding-versions
60
- [z.productions]: https://www.z.productions/
61
+ [zooppa]: https://www.zooppa.com/
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'administrate-field-carrierwave'
5
- gem.version = '0.3.0'
5
+ gem.version = '0.3.2'
6
6
  gem.authors = ['Michele Gerarduzzi']
7
7
  gem.email = ['michele.gerarduzzi@gmail.com']
8
8
  gem.homepage = 'https://github.com/zooppa/administrate-field-carrierwave'
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_runtime_dependency 'administrate', '< 1.0.0'
18
18
  gem.add_runtime_dependency 'rails', '>= 4.2', '< 6'
19
+
20
+ gem.add_development_dependency 'rake', '~> 12.3'
21
+ gem.add_development_dependency 'rspec', '~> 3.7'
19
22
  end
@@ -22,9 +22,9 @@ for this attribute
22
22
  <span>No file(s) uploaded yet</span>
23
23
  <% end %>
24
24
  <% else %>
25
- <% if field.image.present? && field.data.model.persisted? && field.file.version_exists?(field.image) %>
25
+ <% if field.show_preview? %>
26
26
  <%= render 'fields/carrierwave/preview', file: field.file, field: field %>
27
- <% elsif field.file.present? %>
27
+ <% elsif field.show_file? %>
28
28
  <%= render 'fields/carrierwave/file', file: field.file %>
29
29
  <% else %>
30
30
  -
@@ -7,7 +7,7 @@ module Administrate
7
7
  class Engine < ::Rails::Engine; end
8
8
 
9
9
  def image
10
- options.fetch(:image, nil)
10
+ options.fetch(:image, '')
11
11
  end
12
12
 
13
13
  def image_on_index?
@@ -26,7 +26,6 @@ module Administrate
26
26
  options.fetch(:remote_url, false)
27
27
  end
28
28
 
29
- # One-element array when single file field, array of files when multiple
30
29
  def files
31
30
  Array[*data]
32
31
  end
@@ -34,6 +33,14 @@ module Administrate
34
33
  def file
35
34
  files.first
36
35
  end
36
+
37
+ def show_preview?
38
+ data.model.persisted? && file.version_exists?(image) && data.file.present?
39
+ end
40
+
41
+ def show_file?
42
+ file.present?
43
+ end
37
44
  end
38
45
  end
39
46
  end
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ describe Administrate::Field::Carrierwave do
4
+ subject { Administrate::Field::Carrierwave.new(:field, data, :show) }
5
+ let(:model) { double 'Model', persisted?: true }
6
+ let(:file) { double 'File' }
7
+
8
+ let(:cw_file) { double 'CW with file', model: model, file: file, version_exists?: true }
9
+ let(:cw_no_file) { double 'CW without file', model: model, file: nil, version_exists?: true }
10
+
11
+ let(:data) { cw_file }
12
+ let(:options) { {} }
13
+
14
+ before { allow(subject).to receive(:options).and_return(options) }
15
+
16
+ describe '#to_partial_path' do
17
+ it 'returns a partial based on the page being rendered' do
18
+ path = subject.to_partial_path
19
+ expect(path).to eq('/fields/carrierwave/show')
20
+ end
21
+ end
22
+
23
+ describe '#image' do
24
+ let(:output) { subject.image }
25
+
26
+ context 'with nil' do
27
+ before do
28
+ allow(subject).to receive(:options).and_return(options)
29
+ end
30
+
31
+ it 'returns an empty string' do
32
+ expect(output).to eq ''
33
+ end
34
+ end
35
+
36
+ context 'with a valid option' do
37
+ let(:options) { { image: :standard } }
38
+
39
+ it 'returns the value' do
40
+ expect(output).to eq :standard
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#image_on_index?' do
46
+ let(:output) { subject.image_on_index? }
47
+
48
+ context 'with nil' do
49
+ it 'returns false' do
50
+ expect(output).to be false
51
+ end
52
+ end
53
+
54
+ context 'with a valid option' do
55
+ let(:options) { { image_on_index: true } }
56
+
57
+ it 'returns the value' do
58
+ expect(output).to be true
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#multiple?' do
64
+ let(:output) { subject.multiple? }
65
+
66
+ context 'with nil' do
67
+ it 'returns false' do
68
+ expect(output).to be false
69
+ end
70
+ end
71
+
72
+ context 'with a valid option' do
73
+ let(:options) { { multiple: true } }
74
+
75
+ it 'returns the value' do
76
+ expect(output).to be true
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#remove?' do
82
+ let(:output) { subject.remove? }
83
+
84
+ context 'with nil' do
85
+ it 'returns false' do
86
+ expect(output).to be false
87
+ end
88
+ end
89
+
90
+ context 'with a valid option' do
91
+ let(:options) { { remove: true } }
92
+
93
+ it 'returns the value' do
94
+ expect(output).to be true
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '#remote_url?' do
100
+ let(:output) { subject.remote_url? }
101
+
102
+ context 'with nil' do
103
+ it 'returns false' do
104
+ expect(output).to be false
105
+ end
106
+ end
107
+
108
+ context 'with a valid option' do
109
+ let(:options) { { remote_url: true } }
110
+
111
+ it 'returns the value' do
112
+ expect(output).to be true
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '#files' do
118
+ let(:output) { subject.files }
119
+
120
+ it 'returns an array' do
121
+ expect(output).to be_an(Array)
122
+ end
123
+
124
+ context 'when single file' do
125
+ it 'returns an array with one element' do
126
+ expect(output.length).to eq 1
127
+ end
128
+ end
129
+
130
+ context 'when multiple files' do
131
+ let(:data) { [cw_file, cw_file] }
132
+
133
+ it 'returns a multi-element array' do
134
+ expect(output.length).to eq 2
135
+ end
136
+ end
137
+ end
138
+
139
+ describe '#file' do
140
+ let(:output) { subject.file }
141
+ let(:data) { [cw_file, cw_file] }
142
+
143
+ it 'returns the first file in the array' do
144
+ expect(output).to eq cw_file
145
+ end
146
+ end
147
+
148
+ describe '#show_preview?' do
149
+ let(:output) { subject.show_preview? }
150
+
151
+ context 'when there is an image to show' do
152
+ it 'returns true' do
153
+ expect(output).to be_truthy
154
+ end
155
+ end
156
+
157
+ context 'when there is no image to show' do
158
+ let(:model) { double 'Model', persisted?: false }
159
+
160
+ it 'returns false' do
161
+ expect(output).to be_falsey
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '#show_file?' do
167
+ let(:output) { subject.show_file? }
168
+
169
+ context 'when there is a file to show' do
170
+ it 'returns true' do
171
+ expect(output).to be_truthy
172
+ end
173
+ end
174
+
175
+ context 'when there is no file to show' do
176
+ let(:data) { nil }
177
+
178
+ it 'returns false' do
179
+ expect(output).to be_falsey
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'administrate/field/carrierwave'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michele Gerarduzzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-29 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -44,6 +44,34 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '12.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '12.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.7'
47
75
  description: A plugin to manage Carrierwave attachments in Administrate
48
76
  email:
49
77
  - michele.gerarduzzi@gmail.com
@@ -52,10 +80,12 @@ extensions: []
52
80
  extra_rdoc_files: []
53
81
  files:
54
82
  - ".gitignore"
83
+ - ".rspec"
55
84
  - CHANGELOG.md
56
85
  - Gemfile
57
86
  - LICENSE.md
58
87
  - README.md
88
+ - Rakefile
59
89
  - administrate-field-carrierwave.gemspec
60
90
  - app/views/fields/carrierwave/_file.html.erb
61
91
  - app/views/fields/carrierwave/_form.html.erb
@@ -63,6 +93,8 @@ files:
63
93
  - app/views/fields/carrierwave/_preview.html.erb
64
94
  - app/views/fields/carrierwave/_show.html.erb
65
95
  - lib/administrate/field/carrierwave.rb
96
+ - spec/lib/administrate/field/carrierwave_spec.rb
97
+ - spec/spec_helper.rb
66
98
  homepage: https://github.com/zooppa/administrate-field-carrierwave
67
99
  licenses:
68
100
  - MIT
@@ -83,8 +115,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
115
  version: '0'
84
116
  requirements: []
85
117
  rubyforge_project:
86
- rubygems_version: 2.7.3
118
+ rubygems_version: 2.7.6
87
119
  signing_key:
88
120
  specification_version: 4
89
121
  summary: Carrierwave field plugin for Administrate
90
- test_files: []
122
+ test_files:
123
+ - spec/lib/administrate/field/carrierwave_spec.rb
124
+ - spec/spec_helper.rb