refinerycms-resources 2.1.5 → 3.0.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 (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/resources_controller.rb +41 -17
  3. data/app/models/refinery/resource.rb +20 -9
  4. data/app/views/refinery/admin/resources/_actions.html.erb +2 -4
  5. data/app/views/refinery/admin/resources/_existing_resource.html.erb +1 -1
  6. data/app/views/refinery/admin/resources/_form.html.erb +18 -9
  7. data/app/views/refinery/admin/resources/_records.html.erb +3 -3
  8. data/app/views/refinery/admin/resources/_resource.html.erb +31 -16
  9. data/app/views/refinery/admin/resources/insert.html.erb +1 -1
  10. data/config/locales/ca.yml +36 -0
  11. data/config/locales/cs.yml +3 -4
  12. data/config/locales/en.yml +3 -0
  13. data/config/locales/fr.yml +3 -0
  14. data/config/locales/id.yml +36 -0
  15. data/config/locales/it.yml +6 -16
  16. data/config/routes.rb +1 -1
  17. data/db/migrate/20150430180959_add_translated_title_to_refinery_resources.rb +11 -0
  18. data/lib/generators/refinery/resources/templates/config/initializers/refinery/resources.rb.erb +1 -2
  19. data/lib/refinery/resources.rb +4 -1
  20. data/lib/refinery/resources/configuration.rb +12 -4
  21. data/lib/refinery/resources/dragonfly.rb +33 -25
  22. data/lib/refinery/resources/engine.rb +2 -3
  23. data/license.md +1 -1
  24. data/refinerycms-resources.gemspec +7 -4
  25. data/spec/factories/resource.rb +1 -1
  26. data/spec/features/refinery/admin/resources_spec.rb +53 -30
  27. data/spec/lib/generators/refinery/resources/resources_generator_spec.rb +1 -1
  28. data/spec/lib/resources_spec.rb +15 -11
  29. data/spec/models/refinery/resource_spec.rb +54 -25
  30. metadata +36 -14
  31. data/app/helpers/refinery/admin/resources_helper.rb +0 -6
@@ -1,5 +1,5 @@
1
1
  Refinery::Core::Engine.routes.draw do
2
- get '/system/resources/*dragonfly', :to => Dragonfly[:refinery_resources]
2
+ get '/system/resources/*dragonfly', :to => Dragonfly.app(:refinery_resources)
3
3
 
4
4
  namespace :admin, :path => Refinery::Core.backend_route do
5
5
  resources :resources, :except => :show do
@@ -0,0 +1,11 @@
1
+ class AddTranslatedTitleToRefineryResources < ActiveRecord::Migration
2
+ def self.up
3
+ Refinery::Resource.create_translation_table!({
4
+ resource_title: :string
5
+ })
6
+ end
7
+
8
+ def self.down
9
+ Refinery::Resource.drop_translation_table!
10
+ end
11
+ end
@@ -18,8 +18,7 @@ Refinery::Resources.configure do |config|
18
18
  # config.s3_region = ENV['S3_REGION']
19
19
 
20
20
  # Configure Dragonfly
21
- # This is where in the middleware stack to insert the Dragonfly middleware
22
- # config.dragonfly_insert_before = <%= Refinery::Resources.dragonfly_insert_before.inspect %>
21
+ # config.dragonfly_verify_urls = <%= Refinery::Resources.dragonfly_verify_urls %>
23
22
  # config.dragonfly_secret = <%= Refinery::Resources.dragonfly_secret.inspect %>
24
23
  # config.dragonfly_url_format = <%= Refinery::Resources.dragonfly_url_format.inspect %>
25
24
  # config.dragonfly_url_host = <%= Refinery::Resources.dragonfly_url_host.inspect %>
@@ -1,6 +1,5 @@
1
1
  require 'refinerycms-core'
2
2
  require 'dragonfly'
3
- require 'rack/cache'
4
3
 
5
4
  module Refinery
6
5
  autoload :ResourcesGenerator, 'generators/refinery/resources/resources_generator'
@@ -23,3 +22,7 @@ module Refinery
23
22
  end
24
23
  end
25
24
  end
25
+
26
+ ActiveSupport.on_load(:active_record) do
27
+ require 'globalize'
28
+ end
@@ -2,26 +2,34 @@ module Refinery
2
2
  module Resources
3
3
  include ActiveSupport::Configurable
4
4
 
5
- config_accessor :dragonfly_insert_before, :dragonfly_secret, :dragonfly_url_format, :dragonfly_url_host,
5
+ config_accessor :dragonfly_secret, :dragonfly_url_format, :dragonfly_url_host, :dragonfly_verify_urls,
6
6
  :max_file_size, :pages_per_dialog, :pages_per_admin_index,
7
7
  :s3_backend, :s3_bucket_name, :s3_region,
8
8
  :s3_access_key_id, :s3_secret_access_key,
9
9
  :datastore_root_path, :content_disposition,
10
10
  :custom_backend_class, :custom_backend_opts
11
11
 
12
- self.dragonfly_insert_before = 'ActionDispatch::Callbacks'
13
12
  self.dragonfly_secret = Core.dragonfly_secret
14
- self.dragonfly_url_format = '/system/resources/:job/:basename.:format'
13
+ self.dragonfly_url_format = '/system/resources/:job/:basename.:ext'
15
14
  self.dragonfly_url_host = ''
15
+ self.dragonfly_verify_urls = true
16
16
 
17
17
  self.content_disposition = :attachment
18
- self.max_file_size = 52428800
18
+ self.max_file_size = 52_428_800
19
19
  self.pages_per_dialog = 12
20
20
  self.pages_per_admin_index = 20
21
21
 
22
22
  # We have to configure these settings after Rails is available.
23
23
  # But a non-nil custom option can still be provided
24
24
  class << self
25
+ def dragonfly_url_format
26
+ if config.dragonfly_url_format.include?(':format')
27
+ config.dragonfly_url_format.gsub!(':format', ':ext')
28
+ Refinery.deprecate(':format option in Refinery::Resources dragonfly_url_format config', when: '3.1', replacement: ':ext option')
29
+ end
30
+ config.dragonfly_url_format
31
+ end
32
+
25
33
  def datastore_root_path
26
34
  config.datastore_root_path || (Rails.root.join('public', 'system', 'refinery', 'resources').to_s if Rails.root)
27
35
  end
@@ -5,34 +5,35 @@ module Refinery
5
5
  module Dragonfly
6
6
 
7
7
  class << self
8
- def setup!
9
- app_resources = ::Dragonfly[:refinery_resources]
10
-
11
- app_resources.define_macro(::Refinery::Resource, :resource_accessor)
8
+ def configure!
9
+ ActiveRecord::Base.extend ::Dragonfly::Model
10
+ ActiveRecord::Base.extend ::Dragonfly::Model::Validations
12
11
 
13
- app_resources.analyser.register(::Dragonfly::Analysis::FileCommandAnalyser)
14
- app_resources.content_disposition = Refinery::Resources.content_disposition
15
- end
12
+ app_resources = ::Dragonfly.app(:refinery_resources)
16
13
 
17
- def configure!
18
- app_resources = ::Dragonfly[:refinery_resources]
19
- app_resources.configure_with(:rails)
20
14
  app_resources.configure do |c|
21
- c.datastore.root_path = Refinery::Resources.datastore_root_path
22
- c.url_format = Refinery::Resources.dragonfly_url_format
23
- c.url_host = Refinery::Resources.dragonfly_url_host
24
- c.secret = Refinery::Resources.dragonfly_secret
15
+ datastore :file, {
16
+ :root_path => Refinery::Resources.datastore_root_path
17
+ }
18
+ url_format Refinery::Resources.dragonfly_url_format
19
+ url_host Refinery::Resources.dragonfly_url_host
20
+ verify_urls Refinery::Resources.dragonfly_verify_urls
21
+ secret Refinery::Resources.dragonfly_secret
22
+ response_header 'Content-Disposition' do |job, request, headers|
23
+ "attachment; #{headers['Content-Disposition']}"
24
+ end if Refinery::Resources.content_disposition == :attachment
25
+ dragonfly_url nil
25
26
  end
26
27
 
27
28
  if ::Refinery::Resources.s3_backend
28
- app_resources.datastore = ::Dragonfly::DataStorage::S3DataStore.new
29
- app_resources.datastore.configure do |s3|
30
- s3.bucket_name = Refinery::Resources.s3_bucket_name
31
- s3.access_key_id = Refinery::Resources.s3_access_key_id
32
- s3.secret_access_key = Refinery::Resources.s3_secret_access_key
33
- # S3 Region otherwise defaults to 'us-east-1'
34
- s3.region = Refinery::Resources.s3_region if Refinery::Resources.s3_region
35
- end
29
+ require 'dragonfly/s3_data_store'
30
+ options = {
31
+ bucket_name: Refinery::Resources.s3_bucket_name,
32
+ access_key_id: Refinery::Resources.s3_access_key_id,
33
+ secret_access_key: Refinery::Resources.s3_secret_access_key
34
+ }
35
+ options.update(region: Refinery::Resources.s3_region) if Refinery::Resources.s3_region
36
+ app_resources.use_datastore :s3, options
36
37
  end
37
38
 
38
39
  if Resources.custom_backend?
@@ -43,10 +44,17 @@ module Refinery
43
44
  ##
44
45
  # Injects Dragonfly::Middleware for Refinery::Images into the stack
45
46
  def attach!(app)
46
- if ::Rails.application.config.action_controller.perform_caching
47
- app.config.middleware.insert_after 'Rack::Cache', 'Dragonfly::Middleware', :refinery_resources
47
+ if defined?(::Rack::Cache)
48
+ unless app.config.action_controller.perform_caching && app.config.action_dispatch.rack_cache
49
+ app.config.middleware.insert 0, ::Rack::Cache, {
50
+ verbose: true,
51
+ metastore: URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
52
+ entitystore: URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
53
+ }
54
+ end
55
+ app.config.middleware.insert_after ::Rack::Cache, ::Dragonfly::Middleware, :refinery_resources
48
56
  else
49
- app.config.middleware.use 'Dragonfly::Middleware', :refinery_resources
57
+ app.config.middleware.use ::Dragonfly::Middleware, :refinery_resources
50
58
  end
51
59
  end
52
60
  end
@@ -8,17 +8,16 @@ module Refinery
8
8
 
9
9
  config.autoload_paths += %W( #{config.root}/lib )
10
10
 
11
- initializer 'attach-refinery-resources-with-dragonfly', :before => :build_middleware_stack do |app|
11
+ initializer 'attach-refinery-resources-with-dragonfly', :before => :finisher_hook do |app|
12
12
  ::Refinery::Resources::Dragonfly.configure!
13
13
  ::Refinery::Resources::Dragonfly.attach!(app)
14
14
  end
15
15
 
16
- initializer "register refinery_files plugin" do
16
+ before_inclusion do
17
17
  Refinery::Plugin.register do |plugin|
18
18
  plugin.pathname = root
19
19
  plugin.name = 'refinery_files'
20
20
  plugin.menu_match = /refinery\/(refinery_)?(files|resources)$/
21
- plugin.activity = { :class_name => :'refinery/resource' }
22
21
  plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_resources_path }
23
22
  end
24
23
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright (c) 2005-2013 [Resolve Digital](http://www.resolvedigital.com)
3
+ Copyright (c) 2005-2015 [Resolve Digital](http://resolve.digital)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = version
10
10
  s.summary = %q{Resources extension for Refinery CMS}
11
11
  s.description = %q{Handles all file upload and processing functionality in Refinery CMS.}
12
- s.email = %q{info@refinerycms.com}
12
+ s.email = %q{refinerycms@p.arndt.io}
13
13
  s.homepage = %q{http://refinerycms.com}
14
14
  s.rubyforge_project = %q{refinerycms}
15
15
  s.authors = ['Philip Arndt', 'Uģis Ozols', 'Rob Yurkowski']
@@ -19,7 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- spec/*`.split("\n")
21
21
 
22
- s.add_dependency 'dragonfly', '~> 0.9.12'
23
- s.add_dependency 'acts_as_indexed', '~> 0.8.0'
24
- s.add_dependency 'refinerycms-core', version
22
+ s.add_dependency 'acts_as_indexed', '~> 0.8.0'
23
+ s.add_dependency 'dragonfly', '~> 1.0.0'
24
+ s.add_dependency 'globalize', ['>= 4.0.0', '< 5.2']
25
+ s.add_dependency 'refinerycms-core', version
26
+
27
+ s.required_ruby_version = Refinery::Version.required_ruby_version
25
28
  end
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
2
  factory :resource, :class => Refinery::Resource do
3
- file Refinery.roots(:'refinery/resources').join("spec/fixtures/refinery_is_awesome.txt")
3
+ file Refinery.roots('refinery/resources').join("spec/fixtures/refinery_is_awesome.txt")
4
4
  end
5
5
  end
@@ -3,71 +3,70 @@ require "spec_helper"
3
3
 
4
4
  module Refinery
5
5
  module Admin
6
- describe "Resources" do
7
- refinery_login_with :refinery_user
6
+ describe "Resources", :type => :feature do
7
+ refinery_login
8
8
 
9
9
  context "when no files" do
10
10
  it "invites to upload file" do
11
11
  visit refinery.admin_resources_path
12
- page.should have_content(%q{There are no files yet. Click "Upload new file" to add your first file.})
12
+ expect(page).to have_content(%q{There are no files yet. Click "Upload new file" to add your first file.})
13
13
  end
14
14
  end
15
15
 
16
16
  it "shows upload file link" do
17
17
  visit refinery.admin_resources_path
18
- page.should have_content("Upload new file")
19
- page.should have_selector("a[href*='/refinery/resources/new']")
18
+ expect(page).to have_content("Upload new file")
19
+ expect(page).to have_selector("a[href*='/refinery/resources/new']")
20
20
  end
21
21
 
22
-
23
22
  context "new/create" do
24
23
  it "uploads file", :js => true do
25
24
  visit refinery.admin_resources_path
26
- click_link "Upload new file"
25
+ find('a', text: 'Upload new file').trigger(:click)
27
26
 
28
- page.should have_selector 'iframe#dialog_iframe'
27
+ expect(page).to have_selector 'iframe#dialog_iframe'
29
28
 
30
29
  page.within_frame('dialog_iframe') do
31
- attach_file "resource_file", Refinery.roots(:'refinery/resources').
30
+ attach_file "resource_file", Refinery.roots('refinery/resources').
32
31
  join("spec/fixtures/refinery_is_awesome.txt")
33
32
  click_button ::I18n.t('save', :scope => 'refinery.admin.form_actions')
34
33
  end
35
34
 
36
- page.should have_content("Refinery Is Awesome.txt")
37
- Refinery::Resource.count.should == 1
35
+ expect(page).to have_content("Refinery Is Awesome")
36
+ expect(Refinery::Resource.count).to eq(1)
38
37
  end
39
38
 
40
39
  describe "max file size" do
41
40
  before do
42
- Refinery::Resources.stub(:max_file_size).and_return('1224')
41
+ allow(Refinery::Resources).to receive(:max_file_size).and_return('1224')
43
42
  end
44
43
 
45
44
  context "in english" do
46
45
  before do
47
- Refinery::I18n.stub(:current_locale).and_return(:en)
46
+ allow(Refinery::I18n).to receive(:current_locale).and_return(:en)
48
47
  end
49
48
 
50
49
  it "is shown" do
51
50
  visit refinery.admin_resources_path
52
51
  click_link "Upload new file"
53
52
 
54
- within('#maximum_file_size') do
55
- page.should have_content "1.2 KB"
53
+ within('#file') do
54
+ expect(page).to have_selector("a[tooltip='The maximum file size is 1.2 KB.']")
56
55
  end
57
56
  end
58
57
  end
59
58
 
60
59
  context "in danish" do
61
60
  before do
62
- Refinery::I18n.stub(:current_locale).and_return(:da)
61
+ allow(Refinery::I18n).to receive(:current_locale).and_return(:da)
63
62
  end
64
63
 
65
64
  it "is shown" do
66
65
  visit refinery.admin_resources_path
67
66
 
68
67
  click_link "Tilføj en ny fil"
69
- within "#maximum_file_size" do
70
- page.should have_content "1,2 KB"
68
+ within "#file" do
69
+ expect(page).to have_selector("a[tooltip='Filen må maksimalt fylde 1,2 KB.']")
71
70
  end
72
71
  end
73
72
  end
@@ -79,19 +78,43 @@ module Refinery
79
78
 
80
79
  it "updates file" do
81
80
  visit refinery.admin_resources_path
82
- page.should have_content("Refinery Is Awesome.txt")
83
- page.should have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
81
+ expect(page).to have_content("Refinery Is Awesome")
82
+ expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
84
83
 
85
84
  click_link "Edit this file"
86
85
 
87
- page.should have_content("Download current file or replace it with this one...")
88
- page.should have_selector("a[href*='/refinery/resources']")
86
+ expect(page).to have_content("Refinery Is Awesome or replace it with this one...")
87
+ expect(page).to have_selector("a[href*='/refinery/resources']")
89
88
 
90
- attach_file "resource_file", Refinery.roots(:'refinery/resources').join("spec/fixtures/refinery_is_awesome2.txt")
89
+ attach_file "resource_file", Refinery.roots('refinery/resources').join("spec/fixtures/refinery_is_awesome2.txt")
91
90
  click_button "Save"
92
91
 
93
- page.should have_content("Refinery Is Awesome2")
94
- Refinery::Resource.count.should == 1
92
+ expect(page).to have_content("Refinery Is Awesome2")
93
+ expect(Refinery::Resource.count).to eq(1)
94
+ end
95
+
96
+ describe "translate" do
97
+ before do
98
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :fr])
99
+ end
100
+
101
+ it "can have a second locale added to it" do
102
+ visit refinery.admin_resources_path
103
+ expect(page).to have_content("Refinery Is Awesome")
104
+ expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}/edit']")
105
+
106
+ click_link "Edit this file"
107
+
108
+ within "#switch_locale_picker" do
109
+ click_link "FR"
110
+ end
111
+
112
+ fill_in "Title", :with => "Premier fichier"
113
+ click_button "Save"
114
+
115
+ expect(page).to have_content("'Premier fichier' was successfully updated.")
116
+ expect(Resource.translation_class.count).to eq(1)
117
+ end
95
118
  end
96
119
  end
97
120
 
@@ -100,12 +123,12 @@ module Refinery
100
123
 
101
124
  it "removes file" do
102
125
  visit refinery.admin_resources_path
103
- page.should have_selector("a[href='/refinery/resources/#{resource.id}']")
126
+ expect(page).to have_selector("a[href='/refinery/resources/#{resource.id}']")
104
127
 
105
128
  click_link "Remove this file forever"
106
129
 
107
- page.should have_content("'Refinery Is Awesome' was successfully removed.")
108
- Refinery::Resource.count.should == 0
130
+ expect(page).to have_content("'Refinery Is Awesome' was successfully removed.")
131
+ expect(Refinery::Resource.count).to eq(0)
109
132
  end
110
133
  end
111
134
 
@@ -117,7 +140,7 @@ module Refinery
117
140
 
118
141
  click_link "Download this file"
119
142
 
120
- page.should have_content("http://www.refineryhq.com/")
143
+ expect(page).to have_content("http://www.refineryhq.com/")
121
144
  end
122
145
 
123
146
  context 'when the extension is mounted with a named space' do
@@ -139,7 +162,7 @@ module Refinery
139
162
 
140
163
  click_link "Download this file"
141
164
 
142
- page.should have_content("http://www.refineryhq.com/")
165
+ expect(page).to have_content("http://www.refineryhq.com/")
143
166
  end
144
167
 
145
168
  end
@@ -13,7 +13,7 @@ module Refinery
13
13
  end
14
14
 
15
15
  specify do
16
- destination_root.should have_structure {
16
+ expect(destination_root).to have_structure {
17
17
  directory "config" do
18
18
  directory "initializers" do
19
19
  directory "refinery" do
@@ -6,7 +6,7 @@ describe Refinery::Resources do
6
6
  Refinery::Core.s3_bucket_name = "kfc"
7
7
  described_class.s3_bucket_name = "buckethead"
8
8
 
9
- described_class.s3_bucket_name.should == "buckethead"
9
+ expect(described_class.s3_bucket_name).to eq("buckethead")
10
10
  end
11
11
  end
12
12
 
@@ -15,27 +15,31 @@ describe Refinery::Resources do
15
15
  described_class.s3_bucket_name = nil
16
16
  Refinery::Core.s3_bucket_name = "kfc"
17
17
 
18
- described_class.s3_bucket_name.should == "kfc"
18
+ expect(described_class.s3_bucket_name).to eq("kfc")
19
19
  end
20
20
  end
21
21
 
22
22
  describe "with a custom storage backend" do
23
- before do
24
- Refinery::Core.dragonfly_custom_backend_class = 'DummyBackend1'
25
- class DummyBackend1; end
26
- class DummyBackend2; end
23
+ before(:all) do
24
+ DummyBackend1 = Class.new
25
+ DummyBackend2 = Class.new
26
+ end
27
+
28
+ before(:each) do
29
+ allow(Refinery::Core).to receive_messages(:dragonfly_custom_backend_class => DummyBackend1)
30
+ end
31
+
32
+ after(:each) do
33
+ described_class.custom_backend_class = nil
27
34
  end
28
- after { Refinery::Core.dragonfly_custom_backend_class = nil }
29
- let(:backend1) { DummyBackend1.new }
30
- let(:backend2) { DummyBackend2.new }
31
35
 
32
36
  it "uses the default configuration if present" do
33
- described_class.custom_backend_class.should == backend1.class
37
+ expect(described_class.custom_backend_class).to eq(DummyBackend1)
34
38
  end
35
39
 
36
40
  it "prefers custom values over the defaults" do
37
41
  described_class.custom_backend_class = 'DummyBackend2'
38
- described_class.custom_backend_class.should == backend2.class
42
+ expect(described_class.custom_backend_class).to eq(DummyBackend2)
39
43
  end
40
44
  end
41
45
  end