refinerycms-images 0.9.9.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/app/controllers/admin/images_controller.rb +108 -0
- data/app/helpers/admin/images_helper.rb +27 -0
- data/app/models/image.rb +72 -0
- data/app/views/admin/images/_existing_image.html.erb +73 -0
- data/app/views/admin/images/_form.html.erb +54 -0
- data/app/views/admin/images/_grid_view.html.erb +19 -0
- data/app/views/admin/images/_images.html.erb +2 -0
- data/app/views/admin/images/_list_view.html.erb +10 -0
- data/app/views/admin/images/_list_view_image.html.erb +17 -0
- data/app/views/admin/images/edit.html.erb +1 -0
- data/app/views/admin/images/index.html.erb +38 -0
- data/app/views/admin/images/insert.html.erb +47 -0
- data/app/views/admin/images/new.html.erb +1 -0
- data/config/locales/cs.yml +41 -0
- data/config/locales/da.yml +41 -0
- data/config/locales/de.yml +41 -0
- data/config/locales/el.yml +41 -0
- data/config/locales/en.yml +41 -0
- data/config/locales/es.yml +40 -0
- data/config/locales/fr.yml +41 -0
- data/config/locales/it.yml +47 -0
- data/config/locales/lolcat.yml +41 -0
- data/config/locales/lt.yml +41 -0
- data/config/locales/lv.yml +41 -0
- data/config/locales/nb.yml +42 -0
- data/config/locales/nl.yml +40 -0
- data/config/locales/pl.yml +42 -0
- data/config/locales/pt-BR.yml +42 -0
- data/config/locales/rs.yml +42 -0
- data/config/locales/ru.yml +41 -0
- data/config/locales/sl.yml +40 -0
- data/config/locales/sv.yml +41 -0
- data/config/locales/vi.yml +41 -0
- data/config/locales/zh-CN.yml +41 -0
- data/config/locales/zh-TW.yml +41 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20100913234707_create_refinerycms_images_schema.rb +23 -0
- data/features/manage_images.feature +49 -0
- data/features/step_definitions/image_steps.rb +40 -0
- data/features/support/factories.rb +5 -0
- data/features/support/paths.rb +17 -0
- data/features/uploads/beach.jpeg +0 -0
- data/features/uploads/id-rather-be-here.jpg +0 -0
- data/features/uploads/refinery_is_awesome.txt +1 -0
- data/lib/gemspec.rb +35 -0
- data/lib/generators/refinerycms_images_generator.rb +8 -0
- data/lib/refinerycms-images.rb +69 -0
- data/license.md +21 -0
- data/readme.md +34 -0
- data/refinerycms-images.gemspec +97 -0
- data/spec/models/image_spec.rb +87 -0
- data/spec/uploads/beach.jpeg +0 -0
- metadata +142 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
::Refinery::Application.routes.draw do
|
2
|
+
|
3
|
+
match '/system/images/*dragonfly', :to => Dragonfly[:images]
|
4
|
+
|
5
|
+
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
6
|
+
resources :images, :except => :show do
|
7
|
+
collection do
|
8
|
+
get :insert
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateRefinerycmsImagesSchema < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table ::Image.table_name, :force => true do |t|
|
4
|
+
t.string "image_mime_type"
|
5
|
+
t.string "image_name"
|
6
|
+
t.integer "image_size"
|
7
|
+
t.integer "image_width"
|
8
|
+
t.integer "image_height"
|
9
|
+
t.datetime "created_at"
|
10
|
+
t.datetime "updated_at"
|
11
|
+
t.string "image_uid"
|
12
|
+
t.string "image_ext"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
[::Image].reject{|m|
|
18
|
+
!(defined?(m) and m.respond_to?(:table_name))
|
19
|
+
}.each do |model|
|
20
|
+
drop_table model.table_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
@refinerycms @images @images-manage
|
2
|
+
Feature: Manage Images
|
3
|
+
In order to control the content on my website
|
4
|
+
As an administrator
|
5
|
+
I want to create and manage images
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I am a logged in refinery user
|
9
|
+
And I have no images
|
10
|
+
|
11
|
+
@images-valid @valid
|
12
|
+
Scenario: Create Valid Image
|
13
|
+
When I go to the list of images
|
14
|
+
And I follow "Add new image"
|
15
|
+
And I attach the image at "beach.jpeg"
|
16
|
+
And I press "Save"
|
17
|
+
Then the image "beach.jpeg" should have uploaded successfully
|
18
|
+
And I should have 1 image
|
19
|
+
And the image should have size "254718"
|
20
|
+
And the image should have width "500"
|
21
|
+
And the image should have height "375"
|
22
|
+
And the image should have mime_type "image/jpeg"
|
23
|
+
|
24
|
+
@images-invalid @invalid
|
25
|
+
Scenario: Create Invalid Image (format)
|
26
|
+
When I go to the list of images
|
27
|
+
And I follow "Add new image"
|
28
|
+
And I upload the image at "refinery_is_awesome.txt"
|
29
|
+
And I press "Save"
|
30
|
+
Then I should not see "successfully added"
|
31
|
+
And I should have 0 images
|
32
|
+
|
33
|
+
@images-edit @edit
|
34
|
+
Scenario: Edit Existing Image
|
35
|
+
When I upload the image at "beach.jpeg"
|
36
|
+
And I go to the list of images
|
37
|
+
And I follow "Edit this image"
|
38
|
+
And I attach the image at "id-rather-be-here.jpg"
|
39
|
+
And I press "Save"
|
40
|
+
Then I should see "'Id Rather Be Here' was successfully updated."
|
41
|
+
And I should have 1 image
|
42
|
+
|
43
|
+
@images-delete @delete
|
44
|
+
Scenario: Delete Image
|
45
|
+
When I upload the image at "beach.jpeg"
|
46
|
+
When I go to the list of images
|
47
|
+
And I follow "Remove this image forever"
|
48
|
+
Then I should see "'Beach' was successfully removed."
|
49
|
+
And I should have 0 images
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Given /^I have no images$/ do
|
2
|
+
Image.delete_all
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I attach the image at "([^\"]*)"$/ do |file_path|
|
6
|
+
attach_file('image_image', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^the image "([^\"]*)" should have uploaded successfully$/ do |file_name|
|
10
|
+
Image.find_by_image_name(file_name).nil?.should == false
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^the image should have size "([^\"]*)"$/ do |size|
|
14
|
+
Image.first.size.should == size.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^the image should have width "([^\"]*)"$/ do |width|
|
18
|
+
Image.first.width.should == width.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^the image should have height "([^\"]*)"$/ do |height|
|
22
|
+
Image.first.height.should == height.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^the image should have mime_type "([^\"]*)"$/ do |mime_type|
|
26
|
+
Image.first.mime_type.should == mime_type.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should have ([0-9]+) images?$/ do |number|
|
30
|
+
Image.count.should == number.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^I upload the image at "([^\"]*)"$/ do |file_path|
|
34
|
+
original_stderr = $stderr.dup
|
35
|
+
$stderr.reopen(Tempfile.new('stderr'))
|
36
|
+
visit new_admin_image_path
|
37
|
+
attach_file('image_image', File.join(File.expand_path('../../uploads/', __FILE__), file_path))
|
38
|
+
click_button 'Save'
|
39
|
+
$stderr.reopen(original_stderr)
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
module Refinery
|
3
|
+
module Images
|
4
|
+
def path_to(page_name)
|
5
|
+
case page_name
|
6
|
+
when /the list of images/
|
7
|
+
admin_images_path
|
8
|
+
|
9
|
+
when /the new image form/
|
10
|
+
new_admin_image_path
|
11
|
+
else
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
http://www.refineryhq.com/
|
data/lib/gemspec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
gempath = Pathname.new(File.expand_path('../../', __FILE__))
|
3
|
+
require gempath.join('..', 'base', 'lib', 'base', 'refinery')
|
4
|
+
|
5
|
+
gemspec = <<EOF
|
6
|
+
# DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = %q{#{gemname = 'refinerycms-images'}}
|
10
|
+
s.version = %q{#{::Refinery.version}}
|
11
|
+
s.summary = %q{Images engine for Refinery CMS}
|
12
|
+
s.description = %q{Handles all image upload and processing functionality in Refinery CMS.}
|
13
|
+
s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
|
14
|
+
s.email = %q{info@refinerycms.com}
|
15
|
+
s.homepage = %q{http://refinerycms.com}
|
16
|
+
s.rubyforge_project = %q{refinerycms}
|
17
|
+
s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel']
|
18
|
+
s.license = %q{MIT}
|
19
|
+
s.require_paths = %w(lib)
|
20
|
+
s.executables = %w(#{Pathname.glob(gempath.join('bin/*')).map{|d| d.relative_path_from(gempath)}.sort.join(" ")})
|
21
|
+
|
22
|
+
s.files = [
|
23
|
+
'#{%w( **/{*,.rspec,.gitignore,.yardopts} ).map { |file| Pathname.glob(gempath.join(file)) }.flatten.reject{|f|
|
24
|
+
!f.exist? or f.to_s =~ /\.gem$/ or (f.directory? and f.children.empty?)
|
25
|
+
}.map{|d| d.relative_path_from(gempath)}.uniq.sort.join("',\n '")}'
|
26
|
+
]
|
27
|
+
|
28
|
+
s.add_dependency 'refinerycms-core', '~> #{::Refinery::Version}'
|
29
|
+
s.add_dependency 'dragonfly', '~> 0.8.2'
|
30
|
+
s.add_dependency 'rack-cache', '~> 0.5.2'
|
31
|
+
end
|
32
|
+
EOF
|
33
|
+
|
34
|
+
(gemfile = gempath.join("#{gemname}.gemspec")).open('w') {|f| f.puts(gemspec)}
|
35
|
+
puts `cd #{gempath} && gem build #{gemfile}` if ARGV.any?{|a| a == "BUILD=true"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rack/cache'
|
2
|
+
require 'dragonfly'
|
3
|
+
require 'refinerycms-core'
|
4
|
+
|
5
|
+
module Refinery
|
6
|
+
module Images
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :root
|
10
|
+
def root
|
11
|
+
@root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Engine < ::Rails::Engine
|
16
|
+
initializer 'images-with-dragonfly' do |app|
|
17
|
+
app_images = Dragonfly[:images]
|
18
|
+
app_images.configure_with(:imagemagick)
|
19
|
+
app_images.configure_with(:rails) do |c|
|
20
|
+
c.datastore.root_path = Rails.root.join('public', 'system', 'images').to_s
|
21
|
+
c.url_path_prefix = '/system/images'
|
22
|
+
c.secret = RefinerySetting.find_or_set(:dragonfly_secret,
|
23
|
+
Array.new(24) { rand(256) }.pack('C*').unpack('H*').first)
|
24
|
+
end
|
25
|
+
app_images.configure_with(:heroku, ENV['S3_BUCKET']) if Refinery.s3_backend
|
26
|
+
|
27
|
+
app_images.define_macro(ActiveRecord::Base, :image_accessor)
|
28
|
+
app_images.analyser.register(Dragonfly::Analysis::ImageMagickAnalyser)
|
29
|
+
app_images.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)
|
30
|
+
|
31
|
+
# This url_suffix makes it so that dragonfly urls work in traditional
|
32
|
+
# situations where the filename and extension are required, e.g. lightbox.
|
33
|
+
# What this does is takes the url that is about to be produced e.g.
|
34
|
+
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
|
35
|
+
# and adds the filename onto the end (say the image was 'refinery_is_awesome.jpg')
|
36
|
+
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.jpg
|
37
|
+
# Officially the way to do it, from: http://markevans.github.com/dragonfly/file.URLs.html
|
38
|
+
app_images.url_suffix = proc{|job|
|
39
|
+
object_file_name = job.uid_basename.gsub(%r{^(\d{4}|\d{2})[_/]\d{2}[_/]\d{2}[_/]\d{2,3}[_/](\d{2}/\d{2}/\d{3}/)?}, '')
|
40
|
+
"/#{object_file_name}#{job.encoded_extname || job.uid_extname}"
|
41
|
+
}
|
42
|
+
|
43
|
+
### Extend active record ###
|
44
|
+
|
45
|
+
app.config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware', :images, '/system/images'
|
46
|
+
|
47
|
+
app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
48
|
+
:verbose => Rails.env.development?,
|
49
|
+
:metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
|
50
|
+
:entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
config.after_initialize do
|
55
|
+
::Refinery::Plugin.register do |plugin|
|
56
|
+
plugin.name = "refinery_images"
|
57
|
+
plugin.directory = "images"
|
58
|
+
plugin.version = %q{0.9.9}
|
59
|
+
plugin.menu_match = /(refinery|admin)\/image(_dialog)?s$/
|
60
|
+
plugin.activity = {
|
61
|
+
:class => Image
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
::Refinery.engines << 'dashboard'
|
data/license.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2005-2010 [Resolve Digital](http://www.resolvedigital.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Images
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
## About
|
6
|
+
|
7
|
+
All Refinery's images are stored in one place, the images plugin.
|
8
|
+
|
9
|
+
Images and other file uploads are handled using [Dragonfly](http://github.com/markevans/dragonfly)
|
10
|
+
|
11
|
+
## Using a Thumbnail Size in Your View
|
12
|
+
|
13
|
+
Say I want to have a thumbnail of size 400x300 I would collect that image out of the database and apply it like this in my view:
|
14
|
+
|
15
|
+
<%= image_fu @image, '400x300' %>
|
16
|
+
|
17
|
+
``image_fu`` is a command we have created that automatically adds width and height attributes to the
|
18
|
+
generated image so that web browsers render your pages more smoothly as they know in advance how big
|
19
|
+
an image is going to be before it is fully downloaded.
|
20
|
+
|
21
|
+
If I wanted to replace all the images inside a content section without the user having to resize images
|
22
|
+
in the editor then I would use the built in ``content_fu`` command like this in my view:
|
23
|
+
|
24
|
+
<%= content_fu @page[:body], '400x300' %>
|
25
|
+
|
26
|
+
``content_fu`` is a command we have created that automatically changes all images with the url /system/images to use a particular size.
|
27
|
+
This makes it easy to protect your pages from having gigantic images inserted into them that blow out the design.
|
28
|
+
|
29
|
+
## Related Settings
|
30
|
+
|
31
|
+
### "Preferred Image View"
|
32
|
+
|
33
|
+
Set to ``"grid"`` to get your images to display as a grid of thumbnails
|
34
|
+
Set to ``"list"`` to get your images to display as a list with image titles.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{refinerycms-images}
|
5
|
+
s.version = %q{0.9.9.1}
|
6
|
+
s.summary = %q{Images engine for Refinery CMS}
|
7
|
+
s.description = %q{Handles all image upload and processing functionality in Refinery CMS.}
|
8
|
+
s.date = %q{2011-02-15}
|
9
|
+
s.email = %q{info@refinerycms.com}
|
10
|
+
s.homepage = %q{http://refinerycms.com}
|
11
|
+
s.rubyforge_project = %q{refinerycms}
|
12
|
+
s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel']
|
13
|
+
s.license = %q{MIT}
|
14
|
+
s.require_paths = %w(lib)
|
15
|
+
s.executables = %w()
|
16
|
+
|
17
|
+
s.files = [
|
18
|
+
'app',
|
19
|
+
'app/controllers',
|
20
|
+
'app/controllers/admin',
|
21
|
+
'app/controllers/admin/images_controller.rb',
|
22
|
+
'app/helpers',
|
23
|
+
'app/helpers/admin',
|
24
|
+
'app/helpers/admin/images_helper.rb',
|
25
|
+
'app/models',
|
26
|
+
'app/models/image.rb',
|
27
|
+
'app/views',
|
28
|
+
'app/views/admin',
|
29
|
+
'app/views/admin/images',
|
30
|
+
'app/views/admin/images/_existing_image.html.erb',
|
31
|
+
'app/views/admin/images/_form.html.erb',
|
32
|
+
'app/views/admin/images/_grid_view.html.erb',
|
33
|
+
'app/views/admin/images/_images.html.erb',
|
34
|
+
'app/views/admin/images/_list_view.html.erb',
|
35
|
+
'app/views/admin/images/_list_view_image.html.erb',
|
36
|
+
'app/views/admin/images/edit.html.erb',
|
37
|
+
'app/views/admin/images/index.html.erb',
|
38
|
+
'app/views/admin/images/insert.html.erb',
|
39
|
+
'app/views/admin/images/new.html.erb',
|
40
|
+
'config',
|
41
|
+
'config/locales',
|
42
|
+
'config/locales/cs.yml',
|
43
|
+
'config/locales/da.yml',
|
44
|
+
'config/locales/de.yml',
|
45
|
+
'config/locales/el.yml',
|
46
|
+
'config/locales/en.yml',
|
47
|
+
'config/locales/es.yml',
|
48
|
+
'config/locales/fr.yml',
|
49
|
+
'config/locales/it.yml',
|
50
|
+
'config/locales/lolcat.yml',
|
51
|
+
'config/locales/lt.yml',
|
52
|
+
'config/locales/lv.yml',
|
53
|
+
'config/locales/nb.yml',
|
54
|
+
'config/locales/nl.yml',
|
55
|
+
'config/locales/pl.yml',
|
56
|
+
'config/locales/pt-BR.yml',
|
57
|
+
'config/locales/rs.yml',
|
58
|
+
'config/locales/ru.yml',
|
59
|
+
'config/locales/sl.yml',
|
60
|
+
'config/locales/sv.yml',
|
61
|
+
'config/locales/vi.yml',
|
62
|
+
'config/locales/zh-CN.yml',
|
63
|
+
'config/locales/zh-TW.yml',
|
64
|
+
'config/routes.rb',
|
65
|
+
'db',
|
66
|
+
'db/migrate',
|
67
|
+
'db/migrate/20100913234707_create_refinerycms_images_schema.rb',
|
68
|
+
'features',
|
69
|
+
'features/manage_images.feature',
|
70
|
+
'features/step_definitions',
|
71
|
+
'features/step_definitions/image_steps.rb',
|
72
|
+
'features/support',
|
73
|
+
'features/support/factories.rb',
|
74
|
+
'features/support/paths.rb',
|
75
|
+
'features/uploads',
|
76
|
+
'features/uploads/beach.jpeg',
|
77
|
+
'features/uploads/id-rather-be-here.jpg',
|
78
|
+
'features/uploads/refinery_is_awesome.txt',
|
79
|
+
'lib',
|
80
|
+
'lib/gemspec.rb',
|
81
|
+
'lib/generators',
|
82
|
+
'lib/generators/refinerycms_images_generator.rb',
|
83
|
+
'lib/refinerycms-images.rb',
|
84
|
+
'license.md',
|
85
|
+
'readme.md',
|
86
|
+
'refinerycms-images.gemspec',
|
87
|
+
'spec',
|
88
|
+
'spec/models',
|
89
|
+
'spec/models/image_spec.rb',
|
90
|
+
'spec/uploads',
|
91
|
+
'spec/uploads/beach.jpeg'
|
92
|
+
]
|
93
|
+
|
94
|
+
s.add_dependency 'refinerycms-core', '~> 0.9.9.1'
|
95
|
+
s.add_dependency 'dragonfly', '~> 0.8.2'
|
96
|
+
s.add_dependency 'rack-cache', '~> 0.5.2'
|
97
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Image do
|
4
|
+
|
5
|
+
def reset_image(options = {})
|
6
|
+
@valid_attributes = {
|
7
|
+
:id => 1,
|
8
|
+
:image => File.new(File.expand_path('../../uploads/beach.jpeg', __FILE__))
|
9
|
+
}.merge(options)
|
10
|
+
|
11
|
+
@image.destroy if @image
|
12
|
+
@image = Image.create!(@valid_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_can_be_destroyed
|
16
|
+
@image.destroy.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
reset_image
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with valid attributes" do
|
24
|
+
it "should create successfully" do
|
25
|
+
@image.errors.empty?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "image url" do
|
30
|
+
it "should respond to .thumbnail" do
|
31
|
+
@image.respond_to?(:thumbnail).should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should contain its filename at the end" do
|
35
|
+
@image.thumbnail(nil).url.split('/').last.should == @image.image_name
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be different when supplying geometry" do
|
39
|
+
@image.thumbnail(nil).url.should_not == @image.thumbnail('200x200').url
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have different urls for each geometry string" do
|
43
|
+
@image.thumbnail('200x200').url.should_not == @image.thumbnail('200x201').url
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should use right geometry when given a thumbnail name" do
|
47
|
+
name, geometry = Image.user_image_sizes.first
|
48
|
+
@image.thumbnail(name).url.should == @image.thumbnail(geometry).url
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#title" do
|
54
|
+
it "returns a titleized version of the filename" do
|
55
|
+
@image.title.should == "Beach"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".per_page" do
|
60
|
+
context "dialog is true" do
|
61
|
+
context "has_size_options is true" do
|
62
|
+
it "returns image count specified by PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS constant" do
|
63
|
+
Image.per_page(true, true).should == Image::PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "has_size_options is false" do
|
68
|
+
it "returns image count specified by PAGES_PER_DIALOG constant" do
|
69
|
+
Image.per_page(true).should == Image::PAGES_PER_DIALOG
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "dialog is false" do
|
75
|
+
it "returns image count specified by PAGES_PER_ADMIN_INDEX constant" do
|
76
|
+
Image.per_page.should == Image::PAGES_PER_ADMIN_INDEX
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe ".user_image_sizes" do
|
82
|
+
it "sets and returns a hash consisting of the keys contained in the RefinerySetting" do
|
83
|
+
Image.user_image_sizes.should == RefinerySetting.get(:user_image_sizes)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|