media_magick 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +18 -0
- data/app/assets/images/media_magick/.gitkeep +0 -0
- data/app/assets/javascripts/media_magick/application.js +15 -0
- data/app/assets/javascripts/media_magick/plupload_it.js +135 -0
- data/app/assets/javascripts/media_magick/toggleSortable.js +71 -0
- data/app/assets/stylesheets/media_magick/application.css +13 -0
- data/app/controllers/media_magick/application_controller.rb +4 -0
- data/app/controllers/media_magick/attach_controller.rb +50 -0
- data/app/helpers/media_magick/application_helper.rb +13 -0
- data/app/views/_file.html.erb +4 -0
- data/app/views/_image.html.erb +4 -0
- data/app/views/_upload.html.erb +17 -0
- data/app/views/layouts/media_magick/application.html.erb +14 -0
- data/config/locales/en.yml +5 -0
- data/config/locales/pt-BR.yml +8 -0
- data/config/routes.rb +6 -0
- data/lib/carrierwave/mongoid.rb +65 -0
- data/lib/media_magick/attachment_uploader.rb +46 -0
- data/lib/media_magick/engine.rb +9 -0
- data/lib/media_magick/model.rb +39 -0
- data/lib/media_magick/version.rb +3 -0
- data/lib/media_magick.rb +10 -0
- data/lib/tasks/media_magick_tasks.rake +4 -0
- data/media_magick.gemspec +28 -0
- data/script/rails +8 -0
- data/spec/controllers/media_magick/attach_controller_spec.rb +59 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/album.rb +14 -0
- data/spec/dummy/app/models/product.rb +9 -0
- data/spec/dummy/app/uploaders/picture_uploader.rb +55 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/mongoid.yml +20 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/media_magick/application_helper_spec.rb +29 -0
- data/spec/integration/images_spec.rb +47 -0
- data/spec/lib/media_magick/model_spec.rb +80 -0
- data/spec/routing/attach_spec.rb +24 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/fixtures/nu.jpg +0 -0
- data/spec/support/fixtures/nu.txt +1 -0
- metadata +319 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Do not compress assets
|
26
|
+
config.assets.compress = false
|
27
|
+
|
28
|
+
# Expands the lines which load the assets
|
29
|
+
config.assets.debug = true
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to Rails.root.join("public/assets")
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Prepend all log lines with the following tags
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
+
|
39
|
+
# Use a different logger for distributed setups
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
+
|
42
|
+
# Use a different cache store in production
|
43
|
+
# config.cache_store = :mem_cache_store
|
44
|
+
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
+
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
+
# config.assets.precompile += %w( search.js )
|
50
|
+
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable threaded mode
|
55
|
+
# config.threadsafe!
|
56
|
+
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
59
|
+
config.i18n.fallbacks = true
|
60
|
+
|
61
|
+
# Send deprecation notices to registered listeners
|
62
|
+
config.active_support.deprecation = :notify
|
63
|
+
|
64
|
+
# Log the query plan for queries taking more than this (works
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Print deprecation notices to the stderr
|
33
|
+
config.active_support.deprecation = :stderr
|
34
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
+
# inflect.acronym 'RESTful'
|
15
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '0a97a9eaaf07443725e400689e33d3a675a4a4163a52a224376a983d0aa524e22c5b69600ec465b0bebb588bddb40534170068d87af2934730ad9b47320cb52f'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
development:
|
2
|
+
host: localhost
|
3
|
+
database: dummy_development
|
4
|
+
|
5
|
+
test:
|
6
|
+
host: localhost
|
7
|
+
database: dummy_test
|
8
|
+
|
9
|
+
# set these environment variables on your prod server
|
10
|
+
production:
|
11
|
+
host: <%= ENV['MONGOID_HOST'] %>
|
12
|
+
port: <%= ENV['MONGOID_PORT'] %>
|
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
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MediaMagick do
|
4
|
+
describe ApplicationHelper do
|
5
|
+
describe 'attachmentUploader' do
|
6
|
+
it 'should create a div.attachmentUploader.photos' do
|
7
|
+
album = Album.new
|
8
|
+
album.stub(id: '12345678')
|
9
|
+
|
10
|
+
helper.attachment_container(album, :photos) do
|
11
|
+
end.should eq('<div class="attachmentUploader photos" data-id="12345678" data-model="Album" data-relation="photos" id="album-photos"></div>')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should renders default partial if block is not given' do
|
15
|
+
photo = AlbumPhotos.new
|
16
|
+
photo.stub(filename: 'photo.jpg', url: 'url/photo.jpg')
|
17
|
+
|
18
|
+
file = AlbumFiles.new
|
19
|
+
file.stub(filename: 'file.pdf', url: 'url/file.pdf')
|
20
|
+
|
21
|
+
album = Album.new(photos: [photo], files: [file])
|
22
|
+
album.stub(id: '12345678')
|
23
|
+
|
24
|
+
helper.attachment_container(album, :photos).should match(/url\/photo.jpg/)
|
25
|
+
helper.attachment_container(album, :files).should match(/url\/file.pdf/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Images' do
|
4
|
+
let(:image_file) { File.new("#{File.expand_path('../..', __FILE__)}/support/fixtures/nu.jpg") }
|
5
|
+
let(:non_image_file) { File.new("#{File.expand_path('../..', __FILE__)}/support/fixtures/nu.txt") }
|
6
|
+
|
7
|
+
it 'should save the image on mongoid document' do
|
8
|
+
product = Product.create
|
9
|
+
product.images.create(image: image_file)
|
10
|
+
|
11
|
+
product.reload.images.first.filename.should eq('nu.jpg')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should save the file on mongoid document' do
|
15
|
+
product = Product.create
|
16
|
+
file = product.files.create(file: non_image_file)
|
17
|
+
|
18
|
+
product.reload.files.first.url.should eq("/uploads/product_files/file/#{file.id}/nu.txt")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should access Uploader methods from relation class' do
|
22
|
+
product = Product.create
|
23
|
+
image = product.images.create(image: image_file)
|
24
|
+
|
25
|
+
image.url.should eq("/uploads/product_images/image/#{image.id}/nu.jpg")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should access filename from relation class' do
|
29
|
+
product = Product.create
|
30
|
+
product.images.create(image: image_file)
|
31
|
+
|
32
|
+
product.reload.images.first.filename.should eq('nu.jpg')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should add fields on relation class' do
|
36
|
+
product = Product.create
|
37
|
+
product.images.create(image: image_file, tags: ['ruby', 'guru'])
|
38
|
+
|
39
|
+
product.reload.images.first.tags.should eq(['ruby', 'guru'])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should create version of images' do
|
43
|
+
product = Product.create
|
44
|
+
image = product.images.create(image: image_file)
|
45
|
+
product.reload.images.first.thumb.url.should eq("/uploads/product_images/image/#{image.id}/thumb_nu.jpg")
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe MediaMagick::Model do
|
6
|
+
describe '.attachs_many' do
|
7
|
+
before(:all) do
|
8
|
+
@class = Album
|
9
|
+
@instance = @class.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should create a "embeds_many" relationship with photos' do
|
13
|
+
@class.relations['photos'].relation.should eq(Mongoid::Relations::Embedded::Many)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create a relationship with photos through AlbumPhotos model' do
|
17
|
+
@class.relations['photos'].class_name.should eq('AlbumPhotos')
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "naming relations" do
|
21
|
+
it "should transform related compound name classes to camel case" do
|
22
|
+
@instance.should respond_to(:compound_name_files)
|
23
|
+
@instance.compound_name_files.build.class.should eq(AlbumCompoundNameFiles)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#photos' do
|
28
|
+
subject { @instance.photos.new }
|
29
|
+
|
30
|
+
it { should be_an_instance_of(AlbumPhotos) }
|
31
|
+
|
32
|
+
it 'should perform a block in the context of the class' do
|
33
|
+
@class.attachs_many(:documents) do
|
34
|
+
def test_method
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@instance.documents.new.should respond_to(:test_method)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be ordered by ascending priority" do
|
42
|
+
@instance = @class.new
|
43
|
+
|
44
|
+
photo2 = @instance.photos.create(priority: 1)
|
45
|
+
photo1 = @instance.photos.create(priority: 0)
|
46
|
+
|
47
|
+
@instance.reload.photos.should == [photo1, photo2]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should respond to priority" do
|
51
|
+
subject.fields.include?(:priority)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have priority 0 as default" do
|
55
|
+
subject.priority.should be(0)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#photo' do
|
59
|
+
subject { @instance.photos.new.photo }
|
60
|
+
|
61
|
+
it { should be_a_kind_of(CarrierWave::Uploader::Base) }
|
62
|
+
|
63
|
+
describe 'custom_uploader' do
|
64
|
+
before(:all) do
|
65
|
+
class AmazonS3Uploader < CarrierWave::Uploader::Base
|
66
|
+
storage :file
|
67
|
+
end
|
68
|
+
|
69
|
+
@class.attachs_many :musics, uploader: AmazonS3Uploader
|
70
|
+
end
|
71
|
+
|
72
|
+
subject { @instance.musics.new }
|
73
|
+
|
74
|
+
it { should respond_to(:music) }
|
75
|
+
it { subject.music.should be_a_instance_of(AmazonS3Uploader) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'routes for Attach' do
|
4
|
+
it 'routes /upload to create action' do
|
5
|
+
get('/upload').should route_to('media_magick/attach#create')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'routes /remove to destroy action' do
|
9
|
+
get('/remove').should route_to('media_magick/attach#destroy')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'routes /update_priority to update_priority action' do
|
13
|
+
get('/update_priority').should route_to('media_magick/attach#update_priority')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'routes /recreate_versions to recreate_versions action' do
|
17
|
+
get('/recreate_versions').should route_to('media_magick/attach#recreate_versions')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'routes recreate_versions_path to recreate_versions action' do
|
21
|
+
get(recreate_versions_path).should route_to('media_magick/attach#recreate_versions')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start 'rails'
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
6
|
+
require 'rspec/rails'
|
7
|
+
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
+
# in spec/support/ and its subdirectories.
|
10
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
# ## Mock Framework
|
14
|
+
#
|
15
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
16
|
+
#
|
17
|
+
# config.mock_with :mocha
|
18
|
+
# config.mock_with :flexmock
|
19
|
+
# config.mock_with :rr
|
20
|
+
|
21
|
+
# If true, the base class of anonymous controllers will be inferred
|
22
|
+
# automatically. This will be the default behavior in future versions of
|
23
|
+
# rspec-rails.
|
24
|
+
config.infer_base_class_for_anonymous_controllers = false
|
25
|
+
|
26
|
+
config.before :suite do
|
27
|
+
Mongoid.configure do |config|
|
28
|
+
config.master = Mongo::Connection.new.db('media_magick')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after :each do
|
33
|
+
Mongoid.master.collections.select { |c| c.name !~ /^system/ }.each(&:drop)
|
34
|
+
end
|
35
|
+
|
36
|
+
config.after :suite do
|
37
|
+
Mongoid.master.connection.drop_database('media_magick')
|
38
|
+
Mongoid.master.connection.close
|
39
|
+
end
|
40
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
nu design
|