refinerycms-images 2.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/images_controller.rb +40 -6
  3. data/app/helpers/refinery/admin/images_helper.rb +2 -2
  4. data/app/models/refinery/image.rb +40 -21
  5. data/app/views/refinery/admin/images/_existing_image.html.erb +1 -1
  6. data/app/views/refinery/admin/images/_form.html.erb +1 -1
  7. data/app/views/refinery/admin/images/_grid_view.html.erb +2 -2
  8. data/app/views/refinery/admin/images/_list_view_image.html.erb +1 -1
  9. data/app/views/refinery/admin/images/_records.html.erb +4 -6
  10. data/app/views/refinery/admin/images/insert.html.erb +6 -1
  11. data/config/locales/bg.yml +1 -2
  12. data/config/locales/cs.yml +1 -2
  13. data/config/locales/da.yml +1 -2
  14. data/config/locales/de.yml +1 -2
  15. data/config/locales/el.yml +1 -2
  16. data/config/locales/en.yml +2 -2
  17. data/config/locales/es.yml +1 -2
  18. data/config/locales/fi.yml +1 -2
  19. data/config/locales/fr.yml +1 -2
  20. data/config/locales/hu.yml +44 -0
  21. data/config/locales/it.yml +1 -1
  22. data/config/locales/ja.yml +1 -2
  23. data/config/locales/ko.yml +1 -2
  24. data/config/locales/lt.yml +1 -2
  25. data/config/locales/lv.yml +1 -2
  26. data/config/locales/nb.yml +1 -2
  27. data/config/locales/nl.yml +15 -15
  28. data/config/locales/pl.yml +1 -2
  29. data/config/locales/pt-BR.yml +1 -2
  30. data/config/locales/pt.yml +44 -0
  31. data/config/locales/rs.yml +1 -2
  32. data/config/locales/ru.yml +1 -2
  33. data/config/locales/sk.yml +2 -3
  34. data/config/locales/sl.yml +1 -2
  35. data/config/locales/sv.yml +1 -2
  36. data/config/locales/tr.yml +44 -0
  37. data/config/locales/uk.yml +44 -0
  38. data/config/locales/vi.yml +1 -2
  39. data/config/locales/zh-CN.yml +3 -4
  40. data/config/locales/zh-TW.yml +1 -2
  41. data/config/routes.rb +3 -3
  42. data/db/migrate/20120625093918_remove_image_ext_from_refinery_images.rb +9 -0
  43. data/lib/generators/refinery/images/templates/config/initializers/refinery/images.rb.erb +7 -1
  44. data/lib/refinery/images/configuration.rb +22 -8
  45. data/lib/refinery/images/dragonfly.rb +13 -10
  46. data/lib/refinery/images/engine.rb +1 -2
  47. data/lib/refinery/images/validators.rb +1 -0
  48. data/lib/refinery/images/validators/image_update_validator.rb +17 -0
  49. data/refinerycms-images.gemspec +2 -4
  50. data/spec/factories/image.rb +4 -0
  51. data/spec/{requests → features}/refinery/admin/images_spec.rb +65 -7
  52. data/spec/fixtures/beach-alternate.jpeg +0 -0
  53. data/spec/fixtures/cape-town-tide-table.pdf +0 -0
  54. data/spec/models/refinery/image_spec.rb +70 -40
  55. metadata +18 -22
@@ -7,7 +7,6 @@ module Refinery
7
7
  class << self
8
8
  def setup!
9
9
  app_images = ::Dragonfly[:refinery_images]
10
- app_images.configure_with(:imagemagick)
11
10
 
12
11
  app_images.define_macro(::Refinery::Image, :image_accessor)
13
12
 
@@ -17,9 +16,11 @@ module Refinery
17
16
 
18
17
  def configure!
19
18
  app_images = ::Dragonfly[:refinery_images]
19
+ app_images.configure_with(:imagemagick)
20
20
  app_images.configure_with(:rails) do |c|
21
21
  c.datastore.root_path = Refinery::Images.datastore_root_path
22
22
  c.url_format = Refinery::Images.dragonfly_url_format
23
+ c.url_host = Refinery::Images.dragonfly_url_host
23
24
  c.secret = Refinery::Images.dragonfly_secret
24
25
  c.trust_file_extensions = Refinery::Images.trust_file_extensions
25
26
  end
@@ -34,18 +35,20 @@ module Refinery
34
35
  s3.region = Refinery::Images.s3_region if Refinery::Images.s3_region
35
36
  end
36
37
  end
38
+
39
+ if Images.custom_backend?
40
+ app_images.datastore = Images.custom_backend_class.new(Images.custom_backend_opts)
41
+ end
37
42
  end
38
43
 
44
+ ##
45
+ # Injects Dragonfly::Middleware for Refinery::Images into the stack
39
46
  def attach!(app)
40
- ### Extend active record ###
41
- app.config.middleware.insert_before Refinery::Images.dragonfly_insert_before,
42
- 'Dragonfly::Middleware', :refinery_images
43
-
44
- app.config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
45
- :verbose => Rails.env.development?,
46
- :metastore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'meta')}",
47
- :entitystore => "file:#{Rails.root.join('tmp', 'dragonfly', 'cache', 'body')}"
48
- }
47
+ if ::Rails.application.config.action_controller.perform_caching
48
+ app.config.middleware.insert_after 'Rack::Cache', 'Dragonfly::Middleware', :refinery_images
49
+ else
50
+ app.config.middleware.use 'Dragonfly::Middleware', :refinery_images
51
+ end
49
52
  end
50
53
  end
51
54
 
@@ -1,7 +1,7 @@
1
1
  module Refinery
2
2
  module Images
3
3
  class Engine < ::Rails::Engine
4
- include Refinery::Engine
4
+ extend Refinery::Engine
5
5
 
6
6
  isolate_namespace Refinery
7
7
  engine_name :refinery_images
@@ -17,7 +17,6 @@ module Refinery
17
17
  Refinery::Plugin.register do |plugin|
18
18
  plugin.pathname = root
19
19
  plugin.name = 'refinery_images'
20
- plugin.version = %q{2.0.0}
21
20
  plugin.menu_match = %r{refinery/image(_dialog)?s$}
22
21
  plugin.activity = { :class_name => :'refinery/image' }
23
22
  plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_images_path }
@@ -2,6 +2,7 @@ module Refinery
2
2
  module Images
3
3
  module Validators
4
4
  autoload :ImageSizeValidator, 'refinery/images/validators/image_size_validator'
5
+ autoload :ImageUpdateValidator, 'refinery/images/validators/image_update_validator'
5
6
  end
6
7
  end
7
8
  end
@@ -0,0 +1,17 @@
1
+ module Refinery
2
+ module Images
3
+ module Validators
4
+ class ImageUpdateValidator < ActiveModel::Validator
5
+
6
+ def validate(record)
7
+ if record.image_name_changed?
8
+ record.errors.add :image_name,
9
+ ::I18n.t("different_file_name",
10
+ :scope => "activerecord.errors.models.refinery/image")
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,5 @@
1
1
  # Encoding: UTF-8
2
- $:.push File.expand_path('../../core/lib', __FILE__)
3
- require 'refinery/version'
2
+ require File.expand_path('../../core/lib/refinery/version', __FILE__)
4
3
 
5
4
  version = Refinery::Version.to_s
6
5
 
@@ -20,7 +19,6 @@ Gem::Specification.new do |s|
20
19
  s.files = `git ls-files`.split("\n")
21
20
  s.test_files = `git ls-files -- spec/*`.split("\n")
22
21
 
23
- s.add_dependency 'dragonfly', '~> 0.9.8'
24
- s.add_dependency 'rack-cache', '>= 0.5.3'
22
+ s.add_dependency 'dragonfly', '~> 0.9.14'
25
23
  s.add_dependency 'refinerycms-core', version
26
24
  end
@@ -2,4 +2,8 @@ FactoryGirl.define do
2
2
  factory :image, :class => ::Refinery::Image do
3
3
  image Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
4
4
  end
5
+
6
+ factory :alternate_image, :class => ::Refinery::Image do
7
+ image Refinery.roots(:'refinery/images').join("spec/fixtures/beach-alternate.jpeg")
8
+ end
5
9
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  module Refinery
4
4
  describe "AdminImages" do
5
- login_refinery_user
5
+ refinery_login_with :refinery_user
6
6
 
7
7
  context "when no images" do
8
8
  it "invites to add one" do
@@ -35,11 +35,59 @@ module Refinery
35
35
  Refinery::Image.count.should == 1
36
36
  end
37
37
 
38
- it 'is accessible via url' do
39
- image = Refinery::Image.create(:image => Refinery.roots(:'refinery/images').join("spec/fixtures/image-with-dashes.jpg"))
40
- get image.url
38
+ it "cannot upload a pdf", :js => true do
39
+ visit refinery.admin_images_path
40
+
41
+ click_link ::I18n.t('create_new_image', :scope => 'refinery.admin.images.actions')
42
+
43
+ page.should have_selector 'iframe#dialog_iframe'
44
+
45
+ page.within_frame('dialog_iframe') do
46
+ attach_file "image_image", Refinery.roots(:'refinery/images').
47
+ join("spec/fixtures/cape-town-tide-table.pdf")
48
+ click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
49
+ end
41
50
 
42
- response.should be_success
51
+ page.within_frame('dialog_iframe') do
52
+ page.should have_content(::I18n.t('incorrect_format', :scope => 'activerecord.errors.models.refinery/image'))
53
+ end
54
+ Refinery::Image.count.should == 0
55
+ end
56
+ end
57
+
58
+ context "new/create - insert mode" do
59
+ it "uploads image", :js => true do
60
+ visit refinery.insert_admin_images_path(:modal => true, :wymedtior => true)
61
+
62
+ attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/image-with-dashes.jpg")
63
+ click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
64
+
65
+ page.should have_selector('#existing_image_area', :visible => true)
66
+ Refinery::Image.count.should == 1
67
+ end
68
+
69
+ it "gets error message when uploading non-image", :js => true do
70
+ visit refinery.insert_admin_images_path(:modal => true, :wymedtior => true)
71
+
72
+ attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")
73
+ click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
74
+
75
+ page.should have_selector('#upload_image_area', :visible => true)
76
+ page.should have_content(::I18n.t('incorrect_format', :scope => 'activerecord.errors.models.refinery/image'))
77
+ Refinery::Image.count.should == 0
78
+ end
79
+
80
+ it "gets error message when uploading non-image (when an image already exists)", :js => true do
81
+ FactoryGirl.create(:image)
82
+ visit refinery.insert_admin_images_path(:modal => true, :wymedtior => true)
83
+
84
+ choose 'Upload'
85
+ attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")
86
+ click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
87
+
88
+ page.should have_selector('#upload_image_area', :visible => true)
89
+ page.should have_content(::I18n.t('incorrect_format', :scope => 'activerecord.errors.models.refinery/image'))
90
+ Refinery::Image.count.should == 1
43
91
  end
44
92
  end
45
93
 
@@ -56,14 +104,24 @@ module Refinery
56
104
  page.should have_content("Use current image or replace it with this one...")
57
105
  page.should have_selector("a[href*='#{refinery.admin_images_path}']")
58
106
 
59
- attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/fathead.png")
107
+ attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
60
108
  click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
61
109
 
62
- page.should have_content(::I18n.t('updated', :scope => 'refinery.crudify', :what => "'Fathead'"))
110
+ page.should have_content(::I18n.t('updated', :scope => 'refinery.crudify', :what => "'Beach'"))
63
111
  Refinery::Image.count.should == 1
64
112
 
65
113
  lambda { click_link "View this image" }.should_not raise_error
66
114
  end
115
+
116
+ it "doesn't allow updating if image has different file name" do
117
+ visit refinery.edit_admin_image_path(image)
118
+
119
+ attach_file "image_image", Refinery.roots(:'refinery/images').join("spec/fixtures/fathead.png")
120
+ click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
121
+
122
+ page.should have_content(::I18n.t("different_file_name",
123
+ :scope => "activerecord.errors.models.refinery/image"))
124
+ end
67
125
  end
68
126
 
69
127
  context "destroy" do
Binary file
@@ -6,9 +6,59 @@ module Refinery
6
6
  let(:image) { FactoryGirl.build(:image) }
7
7
  let(:created_image) { FactoryGirl.create(:image) }
8
8
 
9
- context "with valid attributes" do
10
- it "should report being valid" do
11
- image.valid?.should be_true
9
+ describe "validations" do
10
+ describe "valid #image" do
11
+ before do
12
+ @file = Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
13
+ Images.stub(:max_image_size).and_return(File.read(@file).size + 10.megabytes)
14
+ end
15
+
16
+ it "should be valid when size does not exceed .max_image_size" do
17
+ Image.new(:image => @file).should be_valid
18
+ end
19
+ end
20
+
21
+ describe "too large #image" do
22
+ before do
23
+ @file = Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
24
+ Images.stub(:max_image_size).and_return(0)
25
+ @image = Image.new(:image => @file)
26
+ end
27
+
28
+ it "should not be valid when size exceeds .max_image_size" do
29
+ @image.should_not be_valid
30
+ end
31
+
32
+ it "should contain an error message" do
33
+ @image.valid?
34
+ @image.errors.should_not be_empty
35
+ @image.errors[:image].should == ["Image should be smaller than #{Images.max_image_size} bytes in size"]
36
+ end
37
+ end
38
+
39
+ describe "invalid argument for #image" do
40
+ before do
41
+ @image = Image.new
42
+ end
43
+
44
+ it "has an error message" do
45
+ @image.valid?
46
+ @image.errors.should_not be_empty
47
+ @image.errors[:image].should == ["You must specify an image for upload"]
48
+ end
49
+ end
50
+
51
+ context "when image exists" do
52
+ it "doesn't allow to replace it with image which has different file name" do
53
+ created_image.image = Refinery.roots(:'refinery/images').join("spec/fixtures/beach-alternate.jpeg")
54
+ created_image.should_not be_valid
55
+ created_image.should have_at_least(1).error_on(:image_name)
56
+ end
57
+
58
+ it "allows to replace it with image which has the same file name" do
59
+ created_image.image = Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
60
+ created_image.should be_valid
61
+ end
12
62
  end
13
63
  end
14
64
 
@@ -22,16 +72,16 @@ module Refinery
22
72
  end
23
73
 
24
74
  it "becomes different when supplying geometry" do
25
- created_image.url.should_not == created_image.thumbnail('200x200').url
75
+ created_image.url.should_not == created_image.thumbnail(:geometry => '200x200').url
26
76
  end
27
77
 
28
78
  it "has different urls for each geometry string" do
29
- created_image.thumbnail('200x200').url.should_not == created_image.thumbnail('200x201').url
79
+ created_image.thumbnail(:geometry => '200x200').url.should_not == created_image.thumbnail(:geometry => '200x201').url
30
80
  end
31
81
 
32
82
  it "uses right geometry when given a thumbnail name" do
33
83
  name, geometry = Refinery::Images.user_image_sizes.first
34
- created_image.thumbnail(name).url.should == created_image.thumbnail(geometry).url
84
+ created_image.thumbnail(:geometry => name).url.should == created_image.thumbnail(:geometry => geometry).url
35
85
  end
36
86
  end
37
87
 
@@ -112,47 +162,27 @@ module Refinery
112
162
  end
113
163
  end
114
164
 
115
- describe "validations" do
116
- describe "valid #image" do
117
- before do
118
- @file = Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
119
- Images.max_image_size = (File.read(@file).size + 10.megabytes)
120
- end
165
+ describe '#thumbnail_dimensions returns correctly with' do
166
+ let(:created_alternate_image) { FactoryGirl.create(:alternate_image) }
121
167
 
122
- it "should be valid when size does not exceed .max_image_size" do
123
- Image.new(:image => @file).should be_valid
124
- end
168
+ it 'nil' do
169
+ created_alternate_image.thumbnail_dimensions(nil).should == { :width => 376, :height => 184 }
125
170
  end
126
171
 
127
- describe "too large #image" do
128
- before do
129
- @file = Refinery.roots(:'refinery/images').join("spec/fixtures/beach.jpeg")
130
- Images.max_image_size = 0
131
- @image = Image.new(:image => @file)
132
- end
133
-
134
- it "should not be valid when size exceeds .max_image_size" do
135
- @image.should_not be_valid
136
- end
137
-
138
- it "should contain an error message" do
139
- @image.valid?
140
- @image.errors.should_not be_empty
141
- @image.errors[:image].should == ["Image should be smaller than #{Images.max_image_size} bytes in size"]
142
- end
172
+ it '225x255>' do
173
+ created_alternate_image.thumbnail_dimensions('225x255>').should == { :width => 225, :height => 110 }
143
174
  end
175
+ end
144
176
 
145
- describe "invalid argument for #image" do
146
- before do
147
- @image = Image.new
148
- end
177
+ describe '#thumbnail_dimensions returns correctly with user-defined geometries' do
178
+ it ':medium' do
179
+ created_image.thumbnail_dimensions(:medium).should == { :width => 225, :height => 169 }
180
+ end
149
181
 
150
- it "has an error message" do
151
- @image.valid?
152
- @image.errors.should_not be_empty
153
- @image.errors[:image].should == ["You must specify an image for upload"]
154
- end
182
+ it ':large' do
183
+ created_image.thumbnail_dimensions(:large).should == { :width => 450, :height => 338 }
155
184
  end
156
185
  end
186
+
157
187
  end
158
188
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-images
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Arndt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-14 00:00:00.000000000 Z
13
+ date: 2013-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dragonfly
@@ -18,42 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.9.8
21
+ version: 0.9.14
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- version: 0.9.8
29
- - !ruby/object:Gem::Dependency
30
- name: rack-cache
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - '>='
34
- - !ruby/object:Gem::Version
35
- version: 0.5.3
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - '>='
41
- - !ruby/object:Gem::Version
42
- version: 0.5.3
28
+ version: 0.9.14
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: refinerycms-core
45
31
  requirement: !ruby/object:Gem::Requirement
46
32
  requirements:
47
33
  - - '='
48
34
  - !ruby/object:Gem::Version
49
- version: 2.0.10
35
+ version: 2.1.0
50
36
  type: :runtime
51
37
  prerelease: false
52
38
  version_requirements: !ruby/object:Gem::Requirement
53
39
  requirements:
54
40
  - - '='
55
41
  - !ruby/object:Gem::Version
56
- version: 2.0.10
42
+ version: 2.1.0
57
43
  description: Handles all image upload and processing functionality in Refinery CMS.
58
44
  email: info@refinerycms.com
59
45
  executables: []
@@ -84,6 +70,7 @@ files:
84
70
  - config/locales/es.yml
85
71
  - config/locales/fi.yml
86
72
  - config/locales/fr.yml
73
+ - config/locales/hu.yml
87
74
  - config/locales/it.yml
88
75
  - config/locales/ja.yml
89
76
  - config/locales/ko.yml
@@ -93,16 +80,20 @@ files:
93
80
  - config/locales/nl.yml
94
81
  - config/locales/pl.yml
95
82
  - config/locales/pt-BR.yml
83
+ - config/locales/pt.yml
96
84
  - config/locales/rs.yml
97
85
  - config/locales/ru.yml
98
86
  - config/locales/sk.yml
99
87
  - config/locales/sl.yml
100
88
  - config/locales/sv.yml
89
+ - config/locales/tr.yml
90
+ - config/locales/uk.yml
101
91
  - config/locales/vi.yml
102
92
  - config/locales/zh-CN.yml
103
93
  - config/locales/zh-TW.yml
104
94
  - config/routes.rb
105
95
  - db/migrate/20100913234707_create_refinerycms_images_schema.rb
96
+ - db/migrate/20120625093918_remove_image_ext_from_refinery_images.rb
106
97
  - lib/generators/refinery/images/images_generator.rb
107
98
  - lib/generators/refinery/images/templates/config/initializers/refinery/images.rb.erb
108
99
  - lib/refinery/images.rb
@@ -111,16 +102,19 @@ files:
111
102
  - lib/refinery/images/engine.rb
112
103
  - lib/refinery/images/validators.rb
113
104
  - lib/refinery/images/validators/image_size_validator.rb
105
+ - lib/refinery/images/validators/image_update_validator.rb
114
106
  - lib/refinerycms-images.rb
115
107
  - license.md
116
108
  - refinerycms-images.gemspec
117
109
  - spec/factories/image.rb
110
+ - spec/features/refinery/admin/images_spec.rb
111
+ - spec/fixtures/beach-alternate.jpeg
118
112
  - spec/fixtures/beach.jpeg
113
+ - spec/fixtures/cape-town-tide-table.pdf
119
114
  - spec/fixtures/fathead.png
120
115
  - spec/fixtures/image-with-dashes.jpg
121
116
  - spec/lib/generators/refinery/images/images_generator_spec.rb
122
117
  - spec/models/refinery/image_spec.rb
123
- - spec/requests/refinery/admin/images_spec.rb
124
118
  homepage: http://refinerycms.com
125
119
  licenses:
126
120
  - MIT
@@ -147,9 +141,11 @@ specification_version: 4
147
141
  summary: Images extension for Refinery CMS
148
142
  test_files:
149
143
  - spec/factories/image.rb
144
+ - spec/features/refinery/admin/images_spec.rb
145
+ - spec/fixtures/beach-alternate.jpeg
150
146
  - spec/fixtures/beach.jpeg
147
+ - spec/fixtures/cape-town-tide-table.pdf
151
148
  - spec/fixtures/fathead.png
152
149
  - spec/fixtures/image-with-dashes.jpg
153
150
  - spec/lib/generators/refinery/images/images_generator_spec.rb
154
151
  - spec/models/refinery/image_spec.rb
155
- - spec/requests/refinery/admin/images_spec.rb