sweet_portfolio 0.1.0

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.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/.powrc +4 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +2 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE +20 -0
  7. data/README.md +37 -0
  8. data/Rakefile +21 -0
  9. data/VERSION +1 -0
  10. data/app/assets/images/sweet_portfolio/blank.gif +0 -0
  11. data/app/assets/images/sweet_portfolio/border.png +0 -0
  12. data/app/assets/images/sweet_portfolio/controls.png +0 -0
  13. data/app/assets/images/sweet_portfolio/fancybox_loading.gif +0 -0
  14. data/app/assets/images/sweet_portfolio/fancybox_overlay.png +0 -0
  15. data/app/assets/images/sweet_portfolio/fancybox_sprite.png +0 -0
  16. data/app/assets/images/sweet_portfolio/jcrop.gif +0 -0
  17. data/app/assets/images/sweet_portfolio/loading.gif +0 -0
  18. data/app/assets/images/sweet_portfolio/loading_background.png +0 -0
  19. data/app/assets/images/sweet_portfolio/overlay.png +0 -0
  20. data/app/assets/javascripts/sweet_portfolio/jquery.colorbox.js +4 -0
  21. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox-media.js +196 -0
  22. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox-thumbs.js +162 -0
  23. data/app/assets/javascripts/sweet_portfolio/jquery.fancybox.pack.js +45 -0
  24. data/app/assets/javascripts/sweet_portfolio/jquery.jcrop.js +246 -0
  25. data/app/assets/stylesheets/sweet_portfolio/colorbox.css +61 -0
  26. data/app/assets/stylesheets/sweet_portfolio/jquery.fancybox-thumbs.css +54 -0
  27. data/app/assets/stylesheets/sweet_portfolio/jquery.fancybox.css +249 -0
  28. data/app/assets/stylesheets/sweet_portfolio/jquery.jcrop.css +32 -0
  29. data/app/controllers/admin/gallery/base_controller.rb +3 -0
  30. data/app/controllers/admin/gallery/galleries_controller.rb +72 -0
  31. data/app/controllers/admin/gallery/photos_controller.rb +90 -0
  32. data/app/controllers/application_controller.rb +7 -0
  33. data/app/helpers/gallery/application_helper.rb +12 -0
  34. data/app/models/gallery/gallery.rb +33 -0
  35. data/app/models/gallery/photo.rb +83 -0
  36. data/app/views/admin/gallery/_navigation.html.erb +1 -0
  37. data/app/views/admin/gallery/galleries/_form.html.haml +15 -0
  38. data/app/views/admin/gallery/galleries/edit.html.haml +5 -0
  39. data/app/views/admin/gallery/galleries/index.html.haml +28 -0
  40. data/app/views/admin/gallery/galleries/new.html.haml +5 -0
  41. data/app/views/admin/gallery/photos/_form.html.haml +12 -0
  42. data/app/views/admin/gallery/photos/crop.html.haml +50 -0
  43. data/app/views/admin/gallery/photos/edit.html.haml +5 -0
  44. data/app/views/admin/gallery/photos/index.html.haml +19 -0
  45. data/app/views/admin/gallery/photos/new.html.haml +5 -0
  46. data/app/views/layouts/gallery/application.html.haml +12 -0
  47. data/config.ru +4 -0
  48. data/config/application.rb +51 -0
  49. data/config/boot.rb +13 -0
  50. data/config/database.yml +16 -0
  51. data/config/environment.rb +5 -0
  52. data/config/environments/development.rb +25 -0
  53. data/config/environments/production.rb +52 -0
  54. data/config/environments/test.rb +39 -0
  55. data/config/initializers/paperclip.rb +3 -0
  56. data/config/initializers/sweet_portfolio.rb +12 -0
  57. data/config/routes.rb +3 -0
  58. data/db/migrate/01_create_sweet_portfolio.rb +37 -0
  59. data/lib/generators/sweet_portfolio/README +10 -0
  60. data/lib/generators/sweet_portfolio/sweet_portfolio.rb +37 -0
  61. data/lib/paperclip_processors/cropper.rb +31 -0
  62. data/lib/sweet_portfolio.rb +28 -0
  63. data/lib/sweet_portfolio/configuration.rb +26 -0
  64. data/lib/sweet_portfolio/engine.rb +21 -0
  65. data/lib/sweet_portfolio/form_builder.rb +50 -0
  66. data/lib/sweet_portfolio/routing.rb +21 -0
  67. data/lib/tasks/sweet_portfolio.rake +4 -0
  68. data/script/rails +6 -0
  69. data/sweet_portfolio.gemspec +134 -0
  70. data/test/fixtures/files/default.jpg +0 -0
  71. data/test/fixtures/files/default.txt +1 -0
  72. data/test/fixtures/files/default2.jpg +0 -0
  73. data/test/fixtures/gallery/galleries.yml +11 -0
  74. data/test/fixtures/gallery/photos.yml +8 -0
  75. data/test/functional/admin/gallery/galleries_controller_test.rb +107 -0
  76. data/test/functional/admin/gallery/photos_controller_test.rb +224 -0
  77. data/test/test_helper.rb +39 -0
  78. data/test/unit/configuration_test.rb +16 -0
  79. data/test/unit/gallery_test.rb +38 -0
  80. data/test/unit/photo_test.rb +40 -0
  81. metadata +228 -0
@@ -0,0 +1,26 @@
1
+ module SweetPortfolio
2
+ class Configuration
3
+
4
+ # Paperclip upload settings for photos
5
+ attr_accessor :upload_options
6
+
7
+ # Default url to access admin area is http://yourhost/cms-admin/
8
+ # You can change 'cms-admin' to 'admin', for example.
9
+ attr_accessor :admin_route_prefix
10
+
11
+ # Controller that should be used for admin area
12
+ attr_accessor :admin_controller
13
+
14
+ # Form builder
15
+ attr_accessor :form_builder
16
+
17
+ # Configuration defaults
18
+ def initialize
19
+ @upload_options = { }
20
+ @admin_route_prefix = 'admin'
21
+ @admin_controller = 'ApplicationController'
22
+ @form_builder = 'SweetPortfolio::FormBuilder'
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'sweet_portfolio'
2
+ require 'rails'
3
+ require 'paperclip'
4
+
5
+ module SweetPortfolio
6
+ class Engine < Rails::Engine
7
+ initializer 'sweet_portfolio.helper' do |app|
8
+ if defined?(ComfortableMexicanSofa)
9
+ # applying configuraion
10
+ SweetPortfolio.configure do |conf|
11
+ conf.admin_route_prefix = SweetPortfolio::Routing.admin
12
+ conf.upload_options = ComfortableMexicanSofa.config.upload_file_options
13
+ conf.admin_controller = 'CmsAdmin::BaseController'
14
+ conf.form_builder = 'ComfortableMexicanSofa::FormBuilder'
15
+ end
16
+ # applying nav elements
17
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/gallery/navigation')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ class SweetPortfolio::FormBuilder < ActionView::Helpers::FormBuilder
2
+
3
+ helpers = field_helpers -
4
+ %w(hidden_field fields_for) +
5
+ %w(select)
6
+
7
+ helpers.each do |name|
8
+ class_eval %Q^
9
+ def #{name}(field, *args)
10
+ options = args.extract_options!
11
+ args << options
12
+ return super if options.delete(:disable_builder)
13
+ default_field('#{name}', field, options){ super }
14
+ end
15
+ ^
16
+ end
17
+
18
+ def default_field(type, field, options = {}, &block)
19
+ errors = if object.respond_to?(:errors) && object.errors[field].present?
20
+ "<div class='errors'>#{[object.errors[field]].flatten.first}</div>"
21
+ end
22
+ if desc = options.delete(:desc)
23
+ desc = "<div class='desc'>#{desc}</div>"
24
+ end
25
+ %(
26
+ <div class='form_element #{type}_element #{'errors' if errors}'>
27
+ <div class='label'>#{label_for(field, options)}</div>
28
+ <div class='value'>#{yield}</div>
29
+ #{desc}
30
+ #{errors}
31
+ </div>
32
+ ).html_safe
33
+ end
34
+
35
+ def label_for(field, options)
36
+ label = options.delete(:label) || field.to_s.titleize.capitalize
37
+ "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe
38
+ end
39
+
40
+ def simple_field(label = nil, content = nil, options = {}, &block)
41
+ content ||= @template.capture(&block) if block_given?
42
+ %(
43
+ <div class='form_element #{options.delete(:class)}'>
44
+ <div class='label'>#{label}</div>
45
+ <div class='value'>#{content}</div>
46
+ </div>
47
+ ).html_safe
48
+ end
49
+
50
+ end
@@ -0,0 +1,21 @@
1
+ module SweetPortfolio::Routing
2
+
3
+ def self.admin(options = {})
4
+ options[:path] ||= 'admin'
5
+
6
+ Rails.application.routes.draw do
7
+ namespace :admin, :path => options[:path] do
8
+ namespace :gallery do
9
+ resources :galleries do
10
+ put :reorder, :on => :collection
11
+ resources :photos do
12
+ put :reorder, :on => :collection
13
+ get :crop, :on => :member
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,4 @@
1
+ # Small hack to auto-run migrations during testing
2
+ namespace :db do
3
+ task :abort_if_pending_migrations => [:migrate]
4
+ end
data/script/rails ADDED
@@ -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,134 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sweet_portfolio"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stephen McLeod", "The Working Group Inc."]
12
+ s.date = "2013-04-19"
13
+ s.description = "Sweet Portfolio is an image gallery engine with nice frontend capabilities for Rails 3.1 apps (and ComfortableMexicanSofa)"
14
+ s.email = "work@stephenmmcleod.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".powrc",
22
+ ".ruby-version",
23
+ ".travis.yml",
24
+ "Gemfile",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "app/assets/images/sweet_portfolio/blank.gif",
30
+ "app/assets/images/sweet_portfolio/border.png",
31
+ "app/assets/images/sweet_portfolio/controls.png",
32
+ "app/assets/images/sweet_portfolio/fancybox_loading.gif",
33
+ "app/assets/images/sweet_portfolio/fancybox_overlay.png",
34
+ "app/assets/images/sweet_portfolio/fancybox_sprite.png",
35
+ "app/assets/images/sweet_portfolio/jcrop.gif",
36
+ "app/assets/images/sweet_portfolio/loading.gif",
37
+ "app/assets/images/sweet_portfolio/loading_background.png",
38
+ "app/assets/images/sweet_portfolio/overlay.png",
39
+ "app/assets/javascripts/sweet_portfolio/jquery.colorbox.js",
40
+ "app/assets/javascripts/sweet_portfolio/jquery.fancybox-media.js",
41
+ "app/assets/javascripts/sweet_portfolio/jquery.fancybox-thumbs.js",
42
+ "app/assets/javascripts/sweet_portfolio/jquery.fancybox.pack.js",
43
+ "app/assets/javascripts/sweet_portfolio/jquery.jcrop.js",
44
+ "app/assets/stylesheets/sweet_portfolio/colorbox.css",
45
+ "app/assets/stylesheets/sweet_portfolio/jquery.fancybox-thumbs.css",
46
+ "app/assets/stylesheets/sweet_portfolio/jquery.fancybox.css",
47
+ "app/assets/stylesheets/sweet_portfolio/jquery.jcrop.css",
48
+ "app/controllers/admin/gallery/base_controller.rb",
49
+ "app/controllers/admin/gallery/galleries_controller.rb",
50
+ "app/controllers/admin/gallery/photos_controller.rb",
51
+ "app/controllers/application_controller.rb",
52
+ "app/helpers/gallery/application_helper.rb",
53
+ "app/models/gallery/gallery.rb",
54
+ "app/models/gallery/photo.rb",
55
+ "app/views/admin/gallery/_navigation.html.erb",
56
+ "app/views/admin/gallery/galleries/_form.html.haml",
57
+ "app/views/admin/gallery/galleries/edit.html.haml",
58
+ "app/views/admin/gallery/galleries/index.html.haml",
59
+ "app/views/admin/gallery/galleries/new.html.haml",
60
+ "app/views/admin/gallery/photos/_form.html.haml",
61
+ "app/views/admin/gallery/photos/crop.html.haml",
62
+ "app/views/admin/gallery/photos/edit.html.haml",
63
+ "app/views/admin/gallery/photos/index.html.haml",
64
+ "app/views/admin/gallery/photos/new.html.haml",
65
+ "app/views/layouts/gallery/application.html.haml",
66
+ "config.ru",
67
+ "config/application.rb",
68
+ "config/boot.rb",
69
+ "config/database.yml",
70
+ "config/environment.rb",
71
+ "config/environments/development.rb",
72
+ "config/environments/production.rb",
73
+ "config/environments/test.rb",
74
+ "config/initializers/paperclip.rb",
75
+ "config/initializers/sweet_portfolio.rb",
76
+ "config/routes.rb",
77
+ "db/migrate/01_create_sweet_portfolio.rb",
78
+ "lib/generators/sweet_portfolio/README",
79
+ "lib/generators/sweet_portfolio/sweet_portfolio.rb",
80
+ "lib/paperclip_processors/cropper.rb",
81
+ "lib/sweet_portfolio.rb",
82
+ "lib/sweet_portfolio/configuration.rb",
83
+ "lib/sweet_portfolio/engine.rb",
84
+ "lib/sweet_portfolio/form_builder.rb",
85
+ "lib/sweet_portfolio/routing.rb",
86
+ "lib/tasks/sweet_portfolio.rake",
87
+ "script/rails",
88
+ "sweet_portfolio.gemspec",
89
+ "test/fixtures/files/default.jpg",
90
+ "test/fixtures/files/default.txt",
91
+ "test/fixtures/files/default2.jpg",
92
+ "test/fixtures/gallery/galleries.yml",
93
+ "test/fixtures/gallery/photos.yml",
94
+ "test/functional/admin/gallery/galleries_controller_test.rb",
95
+ "test/functional/admin/gallery/photos_controller_test.rb",
96
+ "test/test_helper.rb",
97
+ "test/unit/configuration_test.rb",
98
+ "test/unit/gallery_test.rb",
99
+ "test/unit/photo_test.rb"
100
+ ]
101
+ s.homepage = "https://github.com/stephenmmcleod/sweet-portfolio"
102
+ s.licenses = ["MIT"]
103
+ s.require_paths = ["lib"]
104
+ s.rubygems_version = "1.8.24"
105
+ s.summary = ""
106
+
107
+ if s.respond_to? :specification_version then
108
+ s.specification_version = 3
109
+
110
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
111
+ s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
112
+ s.add_runtime_dependency(%q<paperclip>, [">= 2.3.0"])
113
+ s.add_runtime_dependency(%q<jquery-rails>, [">= 1.0.14"])
114
+ s.add_runtime_dependency(%q<haml>, ["~> 4.0.1"])
115
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
116
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
117
+ else
118
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
119
+ s.add_dependency(%q<paperclip>, [">= 2.3.0"])
120
+ s.add_dependency(%q<jquery-rails>, [">= 1.0.14"])
121
+ s.add_dependency(%q<haml>, ["~> 4.0.1"])
122
+ s.add_dependency(%q<sqlite3>, [">= 0"])
123
+ s.add_dependency(%q<jeweler>, [">= 0"])
124
+ end
125
+ else
126
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
127
+ s.add_dependency(%q<paperclip>, [">= 2.3.0"])
128
+ s.add_dependency(%q<jquery-rails>, [">= 1.0.14"])
129
+ s.add_dependency(%q<haml>, ["~> 4.0.1"])
130
+ s.add_dependency(%q<sqlite3>, [">= 0"])
131
+ s.add_dependency(%q<jeweler>, [">= 0"])
132
+ end
133
+ end
134
+
Binary file
@@ -0,0 +1 @@
1
+ text file
Binary file
@@ -0,0 +1,11 @@
1
+ default:
2
+ title: Default Gallery
3
+ identifier: default-gallery
4
+ description: Gallery Description
5
+ full_width: 800
6
+ full_height: 600
7
+ force_ratio_full: false
8
+ thumb_width: 150
9
+ thumb_height: 150
10
+ force_ratio_thumb: true
11
+ position: 0
@@ -0,0 +1,8 @@
1
+ default:
2
+ gallery: default
3
+ title: Default Photo
4
+ description: Photo Description
5
+ position: 0
6
+ image_file_name: default.jpg
7
+ image_content_type: image/jpeg
8
+ image_file_size: 9999
@@ -0,0 +1,107 @@
1
+ require File.expand_path('../../../test_helper', File.dirname(__FILE__))
2
+
3
+ class Admin::Gallery::GalleriesControllerTest < ActionController::TestCase
4
+
5
+ def test_get_index
6
+ get :index
7
+ assert_response :success
8
+ assert_template 'index'
9
+ end
10
+
11
+ def test_get_new
12
+ get :new
13
+ assert_response :success
14
+ assert_template 'new'
15
+ assert assigns(:gallery)
16
+ assert_select "form[action='/admin/gallery/galleries']"
17
+ end
18
+
19
+ def test_creation
20
+ assert_difference 'Gallery::Gallery.count', 1 do
21
+ post :create, :gallery => {
22
+ :title => 'Test Gallery',
23
+ :identifier => 'test-gallery',
24
+ :description => 'Test Description'
25
+ }
26
+ end
27
+ assert_equal 'Gallery created', flash[:notice]
28
+ assert_redirected_to :action => :index
29
+ end
30
+
31
+
32
+ def test_creation_failure
33
+ assert_no_difference 'Gallery::Gallery.count' do
34
+ post :create, :gallery => { }
35
+ end
36
+ assert_response :success
37
+ assert_template 'new'
38
+ assert_equal 'Failed to create Gallery', flash[:error]
39
+ end
40
+
41
+ def test_get_edit
42
+ gallery = gallery_galleries(:default)
43
+ get :edit, :id => gallery
44
+ assert_response :success
45
+ assert_template 'edit'
46
+ assert assigns(:gallery)
47
+ assert_select "form[action='/admin/gallery/galleries/#{gallery.id}']"
48
+ end
49
+
50
+ def test_get_edit_failure
51
+ get :edit, :id => 'invalid'
52
+ assert_response :redirect
53
+ assert_redirected_to :action => :index
54
+ assert_equal 'Gallery not found', flash[:error]
55
+ end
56
+
57
+ def test_update
58
+ gallery = gallery_galleries(:default)
59
+ put :update, :id => gallery, :gallery => {
60
+ :title => 'New Title'
61
+ }
62
+ gallery.reload
63
+ assert_equal 'New Title', gallery.title
64
+ assert_equal 'Gallery updated', flash[:notice]
65
+ assert_redirected_to :action => :index
66
+ end
67
+
68
+ def test_update_failure
69
+ gallery = gallery_galleries(:default)
70
+ put :update, :id => gallery, :gallery => {
71
+ :title => ''
72
+ }
73
+ assert_response :success
74
+ assert_template 'edit'
75
+ assert_equal 'Failed to update Gallery', flash[:error]
76
+ gallery.reload
77
+ assert_not_equal '', gallery.title
78
+ end
79
+
80
+ def test_destroy
81
+ assert_difference 'Gallery::Gallery.count', -1 do
82
+ delete :destroy, :id => gallery_galleries(:default)
83
+ end
84
+ assert_equal 'Gallery deleted', flash[:notice]
85
+ assert_redirected_to :action => :index
86
+ end
87
+
88
+ def test_reorder
89
+ gallery_one = gallery_galleries(:default)
90
+ gallery_two = Gallery::Gallery.create!(
91
+ :title => 'Test Gallery 2',
92
+ :identifier => 'test-gallery2',
93
+ :description => 'Test Description'
94
+ )
95
+ assert_equal 0, gallery_one.position
96
+ assert_equal 1, gallery_two.position
97
+
98
+ post :reorder, :gallery_gallery => [gallery_two.id, gallery_one.id]
99
+ assert_response :success
100
+ gallery_one.reload
101
+ gallery_two.reload
102
+
103
+ assert_equal 1, gallery_one.position
104
+ assert_equal 0, gallery_two.position
105
+ end
106
+
107
+ end
@@ -0,0 +1,224 @@
1
+ require File.expand_path('../../../test_helper', File.dirname(__FILE__))
2
+
3
+ class Admin::Gallery::PhotosControllerTest < ActionController::TestCase
4
+
5
+ def test_get_index
6
+ get :index, :gallery_id => gallery_galleries(:default)
7
+ assert_response :success
8
+ assert_template 'index'
9
+ assert assigns(:photos)
10
+ end
11
+
12
+ def test_get_index_failure
13
+ get :index, :gallery_id => 'invalid'
14
+ assert_response :redirect
15
+ assert_redirected_to admin_gallery_galleries_path
16
+ assert_equal 'Gallery not found', flash[:error]
17
+ end
18
+
19
+ def test_new
20
+ gallery = gallery_galleries(:default)
21
+ get :new, :gallery_id => gallery
22
+ assert_response :success
23
+ assert_template 'new'
24
+ assert assigns(:photo)
25
+ assert_select "form[action='/admin/gallery/galleries/#{gallery.id}/photos']"
26
+ end
27
+
28
+ def test_create
29
+ assert_difference 'Gallery::Photo.count' do
30
+ post :create, :gallery_id => gallery_galleries(:default), :gallery_photo => {
31
+ :title => 'Test Photo',
32
+ :image => [fixture_file_upload('/files/default.jpg', 'image/jpeg')]
33
+ }
34
+ assert_response :redirect
35
+ assert_redirected_to :action => :index
36
+ assert_equal 'Photo created', flash[:notice]
37
+
38
+ photo = Gallery::Photo.last
39
+ assert_equal 'Test Photo', photo.title
40
+ end
41
+ end
42
+
43
+ def test_create_without_title
44
+ assert_difference 'Gallery::Photo.count', 2 do
45
+ post :create, :gallery_id => gallery_galleries(:default), :gallery_photo => {
46
+ :image => [fixture_file_upload('/files/default.jpg', 'image/jpeg')]
47
+ }
48
+ assert_response :redirect
49
+ assert_redirected_to :action => :index
50
+ assert_equal 'Photo created', flash[:notice]
51
+
52
+ photo = Gallery::Photo.last
53
+ assert_equal 'default.jpg', photo.title
54
+
55
+ post :create, :gallery_id => gallery_galleries(:default), :gallery_photo => {
56
+ :image => [fixture_file_upload('/files/default.jpg', 'image/jpeg')]
57
+ }
58
+
59
+ photo = Gallery::Photo.last
60
+ assert_equal 'default.jpg', photo.title
61
+ end
62
+ end
63
+
64
+ def test_create_failure
65
+ assert_no_difference 'Gallery::Photo.count' do
66
+ post :create, :gallery_id => gallery_galleries(:default), :gallery_photo => { }
67
+ assert_response :success
68
+ assert_template 'new'
69
+ assert_equal 'Failed to create Photo', flash[:error]
70
+ end
71
+ end
72
+
73
+
74
+ def test_create_multiple
75
+ Gallery::Photo.delete_all
76
+
77
+ assert_difference 'Gallery::Photo.count', 2 do
78
+ post :create, :gallery_id => gallery_galleries(:default), :gallery_photo => {
79
+ :title => 'Test Photo',
80
+ :image => [
81
+ fixture_file_upload('/files/default.jpg', 'image/jpeg'),
82
+ fixture_file_upload('/files/default.jpg', 'image/jpeg')
83
+ ]
84
+ }
85
+ assert_response :redirect
86
+ assert_redirected_to :action => :index
87
+
88
+ photo_a, photo_b = Gallery::Photo.all
89
+
90
+ assert_equal 'default.jpg', photo_a.image_file_name
91
+ assert_equal 'default.jpg', photo_b.image_file_name
92
+ assert_equal 'Test Photo 1', photo_a.title
93
+ assert_equal 'Test Photo 2', photo_b.title
94
+ assert_equal 'Photo created', flash[:notice]
95
+ end
96
+ end
97
+
98
+
99
+ def test_get_edit
100
+ photo = gallery_photos(:default)
101
+ get :edit, :gallery_id => photo.gallery, :id => photo
102
+ assert_response :success
103
+ assert_template 'edit'
104
+ assert_select "form[action='/admin/gallery/galleries/#{photo.gallery.id}/photos/#{photo.id}']"
105
+ end
106
+
107
+ def test_get_edit_failure
108
+ get :edit, :gallery_id => gallery_galleries(:default), :id => 'invalid'
109
+ assert_response :redirect
110
+ assert_redirected_to :action => :index
111
+ assert_equal 'Photo not found', flash[:error]
112
+ end
113
+
114
+ def test_update
115
+ photo = gallery_photos(:default)
116
+ put :update, :gallery_id => photo.gallery, :id => photo, :gallery_photo => {
117
+ :title => 'Updated Title'
118
+ }
119
+ assert_response :redirect
120
+ assert_redirected_to :action => :index
121
+ assert_equal 'Photo updated', flash[:notice]
122
+
123
+ photo.reload
124
+ assert_equal 'Updated Title', photo.title
125
+ end
126
+
127
+ def test_update_failure
128
+ photo = gallery_photos(:default)
129
+ put :update, :gallery_id => photo.gallery, :id => photo, :gallery_photo => {
130
+ :title => 'Updated Title',
131
+ :image => fixture_file_upload('/files/default.txt', 'text/plain')
132
+ }
133
+ assert_response :success
134
+ assert_template :edit
135
+ assert_equal 'Failed to updated Photo', flash[:error]
136
+
137
+ photo.reload
138
+ assert_not_equal 'Updated Title', photo.description
139
+ end
140
+
141
+ def test_destroy
142
+ photo = gallery_photos(:default)
143
+ assert_difference 'Gallery::Photo.count', -1 do
144
+ delete :destroy, :gallery_id => photo.gallery, :id => photo
145
+ assert_response :redirect
146
+ assert_redirected_to :action => :index
147
+ assert_equal 'Photo deleted', flash[:notice]
148
+ end
149
+ end
150
+
151
+ def test_reorder
152
+ gallery = gallery_galleries(:default)
153
+ photo_one = gallery_photos(:default)
154
+ photo_two = Gallery::Photo.create!(
155
+ :gallery => gallery,
156
+ :title => 'Test Photo',
157
+ :image => fixture_file_upload('/files/default.jpg', 'image/jpeg')
158
+ )
159
+ assert_equal 0, photo_one.position
160
+ assert_equal 1, photo_two.position
161
+
162
+ post :reorder, :gallery_id => photo_one.gallery, :gallery_photo => [photo_two.id, photo_one.id]
163
+ assert_response :success
164
+ photo_one.reload
165
+ photo_two.reload
166
+
167
+ assert_equal 1, photo_one.position
168
+ assert_equal 0, photo_two.position
169
+ end
170
+
171
+ def test_get_crop
172
+ photo = gallery_photos(:default)
173
+ photo.image = fixture_file_upload('/files/default.jpg', 'image/jpeg')
174
+ photo.save!
175
+
176
+ get :crop, :gallery_id => photo.gallery, :id => photo
177
+ assert_response :success
178
+ assert_template 'crop'
179
+ assert assigns(:photo)
180
+ end
181
+
182
+ def test_crop_thumbnail
183
+ photo = gallery_photos(:default)
184
+ put :update, :gallery_id => photo.gallery, :id => photo, :photo => {
185
+ :thumb_crop_x => '0',
186
+ :thumb_crop_y => '0',
187
+ :thumb_crop_w => '100',
188
+ :thumb_crop_h => '100'
189
+ }
190
+
191
+ assert_response :redirect
192
+ assert_redirected_to :action => :index
193
+ assert_equal 'Photo updated', flash[:notice]
194
+ end
195
+
196
+
197
+ def test_crop_thumbnail_and_full
198
+ gallery = Gallery::Gallery.create!(
199
+ :title => 'test',
200
+ :identifier => 'test',
201
+ :force_ratio_full => true
202
+ )
203
+ photo = Gallery::Photo.create!(
204
+ :gallery => gallery,
205
+ :title => 'Test Photo',
206
+ :image => fixture_file_upload('/files/default.jpg', 'image/jpeg')
207
+ )
208
+ put :update, :gallery_id => gallery, :id => photo, :photo => {
209
+ :thumb_crop_x => '0',
210
+ :thumb_crop_y => '0',
211
+ :thumb_crop_w => '100',
212
+ :thumb_crop_h => '100',
213
+ :full_crop_x => '0',
214
+ :full_crop_y => '0',
215
+ :full_crop_w => '100',
216
+ :full_crop_h => '100'
217
+ }
218
+
219
+ assert_response :redirect
220
+ assert_redirected_to :action => :index
221
+ assert_equal 'Photo updated', flash[:notice]
222
+ end
223
+
224
+ end