asset_host_core 2.0.0.beta
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.
- data/MIT-LICENSE +20 -0
- data/README.markdown +138 -0
- data/Rakefile +11 -0
- data/app/assets/images/asset_host_core/alert-overlay.png +0 -0
- data/app/assets/images/asset_host_core/arrow-left.gif +0 -0
- data/app/assets/images/asset_host_core/arrow-right.gif +0 -0
- data/app/assets/images/asset_host_core/fallback-img-rect.png +0 -0
- data/app/assets/images/asset_host_core/videoplayer-play.png +0 -0
- data/app/assets/images/asset_host_core/x.png +0 -0
- data/app/assets/javascripts/asset_host_core/admin/assets.js.coffee +221 -0
- data/app/assets/javascripts/asset_host_core/application.js +20 -0
- data/app/assets/javascripts/asset_host_core/assetadmin.js.coffee +56 -0
- data/app/assets/javascripts/asset_host_core/assethost.js.coffee.erb +17 -0
- data/app/assets/javascripts/asset_host_core/browserui.js.coffee +139 -0
- data/app/assets/javascripts/asset_host_core/chooserui.js.coffee +381 -0
- data/app/assets/javascripts/asset_host_core/client.js.coffee +29 -0
- data/app/assets/javascripts/asset_host_core/clients/BrightcoveVideo.js.coffee +64 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/brightcove_embed.jst.eco +18 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/vimeo_embed.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/youtube_embed.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/clients/vimeo_video.js.coffee +21 -0
- data/app/assets/javascripts/asset_host_core/clients/youtube_video.js.coffee +21 -0
- data/app/assets/javascripts/asset_host_core/cmsplugin.js.coffee +235 -0
- data/app/assets/javascripts/asset_host_core/models.js.coffee +586 -0
- data/app/assets/javascripts/asset_host_core/railsCMS.js.coffee +141 -0
- data/app/assets/javascripts/asset_host_core/slideshow.js.coffee +428 -0
- data/app/assets/javascripts/asset_host_core/templates/after_upload_button.jst.eco +3 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_drop_asset.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_modal.jst.eco +13 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_preview.jst.eco +35 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_search.jst.eco +2 -0
- data/app/assets/javascripts/asset_host_core/templates/browser_asset.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/templates/browser_asset_tip.jst.eco +3 -0
- data/app/assets/javascripts/asset_host_core/templates/edit_modal.jst.eco +40 -0
- data/app/assets/javascripts/asset_host_core/templates/import_help.jst.eco +59 -0
- data/app/assets/javascripts/asset_host_core/templates/pagination_link.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/templates/pagination_links.jst.eco +13 -0
- data/app/assets/javascripts/asset_host_core/templates/queued_file.jst.eco +11 -0
- data/app/assets/javascripts/asset_host_core/templates/save_and_close_view.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/upload_all_button.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/url_input.jst.eco +8 -0
- data/app/assets/stylesheets/asset_host_core/application.css.scss +384 -0
- data/app/assets/stylesheets/asset_host_core/jquery-ui.css +105 -0
- data/app/assets/stylesheets/asset_host_core/public.css.scss +204 -0
- data/app/assets/stylesheets/asset_host_core/slidetest.css.scss +93 -0
- data/app/controllers/asset_host_core/admin/api_users_controller.rb +72 -0
- data/app/controllers/asset_host_core/admin/assets_controller.rb +140 -0
- data/app/controllers/asset_host_core/admin/base_controller.rb +36 -0
- data/app/controllers/asset_host_core/admin/home_controller.rb +13 -0
- data/app/controllers/asset_host_core/admin/outputs_controller.rb +55 -0
- data/app/controllers/asset_host_core/api/assets_controller.rb +110 -0
- data/app/controllers/asset_host_core/api/base_controller.rb +43 -0
- data/app/controllers/asset_host_core/api/outputs_controller.rb +33 -0
- data/app/controllers/asset_host_core/application_controller.rb +43 -0
- data/app/controllers/asset_host_core/public_controller.rb +104 -0
- data/app/models/asset_host_core/api_user.rb +44 -0
- data/app/models/asset_host_core/api_user_permission.rb +6 -0
- data/app/models/asset_host_core/asset.rb +265 -0
- data/app/models/asset_host_core/asset_output.rb +69 -0
- data/app/models/asset_host_core/brightcove_video.rb +20 -0
- data/app/models/asset_host_core/output.rb +52 -0
- data/app/models/asset_host_core/permission.rb +19 -0
- data/app/models/asset_host_core/video.rb +8 -0
- data/app/models/asset_host_core/vimeo_video.rb +17 -0
- data/app/models/asset_host_core/youtube_video.rb +17 -0
- data/app/views/asset_host_core/admin/api_users/_form_fields.html.erb +5 -0
- data/app/views/asset_host_core/admin/api_users/edit.html.erb +26 -0
- data/app/views/asset_host_core/admin/api_users/index.html.erb +31 -0
- data/app/views/asset_host_core/admin/api_users/new.html.erb +17 -0
- data/app/views/asset_host_core/admin/api_users/show.html.erb +23 -0
- data/app/views/asset_host_core/admin/assets/index.html.erb +19 -0
- data/app/views/asset_host_core/admin/assets/metadata.html.erb +24 -0
- data/app/views/asset_host_core/admin/assets/show.html.erb +86 -0
- data/app/views/asset_host_core/admin/home/chooser.html.erb +49 -0
- data/app/views/asset_host_core/admin/outputs/_form_fields.html.erb +5 -0
- data/app/views/asset_host_core/admin/outputs/edit.html.erb +26 -0
- data/app/views/asset_host_core/admin/outputs/index.html.erb +27 -0
- data/app/views/asset_host_core/admin/outputs/new.html.erb +13 -0
- data/app/views/asset_host_core/admin/outputs/show.html.erb +17 -0
- data/app/views/asset_host_core/shared/_footerjs.html.erb +3 -0
- data/app/views/asset_host_core/shared/_navbar.html.erb +28 -0
- data/app/views/kaminari/_first_page.html.erb +3 -0
- data/app/views/kaminari/_gap.html.erb +3 -0
- data/app/views/kaminari/_last_page.html.erb +3 -0
- data/app/views/kaminari/_next_page.html.erb +3 -0
- data/app/views/kaminari/_page.html.erb +3 -0
- data/app/views/kaminari/_paginator.html.erb +17 -0
- data/app/views/kaminari/_prev_page.html.erb +3 -0
- data/app/views/layouts/asset_host_core/application.html.erb +54 -0
- data/app/views/layouts/asset_host_core/full_width.html.erb +32 -0
- data/app/views/layouts/asset_host_core/minimal.html.erb +45 -0
- data/config/initializers/simple_form.rb +142 -0
- data/config/initializers/simple_form_bootstrap.rb +45 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/routes.rb +49 -0
- data/lib/asset_host_core.rb +38 -0
- data/lib/asset_host_core/config.rb +39 -0
- data/lib/asset_host_core/engine.rb +94 -0
- data/lib/asset_host_core/loaders.rb +34 -0
- data/lib/asset_host_core/loaders/asset_host.rb +30 -0
- data/lib/asset_host_core/loaders/base.rb +22 -0
- data/lib/asset_host_core/loaders/brightcove.rb +67 -0
- data/lib/asset_host_core/loaders/flickr.rb +114 -0
- data/lib/asset_host_core/loaders/url.rb +59 -0
- data/lib/asset_host_core/loaders/vimeo.rb +76 -0
- data/lib/asset_host_core/loaders/youtube.rb +90 -0
- data/lib/asset_host_core/model_methods.rb +61 -0
- data/lib/asset_host_core/paperclip.rb +4 -0
- data/lib/asset_host_core/paperclip/asset_thumbnail.rb +92 -0
- data/lib/asset_host_core/paperclip/attachment.rb +206 -0
- data/lib/asset_host_core/paperclip/trimmer.rb +33 -0
- data/lib/asset_host_core/resque_job.rb +13 -0
- data/lib/asset_host_core/version.rb +3 -0
- data/lib/tasks/asset_host_core_tasks.rake +4 -0
- data/spec/controllers/admin/api_users_controller_spec.rb +21 -0
- data/spec/controllers/admin/assets_controller_spec.rb +59 -0
- data/spec/controllers/admin/home_controller_spec.rb +4 -0
- data/spec/controllers/admin/outputs_controller_spec.rb +4 -0
- data/spec/controllers/api/assets_controller_spec.rb +133 -0
- data/spec/controllers/api/outputs_controller_spec.rb +51 -0
- data/spec/controllers/public_controller_spec.rb +4 -0
- data/spec/factories.rb +39 -0
- data/spec/features/api_users_spec.rb +78 -0
- data/spec/fixtures/api/brightcove/video.json +137 -0
- data/spec/fixtures/api/flickr/photos_getInfo.json +78 -0
- data/spec/fixtures/api/flickr/photos_getSizes.json +82 -0
- data/spec/fixtures/api/flickr/photos_licenses_getInfo.json +52 -0
- data/spec/fixtures/api/vimeo/video.json +28 -0
- data/spec/fixtures/api/youtube/discovery.json +5190 -0
- data/spec/fixtures/api/youtube/video.json +44 -0
- data/spec/fixtures/images/chipmunk.jpg +0 -0
- data/spec/fixtures/images/dude.jpg +0 -0
- data/spec/fixtures/images/ernie.jpg +0 -0
- data/spec/fixtures/images/fry.png +0 -0
- data/spec/fixtures/images/hat.jpg +0 -0
- data/spec/fixtures/images/spongebob.png +0 -0
- data/spec/fixtures/images/stars.jpg +0 -0
- data/spec/internal/app/controllers/application_controller.rb +16 -0
- data/spec/internal/app/controllers/sessions_controller.rb +24 -0
- data/spec/internal/app/models/user.rb +10 -0
- data/spec/internal/app/views/sessions/new.html.erb +14 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/assethost_config.rb +57 -0
- data/spec/internal/config/routes.rb +7 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +106 -0
- data/spec/internal/log/test.log +14769 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/public/images/1_27f7745237849975ca90591c1fba5934_original. +0 -0
- data/spec/internal/public/images/1_7d33319deca787d5bb3f62ff06563ad2_original. +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original. +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.jpg +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.txt +0 -0
- data/spec/internal/public/images/1_e179cbd27e07cb55042d0db36cdac095_original. +0 -0
- data/spec/internal/public/images/1_e669edd3dfd74be66fc38416e82e3a37_original. +0 -0
- data/spec/lib/asset_host_core/loaders/asset_host_spec.rb +33 -0
- data/spec/lib/asset_host_core/loaders/brightcove_spec.rb +51 -0
- data/spec/lib/asset_host_core/loaders/flickr_spec.rb +72 -0
- data/spec/lib/asset_host_core/loaders/url_spec.rb +42 -0
- data/spec/lib/asset_host_core/loaders/vimeo_spec.rb +51 -0
- data/spec/lib/asset_host_core/loaders/youtube_spec.rb +73 -0
- data/spec/lib/asset_host_core/loaders_spec.rb +4 -0
- data/spec/lib/asset_host_core/model_methods_spec.rb +4 -0
- data/spec/lib/asset_host_core/paperclip/asset_thumbnail_spec.rb +4 -0
- data/spec/lib/asset_host_core/paperclip/attachment_spec.rb +4 -0
- data/spec/lib/asset_host_core/resque_job_spec.rb +4 -0
- data/spec/lib/asset_host_core_spec.rb +4 -0
- data/spec/models/api_user_spec.rb +58 -0
- data/spec/models/asset_output_spec.rb +4 -0
- data/spec/models/asset_spec.rb +4 -0
- data/spec/models/output_spec.rb +4 -0
- data/spec/models/permission_spec.rb +4 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/fixture_loader.rb +9 -0
- data/spec/support/param_helper.rb +14 -0
- data/spec/support/permission_matcher.rb +17 -0
- data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_flat_10_000000_40x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_222222_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_228ef1_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ef8c08_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ffd27a_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
- data/vendor/assets/javascripts/backbone.js +1158 -0
- data/vendor/assets/javascripts/backbone.modelbinding.js +475 -0
- data/vendor/assets/javascripts/exif.js +695 -0
- data/vendor/assets/javascripts/jquery-ui.js +5614 -0
- data/vendor/assets/javascripts/simplemodal.js +698 -0
- data/vendor/assets/javascripts/spin.jquery.js +81 -0
- data/vendor/assets/javascripts/spin.min.js +1 -0
- data/vendor/assets/javascripts/underscore.min.js +1 -0
- metadata +658 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Paperclip
|
|
2
|
+
class Trimmer < Processor
|
|
3
|
+
def initialize(file, options={}, attachment=nil)
|
|
4
|
+
super
|
|
5
|
+
|
|
6
|
+
@current_format = File.extname(@file.path)
|
|
7
|
+
@basename = File.basename(@file.path, @current_format)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# This class is meant to help trim off letterboxing from
|
|
11
|
+
# YouTube poster images. YouTube always delivers a 4:3 poster
|
|
12
|
+
# image (the HQ version), and adds black edges if the video
|
|
13
|
+
# doesn't fit.
|
|
14
|
+
def make
|
|
15
|
+
source = @file
|
|
16
|
+
destination = Tempfile.new(@basename)
|
|
17
|
+
|
|
18
|
+
Paperclip.run("convert",
|
|
19
|
+
":source " \
|
|
20
|
+
"-quality 100 " \
|
|
21
|
+
"-bordercolor \"#000000\" " \
|
|
22
|
+
"-border 1x1 " \
|
|
23
|
+
"-fuzz 10% " \
|
|
24
|
+
"-trim +repage " \
|
|
25
|
+
":dest",
|
|
26
|
+
:source => File.expand_path(source.path),
|
|
27
|
+
:dest => File.expand_path(destination.path)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
destination
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module AssetHostCore
|
|
2
|
+
class ResqueJob
|
|
3
|
+
@queue = nil
|
|
4
|
+
|
|
5
|
+
def self.perform(instance_klass, instance_id, attachment_name, style_args)
|
|
6
|
+
instance = instance_klass.constantize.find(instance_id)
|
|
7
|
+
|
|
8
|
+
styles = style_args.map(&:to_sym) if style_args
|
|
9
|
+
|
|
10
|
+
instance.send(attachment_name).reprocess!(*styles)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AssetHostCore::Admin::ApiUsersController do
|
|
4
|
+
it 'allows admins' do
|
|
5
|
+
user = create :user, is_admin: true
|
|
6
|
+
controller.stub(:current_user) { user }
|
|
7
|
+
|
|
8
|
+
get :index, admin_request_params
|
|
9
|
+
|
|
10
|
+
response.should be_success
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'does not allow non-admins' do
|
|
14
|
+
user = create :user, is_admin: false
|
|
15
|
+
controller.stub(:current_user) { user }
|
|
16
|
+
|
|
17
|
+
get :index, admin_request_params
|
|
18
|
+
|
|
19
|
+
response.should be_redirect
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AssetHostCore::Admin::AssetsController do
|
|
4
|
+
render_views
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@user = create :user
|
|
8
|
+
controller.stub(:current_user) { @user }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe 'GET index' do
|
|
12
|
+
it 'returns paginated assets' do
|
|
13
|
+
assets = create_list :asset, 2
|
|
14
|
+
get :index, admin_request_params
|
|
15
|
+
assigns(:assets).should eq assets.reverse
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'GET show' do
|
|
20
|
+
it 'gets the previous and next assets' do
|
|
21
|
+
assets = create_list :asset, 3
|
|
22
|
+
get :show, admin_request_params(id: assets[1].id)
|
|
23
|
+
assigns(:prev).should eq assets[2]
|
|
24
|
+
assigns(:next).should eq assets[0]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'GET destroy' do
|
|
29
|
+
it 'destroys the asset' do
|
|
30
|
+
asset = create :asset
|
|
31
|
+
delete :destroy, admin_request_params(id: asset.id)
|
|
32
|
+
AssetHostCore::Asset.count.should eq 0
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "GET metadata" do
|
|
37
|
+
it 'gets all the assets in the ID param' do
|
|
38
|
+
assets = create_list :asset, 2
|
|
39
|
+
get :metadata, admin_request_params(ids: assets.map(&:id).join(","))
|
|
40
|
+
assigns(:assets).should eq assets
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe 'PUT update_metadata' do
|
|
45
|
+
it 'finds the passed-in assets and updates them' do
|
|
46
|
+
assets = create_list :asset, 2
|
|
47
|
+
|
|
48
|
+
put :update_metadata, admin_request_params(
|
|
49
|
+
:assets => {
|
|
50
|
+
assets.first.id => { title: "New Title 1" },
|
|
51
|
+
assets.last.id => { title: "New Title 2" }
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
assets.first.reload.title.should eq "New Title 1"
|
|
56
|
+
assets.last.reload.title.should eq "New Title 2"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AssetHostCore::Api::AssetsController do
|
|
4
|
+
before do
|
|
5
|
+
@api_user = create :api_user
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe 'GET show' do
|
|
9
|
+
before do
|
|
10
|
+
@api_user.permissions.create(
|
|
11
|
+
:resource => "AssetHostCore::Asset",
|
|
12
|
+
:ability => "read"
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'returns the asset as json' do
|
|
17
|
+
asset = create :asset
|
|
18
|
+
get :show, api_request_params(id: asset.id)
|
|
19
|
+
JSON.parse(response.body)["id"].should eq asset.id
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'renders an unauthorized error if there is no auth token provided' do
|
|
23
|
+
get :show, api_request_params(id: 1).except(:auth_token)
|
|
24
|
+
response.status.should eq 401
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'renders a forbidden error if user does not have read permission for assets' do
|
|
28
|
+
@api_user.permissions.clear
|
|
29
|
+
get :show, api_request_params(id: 1)
|
|
30
|
+
response.status.should eq 403
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'POST create' do
|
|
35
|
+
before do
|
|
36
|
+
FakeWeb.register_uri(:get, %r{imgur\.com},
|
|
37
|
+
body: load_image('fry.png'), content_type: "image/png")
|
|
38
|
+
|
|
39
|
+
@api_user.permissions.create(
|
|
40
|
+
:resource => "AssetHostCore::Asset",
|
|
41
|
+
:ability => "write"
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'returns a bad request if URL is not present' do
|
|
46
|
+
post :create, api_request_params
|
|
47
|
+
response.status.should eq 400
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns a 401 if no auth token is provided' do
|
|
51
|
+
post :create, api_request_params(url: "http://imgur.com/someimg.png").except(:auth_token)
|
|
52
|
+
response.status.should eq 401
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'returns a 403 if user does not have asset write permission' do
|
|
56
|
+
@api_user.permissions.clear
|
|
57
|
+
post :create, api_request_params(url: "http://url.com/img.png")
|
|
58
|
+
response.status.should eq 403
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'responds with a 404 and returns asset if no asset is found' do
|
|
62
|
+
post :create, api_request_params(url: "nogoodbro")
|
|
63
|
+
response.status.should eq 404
|
|
64
|
+
response.body["error"].should be_present
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'creates an asset if the URL is valid' do
|
|
68
|
+
post :create, api_request_params(url: "http://imgur.com/someimg.png")
|
|
69
|
+
json = JSON.parse(response.body)
|
|
70
|
+
asset = AssetHostCore::Asset.find(json["id"])
|
|
71
|
+
|
|
72
|
+
asset.should be_present
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'appends to the notes if present' do
|
|
76
|
+
post :create, api_request_params(url: "http://imgur.com/someimg.png", note: "Imported via Tests")
|
|
77
|
+
json = JSON.parse(response.body)
|
|
78
|
+
asset = AssetHostCore::Asset.find(json["id"])
|
|
79
|
+
|
|
80
|
+
asset.notes.should match /Imported via Tests/
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'hides the asset if is_hidden is present' do
|
|
84
|
+
post :create, api_request_params(url: "http://imgur.com/someimg.png", hidden: 1)
|
|
85
|
+
json = JSON.parse(response.body)
|
|
86
|
+
asset = AssetHostCore::Asset.find(json["id"])
|
|
87
|
+
|
|
88
|
+
asset.is_hidden.should eq true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'sets attributes that are present' do
|
|
92
|
+
post :create, api_request_params(
|
|
93
|
+
:url => "http://imgur.com/someimg.png",
|
|
94
|
+
:caption => "Test Image",
|
|
95
|
+
:owner => "Test Owner",
|
|
96
|
+
:title => "Test Title"
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
json = JSON.parse(response.body)
|
|
100
|
+
asset = AssetHostCore::Asset.find(json["id"])
|
|
101
|
+
|
|
102
|
+
asset.caption.should eq "Test Image"
|
|
103
|
+
asset.owner.should eq "Test Owner"
|
|
104
|
+
asset.title.should eq "Test Title"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe 'PUT update' do
|
|
109
|
+
before do
|
|
110
|
+
@api_user.permissions.create(
|
|
111
|
+
:resource => "AssetHostCore::Asset",
|
|
112
|
+
:ability => "write"
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'updates the asset' do
|
|
117
|
+
asset = create :asset
|
|
118
|
+
put :update, api_request_params(id: asset.id, asset: { title: "New Title" })
|
|
119
|
+
asset.reload.title.should eq "New Title"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'returns a 401 if no auth token is provided' do
|
|
123
|
+
put :update, api_request_params(id: 0).except(:auth_token)
|
|
124
|
+
response.status.should eq 401
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'returns a 403 if user does not have asset write permission' do
|
|
128
|
+
@api_user.permissions.clear
|
|
129
|
+
put :update, api_request_params(id: 0)
|
|
130
|
+
response.status.should eq 403
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AssetHostCore::Api::OutputsController do
|
|
4
|
+
before do
|
|
5
|
+
@api_user = create :api_user
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe 'GET index' do
|
|
9
|
+
before do
|
|
10
|
+
@api_user.permissions.create(
|
|
11
|
+
:resource => "AssetHostCore::Output",
|
|
12
|
+
:ability => "read"
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'returns all outputs' do
|
|
17
|
+
output = create :output, code: "thumb"
|
|
18
|
+
get :index, api_request_params
|
|
19
|
+
assigns(:outputs).should eq [output]
|
|
20
|
+
response.body.should match /thumb/
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'returns 403 forbidden if user does not have output read permission' do
|
|
24
|
+
@api_user.permissions.clear
|
|
25
|
+
get :index, api_request_params
|
|
26
|
+
response.status.should eq 403
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'GET show' do
|
|
31
|
+
before do
|
|
32
|
+
@api_user.permissions.create(
|
|
33
|
+
:resource => "AssetHostCore::Output",
|
|
34
|
+
:ability => "read"
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'returns the requested output' do
|
|
39
|
+
output = create :output, code: "large"
|
|
40
|
+
get :show, api_request_params(id: output.code)
|
|
41
|
+
assigns(:output).should eq output
|
|
42
|
+
response.body.should match /large/
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'returns 403 forbidden if user does not have output read permission' do
|
|
46
|
+
@api_user.permissions.clear
|
|
47
|
+
get :show, api_request_params(id: "lol")
|
|
48
|
+
response.status.should eq 403
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/spec/factories.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
FactoryGirl.define do
|
|
2
|
+
factory :user do
|
|
3
|
+
username "bricker"
|
|
4
|
+
password "secret"
|
|
5
|
+
password_confirmation "secret"
|
|
6
|
+
is_admin false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
factory :api_user, class: "AssetHostCore::ApiUser" do
|
|
10
|
+
name "Bryan"
|
|
11
|
+
email "bricker@scpr.org"
|
|
12
|
+
is_active true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
factory :permission, class: "AssetHostCore::Permission" do
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
factory :asset, class: "AssetHostCore::Asset" do
|
|
19
|
+
title "Asset"
|
|
20
|
+
caption "This has been an asset"
|
|
21
|
+
owner "SCPR"
|
|
22
|
+
url "http://www.scpr.org/assets/logo-mark-sm.png"
|
|
23
|
+
is_hidden false
|
|
24
|
+
image_file_name "logo-mark-sm.png"
|
|
25
|
+
image_content_type "image/jpeg"
|
|
26
|
+
image_width 300
|
|
27
|
+
image_height 200
|
|
28
|
+
image_file_size 1000
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
factory :output, class: "AssetHostCore::Output" do
|
|
33
|
+
code "thumb"
|
|
34
|
+
size "88x88#"
|
|
35
|
+
extension "jpg"
|
|
36
|
+
is_rich 0
|
|
37
|
+
prerender 0
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Managing API Users' do
|
|
4
|
+
before do
|
|
5
|
+
@user = create :user, is_admin: true
|
|
6
|
+
visit login_path
|
|
7
|
+
fill_in 'username', with: @user.username
|
|
8
|
+
fill_in 'password', with: "secret"
|
|
9
|
+
click_button "Submit"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "creation" do
|
|
13
|
+
context 'with valid attributes' do
|
|
14
|
+
it "creates a user" do
|
|
15
|
+
AssetHostCore::ApiUser.count.should eq 0
|
|
16
|
+
|
|
17
|
+
visit assethost.new_a_api_user_path
|
|
18
|
+
fill_in 'api_user_name', with: "KPCC"
|
|
19
|
+
fill_in 'api_user_email', with: 'scprweb@scpr.org'
|
|
20
|
+
#check 'api_user_is_active'
|
|
21
|
+
click_button 'Save'
|
|
22
|
+
|
|
23
|
+
api_user = AssetHostCore::ApiUser.last
|
|
24
|
+
api_user.name.should eq "KPCC"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'with invalid attributes' do
|
|
29
|
+
it "rerenders the form and shows error messages" do
|
|
30
|
+
visit assethost.new_a_api_user_path
|
|
31
|
+
click_button 'Save'
|
|
32
|
+
|
|
33
|
+
page.should have_css '.alert.alert-error'
|
|
34
|
+
page.should have_content "can't be blank"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "updating" do
|
|
40
|
+
before do
|
|
41
|
+
@api_user = create :api_user
|
|
42
|
+
visit assethost.edit_a_api_user_path(@api_user)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context 'with valid attributes' do
|
|
46
|
+
it "updates the user" do
|
|
47
|
+
fill_in 'api_user_name', with: "New Name"
|
|
48
|
+
click_button 'Update'
|
|
49
|
+
|
|
50
|
+
@api_user.reload
|
|
51
|
+
@api_user.name.should eq 'New Name'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'with invalid attributes' do
|
|
56
|
+
it 'rerenders the form and shows error messages' do
|
|
57
|
+
fill_in 'api_user_name', with: ""
|
|
58
|
+
click_button "Update"
|
|
59
|
+
|
|
60
|
+
page.should have_css '.alert.alert-error'
|
|
61
|
+
page.should have_content "can't be blank"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe 'deleting' do
|
|
67
|
+
before do
|
|
68
|
+
@api_user = create :api_user
|
|
69
|
+
visit assethost.edit_a_api_user_path(@api_user)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "deletes the record" do
|
|
73
|
+
AssetHostCore::ApiUser.count.should eq 1
|
|
74
|
+
click_link "Delete"
|
|
75
|
+
AssetHostCore::ApiUser.count.should eq 0
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|