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 +4 -4
- data/Gemfile.lock +67 -61
- data/README.md +9 -3
- data/app/controllers/simple_form_attachments/upload_controller.rb +2 -4
- data/app/models/concerns/simple_form_attachments/attachment.rb +4 -4
- data/lib/assets/javascripts/simple_form_attachments/simple_form_attachments.js.coffee +0 -1
- data/lib/simple_form_attachments/version.rb +1 -1
- data/test/controllers/simple_form_attachments/upload_controller_test.rb +8 -2
- data/test/models/concerns/simple_form_attachments/attachment_test.rb +2 -2
- data/test/models/concerns/simple_form_attachments/has_attachments_test.rb +7 -9
- data/test/test_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce1bd3097d0aa3aa18e79ba677d6f9058050d972
|
|
4
|
+
data.tar.gz: 09e01a5273bb2747e5061a74812d6de053da5acc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
17
|
-
actionpack (= 4.2.
|
|
18
|
-
actionview (= 4.2.
|
|
19
|
-
activejob (= 4.2.
|
|
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.
|
|
23
|
-
actionview (= 4.2.
|
|
24
|
-
activesupport (= 4.2.
|
|
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.
|
|
30
|
-
activesupport (= 4.2.
|
|
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.
|
|
36
|
-
activesupport (= 4.2.
|
|
35
|
+
activejob (4.2.5)
|
|
36
|
+
activesupport (= 4.2.5)
|
|
37
37
|
globalid (>= 0.3.0)
|
|
38
|
-
activemodel (4.2.
|
|
39
|
-
activesupport (= 4.2.
|
|
38
|
+
activemodel (4.2.5)
|
|
39
|
+
activesupport (= 4.2.5)
|
|
40
40
|
builder (~> 3.1)
|
|
41
|
-
activerecord (4.2.
|
|
42
|
-
activemodel (= 4.2.
|
|
43
|
-
activesupport (= 4.2.
|
|
41
|
+
activerecord (4.2.5)
|
|
42
|
+
activemodel (= 4.2.5)
|
|
43
|
+
activesupport (= 4.2.5)
|
|
44
44
|
arel (~> 6.0)
|
|
45
|
-
activesupport (4.2.
|
|
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.
|
|
51
|
+
addressable (2.4.0)
|
|
52
52
|
arel (6.0.3)
|
|
53
|
-
bson (3.
|
|
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.
|
|
58
|
+
coveralls (0.8.10)
|
|
58
59
|
json (~> 1.8)
|
|
59
60
|
rest-client (>= 1.6.8, < 2)
|
|
60
|
-
simplecov (~> 0.
|
|
61
|
+
simplecov (~> 0.11.0)
|
|
61
62
|
term-ansicolor (~> 1.3)
|
|
62
63
|
thor (~> 0.19.1)
|
|
63
|
-
|
|
64
|
+
tins (~> 1.6.0)
|
|
65
|
+
database_cleaner (1.5.1)
|
|
64
66
|
docile (1.1.5)
|
|
65
|
-
domain_name (0.5.
|
|
67
|
+
domain_name (0.5.25)
|
|
66
68
|
unf (>= 0.0.5, < 1.0.0)
|
|
67
|
-
dragonfly (1.0.
|
|
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.
|
|
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.
|
|
97
|
+
listen (3.0.5)
|
|
96
98
|
rb-fsevent (>= 0.9.3)
|
|
97
99
|
rb-inotify (>= 0.9)
|
|
98
|
-
loofah (2.0.
|
|
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.
|
|
105
|
-
|
|
106
|
-
minitest (5.
|
|
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.
|
|
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.
|
|
122
|
-
nokogiri (1.6.
|
|
123
|
-
|
|
124
|
-
notiffany (0.0.
|
|
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.
|
|
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.
|
|
137
|
-
actionmailer (= 4.2.
|
|
138
|
-
actionpack (= 4.2.
|
|
139
|
-
actionview (= 4.2.
|
|
140
|
-
activejob (= 4.2.
|
|
141
|
-
activemodel (= 4.2.
|
|
142
|
-
activerecord (= 4.2.
|
|
143
|
-
activesupport (= 4.2.
|
|
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.
|
|
147
|
+
railties (= 4.2.5)
|
|
146
148
|
sprockets-rails
|
|
147
|
-
rails-assets-blueimp-canvas-to-blob (2.2.
|
|
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.
|
|
155
|
-
rails-assets-handlebars (4.0.
|
|
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.
|
|
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.
|
|
166
|
-
actionpack (= 4.2.
|
|
167
|
-
activesupport (= 4.2.
|
|
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.
|
|
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.
|
|
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.
|
|
193
|
+
sprockets (3.5.2)
|
|
194
|
+
concurrent-ruby (~> 1.0)
|
|
192
195
|
rack (> 1, < 3)
|
|
193
|
-
sprockets-rails (
|
|
194
|
-
actionpack (>=
|
|
195
|
-
activesupport (>=
|
|
196
|
-
sprockets (>=
|
|
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.
|
|
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
|
|
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:
|
|
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
|
-
|
|
16
|
-
|
|
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: () ->
|
|
@@ -11,7 +11,7 @@ module SimpleFormAttachments
|
|
|
11
11
|
|
|
12
12
|
let(:params) {
|
|
13
13
|
{
|
|
14
|
-
attachment: {
|
|
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
|
|
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
|
|
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
|
|
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
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.
|
|
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-
|
|
12
|
+
date: 2015-12-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|