brightcontent-attachments 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightcontent-attachments (2.0.9)
5
- brightcontent-core (= 2.0.9)
4
+ brightcontent-attachments (2.0.10)
5
+ brightcontent-core (= 2.0.10)
6
6
  jquery-fileupload-rails
7
7
  paperclip
8
8
 
9
9
  PATH
10
10
  remote: ../core
11
11
  specs:
12
- brightcontent-core (2.0.9)
12
+ brightcontent-core (2.0.10)
13
13
  bcrypt-ruby
14
14
  bootstrap-wysihtml5-rails
15
15
  has_scope
@@ -11,11 +11,16 @@ module Brightcontent
11
11
  def create
12
12
  @attachment = Attachment.new(params.slice(:attachable_id, :attachable_type, :asset))
13
13
  if @attachment.save
14
- render json: @attachments.to_json, status: :created
14
+ render json: @attachment.to_json, status: :created
15
15
  else
16
- render json: @attachments.errors, status: :unprocessable_entity
16
+ render json: @attachment.errors, status: :unprocessable_entity
17
17
  end
18
18
  end
19
19
 
20
+ def destroy
21
+ attachment = Attachment.destroy(params[:id])
22
+ redirect_to attachment.attachable
23
+ end
24
+
20
25
  end
21
26
  end
@@ -0,0 +1,4 @@
1
+ <%= div_for attachment do %>
2
+ <%= image_tag attachment.url(:brightcontent) %>
3
+ <%= link_to "Delete", destroy_attachment_path(attachment.id), method: :delete, confirm: "Are you sure?", class: "btn btn-danger btn-mini" %>
4
+ <% end %>
@@ -1,3 +1 @@
1
- <% @attachments.each do |attachment| %>
2
- <%= image_tag attachment.url(:brightcontent) %>
3
- <% end %>
1
+ <%= render @attachments %>
@@ -2,10 +2,8 @@
2
2
  <label class="optional control-label">Attachments</label>
3
3
  <div class="controls">
4
4
  <% if item.persisted? %>
5
- <div id="attachments">
6
- <% item.attachments.each do |attachment| %>
7
- <%= image_tag attachment.url(:brightcontent) %>
8
- <% end %>
5
+ <div id="attachments" class="clearfix">
6
+ <%= render item.attachments %>
9
7
  </div>
10
8
 
11
9
  <input id="fileupload" type="file" name="asset" data-url="<%= new_attachment_path %>" multiple>
data/config/routes.rb CHANGED
@@ -2,4 +2,5 @@ Brightcontent::Engine.routes.draw do
2
2
  # TODO: put instead of create
3
3
  get 'attachments/:type/:id' => 'attachments#show', as: :attachments
4
4
  put 'attachments' => 'attachments#create', as: :new_attachment
5
+ delete 'attachments/:id' => 'attachments#destroy', as: :destroy_attachment
5
6
  end
Binary file
@@ -1,18 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Attachments" do
4
- it "show message if item is not saved" do
4
+ background do
5
5
  sign_in
6
+ end
7
+
8
+ scenario "show message if item is not saved" do
6
9
  click_link "Blogs"
7
10
  click_link "Create new Blog"
8
11
  page.should have_content "First save to enable uploads"
9
12
  end
10
13
 
11
- it "show upload form" do
14
+ scenario "show upload form" do
12
15
  create(:blog)
13
- sign_in
14
16
  click_link "Blogs"
15
17
  click_link "Edit"
16
18
  page.should have_selector "#attachments"
17
19
  end
20
+
21
+ context "with image" do
22
+ background do
23
+ blog = create(:blog)
24
+ @attachment = Brightcontent::Attachment.create!(:asset => Rails.root.join("public/rails.png").open)
25
+ blog.attachments << @attachment
26
+ click_link "Blogs"
27
+ click_link "Edit"
28
+ end
29
+
30
+ scenario "shows images" do
31
+ page.should have_selector "#attachment_#{@attachment.id}"
32
+ end
33
+
34
+ scenario "delete image" do
35
+ within "#attachment_#{@attachment.id}" do
36
+ click_link "Delete"
37
+ end
38
+ page.should_not have_selector "#attachment_#{@attachment.id}"
39
+ end
40
+ end
18
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcontent-attachments
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.9
21
+ version: 2.0.10
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 2.0.9
29
+ version: 2.0.10
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: paperclip
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +154,7 @@ files:
154
154
  - app/controllers/brightcontent/attachments_controller.rb
155
155
  - app/helpers/brightcontent/attachments_helper.rb
156
156
  - app/models/brightcontent/attachment.rb
157
+ - app/views/brightcontent/attachments/_attachment.html.erb
157
158
  - app/views/brightcontent/attachments/show.html.erb
158
159
  - app/views/brightcontent/base/_form_field_attachments.html.erb
159
160
  - brightcontent-attachments.gemspec
@@ -203,6 +204,7 @@ files:
203
204
  - spec/dummy/public/422.html
204
205
  - spec/dummy/public/500.html
205
206
  - spec/dummy/public/favicon.ico
207
+ - spec/dummy/public/rails.png
206
208
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/001/original/icon-socialmedia.png
207
209
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/002/original/bg_direction_nav.png
208
210
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/003/original/icon-android.png
@@ -236,7 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
238
  version: '0'
237
239
  segments:
238
240
  - 0
239
- hash: -2508442452034506775
241
+ hash: 1632068659845575571
240
242
  required_rubygems_version: !ruby/object:Gem::Requirement
241
243
  none: false
242
244
  requirements:
@@ -245,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
247
  version: '0'
246
248
  segments:
247
249
  - 0
248
- hash: -2508442452034506775
250
+ hash: 1632068659845575571
249
251
  requirements: []
250
252
  rubyforge_project:
251
253
  rubygems_version: 1.8.24
@@ -291,6 +293,7 @@ test_files:
291
293
  - spec/dummy/public/422.html
292
294
  - spec/dummy/public/500.html
293
295
  - spec/dummy/public/favicon.ico
296
+ - spec/dummy/public/rails.png
294
297
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/001/original/icon-socialmedia.png
295
298
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/002/original/bg_direction_nav.png
296
299
  - spec/dummy/public/system/brightcontent/assets/assets/000/000/003/original/icon-android.png