simple_form_attachments 0.2.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +118 -113
  5. data/README.md +29 -14
  6. data/app/controllers/simple_form_attachments/upload_controller.rb +3 -1
  7. data/app/models/concerns/simple_form_attachments/attachment.rb +1 -1
  8. data/app/models/concerns/simple_form_attachments/has_attachments.rb +11 -8
  9. data/app/views/layouts/simple_form_attachments/_attachment_layout.html.slim +8 -8
  10. data/app/views/simple_form_attachments/_errors.html.slim +4 -3
  11. data/app/views/simple_form_attachments/attachments/_attachment.hbs.slim +14 -15
  12. data/app/views/simple_form_attachments/attachments/_attachment.html.slim +4 -2
  13. data/config/locales/simple_form_attachments/simple_form_attachments.en.yml +8 -3
  14. data/config/routes.rb +2 -2
  15. data/lib/assets/javascripts/simple_form_attachments/{simple_form_attachments.js.coffee → simple_form_attachments.coffee.erb} +24 -41
  16. data/lib/assets/stylesheets/simple_form_attachments/__attachment.scss.erb +8 -0
  17. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col.scss.erb +1 -0
  18. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__actions.scss.erb +3 -0
  19. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__errors.scss.erb +10 -0
  20. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__fields.scss.erb +4 -0
  21. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__file_info.scss.erb +4 -0
  22. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__handle.scss.erb +6 -0
  23. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__hidden.scss.erb +3 -0
  24. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__progress.scss.erb +14 -0
  25. data/lib/assets/stylesheets/simple_form_attachments/__attachment__col__thumb.scss.erb +9 -0
  26. data/lib/assets/stylesheets/simple_form_attachments/__attachment_list.scss.erb +11 -0
  27. data/lib/assets/stylesheets/simple_form_attachments/__button.scss.erb +9 -0
  28. data/lib/assets/stylesheets/simple_form_attachments/__label.scss.erb +3 -0
  29. data/lib/assets/stylesheets/simple_form_attachments/simple_form_attachments.scss.erb +29 -0
  30. data/lib/assets/stylesheets/simple_form_attachments.css +4 -0
  31. data/lib/simple_form_attachments/attachment_input.rb +12 -11
  32. data/lib/simple_form_attachments/version.rb +1 -1
  33. data/lib/simple_form_attachments.rb +12 -0
  34. data/simple_form_attachments.gemspec +2 -1
  35. data/test/controllers/simple_form_attachments/upload_controller_test.rb +53 -57
  36. data/test/dummy/Gemfile +1 -0
  37. data/test/dummy/Gemfile.lock +80 -74
  38. data/test/dummy/app/assets/stylesheets/application.css +5 -0
  39. data/test/dummy/app/models/attachment_image.rb +1 -0
  40. data/test/dummy/app/views/simple_form_attachments/attachment_images/_attachment_image.html.slim +12 -9
  41. data/test/dummy/config/environments/test.rb +2 -2
  42. data/test/dummy/config/mongoid.yml +5 -8
  43. data/test/dummy/config/routes.rb +1 -3
  44. data/test/simple_form_attachments_test.rb +30 -0
  45. data/test/test_helper.rb +5 -1
  46. metadata +46 -16
  47. data/test/dummy/app/assets/stylesheets/application.css.scss +0 -5
  48. data/test/dummy/app/assets/stylesheets/tests.scss +0 -233
@@ -1,33 +1,20 @@
1
1
  # https://github.com/zenorocha/jquery-boilerplate
2
2
  (($, window) ->
3
-
4
- # ---------------------------------------------------------------------
5
-
6
3
  pluginName = 'simple_form_attachments'
7
4
  document = window.document
8
5
 
9
6
  defaults =
10
7
  debug: false
11
8
  sortable_options:
12
- handle: '.handle'
9
+ handle: '.<%= SimpleFormAttachments.dom_class(:attachment, :col, :handle) %>'
13
10
  axis: 'y'
14
- items: '> tr'
11
+ items: '> .<%= SimpleFormAttachments.dom_class(:attachment) %>'
15
12
  forcePlaceholderSize: true
16
- placeholder: 'attachment-placeholder'
13
+ placeholder: '<%= SimpleFormAttachments.dom_class(:attachment, :placeholder) %>'
17
14
  containment: 'parent'
18
- start: (event, ui) ->
19
- cellCount = 0
20
- $('td, th', ui.helper).each ->
21
- colspan = 1
22
- colspanAttr = $(this).attr('colspan')
23
- if colspanAttr > 1 then colspan = colspanAttr
24
- cellCount += colspan
25
- ui.placeholder.html '<td colspan="#{cellCount}">&nbsp;</td>'
26
15
 
27
16
  slide_speed: 'fast'
28
17
 
29
- # ---------------------------------------------------------------------
30
-
31
18
  class Plugin
32
19
  constructor: (@element, options) ->
33
20
  @options = $.extend {}, defaults, options
@@ -46,7 +33,7 @@
46
33
  @init_fileupload()
47
34
 
48
35
  init_sortable: () ->
49
- @get_attachment_list().find('tbody').sortable(@options.sortable_options)#.disableSelection()
36
+ @get_attachment_list().sortable(@options.sortable_options)#.disableSelection()
50
37
 
51
38
  init_fileupload: () ->
52
39
  console.log "init jQuery.fileupload" if @options.debug
@@ -75,7 +62,7 @@
75
62
 
76
63
  add: (e, data) =>
77
64
  @set_logs(e, data) if @options.debug
78
- @get_attachment_list().find('tr').remove() unless @is_multiple()
65
+ @get_attachment_list().find('.<%= SimpleFormAttachments.dom_class(:attachment) %>').remove() unless @is_multiple()
79
66
 
80
67
  for file in data.files
81
68
  properties = {
@@ -85,7 +72,7 @@
85
72
  thumb_url: URL.createObjectURL(file)
86
73
  }
87
74
  result = $.extend({}, file, properties)
88
- $template = @get_attachment_template(result).addClass('uploading')
75
+ $template = @get_attachment_template(result).addClass('<%= SimpleFormAttachments.dom_class(:attachment, :is_uploading) %>')
89
76
  data.context = $template
90
77
  $template.data('data', data)
91
78
  @get_attachment_list().append($template)
@@ -94,43 +81,44 @@
94
81
 
95
82
  fail: (e, data) =>
96
83
  @set_logs(e, data) if @options.debug
97
- $result = $(JSON.parse(data.jqXHR.responseText).html).addClass('has_error')
98
- $result.find('td.errors').attr('colspan', '3');
99
- data.context.replaceWith($result)
84
+ if !!data.jqXHR.responseText
85
+ $result = $(JSON.parse(data.jqXHR.responseText).html).addClass('<%= SimpleFormAttachments.dom_class(:attachment, :has_error) %>')
86
+ $result.find('.<%= SimpleFormAttachments.dom_class(:attachment, :col, :errors) %>');
87
+ data.context.replaceWith($result)
100
88
 
101
89
  progress: (e, data) =>
102
90
  @set_logs(e, data) if @options.debug
103
91
  progress = parseInt(data.loaded / data.total * 100, 10)
104
- data.context.find('.progress.bar').width(progress+'%')
92
+ data.context.find('.<%= SimpleFormAttachments.dom_class(:attachment, :col, :progress, :bar) %>').width(progress+'%')
105
93
 
106
94
  done: (e, data) =>
107
95
  @set_logs(e, data) if @options.debug
108
96
  console.log data.result.html if @options.debug
109
- $result = $(data.result.html).addClass('uploaded')
110
- data.context.replaceWith $result
97
+ $result = $(data.result.html).addClass('<%= SimpleFormAttachments.dom_class(:attachment, :is_uploaded) %>')
98
+ data.context.replaceWith($result)
111
99
 
112
100
  stop: (e, data) =>
113
101
  @set_logs(e, data) if @options.debug
114
102
  @enable_form_submit()
115
103
 
116
- @$element.on 'click', 'button.delete, button.close', (e) =>
104
+ @$element.on 'click', '.<%= SimpleFormAttachments.dom_class(:button, :delete) %>, .<%= SimpleFormAttachments.dom_class(:button, :close) %>', (e) =>
117
105
  e.preventDefault()
118
106
  e.stopPropagation()
119
- $template = $(e.currentTarget).closest('tr')
107
+ $template = $(e.currentTarget).closest('.<%= SimpleFormAttachments.dom_class(:attachment) %>')
120
108
  @remove_template($template)
121
109
 
122
- @$element.on 'click', 'button.cancel', (e) =>
110
+ @$element.on 'click', '.<%= SimpleFormAttachments.dom_class(:button, :cancel) %>', (e) =>
123
111
  e.preventDefault()
124
112
  e.stopPropagation()
125
- $template = $(e.currentTarget).closest('tr')
113
+ $template = $(e.currentTarget).closest('.<%= SimpleFormAttachments.dom_class(:attachment) %>')
126
114
  data = $template.data('data') || {}
127
115
  @enable_form_submit()
128
116
 
129
- if !data.jqXHR
117
+ if !!data.jqXHR
118
+ data.jqXHR.abort()
119
+ else
130
120
  data.errorThrown = 'abort'
131
121
  e.data.fileupload._trigger('fail', e, data)
132
- else
133
- data.jqXHR.abort()
134
122
 
135
123
  @remove_template($template)
136
124
 
@@ -148,14 +136,14 @@
148
136
 
149
137
  # ---------------------------------------------------------------------
150
138
 
151
- get_attachment_list: -> @$element.find('table.attachments.list')
139
+ get_attachment_list: -> @$element.find('.<%= SimpleFormAttachments.dom_class(:attachment_list) %>')
152
140
  get_attachments_path: -> @$element.data('attachments-path')
153
141
  get_disabled_submit_text: -> @$element.data('disabled-submit-text')
154
142
  get_file_input: -> @$element.find('input.file')
155
143
  get_form: -> @$element.parents('form').first()
156
144
  get_form_submit: -> @get_form().find('input[type="submit"]').first()
157
145
  get_max_number_of_files: -> @$element.data('max-number-of-files')
158
- get_number_of_files: -> @get_attachment_list().children('tr').not('.has_error').length
146
+ get_number_of_files: -> @get_attachment_list().children('.<%= SimpleFormAttachments.dom_class(:attachment) %>').not('.<%= SimpleFormAttachments.dom_class(:attachment, :has_error) %>').length
159
147
 
160
148
  get_attachment_type_input: -> @$element.find('input[name="attachment_type"]')
161
149
  get_attachment_multiple_input: -> @$element.find('input[name="attachment[multiple]"]')
@@ -172,7 +160,7 @@
172
160
  get_kb_from_bytes: (bytes) -> parseInt(parseInt(bytes)/1024)
173
161
 
174
162
  get_attachment_template: (file) =>
175
- template = Handlebars.compile(@$element.find('script#attachment_template').html())
163
+ template = Handlebars.compile(@$element.find('script#simple_form_attachments__template').html())
176
164
  $(template(file))
177
165
 
178
166
  # ---------------------------------------------------------------------
@@ -200,7 +188,7 @@
200
188
  # ---------------------------------------------------------------------
201
189
 
202
190
  is_multiple: -> @get_file_input().attr('multiple') != undefined
203
- is_sortable: -> @get_attachment_list().hasClass('sortable')
191
+ is_sortable: -> @get_attachment_list().hasClass('<%= SimpleFormAttachments.dom_class(:attachment_list, :is_sortable) %>')
204
192
 
205
193
  # ---------------------------------------------------------------------
206
194
 
@@ -208,11 +196,6 @@
208
196
  @each ->
209
197
  if !$.data(this, "plugin_#{pluginName}")
210
198
  $.data(@, "plugin_#{pluginName}", new Plugin(@, options))
211
-
212
- # ---------------------------------------------------------------------
213
-
214
199
  )(jQuery, window)
215
200
 
216
- # =====================================================================
217
-
218
201
  $ -> $('div.simple_form_attachments').simple_form_attachments()
@@ -0,0 +1,8 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment) %> {
2
+ display: flex;
3
+ flex-direction: row;
4
+ }
5
+
6
+ .<%= SimpleFormAttachments.dom_class(:attachment, :has_error) %> {
7
+ color: red;
8
+ }
@@ -0,0 +1 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col) %> {}
@@ -0,0 +1,3 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :actions) %> {
2
+ flex: 0 0 auto;
3
+ }
@@ -0,0 +1,10 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :errors) %> {
2
+ flex: 1 1 auto;
3
+ width: 100%;
4
+
5
+ > ul {
6
+ list-style: none;
7
+ margin: 0;
8
+ padding: 0;
9
+ }
10
+ }
@@ -0,0 +1,4 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :fields) %> {
2
+ flex: 1 1 auto;
3
+ width: 100%;
4
+ }
@@ -0,0 +1,4 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :file_info) %> {
2
+ flex: 1 1 auto;
3
+ width: 100%;
4
+ }
@@ -0,0 +1,6 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :handle) %> {
2
+ background: gray;
3
+ cursor: move;
4
+ flex: 0 0 auto;
5
+ width: 1em;
6
+ }
@@ -0,0 +1,3 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :hidden) %> {
2
+ display: none;
3
+ }
@@ -0,0 +1,14 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :progress) %> {
2
+ flex: 1 1 auto;
3
+ width: 100%;
4
+ }
5
+
6
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :progress, :container) %> {
7
+ width: 100%;
8
+ }
9
+
10
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :progress, :bar) %> {
11
+ height: 1em;
12
+ background-color: blue;
13
+ width: 0;
14
+ }
@@ -0,0 +1,9 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :thumb) %> {
2
+ flex: 0 0 auto;
3
+ width: 20%;
4
+
5
+ img {
6
+ display: block;
7
+ object-fit: contain;
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ .<%= SimpleFormAttachments.dom_class(:attachment_list) %> {
2
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :handle) %> {
3
+ display: none;
4
+ }
5
+ }
6
+
7
+ .<%= SimpleFormAttachments.dom_class(:attachment_list, :is_sortable) %> {
8
+ .<%= SimpleFormAttachments.dom_class(:attachment, :col, :handle) %> {
9
+ display: block;
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ .<%= SimpleFormAttachments.dom_class(:button) %> {
2
+ white-space: nowrap;
3
+ }
4
+
5
+ .<%= SimpleFormAttachments.dom_class(:button, :cancel) %>,
6
+ .<%= SimpleFormAttachments.dom_class(:button, :close) %>,
7
+ .<%= SimpleFormAttachments.dom_class(:button, :delete) %> {
8
+ color: red;
9
+ }
@@ -0,0 +1,3 @@
1
+ .<%= SimpleFormAttachments.dom_class(:label, :choose_file) %> {
2
+ // custom upload label
3
+ }
@@ -0,0 +1,29 @@
1
+ .<%= SimpleFormAttachments.dom_class %> {
2
+ input[type="file"] {
3
+ margin: 0;
4
+ padding: 0;
5
+
6
+ // hide so that the label can be styled
7
+ width: .1px;
8
+ height: .1px;
9
+ opacity: 0;
10
+ overflow: hidden;
11
+ position: absolute;
12
+ z-index: -1;
13
+
14
+ label {
15
+ display: inline-block;
16
+ vertical-align: bottom;
17
+ }
18
+ }
19
+
20
+ label[for="attachment_file"] {
21
+ .<%= SimpleFormAttachments.dom_class(:attachment, :button) %> {
22
+ display: none;
23
+ }
24
+ }
25
+
26
+ &.dragover {
27
+ background-color: yellow;
28
+ }
29
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_tree .
3
+ *= require_self
4
+ */
@@ -37,18 +37,18 @@ module SimpleFormAttachments
37
37
  private # =============================================================
38
38
 
39
39
  def input_html_options
40
- super.merge!(
40
+ super.merge(
41
41
  data: {
42
42
  attachments_path: options.fetch(:route, route_from_configuration),
43
43
  max_number_of_files: options.fetch(:max_number_of_files, nil),
44
44
  disabled_submit_text: I18n.t(:disabled, scope: 'simple_form_attachments.buttons'),
45
- sortable: sortable?.to_s
46
- }
45
+ sortable: sortable?
46
+ }.reject{ |k, v| v.nil? }
47
47
  )
48
48
  end
49
49
 
50
50
  def input_html_classes
51
- super.push('simple_form_attachments')
51
+ super.push(SimpleFormAttachments.dom_class)
52
52
  end
53
53
 
54
54
  # ---------------------------------------------------------------------
@@ -189,7 +189,8 @@ module SimpleFormAttachments
189
189
  class: 'file'
190
190
  }
191
191
  template.label_tag('attachment[file]') do
192
- template.file_field_tag('attachment[file]', input_html_options)
192
+ template.file_field_tag('attachment[file]', input_html_options) +
193
+ template.content_tag(:span, I18n.t(:choose_file, scope: 'simple_form_attachments.links', count: (multiple? ? 2 : 1)), class: SimpleFormAttachments.dom_class(:label, [:choose_file]))
193
194
  end
194
195
  end
195
196
 
@@ -228,12 +229,12 @@ module SimpleFormAttachments
228
229
  # ---------------------------------------------------------------------
229
230
 
230
231
  def attachment_list
231
- table_classes = %w(attachments list)
232
- table_classes << 'sortable' if sortable?
233
- template.content_tag :table, class: table_classes do
232
+ container_classes = [SimpleFormAttachments.dom_class(:attachment_list)]
233
+ container_classes << SimpleFormAttachments.dom_class(:attachment_list, :is_sortable) if sortable?
234
+ template.content_tag :div, class: container_classes do
234
235
  @builder.simple_fields_for attribute_name do |attachment_fields|
235
236
  template.render(
236
- partial: "simple_form_attachments/#{attachment_fields.object.to_partial_path}", format: :html, layout: 'layouts/simple_form_attachments/attachment_layout',
237
+ partial: File.join('simple_form_attachments', attachment_fields.object.to_partial_path), format: :html, layout: File.join('layouts', 'simple_form_attachments', 'attachment_layout'),
237
238
  locals: {
238
239
  attachment: attachment_fields.object,
239
240
  fields: attachment_fields,
@@ -249,8 +250,8 @@ module SimpleFormAttachments
249
250
  # ---------------------------------------------------------------------
250
251
 
251
252
  def handlebars_js_template
252
- template.content_tag :script, id: 'attachment_template', type: 'text/html' do
253
- template.render('simple_form_attachments/attachments/attachment.hbs.slim')
253
+ template.content_tag :script, id: 'simple_form_attachments__template', type: 'text/html' do
254
+ template.render(File.join('simple_form_attachments', 'attachments', 'attachment.hbs.slim'))
254
255
  end
255
256
  end
256
257
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormAttachments
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -14,6 +14,18 @@ require "i18n"
14
14
 
15
15
  # ---------------------------------------------------------------------
16
16
 
17
+ module SimpleFormAttachments
18
+ def self.dom_class(*args)
19
+ prefix, alts = args.partition { |i| !i.is_a?(Array) }
20
+ prefix = ['simple_form_attachments'] + prefix
21
+ return prefix.compact.join('__') if alts.empty?
22
+ alts.flatten.map do |item|
23
+ prefix += [item]
24
+ prefix.compact.join('__')
25
+ end
26
+ end
27
+ end
28
+
17
29
  module SimpleForm
18
30
  class FormBuilder
19
31
  map_type :attachment, to: SimpleFormAttachments::AttachmentInput
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  # ---------------------------------------------------------------------
21
21
 
22
22
  spec.add_dependency 'rails', '>= 4.2'
23
+ spec.add_dependency 'mongoid', '> 4.0'
23
24
  spec.add_dependency 'simple_form', '>= 3.0.2'
24
25
 
25
26
  spec.add_dependency 'slim'
@@ -38,6 +39,6 @@ Gem::Specification.new do |spec|
38
39
  spec.add_development_dependency 'minitest', '~> 5.0'
39
40
  spec.add_development_dependency 'minitest-rails'
40
41
  spec.add_development_dependency 'dragonfly'
42
+ spec.add_development_dependency 'rails-controller-testing'
41
43
  spec.add_development_dependency 'rake', '~> 10.0'
42
- spec.add_development_dependency 'mongoid', '~> 4.0'
43
44
  end
@@ -1,76 +1,72 @@
1
1
  require 'test_helper'
2
2
 
3
- require_relative '../../../app/controllers/simple_form_attachments/upload_controller'
3
+ describe SimpleFormAttachments::UploadController do
4
+ before do
5
+ @routes = SimpleFormAttachments::Engine.routes
6
+ end
4
7
 
5
- module SimpleFormAttachments
6
- describe UploadController do
7
- setup do
8
- @routes = SimpleFormAttachments::Engine.routes
9
- end
8
+ let(:count) { AttachmentTest.count }
10
9
 
11
- let(:count) { AttachmentTest.count }
10
+ # ---------------------------------------------------------------------
12
11
 
13
- # ---------------------------------------------------------------------
12
+ describe '#create' do
13
+ let(:params) do
14
+ {
15
+ attachment: { body: 'foo' },
16
+ attachment_parent: { class: 'Parent' },
17
+ attachment_relation: { name: 'attachments', multiple: true },
18
+ attachment_type: 'AttachmentTest'
19
+ }
20
+ end
21
+ let(:action) { post :create, params: params }
14
22
 
15
- describe '#create' do
16
- let(:params) do
17
- {
18
- attachment: { body: 'foo' },
19
- attachment_parent: { class: 'Parent' },
20
- attachment_relation: { name: 'attachments', multiple: true },
21
- attachment_type: 'AttachmentTest'
22
- }
23
- end
24
- let(:action) { post :create, params }
23
+ it 'should succeed' do
24
+ action
25
+ must_respond_with :success
26
+ end
25
27
 
26
- it 'should succeed' do
27
- action
28
- must_respond_with :success
29
- end
28
+ it 'should create attachment of specified model' do
29
+ assert_difference('AttachmentTest.count') { action }
30
+ end
30
31
 
31
- it 'should create attachment of specified model' do
32
- assert_difference('AttachmentTest.count') { action }
33
- end
32
+ it 'must mark the newly upladed attachment as temporary' do
33
+ action
34
+ assigns(:attachment).must_be :present?
35
+ assigns(:attachment).body.must_equal 'foo'
36
+ assigns(:attachment).temporary.must_equal true
37
+ end
34
38
 
35
- it 'must mark the newly upladed attachment as temporary' do
39
+ describe 'returned JSON' do
40
+ it 'should contain template with correct locals' do
36
41
  action
37
- assigns(:attachment).must_be :present?
38
- assigns(:attachment).body.must_equal 'foo'
39
- assigns(:attachment).temporary.must_equal true
40
- end
41
-
42
- describe 'returned JSON' do
43
- it 'should contain template with correct locals' do
44
- action
45
- assert_template 'simple_form_attachments/_attachment_upload_template', locals: { multiple: true, parent_class: params[:attachment_parent][:class].constantize }
46
- end
42
+ assert_template 'simple_form_attachments/_attachment_upload_template', locals: { multiple: true, parent_class: params[:attachment_parent][:class].constantize }
47
43
  end
48
44
  end
45
+ end
49
46
 
50
- # ---------------------------------------------------------------------
47
+ # ---------------------------------------------------------------------
51
48
 
52
- describe '#show' do
53
- let(:attachment) { AttachmentTest.create! }
54
- let(:params) do
55
- {
56
- id: attachment.id.to_s,
57
- attachment_parent: { class: 'Parent' },
58
- attachment_relation: { name: 'attachments', multiple: true },
59
- attachment_type: 'AttachmentTest'
60
- }
61
- end
62
- let(:action) { get :show, params }
49
+ describe '#show' do
50
+ let(:attachment) { AttachmentTest.create! }
51
+ let(:params) do
52
+ {
53
+ id: attachment.id.to_s,
54
+ attachment_parent: { class: 'Parent' },
55
+ attachment_relation: { name: 'attachments', multiple: true },
56
+ attachment_type: 'AttachmentTest'
57
+ }
58
+ end
59
+ let(:action) { get :show, params: params }
63
60
 
64
- it 'should succeed' do
65
- action
66
- must_respond_with :success
67
- end
61
+ it 'should succeed' do
62
+ action
63
+ must_respond_with :success
64
+ end
68
65
 
69
- describe 'returned JSON' do
70
- it 'should contain template with correct locals' do
71
- action
72
- assert_template 'simple_form_attachments/_attachment_upload_template', locals: { multiple: true, parent_class: params[:attachment_parent][:class].constantize }
73
- end
66
+ describe 'returned JSON' do
67
+ it 'should contain template with correct locals' do
68
+ action
69
+ assert_template 'simple_form_attachments/_attachment_upload_template', locals: { multiple: true, parent_class: params[:attachment_parent][:class].constantize }
74
70
  end
75
71
  end
76
72
  end
data/test/dummy/Gemfile CHANGED
@@ -17,6 +17,7 @@ gem 'dragonfly-mongoid_data_store'
17
17
  gem 'simple_form_attachments', path: '../../../simple_form_attachments'
18
18
 
19
19
  group :development, :test do
20
+ gem 'rb-readline'
20
21
  gem 'byebug'
21
22
  gem 'web-console', '~> 2.0'
22
23
  gem 'spring'