tb_media 1.2.2 → 1.3.beta1
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/Rakefile +2 -2
- data/app/controllers/admin/media_controller.rb +57 -61
- data/app/controllers/admin/media_picker_controller.rb +9 -9
- data/app/controllers/protected_media_controller.rb +7 -7
- data/app/helpers/protected_media_helper.rb +1 -1
- data/app/models/spud_media.rb +61 -67
- data/lib/spud_media/configuration.rb +3 -3
- data/lib/spud_media/content_types.rb +2 -2
- data/lib/spud_media/engine.rb +17 -17
- data/lib/spud_media/version.rb +3 -3
- data/lib/tasks/spud_media_tasks.rake +4 -6
- data/spec/controllers/admin/media_controller_spec.rb +24 -24
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -7
- data/spec/dummy/config/environments/test.rb +3 -5
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20130904141442_create_spud_users.tb_core.rb +12 -12
- data/spec/dummy/db/migrate/20130904141443_add_time_zone_to_spud_user.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20130904141444_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
- data/spec/dummy/db/migrate/20130904141446_create_spud_media.tb_media.rb +1 -1
- data/spec/dummy/db/migrate/20130904141447_add_protected_to_spud_media.tb_media.rb +1 -1
- data/spec/dummy/db/migrate/20130904141448_add_cropping_to_spud_media.tb_media.rb +3 -3
- data/spec/dummy/db/migrate/20151012194531_create_spud_permissions.tb_core.rb +3 -3
- data/spec/dummy/db/migrate/20151012194532_create_spud_role_permissions.tb_core.rb +2 -2
- data/spec/dummy/db/migrate/20151012194534_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
- data/spec/dummy/db/schema.rb +63 -67
- data/spec/dummy/public/system/spud_media/1/cropped/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/1/small/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/2/cropped/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/2/small/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/3/cropped/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/3/small/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/4/cropped/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/4/small/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/5/cropped/test_img1.png +0 -0
- data/spec/dummy/public/system/spud_media/5/small/test_img1.png +0 -0
- data/spec/dummy/script/rails +2 -2
- data/spec/javascripts/support/jasmine_helper.rb +6 -7
- data/spec/models/spud_media_spec.rb +2 -2
- data/spec/rails_helper.rb +13 -6
- data/spec/spec_helper.rb +42 -44
- metadata +51 -49
- data/spec/dummy/public/system/spud_media/1/cropped/test_img1.jpg +0 -0
- data/spec/dummy/public/system/spud_media/2/cropped/test_img1.jpg +0 -0
- data/spec/dummy/public/system/spud_media/3/cropped/test_img1.jpg +0 -0
- data/spec/dummy/public/system/spud_media/4/cropped/test_img1.jpg +0 -0
- data/spec/dummy/public/system/spud_media/5/cropped/test_img1.jpg +0 -0
- data/spec/support/authlogic_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a862633260e57320e4243988457416b202bbf465
|
4
|
+
data.tar.gz: 0863154571f9dd3e999a6adb0bd0b26e6cc98bcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10e2eb4365828d56527a9b5740ff11b7951a005b41aff5640df2557f598d9c3c4a0cf6328a5ddb79e4da67ffd8533bb7ec9e23a88c7902d5858db38939782e7d
|
7
|
+
data.tar.gz: e24aafa8d7f07446f676c92f0f031a184176328d0587bb65435786b51c979b477612eb2daee026fb80b359f1db3ad4899ba86791d792e23916f91b75852d4106
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path(
|
23
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
@@ -32,6 +32,6 @@ begin
|
|
32
32
|
load 'jasmine/tasks/jasmine.rake'
|
33
33
|
rescue LoadError
|
34
34
|
task :jasmine do
|
35
|
-
abort
|
35
|
+
abort 'Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine'
|
36
36
|
end
|
37
37
|
end
|
@@ -1,72 +1,68 @@
|
|
1
1
|
class Admin::MediaController < Admin::ApplicationController
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def index
|
8
|
-
@media = SpudMedia.order("created_at DESC").paginate :page => params[:page]
|
9
|
-
respond_with @media
|
10
|
-
end
|
2
|
+
layout 'admin/detail'
|
3
|
+
add_breadcrumb 'Media', :admin_media_path
|
4
|
+
belongs_to_app :media
|
5
|
+
before_action :load_media, only: [:edit, :update, :show, :destroy, :set_private, :set_access]
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
respond_with @media
|
17
|
-
end
|
7
|
+
def index
|
8
|
+
@media = SpudMedia.order('created_at DESC').paginate page: params[:page]
|
9
|
+
respond_with @media
|
10
|
+
end
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
flash[:notice] = "File uploaded successfully"
|
26
|
-
if @media.is_image?
|
27
|
-
location = edit_admin_medium_path(@media.id)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
respond_with @media, :location => location
|
31
|
-
end
|
12
|
+
def new
|
13
|
+
@page_name = 'New Media'
|
14
|
+
add_breadcrumb 'New', :new_admin_medium_path
|
15
|
+
@media = SpudMedia.new
|
16
|
+
respond_with @media
|
17
|
+
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
19
|
+
def create
|
20
|
+
@page_name = 'New Media'
|
21
|
+
add_breadcrumb 'New', :new_admin_medium_path
|
22
|
+
@media = SpudMedia.new(media_params)
|
23
|
+
location = admin_media_path
|
24
|
+
if @media.save
|
25
|
+
flash[:notice] = 'File uploaded successfully'
|
26
|
+
location = edit_admin_medium_path(@media.id) if @media.is_image?
|
27
|
+
end
|
28
|
+
respond_with @media, location: location
|
29
|
+
end
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
def edit
|
32
|
+
unless @media.is_image?
|
33
|
+
flash[:error] = "Unable to edit #{@media.attachment_file_name}"
|
34
|
+
redirect_to admin_media_path
|
35
|
+
end
|
36
|
+
end
|
46
37
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
def update
|
39
|
+
@media.attachment.reprocess! if @media.update_attributes(media_params)
|
40
|
+
respond_with @media, location: admin_media_path
|
41
|
+
end
|
51
42
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
43
|
+
def destroy
|
44
|
+
flash[:notice] = 'File successfully destroyed' if @media.destroy
|
45
|
+
respond_with @media, location: admin_media_path
|
46
|
+
end
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
redirect_to admin_media_path() and return
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
48
|
+
def set_access
|
49
|
+
is_protected = params[:protected] || false
|
50
|
+
@media.update_attribute(:is_protected, is_protected)
|
51
|
+
respond_with @media, location: admin_media_path
|
52
|
+
end
|
67
53
|
|
68
|
-
|
69
|
-
|
70
|
-
|
54
|
+
private
|
55
|
+
|
56
|
+
def load_media
|
57
|
+
@media = SpudMedia.where(id: params[:id]).first
|
58
|
+
if @media.blank?
|
59
|
+
flash[:error] = 'Media Asset not found!'
|
60
|
+
redirect_to(admin_media_path()) && return
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def media_params
|
65
|
+
params.require(:spud_media).permit(:attachment_content_type, :attachment_file_name, :attachment_file_size, :attachment, :is_protected, :crop_x, :crop_y, :crop_w, :crop_h, :crop_s)
|
66
|
+
end
|
71
67
|
|
72
68
|
end
|
@@ -6,15 +6,15 @@ class Admin::MediaPickerController < Admin::ApplicationController
|
|
6
6
|
respond_to :html
|
7
7
|
|
8
8
|
def index
|
9
|
-
@media = SpudMedia.order('attachment_file_name asc').paginate(:
|
9
|
+
@media = SpudMedia.order('attachment_file_name asc').paginate(page: params[:page], per_page: 30)
|
10
10
|
respond_with @media do |format|
|
11
|
-
format.html
|
11
|
+
format.html do
|
12
12
|
if params[:only_list]
|
13
|
-
render :
|
13
|
+
render partial: 'media', collection: @media
|
14
14
|
else
|
15
15
|
render 'index'
|
16
16
|
end
|
17
|
-
|
17
|
+
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,21 +22,21 @@ class Admin::MediaPickerController < Admin::ApplicationController
|
|
22
22
|
@media = SpudMedia.new(media_params)
|
23
23
|
if @media.save
|
24
24
|
if request.xhr?
|
25
|
-
render 'create', :
|
25
|
+
render 'create', status: 200
|
26
26
|
else
|
27
27
|
respond_to_parent do
|
28
|
-
render 'create.js', :
|
28
|
+
render 'create.js', status: 200
|
29
29
|
end
|
30
30
|
end
|
31
31
|
else
|
32
|
-
render :
|
32
|
+
render text: @media.errors.full_messages.first, status: 422
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
private
|
36
|
+
private
|
37
37
|
|
38
38
|
def media_params
|
39
|
-
params.require(:spud_media).permit(:attachment_content_type
|
39
|
+
params.require(:spud_media).permit(:attachment_content_type, :attachment_file_name, :attachment_file_size, :attachment, :is_protected, :crop_x, :crop_y, :crop_w, :crop_h, :crop_s)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
class ProtectedMediaController < Spud::ApplicationController
|
2
2
|
|
3
|
-
|
3
|
+
before_action :require_user
|
4
4
|
|
5
5
|
def show
|
6
|
-
@media = SpudMedia.where(:
|
6
|
+
@media = SpudMedia.where(id: params[:id]).first
|
7
7
|
if @media.blank?
|
8
|
-
raise Spud::NotFoundError
|
8
|
+
raise Spud::NotFoundError, item: 'media'
|
9
9
|
else
|
10
10
|
if Spud::Media.config.paperclip_storage == :s3
|
11
|
-
secure_url = @media.attachment.s3_object(params[:style]).url_for(:read, :
|
11
|
+
secure_url = @media.attachment.s3_object(params[:style]).url_for(:read, secure: true, expires: 10.minutes)
|
12
12
|
redirect_to(secure_url.to_s)
|
13
13
|
else
|
14
14
|
filepath = @media.attachment.path(params[:style])
|
15
|
-
if !File.
|
16
|
-
raise Spud::NotFoundError
|
15
|
+
if !File.exist?(filepath)
|
16
|
+
raise Spud::NotFoundError, item: 'media'
|
17
17
|
else
|
18
|
-
send_file(filepath, :
|
18
|
+
send_file(filepath, disposition: 'inline')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/app/models/spud_media.rb
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
class SpudMedia < ActiveRecord::Base
|
2
2
|
|
3
|
-
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:
|
7
|
-
attachment.instance.is_protected ? 'private' : 'public-read'
|
3
|
+
has_attached_file :attachment,
|
4
|
+
storage: Spud::Media.paperclip_storage,
|
5
|
+
s3_credentials: Spud::Media.s3_credentials,
|
6
|
+
s3_permissions: lambda { |attachment, _style|
|
7
|
+
attachment.instance.is_protected ? 'private' : 'public-read'
|
8
8
|
},
|
9
|
-
:
|
9
|
+
path: Spud::Media.paperclip_storage == :s3 ? Spud::Media.storage_path : lambda { |attachment|
|
10
10
|
attachment.instance.is_protected ? Spud::Media.storage_path_protected : Spud::Media.storage_path
|
11
11
|
},
|
12
|
-
:
|
13
|
-
:
|
12
|
+
url: Spud::Media.storage_url,
|
13
|
+
styles: ->(attachment) { attachment.instance.dynamic_styles }
|
14
14
|
|
15
|
-
|
15
|
+
validates :crop_x, :crop_y, :crop_w, :crop_h, :crop_s, numericality: { allow_nil: true }
|
16
16
|
|
17
17
|
extend ActionView::Helpers::NumberHelper
|
18
18
|
|
19
19
|
validates_attachment :attachment,
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
20
|
+
presence: true,
|
21
|
+
content_type: { content_type: Spud::Media::CONTENT_TYPES },
|
22
|
+
size: {
|
23
|
+
less_than: Spud::Media.max_upload_size,
|
24
|
+
message: 'size cannot exceed ' + number_to_human_size(Spud::Media.max_upload_size),
|
25
|
+
if: proc { |_p| Spud::Media.max_upload_size.positive? }
|
26
26
|
}
|
27
27
|
|
28
28
|
before_create :rename_file
|
29
|
-
#after_create :validate_permissions
|
30
29
|
before_update :validate_permissions
|
31
30
|
|
32
31
|
def rename_file
|
@@ -37,46 +36,45 @@ class SpudMedia < ActiveRecord::Base
|
|
37
36
|
end
|
38
37
|
|
39
38
|
def image_from_type
|
39
|
+
if is_image?
|
40
|
+
return attachment_url(:small)
|
40
41
|
|
41
|
-
|
42
|
-
return
|
43
|
-
|
44
|
-
elsif
|
45
|
-
|
46
|
-
|
47
|
-
elsif
|
48
|
-
|
49
|
-
|
50
|
-
elsif
|
51
|
-
|
52
|
-
|
53
|
-
elsif
|
54
|
-
|
55
|
-
|
56
|
-
elsif
|
57
|
-
|
58
|
-
|
59
|
-
elsif
|
60
|
-
|
61
|
-
|
62
|
-
elsif
|
63
|
-
|
64
|
-
|
65
|
-
elsif
|
66
|
-
|
67
|
-
|
68
|
-
elsif
|
69
|
-
|
70
|
-
|
71
|
-
elsif self.attachment_content_type.match(/mp3|wav|aac/)
|
72
|
-
return "admin/files_thumbs/mp3_thumb.png"
|
42
|
+
elsif attachment_content_type.blank?
|
43
|
+
return 'admin/files_thumbs/dat_thumb.png'
|
44
|
+
|
45
|
+
elsif attachment_content_type =~ /jpeg|jpg/
|
46
|
+
return 'admin/files_thumbs/jpg_thumb.png'
|
47
|
+
|
48
|
+
elsif attachment_content_type =~ /png/
|
49
|
+
return 'admin/files_thumbs/png_thumb.png'
|
50
|
+
|
51
|
+
elsif attachment_content_type =~ /zip|tar|tar\.gz|gz/
|
52
|
+
return 'admin/files_thumbs/zip_thumb.png'
|
53
|
+
|
54
|
+
elsif attachment_content_type =~ /xls|xlsx/
|
55
|
+
return 'admin/files_thumbs/xls_thumb.png'
|
56
|
+
|
57
|
+
elsif attachment_content_type =~ /doc|docx/
|
58
|
+
return 'admin/files_thumbs/doc_thumb.png'
|
59
|
+
|
60
|
+
elsif attachment_content_type =~ /ppt|pptx/
|
61
|
+
return 'admin/files_thumbs/ppt_thumb.png'
|
62
|
+
|
63
|
+
elsif attachment_content_type =~ /txt|text/
|
64
|
+
return 'admin/files_thumbs/txt_thumb.png'
|
65
|
+
|
66
|
+
elsif attachment_content_type =~ /pdf|ps/
|
67
|
+
return 'admin/files_thumbs/pdf_thumb.png'
|
68
|
+
|
69
|
+
elsif attachment_content_type =~ /mp3|wav|aac/
|
70
|
+
return 'admin/files_thumbs/mp3_thumb.png'
|
73
71
|
end
|
74
|
-
|
75
|
-
return
|
72
|
+
|
73
|
+
return 'admin/files_thumbs/dat_thumb.png'
|
76
74
|
end
|
77
75
|
|
78
76
|
def is_image?
|
79
|
-
if
|
77
|
+
if attachment_content_type =~ /jpeg|jpg|png/
|
80
78
|
return true
|
81
79
|
else
|
82
80
|
return false
|
@@ -84,7 +82,7 @@ class SpudMedia < ActiveRecord::Base
|
|
84
82
|
end
|
85
83
|
|
86
84
|
def is_pdf?
|
87
|
-
if
|
85
|
+
if attachment_content_type =~ /pdf/
|
88
86
|
return true
|
89
87
|
else
|
90
88
|
return false
|
@@ -97,25 +95,23 @@ class SpudMedia < ActiveRecord::Base
|
|
97
95
|
|
98
96
|
def dynamic_styles
|
99
97
|
styles = {}
|
100
|
-
if is_image?
|
98
|
+
if is_image? # || is_pdf?
|
101
99
|
styles[:small] = '50'
|
102
100
|
if has_custom_crop?
|
103
|
-
styles[:cropped] = {:
|
101
|
+
styles[:cropped] = { geometry: '', convert_options: "-strip -resize #{crop_s}% -crop #{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}" }
|
104
102
|
else
|
105
|
-
styles[:cropped] = {:
|
103
|
+
styles[:cropped] = { geometry: '1280x1280>', convert_options: '-strip -quality 85', source_file_options: '-density 72' }
|
106
104
|
end
|
107
105
|
end
|
108
106
|
return styles
|
109
|
-
|
107
|
+
end
|
110
108
|
|
111
109
|
# if you are using S3, attachment.url will automatically point to the S3 url
|
112
110
|
# protected files need to hit the rails middle-man first
|
113
|
-
|
114
|
-
def attachment_url(style=nil)
|
111
|
+
# this method will provide the correct url for either case
|
112
|
+
def attachment_url(style = nil)
|
115
113
|
# defaults to cropped style if that style exists, otherwise use original
|
116
|
-
|
117
|
-
style = (is_image?) ? 'cropped' : 'original'
|
118
|
-
end
|
114
|
+
style = is_image? ? 'cropped' : 'original' unless style
|
119
115
|
if Spud::Media.paperclip_storage == :s3 && is_protected
|
120
116
|
return Paperclip::Interpolations.interpolate(Spud::Media.config.storage_url, attachment, style)
|
121
117
|
else
|
@@ -124,7 +120,7 @@ class SpudMedia < ActiveRecord::Base
|
|
124
120
|
end
|
125
121
|
|
126
122
|
# If is_protected has changed, we need to make sure we are setting the appropriate permissions
|
127
|
-
|
123
|
+
# This means either moving the file in the filesystem or setting the appropriate ACL in S3
|
128
124
|
def validate_permissions
|
129
125
|
if Spud::Media.config.paperclip_storage == :filesystem
|
130
126
|
validate_permissions_filesystem
|
@@ -133,7 +129,7 @@ class SpudMedia < ActiveRecord::Base
|
|
133
129
|
end
|
134
130
|
end
|
135
131
|
|
136
|
-
private
|
132
|
+
private
|
137
133
|
|
138
134
|
def validate_permissions_filesystem
|
139
135
|
if is_protected
|
@@ -141,13 +137,11 @@ private
|
|
141
137
|
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
142
138
|
else
|
143
139
|
old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
144
|
-
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
140
|
+
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
145
141
|
end
|
146
142
|
new_base_dir = File.dirname(File.dirname(new_path))
|
147
143
|
old_base_dir = File.dirname(File.dirname(old_path))
|
148
|
-
if File.directory?(old_base_dir)
|
149
|
-
FileUtils.mv(old_base_dir, new_base_dir)
|
150
|
-
end
|
144
|
+
FileUtils.mv(old_base_dir, new_base_dir) if File.directory?(old_base_dir)
|
151
145
|
end
|
152
146
|
|
153
147
|
def validate_permissions_s3
|
@@ -5,9 +5,9 @@ module Spud
|
|
5
5
|
config_accessor :paperclip_storage, :s3_credentials, :storage_path, :storage_path_protected, :storage_url, :max_upload_size
|
6
6
|
self.paperclip_storage = :filesystem
|
7
7
|
self.s3_credentials = "#{Rails.root}/config/s3.yml"
|
8
|
-
self.storage_path =
|
9
|
-
self.storage_path_protected =
|
10
|
-
self.storage_url =
|
8
|
+
self.storage_path = ':rails_root/public/system/spud_media/:id/:style/:basename.:extension'
|
9
|
+
self.storage_path_protected = ':rails_root/public/system/spud_media_protected/:id/:style/:basename.:extension'
|
10
|
+
self.storage_url = '/system/spud_media/:id/:style/:basename.:extension'
|
11
11
|
self.max_upload_size = 15.megabytes
|
12
12
|
end
|
13
13
|
end
|
@@ -8,7 +8,7 @@ module Spud
|
|
8
8
|
'application/msword',
|
9
9
|
'application/vnd.ms-excel',
|
10
10
|
'application/vnd.ms-powerpoint',
|
11
|
-
|
11
|
+
|
12
12
|
# Documents
|
13
13
|
'application/pdf',
|
14
14
|
'text/html',
|
@@ -57,6 +57,6 @@ module Spud
|
|
57
57
|
'image/vnd.adobe.photoshop',
|
58
58
|
'application/postscript',
|
59
59
|
'application/x-shockwave-flash'
|
60
|
-
]
|
60
|
+
].freeze
|
61
61
|
end
|
62
62
|
end
|
data/lib/spud_media/engine.rb
CHANGED
@@ -2,23 +2,23 @@ require 'tb_core'
|
|
2
2
|
require 'paperclip'
|
3
3
|
|
4
4
|
module Spud
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
initializer :admin do
|
10
|
-
config.assets.precompile += ['admin/media/picker.js']
|
11
|
-
Spud::Core.append_admin_javascripts('admin/media/application')
|
12
|
-
Spud::Core.append_admin_stylesheets('admin/media/application')
|
13
|
-
Spud::Core.configure do |config|
|
14
|
-
config.admin_applications += [{:name => "Media", :thumbnail => "admin/media_thumb.png", :url => "/admin/media", :order => 3, :retina => true}]
|
15
|
-
end
|
16
|
-
end
|
5
|
+
module Media
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
engine_name :tb_media
|
17
8
|
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
initializer :admin do
|
10
|
+
config.assets.precompile += ['admin/media/picker.js']
|
11
|
+
Spud::Core.append_admin_javascripts('admin/media/application')
|
12
|
+
Spud::Core.append_admin_stylesheets('admin/media/application')
|
13
|
+
Spud::Core.configure do |config|
|
14
|
+
config.admin_applications += [{ name: 'Media', thumbnail: 'admin/media_thumb.png', url: '/admin/media', order: 3, retina: true }]
|
15
|
+
end
|
16
|
+
end
|
21
17
|
|
22
|
-
|
23
|
-
|
18
|
+
initializer 'tb_media.assets' do
|
19
|
+
Rails.application.config.assets.precompile += ['admin/media_thumb.png']
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
24
|
end
|
data/lib/spud_media/version.rb
CHANGED
@@ -5,11 +5,9 @@
|
|
5
5
|
|
6
6
|
namespace :spud_media do
|
7
7
|
|
8
|
-
desc
|
9
|
-
task :
|
10
|
-
SpudMedia.find_each
|
11
|
-
m.validate_permissions
|
12
|
-
end
|
8
|
+
desc 'Validate that all media files have the proper permission settings'
|
9
|
+
task validate_permissions: :environment do
|
10
|
+
SpudMedia.find_each(&:validate_permissions)
|
13
11
|
end
|
14
12
|
|
15
|
-
end
|
13
|
+
end
|
@@ -1,44 +1,44 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe Admin::MediaController, :
|
3
|
+
describe Admin::MediaController, type: :controller do
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
activate_authlogic
|
7
|
-
u = SpudUser.new(:
|
7
|
+
u = SpudUser.new(login: 'testuser', email: 'test@testuser.com', password: 'test', password_confirmation: 'test')
|
8
8
|
u.super_admin = true
|
9
9
|
u.save
|
10
10
|
@user = SpudUserSession.create(u)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe 'index' do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
it 'index page should return all media in descending order by create_at' do
|
15
|
+
@media1 = FactoryGirl.create(:spud_media, created_at: 1.hour.ago)
|
16
|
+
@media2 = FactoryGirl.create(:spud_media, created_at: 2.hours.ago)
|
17
|
+
@media3 = FactoryGirl.create(:spud_media, created_at: 3.hours.ago)
|
18
|
+
get :index
|
19
|
+
@medias = assigns(:media)
|
20
|
+
expect(@medias.count).to eq(3)
|
21
|
+
expect(@medias[0].id).to eq(@media1.id)
|
22
|
+
expect(@medias[1].id).to eq(@media2.id)
|
23
|
+
expect(@medias[2].id).to eq(@media3.id)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe 'new' do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it 'should return a new media object' do
|
29
|
+
get :new
|
30
|
+
@media = assigns(:media)
|
31
|
+
expect(@media).to_not be_blank
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe 'create' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
it "should create a new media and returned the saved object's edit page" do
|
37
|
+
post :create, params: { spud_media: FactoryGirl.attributes_for(:spud_media) }
|
38
|
+
expect do
|
39
|
+
post :create, params: { spud_media: FactoryGirl.attributes_for(:spud_media) }
|
40
|
+
end.to change(SpudMedia, :count).by(1)
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
|
-
end
|
44
|
+
end
|
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
|
|
3
3
|
require 'rails/all'
|
4
4
|
|
5
5
|
Bundler.require
|
6
|
-
require
|
6
|
+
require 'tb_media'
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
@@ -31,7 +31,7 @@ module Dummy
|
|
31
31
|
config.i18n.enforce_available_locales = true
|
32
32
|
|
33
33
|
# Configure the default encoding used in templates for Ruby 1.9.
|
34
|
-
config.encoding =
|
34
|
+
config.encoding = 'utf-8'
|
35
35
|
|
36
36
|
# Configure sensitive parameters which will be filtered from the log file.
|
37
37
|
config.filter_parameters += [:password]
|
@@ -54,4 +54,3 @@ module Dummy
|
|
54
54
|
config.assets.version = '1.0'
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
data/spec/dummy/config/boot.rb
CHANGED