media_magick 0.1.0 → 0.1.1
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/.gitignore +2 -1
- data/.travis.yml +7 -3
- data/CHANGELOG.md +92 -1
- data/README.md +1 -1
- data/app/assets/javascripts/media_magick/plupload_it.js +30 -9
- data/app/controllers/media_magick/attach_controller.rb +16 -28
- data/app/helpers/media_magick/application_helper.rb +46 -5
- data/app/views/_file.html.erb +2 -2
- data/app/views/_image.html.erb +3 -3
- data/app/views/_upload.html.erb +3 -10
- data/app/views/_video.html.erb +8 -0
- data/gemfiles/mongoid-3.0.gemfile +7 -0
- data/lib/media_magick.rb +1 -5
- data/lib/media_magick/controller/helpers.rb +20 -0
- data/lib/media_magick/engine.rb +1 -1
- data/lib/media_magick/model.rb +41 -48
- data/lib/media_magick/version.rb +1 -1
- data/lib/media_magick/video/parser.rb +62 -0
- data/media_magick.gemspec +8 -4
- data/spec/controllers/media_magick/attach_controller_spec.rb +12 -11
- data/spec/dummy/app/assets/javascripts/application.js +5 -0
- data/spec/dummy/app/assets/javascripts/posts.js +2 -0
- data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +83 -0
- data/spec/dummy/app/helpers/posts_helper.rb +2 -0
- data/spec/dummy/app/models/album.rb +3 -1
- data/spec/dummy/app/models/post.rb +10 -0
- data/spec/dummy/app/models/track.rb +1 -0
- data/spec/dummy/app/uploaders/post_uploader.rb +17 -0
- data/spec/dummy/app/views/posts/_form.html.erb +47 -0
- data/spec/dummy/app/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/views/posts/index.html.erb +25 -0
- data/spec/dummy/app/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/views/posts/show.html.erb +15 -0
- data/spec/dummy/app/views/users/index.html.erb +1 -1
- data/spec/dummy/config/mongoid.yml +65 -17
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/helpers/media_magick/application_helper_spec.rb +90 -27
- data/spec/integration/images_spec.rb +1 -1
- data/spec/lib/media_magick/controller/helper_spec.rb +37 -0
- data/spec/lib/media_magick/model_spec.rb +41 -9
- data/spec/lib/media_magick/video/parser_spec.rb +67 -0
- data/spec/spec_helper.rb +11 -8
- data/spec/views/_upload.html.erb_spec.rb +26 -0
- metadata +76 -21
- data/.rvmrc +0 -1
- data/spec/dummy/app/helpers/users_helper.rb +0 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing posts</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Title</th>
|
6
|
+
<th>Text</th>
|
7
|
+
<th></th>
|
8
|
+
<th></th>
|
9
|
+
<th></th>
|
10
|
+
</tr>
|
11
|
+
|
12
|
+
<% @posts.each do |post| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= post.title %></td>
|
15
|
+
<td><%= post.text %></td>
|
16
|
+
<td><%= link_to 'Show', post %></td>
|
17
|
+
<td><%= link_to 'Edit', edit_post_path(post) %></td>
|
18
|
+
<td><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br />
|
24
|
+
|
25
|
+
<%= link_to 'New Post', new_post_path %>
|
@@ -13,7 +13,7 @@
|
|
13
13
|
<td><%= user.name %></td>
|
14
14
|
<td><%= link_to 'Show', user %></td>
|
15
15
|
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
16
|
-
<td><%= link_to 'Destroy', user, confirm: 'Are you sure?'
|
16
|
+
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
17
17
|
</tr>
|
18
18
|
<% end %>
|
19
19
|
</table>
|
@@ -1,20 +1,68 @@
|
|
1
1
|
development:
|
2
|
-
|
3
|
-
|
2
|
+
# Configure available database sessions. (required)
|
3
|
+
sessions:
|
4
|
+
# Defines the default session. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: dummy_development
|
9
|
+
# Provides the hosts the default session can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
options:
|
14
|
+
# Change whether the session persists in safe mode by default.
|
15
|
+
# (default: false)
|
16
|
+
# safe: false
|
4
17
|
|
18
|
+
# Change the default consistency model to :eventual or :strong.
|
19
|
+
# :eventual will send reads to secondaries, :strong sends everything
|
20
|
+
# to master. (default: :eventual)
|
21
|
+
consistency: :strong
|
22
|
+
# Configure Mongoid specific options. (optional)
|
23
|
+
options:
|
24
|
+
# Configuration for whether or not to allow access to fields that do
|
25
|
+
# not have a field definition on the model. (default: true)
|
26
|
+
# allow_dynamic_fields: true
|
27
|
+
|
28
|
+
# Enable the identity map, needed for eager loading. (default: false)
|
29
|
+
# identity_map_enabled: false
|
30
|
+
|
31
|
+
# Includes the root model name in json serialization. (default: false)
|
32
|
+
# include_root_in_json: false
|
33
|
+
|
34
|
+
# Include the _type field in serializaion. (default: false)
|
35
|
+
# include_type_for_serialization: false
|
36
|
+
|
37
|
+
# Preload all models in development, needed when models use
|
38
|
+
# inheritance. (default: false)
|
39
|
+
# preload_models: false
|
40
|
+
|
41
|
+
# Protect id and type from mass assignment. (default: true)
|
42
|
+
# protect_sensitive_fields: true
|
43
|
+
|
44
|
+
# Raise an error when performing a #find and the document is not found.
|
45
|
+
# (default: true)
|
46
|
+
# raise_not_found_error: true
|
47
|
+
|
48
|
+
# Raise an error when defining a scope with the same name as an
|
49
|
+
# existing method. (default: false)
|
50
|
+
# scope_overwrite_exception: false
|
51
|
+
|
52
|
+
# Skip the database version check, used when connecting to a db without
|
53
|
+
# admin access. (default: false)
|
54
|
+
# skip_version_check: false
|
55
|
+
|
56
|
+
# User Active Support's time zone in conversions. (default: true)
|
57
|
+
# use_activesupport_time_zone: true
|
58
|
+
|
59
|
+
# Ensure all times are UTC in the app side. (default: false)
|
60
|
+
# use_utc: false
|
5
61
|
test:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
username: <%= ENV['MONGOID_USERNAME'] %>
|
14
|
-
password: <%= ENV['MONGOID_PASSWORD'] %>
|
15
|
-
database: <%= ENV['MONGOID_DATABASE'] %>
|
16
|
-
# slaves:
|
17
|
-
# - host: slave1.local
|
18
|
-
# port: 27018
|
19
|
-
# - host: slave2.local
|
20
|
-
# port: 27019
|
62
|
+
sessions:
|
63
|
+
default:
|
64
|
+
database: dummy_test
|
65
|
+
hosts:
|
66
|
+
- localhost:27017
|
67
|
+
options:
|
68
|
+
consistency: :strong
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -3,45 +3,108 @@ require 'spec_helper'
|
|
3
3
|
describe MediaMagick do
|
4
4
|
describe ApplicationHelper do
|
5
5
|
describe 'attachmentUploader' do
|
6
|
-
|
7
|
-
|
6
|
+
let(:album) { Album.new }
|
7
|
+
|
8
|
+
before do
|
8
9
|
album.stub(id: '12345678')
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
def conteiner_html(model, relation, data_attributes, &block)
|
13
|
+
content_tag(:div, nil, id: "#{model}-#{relation}", class: "attachmentUploader #{relation}", data: data_attributes) do
|
14
|
+
class_eval(&block) if block_given?
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
context 'without block' do
|
19
|
+
before do
|
20
|
+
album.stub(id: '12345678')
|
17
21
|
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
22
|
+
helper.stub(:render)
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
it 'should create a div with data attributes' do
|
26
|
+
helper.attachment_container(album, :photos).should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/image' }))
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
it 'should render /upload partial' do
|
30
|
+
helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: {}, partial: '/image')
|
28
31
|
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
+
helper.attachment_container(album, :photos)
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
context 'using partials' do
|
36
|
+
it 'should create a div with data-partial attributes' do
|
37
|
+
helper.attachment_container(album, :photos, partial: 'albums/photo').should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: 'albums/photo'}))
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
it 'should include partial option on data attributes' do
|
41
|
+
helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: {}, partial: 'albums/photo')
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
helper.attachment_container(album, :photos, partial: 'albums/photo')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'partial for images' do
|
48
|
+
it 'should create a div with data-partial attributes' do
|
49
|
+
helper.attachment_container(album, :photos, as: 'file').should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/file'}))
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should include partial option on data attributes' do
|
53
|
+
helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: {}, partial: '/file')
|
54
|
+
|
55
|
+
helper.attachment_container(album, :photos, as: 'file')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'embbeded models' do
|
60
|
+
let(:track) { album.tracks.new }
|
61
|
+
|
62
|
+
before do
|
63
|
+
track.stub(id: '87654321')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should create a div with data-embedded-in-id and data-embedded-in-model attributes' do
|
67
|
+
helper.attachment_container(track, :files, embedded_in: album).should eq(conteiner_html('track', 'files', { id: 87654321, model: 'Track', embedded_in_id: 12345678, embedded_in_model: 'Album', relation: 'files', partial: '/image'}))
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should render /upload partial' do
|
71
|
+
helper.should_receive(:render).with('/upload', model: track, relations: :files, newAttachments: {}, loadedAttachments: {}, partial: '/image')
|
72
|
+
|
73
|
+
helper.attachment_container(track, :files, embedded_in: album)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'customizing newAttachments element' do
|
78
|
+
it 'should create a div with data attributes' do
|
79
|
+
helper.attachment_container(album, :photos, newAttachments: { class: 'thumbnails' }).should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/image' }))
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should render /upload partial with newAttachments attributes' do
|
83
|
+
helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: { class: 'thumbnails' }, loadedAttachments: {}, partial: '/image')
|
84
|
+
|
85
|
+
helper.attachment_container(album, :photos, newAttachments: { class: 'thumbnails' })
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'customizing loadedAttachments element' do
|
90
|
+
it 'should create a div with data attributes' do
|
91
|
+
helper.attachment_container(album, :photos, loadedAttachments: { class: 'span3' }).should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/image' }))
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should render /upload partial with loadedAttachments attributes' do
|
95
|
+
helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: { class: 'span3' }, partial: '/image')
|
96
|
+
|
97
|
+
helper.attachment_container(album, :photos, loadedAttachments: { class: 'span3' })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with block' do
|
103
|
+
it 'should create a div with data attributes and content inside' do
|
104
|
+
expected = conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/image' }) { 'template here' }
|
42
105
|
|
43
|
-
|
44
|
-
|
106
|
+
helper.attachment_container(album, :photos) { 'template here' }.should eq(expected)
|
107
|
+
end
|
45
108
|
end
|
46
109
|
end
|
47
110
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MediaMagick::Controller::Helpers do
|
4
|
+
before do
|
5
|
+
@controller = Class.new
|
6
|
+
@controller.extend MediaMagick::Controller::Helpers
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "getting doc by params" do
|
10
|
+
before do
|
11
|
+
@track = Track.new
|
12
|
+
@album = Album.create(tracks: [@track])
|
13
|
+
end
|
14
|
+
|
15
|
+
context "document is embedded" do
|
16
|
+
it "should get parent by params" do
|
17
|
+
params = {
|
18
|
+
:embedded_in_model => "album",
|
19
|
+
:embedded_in_id => "#{@album.id.to_s}",
|
20
|
+
:model => "track",
|
21
|
+
:model_id => "#{@track.id.to_s}"
|
22
|
+
}
|
23
|
+
@controller.find_doc_by_params(params).should eq(@track)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "document is root" do
|
28
|
+
it "should get parent by params" do
|
29
|
+
params = {
|
30
|
+
:model => "album",
|
31
|
+
:model_id => "#{@album.id.to_s}"
|
32
|
+
}
|
33
|
+
@controller.find_doc_by_params(params).should eq(@album)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -8,11 +8,11 @@ describe MediaMagick::Model do
|
|
8
8
|
@klass = User
|
9
9
|
end
|
10
10
|
|
11
|
-
it "should includes .attaches_many" do
|
11
|
+
it "should includes .attaches_many" do
|
12
12
|
@klass.should respond_to(:attaches_many)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "should includes .attaches_one" do
|
15
|
+
it "should includes .attaches_one" do
|
16
16
|
@klass.should respond_to(:attaches_one)
|
17
17
|
end
|
18
18
|
end
|
@@ -23,10 +23,6 @@ describe MediaMagick::Model do
|
|
23
23
|
@instance = @klass.new
|
24
24
|
end
|
25
25
|
|
26
|
-
it 'should create a "has_many" relationship with photos' do
|
27
|
-
@klass.relations['files'].relation.should eq(Mongoid::Relations::Referenced::Many)
|
28
|
-
end
|
29
|
-
|
30
26
|
it 'should create a "embeds_many" relationship with photos' do
|
31
27
|
@klass.relations['photos'].relation.should eq(Mongoid::Relations::Embedded::Many)
|
32
28
|
end
|
@@ -42,6 +38,42 @@ describe MediaMagick::Model do
|
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
41
|
+
describe 'allow_videos' do
|
42
|
+
let(:album) { Album.create }
|
43
|
+
subject { album.photos_and_videos.create }
|
44
|
+
|
45
|
+
it 'should include type field' do
|
46
|
+
subject.fields.should include('type')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should include video field' do
|
50
|
+
subject.fields.should include('video')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should accept youtube videos' do
|
54
|
+
video = album.photos_and_videos.create(video: 'youtube.com/watch?v=FfUHkPf9D9k')
|
55
|
+
|
56
|
+
video.type.should eq('video')
|
57
|
+
|
58
|
+
video.url.should eq("/uploads/album_photos_and_videos/photos_and_video/#{video.id}/FfUHkPf9D9k.jpg")
|
59
|
+
video.thumb.url.should eq("/uploads/album_photos_and_videos/photos_and_video/#{video.id}/thumb_FfUHkPf9D9k.jpg")
|
60
|
+
video.source.should eq('<iframe width="560" height="315" src="http://www.youtube.com/embed/FfUHkPf9D9k" frameborder="0" allowfullscreen></iframe>')
|
61
|
+
|
62
|
+
video.source(width: 156, height: 88).should eq('<iframe width="156" height="88" src="http://www.youtube.com/embed/FfUHkPf9D9k" frameborder="0" allowfullscreen></iframe>')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should accept vimeo videos' do
|
66
|
+
video = album.photos_and_videos.create(video: 'vimeo.com/43401461')
|
67
|
+
|
68
|
+
video.type.should eq('video')
|
69
|
+
|
70
|
+
video.url.should eq("/uploads/album_photos_and_videos/photos_and_video/#{video.id}/43401461.jpg")
|
71
|
+
video.thumb.url.should eq("/uploads/album_photos_and_videos/photos_and_video/#{video.id}/thumb_43401461.jpg")
|
72
|
+
video.source.should eq('<iframe src="http://player.vimeo.com/video/43401461?title=0&byline=0&portrait=0" width="500" height="341" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>')
|
73
|
+
video.source(width: 156, height: 88).should eq('<iframe src="http://player.vimeo.com/video/43401461?title=0&byline=0&portrait=0" width="156" height="88" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
45
77
|
describe '#photos' do
|
46
78
|
subject { @instance.photos.new }
|
47
79
|
|
@@ -56,7 +88,7 @@ describe MediaMagick::Model do
|
|
56
88
|
end
|
57
89
|
|
58
90
|
it "should be ordered by ascending priority" do
|
59
|
-
@instance = @klass.
|
91
|
+
@instance = @klass.create
|
60
92
|
|
61
93
|
photo2 = @instance.photos.create(priority: 1)
|
62
94
|
photo1 = @instance.photos.create(priority: 0)
|
@@ -125,8 +157,8 @@ describe MediaMagick::Model do
|
|
125
157
|
@klass.attaches_one(:image) do
|
126
158
|
def test_method; end
|
127
159
|
end
|
128
|
-
|
129
|
-
@instance.build_image.should respond_to(:test_method)
|
160
|
+
|
161
|
+
@instance.build_image.should respond_to(:test_method)
|
130
162
|
end
|
131
163
|
end
|
132
164
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MediaMagick::Video::Parser do
|
4
|
+
describe 'youtube' do
|
5
|
+
describe 'valid?' do
|
6
|
+
context 'with a valid url' do
|
7
|
+
subject { MediaMagick::Video::Parser.new('youtube.com/watch?v=FfUHkPf9D9k') }
|
8
|
+
|
9
|
+
it { should be_valid }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with a invalid url' do
|
13
|
+
subject { MediaMagick::Video::Parser.new('youtube.com') }
|
14
|
+
|
15
|
+
it { should_not be_valid }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_image' do
|
20
|
+
it 'should return a file with video image' do
|
21
|
+
video = MediaMagick::Video::Parser.new('youtube.com/watch?v=FfUHkPf9D9k')
|
22
|
+
|
23
|
+
video.to_image.should be_instance_of(File)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#to_html' do
|
28
|
+
it 'should return video html' do
|
29
|
+
video = MediaMagick::Video::Parser.new('youtube.com/watch?v=FfUHkPf9D9k')
|
30
|
+
|
31
|
+
video.to_html.should eq('<iframe width="560" height="315" src="http://www.youtube.com/embed/FfUHkPf9D9k" frameborder="0" allowfullscreen></iframe>')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'vimeo' do
|
37
|
+
describe 'valid?' do
|
38
|
+
context 'with a valid url' do
|
39
|
+
subject { MediaMagick::Video::Parser.new('vimeo.com/44539044') }
|
40
|
+
|
41
|
+
it { should be_valid }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with a invalid url' do
|
45
|
+
subject { MediaMagick::Video::Parser.new('vimeo.com') }
|
46
|
+
|
47
|
+
it { should_not be_valid }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#to_image' do
|
52
|
+
it 'should return a file with video image' do
|
53
|
+
video = MediaMagick::Video::Parser.new('vimeo.com/44539044')
|
54
|
+
|
55
|
+
video.to_image.should be_instance_of(File)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#to_html' do
|
60
|
+
it 'should return video html' do
|
61
|
+
video = MediaMagick::Video::Parser.new('vimeo.com/44539044')
|
62
|
+
|
63
|
+
video.to_html.should eq('<iframe src="http://player.vimeo.com/video/44539044?title=0&byline=0&portrait=0" width="500" height="341" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|