asset_host_core 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- 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
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::AssetHost do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it "can load from an api url" do
|
6
|
+
assethost_root = "#{Rails.application.config.assethost.server}#{AssetHostCore::Engine.mounted_path}"
|
7
|
+
|
8
|
+
asset = create :asset
|
9
|
+
loader = AssetHostCore::Loaders::AssetHost.build_from_url("#{assethost_root}/api/assets/#{asset.id}")
|
10
|
+
loader.should_not eq nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can load from asset's actual URL" do
|
14
|
+
asset = create :asset, url: "http://a.scpr.org/i/b0d21881d4563e38bacbf068d27afc04/59661-small.jpg"
|
15
|
+
loader = AssetHostCore::Loaders::AssetHost.build_from_url(asset.url)
|
16
|
+
loader.should_not eq nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the URL doesn't match" do
|
20
|
+
loader = AssetHostCore::Loaders::AssetHost.build_from_url("http://nope.com")
|
21
|
+
loader.should eq nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
describe '#load' do
|
27
|
+
it "just finds the asset from the database and returns it" do
|
28
|
+
asset = create :asset, url: "http://a.scpr.org/i/b0d21881d4563e38bacbf068d27afc04/59661-small.jpg"
|
29
|
+
loader = AssetHostCore::Loaders::AssetHost.new(id: asset.id, url: asset.url)
|
30
|
+
loader.load.should eq asset
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::Brightcove do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it 'matches a brightcove key' do
|
6
|
+
AssetHostCore::Loaders::Brightcove.build_from_url('brightcove:2396253845001').should be_a AssetHostCore::Loaders::Brightcove
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns nil for invalid url' do
|
10
|
+
AssetHostCore::Loaders::Brightcove.build_from_url('nope.com/nope').should eq nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#load' do
|
15
|
+
before :each do
|
16
|
+
FakeWeb.register_uri(:get, %r{api\.brightcove\.com},
|
17
|
+
content_type: "application/json", body: load_api_response('brightcove/video.json'))
|
18
|
+
|
19
|
+
FakeWeb.register_uri(:get, %r{brightcove\.vo\.llnwd\.net},
|
20
|
+
content_type: "image/jpeg", body: load_image('stars.jpg'))
|
21
|
+
|
22
|
+
@loader = AssetHostCore::Loaders::Brightcove.build_from_url('brightcove:2396253845001')
|
23
|
+
@asset = @loader.load
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates a new asset' do
|
27
|
+
@asset.should be_a AssetHostCore::Asset
|
28
|
+
@asset.persisted?.should eq true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets the native to be a vimeo video' do
|
32
|
+
@asset.native.should be_a AssetHostCore::BrightcoveVideo
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sets the owner' do
|
36
|
+
@asset.owner.should match /KPCC/
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the title' do
|
40
|
+
@asset.title.should match /NEXT/
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets the caption' do
|
44
|
+
@asset.caption.should match /Dark Matter/
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the image' do
|
48
|
+
@asset.image.should be_a Paperclip::Attachment
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::Flickr do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it 'matches flickr urls and returns a new loader' do
|
6
|
+
loader = AssetHostCore::Loaders::Flickr.build_from_url("http://www.flickr.com/photos/kpcc/123")
|
7
|
+
loader.should be_a AssetHostCore::Loaders::Flickr
|
8
|
+
loader.id.should eq "123"
|
9
|
+
|
10
|
+
loader = AssetHostCore::Loaders::Flickr.build_from_url("http://staticflickr.com/999/456_abc")
|
11
|
+
loader.should be_a AssetHostCore::Loaders::Flickr
|
12
|
+
loader.id.should eq "456"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil if the URL doesn't match" do
|
16
|
+
loader = AssetHostCore::Loaders::Flickr.build_from_url("http://nope.nope/nope")
|
17
|
+
loader.should eq nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns nil if flickr key is not set' do
|
21
|
+
AssetHostCore.config.stub(:flickr_api_key) { nil }
|
22
|
+
loader = AssetHostCore::Loaders::Flickr.build_from_url("http://staticflickr.com/999/456_abc")
|
23
|
+
|
24
|
+
loader.should eq nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
describe '#load' do
|
30
|
+
context 'flickr success' do
|
31
|
+
before :each do
|
32
|
+
FakeWeb.register_uri(:get, %r{flickr\.photos\.getInfo},
|
33
|
+
content_type: "application/json", body: load_api_response('flickr/photos_getInfo.json'))
|
34
|
+
|
35
|
+
FakeWeb.register_uri(:get, %r{flickr\.photos\.getSizes},
|
36
|
+
content_type: "application/json", body: load_api_response('flickr/photos_getSizes.json'))
|
37
|
+
|
38
|
+
FakeWeb.register_uri(:get, %r{flickr\.photos\.licenses\.getInfo},
|
39
|
+
content_type: "application/json", body: load_api_response('flickr/photos_licenses_getInfo.json'))
|
40
|
+
|
41
|
+
FakeWeb.register_uri(:get, %r{staticflickr},
|
42
|
+
content_type: "image/jpeg", body: load_image('hat.jpg'))
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it 'gets the image information from flickr' do
|
47
|
+
loader = AssetHostCore::Loaders::Flickr.new(url: "http://staticflickr.com/999/456_abc", id: "456")
|
48
|
+
asset = loader.load
|
49
|
+
|
50
|
+
asset.title.should eq "John's Wayne cowboy hat"
|
51
|
+
asset.caption.should eq "This is a cowboy hat."
|
52
|
+
asset.owner.should eq "AudioVision"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "uses the last size as the source image" do
|
56
|
+
loader = AssetHostCore::Loaders::Flickr.new(url: "http://staticflickr.com/999/456_abc", id: "456")
|
57
|
+
loader.should_receive(:image_file).with("http://farm7.staticflickr.com/6112/6238340909_234e5623a1_o.jpg")
|
58
|
+
loader.load
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'flickr failure' do
|
63
|
+
it "returns nil if photo isn't present" do
|
64
|
+
FakeWeb.register_uri(:get, %r{flickr\.photos\.getInfo},
|
65
|
+
content_type: "application/json", body: {}.to_json)
|
66
|
+
|
67
|
+
loader = AssetHostCore::Loaders::Flickr.new(url: "http://static.flickr.com/999/456_abc", id: "456")
|
68
|
+
loader.load.should eq nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::URL do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it 'returns a loader if the URL is an image' do
|
6
|
+
FakeWeb.register_uri(:get, %r{imgur\.com},
|
7
|
+
body: "raw image", content_type: "image/jpeg")
|
8
|
+
|
9
|
+
loader = AssetHostCore::Loaders::URL.build_from_url("http://imgur.com/a/whatever.jpg")
|
10
|
+
loader.should_not eq nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns nil if the URL is not an image" do
|
14
|
+
FakeWeb.register_uri(:get, %r{news\.com},
|
15
|
+
body: "Not an image!", content_type: "text/html")
|
16
|
+
|
17
|
+
loader = AssetHostCore::Loaders::URL.build_from_url("http://news.com/whatever.html")
|
18
|
+
loader.should eq nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#load' do
|
23
|
+
before :each do
|
24
|
+
FakeWeb.register_uri(:get, %r{imgur\.com},
|
25
|
+
body: load_image('fry.png'), content_type: "image/png")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates and returns an asset' do
|
29
|
+
loader = AssetHostCore::Loaders::URL.build_from_url('http://imgur.com/a/whatever.jpg')
|
30
|
+
asset = loader.load
|
31
|
+
asset.persisted?.should eq true
|
32
|
+
asset.image.file?.should eq true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the filename correctly" do
|
36
|
+
loader = AssetHostCore::Loaders::URL.build_from_url('http://imgur.com/a/whatever.jpg')
|
37
|
+
asset = loader.load
|
38
|
+
|
39
|
+
asset.title.should eq "whatever.jpg"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::Vimeo do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it 'matches a vimeo url' do
|
6
|
+
AssetHostCore::Loaders::Vimeo.build_from_url('http://vimeo.com/29695463').should be_a AssetHostCore::Loaders::Vimeo
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns nil for invalid url' do
|
10
|
+
AssetHostCore::Loaders::Vimeo.build_from_url('nope.com/nope').should eq nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#load' do
|
15
|
+
before :each do
|
16
|
+
FakeWeb.register_uri(:get, %r{vimeo\.com/api},
|
17
|
+
content_type: "application/json", body: load_api_response('vimeo/video.json'))
|
18
|
+
|
19
|
+
FakeWeb.register_uri(:get, %r{b\.vimeocdn\.com},
|
20
|
+
content_type: "image/jpeg", body: load_image('dude.jpg'))
|
21
|
+
|
22
|
+
@loader = AssetHostCore::Loaders::Vimeo.build_from_url('http://vimeo.com/29695463')
|
23
|
+
@asset = @loader.load
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates a new asset' do
|
27
|
+
@asset.should be_a AssetHostCore::Asset
|
28
|
+
@asset.persisted?.should eq true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets the native to be a vimeo video' do
|
32
|
+
@asset.native.should be_a AssetHostCore::VimeoVideo
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sets the owner' do
|
36
|
+
@asset.owner.should match /KPCC/
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the title' do
|
40
|
+
@asset.title.should match /Lebowski/
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets the caption' do
|
44
|
+
@asset.caption.should match /Living Lebowski, Dude/
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the image' do
|
48
|
+
@asset.image.should be_a Paperclip::Attachment
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::Loaders::YouTube do
|
4
|
+
describe '::build_from_url' do
|
5
|
+
it 'matches a youtube URL' do
|
6
|
+
loader = AssetHostCore::Loaders::YouTube.build_from_url('http://www.youtube.com/watch?v=y8Kyi0WNg40')
|
7
|
+
loader.should be_a AssetHostCore::Loaders::YouTube
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not match other stuff' do
|
11
|
+
loader = AssetHostCore::Loaders::YouTube.build_from_url('nope.com/nope')
|
12
|
+
loader.should eq nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#load' do
|
17
|
+
before :each do
|
18
|
+
FakeWeb.register_uri(:get, %r{googleapis\.com/discovery},
|
19
|
+
content_type: "application/json", body: load_api_response('youtube/discovery.json'))
|
20
|
+
|
21
|
+
FakeWeb.register_uri(:get, %r{googleapis\.com/youtube},
|
22
|
+
content_type: "application/json", body: load_api_response('youtube/video.json'))
|
23
|
+
|
24
|
+
FakeWeb.register_uri(:get, %r{i\.ytimg\.com},
|
25
|
+
content_type: "image/jpeg", body: load_image('chipmunk.jpg'))
|
26
|
+
|
27
|
+
@loader = AssetHostCore::Loaders::YouTube.build_from_url('http://www.youtube.com/watch?v=y8Kyi0WNg40?ah-noTrim')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'creates a new asset' do
|
31
|
+
asset = @loader.load
|
32
|
+
asset.should be_a AssetHostCore::Asset
|
33
|
+
asset.persisted?.should eq true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets the native to be a youtube video' do
|
37
|
+
asset = @loader.load
|
38
|
+
asset.native.should be_a AssetHostCore::YoutubeVideo
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the owner' do
|
42
|
+
asset = @loader.load
|
43
|
+
asset.owner.should match /cregets/
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'sets the title' do
|
47
|
+
asset = @loader.load
|
48
|
+
asset.title.should eq "Dramatic Chipmunk"
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets the caption' do
|
52
|
+
asset = @loader.load
|
53
|
+
asset.caption.should match /best 5 second clip/
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'sets the image' do
|
57
|
+
asset = @loader.load
|
58
|
+
asset.image.should be_a Paperclip::Attachment
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'trims letterboxing by default' do
|
62
|
+
loader = AssetHostCore::Loaders::YouTube.build_from_url('http://www.youtube.com/watch?v=y8Kyi0WNg40')
|
63
|
+
Paperclip::Trimmer.should_receive(:make).and_return(load_image('chipmunk.jpg'))
|
64
|
+
loader.load
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'does not trim if requested' do
|
68
|
+
no_trim_loader = AssetHostCore::Loaders::YouTube.build_from_url('http://www.youtube.com/watch?v=y8Kyi0WNg40?ah-noTrim')
|
69
|
+
Paperclip::Trimmer.should_not_receive(:make)
|
70
|
+
no_trim_loader.load
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AssetHostCore::ApiUser do
|
4
|
+
describe '::authenticate' do
|
5
|
+
it "finds the user by auth token" do
|
6
|
+
user = create :api_user, auth_token: "12345"
|
7
|
+
|
8
|
+
AssetHostCore::ApiUser.authenticate("12345").should eq user
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not allow inactive users' do
|
12
|
+
user = create :api_user, auth_token: "12345", is_active: false
|
13
|
+
AssetHostCore::ApiUser.authenticate("12345").should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'updates the last_authenticated column' do
|
17
|
+
user = create :api_user, auth_token: "12345"
|
18
|
+
AssetHostCore::ApiUser.authenticate("12345")
|
19
|
+
user.reload.last_authenticated.should be > 1.minute.ago
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "auth token generation" do
|
24
|
+
let(:api_user) { build :api_user }
|
25
|
+
subject { api_user }
|
26
|
+
|
27
|
+
context 'before save' do
|
28
|
+
its(:auth_token) { should be_blank }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'on create' do
|
32
|
+
before { subject.save! }
|
33
|
+
its(:auth_token) { should be_present }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe '#may?' do
|
39
|
+
let(:api_user) { create :api_user }
|
40
|
+
|
41
|
+
context "when the user has the permission" do
|
42
|
+
subject { api_user }
|
43
|
+
|
44
|
+
before :each do
|
45
|
+
api_user.permissions.create(
|
46
|
+
:ability => "read",
|
47
|
+
:resource => "AssetHostCore::Asset"
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
it { should be_allowed_to :read, "AssetHostCore::Asset" }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when the user does not have the permission" do
|
55
|
+
it { should_not be_allowed_to :read, "AssetHostCore::Asset" }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|