simple_form_attachments 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2258db71defc38e2818791f75ebbb8df6a8b9a7f
4
- data.tar.gz: be8694a80360a84c54b3e345073b66fe29eebfd3
3
+ metadata.gz: ce1bd3097d0aa3aa18e79ba677d6f9058050d972
4
+ data.tar.gz: 09e01a5273bb2747e5061a74812d6de053da5acc
5
5
  SHA512:
6
- metadata.gz: 677708881bad666a8c65256c421e7896f516d7dad25a969f96dd1c145d7bc4a1cc8639189a2dcdb05d0b00208189cc93b4ddc96532d630276388cbaeb4246d23
7
- data.tar.gz: 9b68dcc3467b94a9c104473d24b71d426e416d2e0ff8263d1d30005694eac958c538146bda49d984e212f31f20b62d2973463ce0f5cacbca271ee03a8109652b
6
+ metadata.gz: 039f6e3c511157ed6dffce2ca266143272224679d41f1198102923da0f1f97393b6027247d1db8ebe81104e99f4d5cdfd04173d58e59413b5cd6dd4347f14c09
7
+ data.tar.gz: 55fa16f575026d174766a15512762e3f60b6074a6ef94238a2ae97fabf3da3bfa814b5b8d85f6d79fd5b95a7a452ef57a4f67f288dc430823a76ef6ab6216b57
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_attachments (0.1.5)
4
+ simple_form_attachments (0.2.0)
5
5
  jquery-ui-rails
6
6
  rails (>= 4.2)
7
7
  rails-assets-blueimp-file-upload (>= 9.6.0)
@@ -13,58 +13,60 @@ GEM
13
13
  remote: https://rubygems.org/
14
14
  remote: https://rails-assets.org/
15
15
  specs:
16
- actionmailer (4.2.3)
17
- actionpack (= 4.2.3)
18
- actionview (= 4.2.3)
19
- activejob (= 4.2.3)
16
+ actionmailer (4.2.5)
17
+ actionpack (= 4.2.5)
18
+ actionview (= 4.2.5)
19
+ activejob (= 4.2.5)
20
20
  mail (~> 2.5, >= 2.5.4)
21
21
  rails-dom-testing (~> 1.0, >= 1.0.5)
22
- actionpack (4.2.3)
23
- actionview (= 4.2.3)
24
- activesupport (= 4.2.3)
22
+ actionpack (4.2.5)
23
+ actionview (= 4.2.5)
24
+ activesupport (= 4.2.5)
25
25
  rack (~> 1.6)
26
26
  rack-test (~> 0.6.2)
27
27
  rails-dom-testing (~> 1.0, >= 1.0.5)
28
28
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (4.2.3)
30
- activesupport (= 4.2.3)
29
+ actionview (4.2.5)
30
+ activesupport (= 4.2.5)
31
31
  builder (~> 3.1)
32
32
  erubis (~> 2.7.0)
33
33
  rails-dom-testing (~> 1.0, >= 1.0.5)
34
34
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
35
- activejob (4.2.3)
36
- activesupport (= 4.2.3)
35
+ activejob (4.2.5)
36
+ activesupport (= 4.2.5)
37
37
  globalid (>= 0.3.0)
38
- activemodel (4.2.3)
39
- activesupport (= 4.2.3)
38
+ activemodel (4.2.5)
39
+ activesupport (= 4.2.5)
40
40
  builder (~> 3.1)
41
- activerecord (4.2.3)
42
- activemodel (= 4.2.3)
43
- activesupport (= 4.2.3)
41
+ activerecord (4.2.5)
42
+ activemodel (= 4.2.5)
43
+ activesupport (= 4.2.5)
44
44
  arel (~> 6.0)
45
- activesupport (4.2.3)
45
+ activesupport (4.2.5)
46
46
  i18n (~> 0.7)
47
47
  json (~> 1.7, >= 1.7.7)
48
48
  minitest (~> 5.1)
49
49
  thread_safe (~> 0.3, >= 0.3.4)
50
50
  tzinfo (~> 1.1)
51
- addressable (2.3.8)
51
+ addressable (2.4.0)
52
52
  arel (6.0.3)
53
- bson (3.1.2)
53
+ bson (3.2.6)
54
54
  builder (3.2.2)
55
55
  coderay (1.1.0)
56
+ concurrent-ruby (1.0.0)
56
57
  connection_pool (2.2.0)
57
- coveralls (0.8.2)
58
+ coveralls (0.8.10)
58
59
  json (~> 1.8)
59
60
  rest-client (>= 1.6.8, < 2)
60
- simplecov (~> 0.10.0)
61
+ simplecov (~> 0.11.0)
61
62
  term-ansicolor (~> 1.3)
62
63
  thor (~> 0.19.1)
63
- database_cleaner (1.4.1)
64
+ tins (~> 1.6.0)
65
+ database_cleaner (1.5.1)
64
66
  docile (1.1.5)
65
- domain_name (0.5.24)
67
+ domain_name (0.5.25)
66
68
  unf (>= 0.0.5, < 1.0.0)
67
- dragonfly (1.0.10)
69
+ dragonfly (1.0.12)
68
70
  addressable (~> 2.3)
69
71
  multi_json (~> 1.0)
70
72
  rack (>= 1.3.0)
@@ -73,7 +75,7 @@ GEM
73
75
  formatador (0.2.5)
74
76
  globalid (0.3.6)
75
77
  activesupport (>= 4.1.0)
76
- guard (2.12.8)
78
+ guard (2.13.0)
77
79
  formatador (>= 0.2.4)
78
80
  listen (>= 2.7, <= 4.0)
79
81
  lumberjack (~> 1.0)
@@ -92,18 +94,18 @@ GEM
92
94
  jquery-ui-rails (5.0.5)
93
95
  railties (>= 3.2.16)
94
96
  json (1.8.3)
95
- listen (3.0.2)
97
+ listen (3.0.5)
96
98
  rb-fsevent (>= 0.9.3)
97
99
  rb-inotify (>= 0.9)
98
- loofah (2.0.2)
100
+ loofah (2.0.3)
99
101
  nokogiri (>= 1.5.9)
100
102
  lumberjack (1.0.9)
101
103
  mail (2.6.3)
102
104
  mime-types (>= 1.16, < 3)
103
105
  method_source (0.8.2)
104
- mime-types (2.6.1)
105
- mini_portile (0.6.2)
106
- minitest (5.7.0)
106
+ mime-types (2.99)
107
+ mini_portile2 (2.0.0)
108
+ minitest (5.8.3)
107
109
  minitest-rails (2.2.0)
108
110
  minitest (~> 5.7)
109
111
  railties (~> 4.1)
@@ -112,63 +114,63 @@ GEM
112
114
  moped (~> 2.0.0)
113
115
  origin (~> 2.1)
114
116
  tzinfo (>= 0.3.37)
115
- moped (2.0.6)
117
+ moped (2.0.7)
116
118
  bson (~> 3.0)
117
119
  connection_pool (~> 2.0)
118
120
  optionable (~> 0.2.0)
119
121
  multi_json (1.11.2)
120
122
  nenv (0.2.0)
121
- netrc (0.10.3)
122
- nokogiri (1.6.6.2)
123
- mini_portile (~> 0.6.0)
124
- notiffany (0.0.6)
123
+ netrc (0.11.0)
124
+ nokogiri (1.6.7.1)
125
+ mini_portile2 (~> 2.0.0.rc2)
126
+ notiffany (0.0.8)
125
127
  nenv (~> 0.1)
126
128
  shellany (~> 0.0)
127
129
  optionable (0.2.0)
128
130
  origin (2.1.1)
129
- pry (0.10.1)
131
+ pry (0.10.3)
130
132
  coderay (~> 1.1.0)
131
133
  method_source (~> 0.8.1)
132
134
  slop (~> 3.4)
133
135
  rack (1.6.4)
134
136
  rack-test (0.6.3)
135
137
  rack (>= 1.0)
136
- rails (4.2.3)
137
- actionmailer (= 4.2.3)
138
- actionpack (= 4.2.3)
139
- actionview (= 4.2.3)
140
- activejob (= 4.2.3)
141
- activemodel (= 4.2.3)
142
- activerecord (= 4.2.3)
143
- activesupport (= 4.2.3)
138
+ rails (4.2.5)
139
+ actionmailer (= 4.2.5)
140
+ actionpack (= 4.2.5)
141
+ actionview (= 4.2.5)
142
+ activejob (= 4.2.5)
143
+ activemodel (= 4.2.5)
144
+ activerecord (= 4.2.5)
145
+ activesupport (= 4.2.5)
144
146
  bundler (>= 1.3.0, < 2.0)
145
- railties (= 4.2.3)
147
+ railties (= 4.2.5)
146
148
  sprockets-rails
147
- rails-assets-blueimp-canvas-to-blob (2.2.0)
149
+ rails-assets-blueimp-canvas-to-blob (2.2.4)
148
150
  rails-assets-blueimp-file-upload (9.11.2)
149
151
  rails-assets-blueimp-canvas-to-blob (>= 2.1.1)
150
152
  rails-assets-blueimp-load-image (>= 1.13.0)
151
153
  rails-assets-blueimp-tmpl (>= 2.5.4)
152
154
  rails-assets-jquery (>= 1.6)
153
155
  rails-assets-blueimp-load-image (1.14.0)
154
- rails-assets-blueimp-tmpl (2.5.5)
155
- rails-assets-handlebars (4.0.3)
156
+ rails-assets-blueimp-tmpl (2.5.7)
157
+ rails-assets-handlebars (4.0.5)
156
158
  rails-assets-jquery (2.1.4)
157
159
  rails-deprecated_sanitizer (1.0.3)
158
160
  activesupport (>= 4.2.0.alpha)
159
- rails-dom-testing (1.0.6)
161
+ rails-dom-testing (1.0.7)
160
162
  activesupport (>= 4.2.0.beta, < 5.0)
161
163
  nokogiri (~> 1.6.0)
162
164
  rails-deprecated_sanitizer (>= 1.0.1)
163
165
  rails-html-sanitizer (1.0.2)
164
166
  loofah (~> 2.0)
165
- railties (4.2.3)
166
- actionpack (= 4.2.3)
167
- activesupport (= 4.2.3)
167
+ railties (4.2.5)
168
+ actionpack (= 4.2.5)
169
+ activesupport (= 4.2.5)
168
170
  rake (>= 0.8.7)
169
171
  thor (>= 0.18.1, < 2.0)
170
172
  rake (10.4.2)
171
- rb-fsevent (0.9.5)
173
+ rb-fsevent (0.9.6)
172
174
  rb-inotify (0.9.5)
173
175
  ffi (>= 0.5.0)
174
176
  rest-client (1.8.0)
@@ -179,7 +181,7 @@ GEM
179
181
  simple_form (3.2.0)
180
182
  actionpack (~> 4.0)
181
183
  activemodel (~> 4.0)
182
- simplecov (0.10.0)
184
+ simplecov (0.11.1)
183
185
  docile (~> 1.1.0)
184
186
  json (~> 1.8)
185
187
  simplecov-html (~> 0.10.0)
@@ -188,19 +190,20 @@ GEM
188
190
  temple (~> 0.7.3)
189
191
  tilt (>= 1.3.3, < 2.1)
190
192
  slop (3.6.0)
191
- sprockets (3.4.0)
193
+ sprockets (3.5.2)
194
+ concurrent-ruby (~> 1.0)
192
195
  rack (> 1, < 3)
193
- sprockets-rails (2.3.3)
194
- actionpack (>= 3.0)
195
- activesupport (>= 3.0)
196
- sprockets (>= 2.8, < 4.0)
196
+ sprockets-rails (3.0.0)
197
+ actionpack (>= 4.0)
198
+ activesupport (>= 4.0)
199
+ sprockets (>= 3.0.0)
197
200
  temple (0.7.6)
198
201
  term-ansicolor (1.3.2)
199
202
  tins (~> 1.0)
200
203
  thor (0.19.1)
201
204
  thread_safe (0.3.5)
202
205
  tilt (2.0.1)
203
- tins (1.5.4)
206
+ tins (1.6.0)
204
207
  tzinfo (1.2.2)
205
208
  thread_safe (~> 0.1)
206
209
  unf (0.1.4)
@@ -221,3 +224,6 @@ DEPENDENCIES
221
224
  mongoid (~> 4.0)
222
225
  rake
223
226
  simple_form_attachments!
227
+
228
+ BUNDLED WITH
229
+ 1.10.6
data/README.md CHANGED
@@ -38,7 +38,7 @@ class AttachmentImage
38
38
  end
39
39
  ```
40
40
 
41
- This adds a `:temporary` Boolean field and two scopes: `temporary` and `permanent` to the model.
41
+ This adds a `:temporary` Boolean field (set to `false` by default) and two scopes: `temporary` and `permanent` to the model.
42
42
 
43
43
  Note that the concern does not include any specific accessors (ie Dragonfly). You need to define those yourself in your model.
44
44
 
@@ -66,7 +66,7 @@ You could use for example the `before_save` callback to embed the attachments yo
66
66
 
67
67
  #### Callbacks
68
68
 
69
- Since attachments can be added/removed dynamically in the form, we need to indicate which ones are actually submitted in the end, so that we can – immediately or later – delete the temporary ones.
69
+ Since attachments can be added/removed dynamically in the form, we need to indicate which ones are actually submitted in the end, so that we can – immediately or later (left up to you) – delete the temporary ones.
70
70
 
71
71
  For that each relation defines a method named after the relation name, which can be called for example via a callback:
72
72
 
@@ -77,7 +77,7 @@ after_save :mark_attachment_images_permanent
77
77
 
78
78
  These methods (atomically) set the attachment's `:temporary` attribute to `false`.
79
79
 
80
- Alternatively the `mark_all_attachments_permanent` method can be used to loop through all attachment relations, triggering individual abovementioned methods. This means the two `after_save` callbacks above can be replaced with:
80
+ Alternatively the `mark_all_attachments_permanent` method can be used to loop through all attachment relations, triggering individual above-mentioned methods. This means the two `after_save` callbacks above can be replaced with:
81
81
 
82
82
  ```ruby
83
83
  after_save :mark_all_attachments_permanent
@@ -91,6 +91,12 @@ If you want to validate the number of attachments allowed on the owner, you can
91
91
  validates :attachment_pdfs, length: { maximum: 2 }
92
92
  ```
93
93
 
94
+ ### Controller
95
+
96
+ The default `UploadController` receives the uploaded attachment, sets its `temporary` to `true` and creates corresponding record in the database.
97
+
98
+ Remember, you need to mark attachments as permanent (ie `temporary` to `false`) yourself. See Callbacks above.
99
+
94
100
  ### Routes
95
101
 
96
102
  Mount the engine in your routes:
@@ -1,6 +1,5 @@
1
1
  module SimpleFormAttachments
2
2
  class UploadController < ActionController::Base
3
-
4
3
  def create
5
4
  res = attachment.save
6
5
  render json: attachment_json, status: (res ? :ok : :unprocessable_entity)
@@ -9,7 +8,7 @@ module SimpleFormAttachments
9
8
  private # =============================================================
10
9
 
11
10
  def attachment
12
- @attachment ||= attachment_class.new attachment_params
11
+ @attachment ||= attachment_class.new({ temporary: true }.merge(attachment_params))
13
12
  end
14
13
 
15
14
  def attachment_json
@@ -52,7 +51,7 @@ module SimpleFormAttachments
52
51
  def parent
53
52
  return unless params[:attachment_relation]
54
53
  if multiple? && attachment.errors.empty?
55
- parent_class.new{ |o| o.send(params.fetch(:attachment_relation).fetch(:name).to_sym) << attachment }
54
+ parent_class.new { |o| o.send(params.fetch(:attachment_relation).fetch(:name).to_sym) << attachment }
56
55
  else
57
56
  parent_class.new
58
57
  end
@@ -71,6 +70,5 @@ module SimpleFormAttachments
71
70
  def referenced?
72
71
  ['true', true, '1', 1].include? params.fetch(:attachment_relation, {}).fetch(:referenced, false)
73
72
  end
74
-
75
73
  end
76
74
  end
@@ -7,14 +7,14 @@ module SimpleFormAttachments
7
7
  included do
8
8
  include Mongoid::Document
9
9
 
10
- field :temporary, type: Boolean, default: true
10
+ field :temporary, type: Boolean, default: false
11
11
 
12
12
  scope :temporary, -> { where(temporary: true) }
13
13
  scope :permanent, -> { where(temporary: false) }
14
+ end
14
15
 
15
- def to_simple_form_partial_path
16
- ['simple_form_attachments', to_partial_path].join('/')
17
- end
16
+ def to_simple_form_partial_path
17
+ ['simple_form_attachments', to_partial_path].join('/')
18
18
  end
19
19
  end
20
20
  end
@@ -45,7 +45,6 @@
45
45
  @init_fileupload()
46
46
 
47
47
  init_sortable: () ->
48
- @get_attachment_list().add( @get_attachment_list().find('th, td') ).each -> $(this).outerWidth $(this).outerWidth()
49
48
  @get_attachment_list().find('tbody').sortable(@options.sortable_options).disableSelection()
50
49
 
51
50
  init_fileupload: () ->
@@ -1,3 +1,3 @@
1
1
  module SimpleFormAttachments
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -11,7 +11,7 @@ module SimpleFormAttachments
11
11
 
12
12
  let(:params) {
13
13
  {
14
- attachment: { temporary: true },
14
+ attachment: { body: 'foo' },
15
15
  attachment_parent: { class: 'Parent' },
16
16
  attachment_relation: { name: 'attachments', multiple: true },
17
17
  attachment_type: "Attachment"
@@ -23,7 +23,6 @@ module SimpleFormAttachments
23
23
  # ---------------------------------------------------------------------
24
24
 
25
25
  describe '#create' do
26
-
27
26
  it 'should succeed' do
28
27
  action
29
28
  must_respond_with :success
@@ -35,6 +34,13 @@ module SimpleFormAttachments
35
34
  end
36
35
  end
37
36
 
37
+ it 'must mark the newly upladed attachment as temporary' do
38
+ action
39
+ assigns(:attachment).must_be :present?
40
+ assigns(:attachment).body.must_equal 'foo'
41
+ assigns(:attachment).temporary.must_equal true
42
+ end
43
+
38
44
  describe 'returned JSON' do
39
45
  it 'should contain template with correct locals' do
40
46
  action
@@ -2,8 +2,8 @@ require 'test_helper'
2
2
  require_relative '../../../../app/models/concerns/simple_form_attachments/attachment'
3
3
 
4
4
  describe Attachment do
5
- let(:temporary_attachment) { Attachment.new }
6
- let(:permanent_attachment) { Attachment.new(temporary: false) }
5
+ let(:temporary_attachment) { Attachment.new(temporary: true) }
6
+ let(:permanent_attachment) { Attachment.new }
7
7
 
8
8
  before do
9
9
  temporary_attachment.save
@@ -2,15 +2,14 @@ require 'test_helper'
2
2
  require_relative '../../../../app/models/concerns/simple_form_attachments/has_attachments'
3
3
 
4
4
  describe Parent do
5
-
6
5
  let(:parent) { Parent.new }
7
6
 
8
7
  let(:attachment_reflection) { parent.reflect_on_association(:attachment) }
9
8
  let(:attachments_reflection) { parent.reflect_on_association(:attachments) }
10
9
 
11
- let(:related_attachment_one) { Attachment.create }
12
- let(:related_attachment_two) { Attachment.create }
13
- let(:unrelated_attachment) { Attachment.create }
10
+ let(:related_attachment_one) { Attachment.create(temporary: true) }
11
+ let(:related_attachment_two) { Attachment.create(temporary: true) }
12
+ let(:unrelated_attachment) { Attachment.create(temporary: true) }
14
13
 
15
14
  # ---------------------------------------------------------------------
16
15
 
@@ -26,7 +25,7 @@ describe Parent do
26
25
  end
27
26
 
28
27
  it 'respects definition of :class_name' do
29
- attachments_reflection.class_name.must_equal "Attachment"
28
+ attachments_reflection.class_name.must_equal 'Attachment'
30
29
  end
31
30
 
32
31
  it 'passes the :dependent option to the relation' do
@@ -34,12 +33,12 @@ describe Parent do
34
33
  end
35
34
 
36
35
  it 'returns attachments in same order as in which its ids have been stored' do
37
- parent.attachments.sorted.must_equal parent.attachments.sort_by{ |a| parent.attachment_ids.index(a.id) }
36
+ parent.attachments.sorted.must_equal parent.attachments.sort_by { |a| parent.attachment_ids.index(a.id) }
38
37
  end
39
38
 
40
39
  it 'returns attachments in the same order as attachment_ids' do
41
40
  parent.attachment_ids = [related_attachment_one.id, related_attachment_two.id]
42
- parent.attachments.sorted.must_equal parent.attachments.sort_by{ |a| parent.attachment_ids.index(a.id) }
41
+ parent.attachments.sorted.must_equal parent.attachments.sort_by { |a| parent.attachment_ids.index(a.id) }
43
42
  end
44
43
  end
45
44
 
@@ -50,7 +49,7 @@ describe Parent do
50
49
  parent.must_respond_to :attachment
51
50
  end
52
51
  it 'respects definition of :class_name' do
53
- attachment_reflection.class_name.must_equal "Attachment"
52
+ attachment_reflection.class_name.must_equal 'Attachment'
54
53
  end
55
54
  it 'passes the :dependent option to the relation' do
56
55
  attachments_reflection.dependent.must_equal :destroy
@@ -111,5 +110,4 @@ describe Parent do
111
110
  end
112
111
 
113
112
  # ---------------------------------------------------------------------
114
-
115
113
  end
data/test/test_helper.rb CHANGED
@@ -54,6 +54,7 @@ end
54
54
 
55
55
  class Attachment
56
56
  include SimpleFormAttachments::Attachment
57
+ field :body, type: String
57
58
  end
58
59
 
59
60
  class Parent
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_attachments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-15 00:00:00.000000000 Z
12
+ date: 2015-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails