comfortable_mexican_sofa 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/VERSION +1 -1
- data/app/assets/images/comfortable_mexican_sofa/jquery_ui/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
- data/app/assets/javascripts/comfortable_mexican_sofa/application.js +38 -25
- data/app/assets/javascripts/comfortable_mexican_sofa/jquery_ui.js +176 -174
- data/app/assets/stylesheets/comfortable_mexican_sofa/content.css +142 -32
- data/app/assets/stylesheets/comfortable_mexican_sofa/form.css +12 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/jquery_ui.css +16 -16
- data/app/assets/stylesheets/comfortable_mexican_sofa/structure.css +3 -2
- data/app/assets/stylesheets/comfortable_mexican_sofa/widgets.css +2 -1
- data/app/controllers/cms_admin/categories_controller.rb +33 -0
- data/app/controllers/cms_admin/files_controller.rb +82 -0
- data/app/controllers/cms_admin/pages_controller.rb +8 -4
- data/app/controllers/cms_admin/snippets_controller.rb +1 -1
- data/app/models/cms/categorization.rb +17 -0
- data/app/models/cms/category.rb +22 -0
- data/app/models/cms/{upload.rb → file.rb} +17 -3
- data/app/models/cms/page.rb +1 -0
- data/app/models/cms/site.rb +1 -1
- data/app/models/cms/snippet.rb +2 -0
- data/app/views/cms_admin/categories/_categories.html.erb +6 -0
- data/app/views/cms_admin/categories/_edit.html.erb +7 -0
- data/app/views/cms_admin/categories/_form.html.erb +12 -0
- data/app/views/cms_admin/categories/_index.html.erb +31 -0
- data/app/views/cms_admin/categories/_show.html.erb +16 -0
- data/app/views/cms_admin/categories/create.js.erb +7 -0
- data/app/views/cms_admin/categories/destroy.js.erb +3 -0
- data/app/views/cms_admin/categories/edit.js.erb +3 -0
- data/app/views/cms_admin/categories/update.js.erb +6 -0
- data/app/views/cms_admin/{uploads → files}/_file.html.erb +1 -1
- data/app/views/cms_admin/files/_form.html.erb +15 -0
- data/app/views/cms_admin/files/_index.html.erb +13 -0
- data/app/views/cms_admin/files/create.js.erb +3 -0
- data/app/views/cms_admin/files/destroy.js.erb +3 -0
- data/app/views/cms_admin/files/edit.html.erb +5 -0
- data/app/views/cms_admin/files/index.html.erb +25 -0
- data/app/views/cms_admin/files/new.html.erb +5 -0
- data/app/views/cms_admin/layouts/_form.html.erb +1 -1
- data/app/views/cms_admin/pages/_form.html.erb +3 -1
- data/app/views/cms_admin/pages/_index_branch.html.erb +6 -4
- data/app/views/cms_admin/pages/index.html.erb +2 -0
- data/app/views/cms_admin/snippets/_form.html.erb +3 -1
- data/app/views/cms_admin/snippets/index.html.erb +3 -0
- data/app/views/layouts/cms_admin/_head.html.erb +2 -6
- data/app/views/layouts/cms_admin/_left.html.erb +1 -0
- data/comfortable_mexican_sofa.gemspec +44 -21
- data/config/database.yml +2 -8
- data/config/locales/en.yml +35 -2
- data/config/locales/es.yml +38 -5
- data/config/routes.rb +3 -2
- data/db/migrate/01_create_cms.rb +23 -4
- data/db/migrate/upgrades/05_upgrade_to_1_4_0.rb +33 -0
- data/lib/comfortable_mexican_sofa.rb +6 -5
- data/lib/comfortable_mexican_sofa/{acts_as_tree.rb → extensions/acts_as_tree.rb} +0 -0
- data/lib/comfortable_mexican_sofa/{has_revisions.rb → extensions/has_revisions.rb} +0 -0
- data/lib/comfortable_mexican_sofa/extensions/is_categorized.rb +45 -0
- data/lib/comfortable_mexican_sofa/{is_mirrored.rb → extensions/is_mirrored.rb} +0 -0
- data/lib/comfortable_mexican_sofa/{rails_extensions.rb → extensions/rails.rb} +0 -0
- data/lib/comfortable_mexican_sofa/tag.rb +2 -2
- data/lib/comfortable_mexican_sofa/tags/{upload.rb → file.rb} +6 -6
- data/test/fixtures/cms/categories.yml +3 -0
- data/test/fixtures/cms/categorizations.yml +3 -0
- data/test/fixtures/cms/{uploads.yml → files.yml} +3 -1
- data/test/functional/cms_admin/categories_controller_test.rb +70 -0
- data/test/functional/cms_admin/files_controller_test.rb +168 -0
- data/test/functional/cms_admin/pages_controller_test.rb +19 -1
- data/test/functional/cms_admin/snippets_controller_test.rb +18 -0
- data/test/unit/models/block_test.rb +1 -1
- data/test/unit/models/categorization_test.rb +76 -0
- data/test/unit/models/category_test.rb +39 -0
- data/test/unit/models/file_test.rb +33 -0
- data/test/unit/models/site_test.rb +9 -0
- data/test/unit/tags/asset_test.rb +1 -1
- data/test/unit/tags/field_datetime_test.rb +1 -1
- data/test/unit/tags/field_integer_test.rb +1 -1
- data/test/unit/tags/field_string_test.rb +1 -1
- data/test/unit/tags/field_text_test.rb +1 -1
- data/test/unit/tags/file_test.rb +67 -0
- data/test/unit/tags/helper_test.rb +1 -1
- data/test/unit/tags/page_datetime_test.rb +1 -1
- data/test/unit/tags/page_integer_test.rb +1 -1
- data/test/unit/tags/page_rich_text.rb +1 -1
- data/test/unit/tags/page_string_test.rb +1 -1
- data/test/unit/tags/page_text_test.rb +1 -1
- data/test/unit/tags/partial_test.rb +1 -1
- data/test/unit/tags/snippet_test.rb +1 -1
- metadata +49 -26
- data/app/assets/javascripts/comfortable_mexican_sofa/plupload/plupload.html5.js +0 -1
- data/app/assets/javascripts/comfortable_mexican_sofa/plupload/plupload.js +0 -2
- data/app/controllers/cms_admin/uploads_controller.rb +0 -29
- data/app/views/cms_admin/uploads/_index.html.erb +0 -10
- data/app/views/cms_admin/uploads/destroy.js.erb +0 -3
- data/test/functional/cms_admin/uploads_controller_test.rb +0 -26
- data/test/unit/models/upload_test.rb +0 -32
- data/test/unit/tags/upload_test.rb +0 -67
data/config/routes.rb
CHANGED
@@ -15,17 +15,18 @@ Rails.application.routes.draw do
|
|
15
15
|
put :revert, :on => :member
|
16
16
|
end
|
17
17
|
end
|
18
|
-
resources :
|
18
|
+
resources :files
|
19
19
|
resources :layouts do
|
20
20
|
resources :revisions, :only => [:index, :show, :revert] do
|
21
21
|
put :revert, :on => :member
|
22
22
|
end
|
23
23
|
end
|
24
|
-
resources :snippets do
|
24
|
+
resources :snippets do
|
25
25
|
resources :revisions, :only => [:index, :show, :revert] do
|
26
26
|
put :revert, :on => :member
|
27
27
|
end
|
28
28
|
end
|
29
|
+
resources :categories
|
29
30
|
end
|
30
31
|
end unless ComfortableMexicanSofa.config.admin_route_prefix.blank?
|
31
32
|
|
data/db/migrate/01_create_cms.rb
CHANGED
@@ -68,15 +68,18 @@ class CreateCms < ActiveRecord::Migration
|
|
68
68
|
end
|
69
69
|
add_index :cms_snippets, [:site_id, :slug], :unique => true
|
70
70
|
|
71
|
-
# --
|
72
|
-
create_table :
|
71
|
+
# -- Files --------------------------------------------------------------
|
72
|
+
create_table :cms_files do |t|
|
73
73
|
t.integer :site_id
|
74
|
+
t.string :label
|
74
75
|
t.string :file_file_name
|
75
76
|
t.string :file_content_type
|
76
77
|
t.integer :file_file_size
|
78
|
+
t.string :description, :limit => 2048
|
77
79
|
t.timestamps
|
78
80
|
end
|
79
|
-
add_index :
|
81
|
+
add_index :cms_files, [:site_id, :label]
|
82
|
+
add_index :cms_files, [:site_id, :file_file_name]
|
80
83
|
|
81
84
|
# -- Revisions -----------------------------------------------------------
|
82
85
|
create_table :cms_revisions, :force => true do |t|
|
@@ -87,6 +90,20 @@ class CreateCms < ActiveRecord::Migration
|
|
87
90
|
end
|
88
91
|
add_index :cms_revisions, [:record_type, :record_id, :created_at]
|
89
92
|
|
93
|
+
# -- Categories ---------------------------------------------------------
|
94
|
+
create_table :cms_categories, :force => true do |t|
|
95
|
+
t.string :label
|
96
|
+
t.string :categorized_type
|
97
|
+
end
|
98
|
+
add_index :cms_categories, [:categorized_type, :label], :unique => true
|
99
|
+
|
100
|
+
create_table :cms_categorizations, :force => true do |t|
|
101
|
+
t.integer :category_id
|
102
|
+
t.string :categorized_type
|
103
|
+
t.integer :categorized_id
|
104
|
+
end
|
105
|
+
add_index :cms_categorizations, [:category_id, :categorized_type, :categorized_id], :unique => true,
|
106
|
+
:name => 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
|
90
107
|
end
|
91
108
|
|
92
109
|
def self.down
|
@@ -95,7 +112,9 @@ class CreateCms < ActiveRecord::Migration
|
|
95
112
|
drop_table :cms_pages
|
96
113
|
drop_table :cms_snippets
|
97
114
|
drop_table :cms_blocks
|
98
|
-
drop_table :
|
115
|
+
drop_table :cms_files
|
99
116
|
drop_table :cms_revisions
|
117
|
+
drop_table :cms_categories
|
118
|
+
drop_table :cms_categorizations
|
100
119
|
end
|
101
120
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class UpgradeTo140 < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
rename_table :cms_uploads, :cms_files
|
4
|
+
add_column :cms_files, :label, :string
|
5
|
+
add_column :cms_files, :description, :string, :limit => 2048
|
6
|
+
add_index :cms_files, [:site_id, :label]
|
7
|
+
|
8
|
+
# -- Categories ---------------------------------------------------------
|
9
|
+
create_table :cms_categories, :force => true do |t|
|
10
|
+
t.string :label
|
11
|
+
t.string :categorized_type
|
12
|
+
end
|
13
|
+
add_index :cms_categories, [:categorized_type, :label], :unique => true
|
14
|
+
|
15
|
+
create_table :cms_categorizations, :force => true do |t|
|
16
|
+
t.integer :category_id
|
17
|
+
t.string :categorized_type
|
18
|
+
t.integer :categorized_id
|
19
|
+
end
|
20
|
+
add_index :cms_categorizations, [:category_id, :categorized_type, :categorized_id], :unique => true,
|
21
|
+
:name => 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
remove_index :cms_files, [:site_id, :label]
|
26
|
+
remove_column :cms_files, :description
|
27
|
+
remove_column :cms_files, :label
|
28
|
+
rename_table :cms_files, :cms_uploads
|
29
|
+
|
30
|
+
drop_table :cms_categories
|
31
|
+
drop_table :cms_categorizations
|
32
|
+
end
|
33
|
+
end
|
@@ -7,16 +7,17 @@ end
|
|
7
7
|
'comfortable_mexican_sofa/error',
|
8
8
|
'comfortable_mexican_sofa/configuration',
|
9
9
|
'comfortable_mexican_sofa/http_auth',
|
10
|
-
'comfortable_mexican_sofa/rails_extensions',
|
11
10
|
'comfortable_mexican_sofa/controller_methods',
|
12
11
|
'comfortable_mexican_sofa/view_hooks',
|
13
12
|
'comfortable_mexican_sofa/view_methods',
|
14
13
|
'comfortable_mexican_sofa/form_builder',
|
15
|
-
'comfortable_mexican_sofa/acts_as_tree',
|
16
|
-
'comfortable_mexican_sofa/has_revisions',
|
17
|
-
'comfortable_mexican_sofa/is_mirrored',
|
18
14
|
'comfortable_mexican_sofa/tag',
|
19
|
-
'comfortable_mexican_sofa/fixtures'
|
15
|
+
'comfortable_mexican_sofa/fixtures',
|
16
|
+
'comfortable_mexican_sofa/extensions/rails',
|
17
|
+
'comfortable_mexican_sofa/extensions/acts_as_tree',
|
18
|
+
'comfortable_mexican_sofa/extensions/has_revisions',
|
19
|
+
'comfortable_mexican_sofa/extensions/is_mirrored',
|
20
|
+
'comfortable_mexican_sofa/extensions/is_categorized'
|
20
21
|
].each do |path|
|
21
22
|
require File.expand_path(path, File.dirname(__FILE__))
|
22
23
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ComfortableMexicanSofa::IsCategorized
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def cms_is_categorized
|
9
|
+
include ComfortableMexicanSofa::IsCategorized::InstanceMethods
|
10
|
+
|
11
|
+
has_many :categorizations,
|
12
|
+
:as => :categorized,
|
13
|
+
:dependent => :destroy
|
14
|
+
has_many :categories,
|
15
|
+
:through => :categorizations
|
16
|
+
|
17
|
+
attr_accessor :category_ids
|
18
|
+
|
19
|
+
after_save :sync_categories
|
20
|
+
|
21
|
+
scope :for_category, lambda { |*categories|
|
22
|
+
if (categories = [categories].flatten.compact).present?
|
23
|
+
select("DISTINCT #{table_name}.*").joins(:categorizations => :category).where('cms_categories.label' => categories)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
def sync_categories
|
31
|
+
(self.category_ids || {}).each do |category_id, flag|
|
32
|
+
case flag.to_i
|
33
|
+
when 1
|
34
|
+
if category = Cms::Category.find_by_id(category_id)
|
35
|
+
category.categorizations.create(:categorized => self)
|
36
|
+
end
|
37
|
+
when 0
|
38
|
+
self.categorizations.where(:category_id => category_id).destroy_all
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveRecord::Base.send :include, ComfortableMexicanSofa::IsCategorized
|
File without changes
|
File without changes
|
@@ -85,8 +85,8 @@ module ComfortableMexicanSofa::Tag
|
|
85
85
|
end
|
86
86
|
|
87
87
|
# Initializing Cms::Upload object
|
88
|
-
def
|
89
|
-
page.site.
|
88
|
+
def file
|
89
|
+
page.site.files.detect{|f| f.file_file_name == self.label.to_s}
|
90
90
|
end
|
91
91
|
|
92
92
|
# Checks if this tag is using Cms::Block
|
@@ -1,24 +1,24 @@
|
|
1
|
-
class ComfortableMexicanSofa::Tag::
|
1
|
+
class ComfortableMexicanSofa::Tag::File
|
2
2
|
include ComfortableMexicanSofa::Tag
|
3
3
|
|
4
4
|
def self.regex_tag_signature(label = nil)
|
5
5
|
label ||= /[\w\-\.]+/
|
6
|
-
/\{\{\s*cms:
|
6
|
+
/\{\{\s*cms:file:(#{label}):?(.*?)\s*\}\}/
|
7
7
|
end
|
8
8
|
|
9
9
|
def content
|
10
|
-
return unless
|
10
|
+
return unless file
|
11
11
|
|
12
12
|
format = params[0]
|
13
13
|
text = params[1] || label
|
14
14
|
|
15
15
|
case format
|
16
16
|
when 'link'
|
17
|
-
"<a href='#{
|
17
|
+
"<a href='#{file.file.url}' target='_blank'>#{text}</a>"
|
18
18
|
when 'image'
|
19
|
-
"<img src='#{
|
19
|
+
"<img src='#{file.file.url}' alt='#{text}' />"
|
20
20
|
else
|
21
|
-
|
21
|
+
file.file.url
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class CmsAdmin::CategoriesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_edit
|
6
|
+
xhr :get, :edit, :site_id => cms_sites(:default), :id => cms_categories(:default)
|
7
|
+
assert_response :success
|
8
|
+
assert_template :edit
|
9
|
+
assert assigns(:category)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_edit_failure
|
13
|
+
xhr :get, :edit, :site_id => cms_sites(:default), :id => 'invalid'
|
14
|
+
assert_response :success
|
15
|
+
assert response.body.blank?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_creation
|
19
|
+
assert_difference 'Cms::Category.count' do
|
20
|
+
xhr :post, :create, :site_id => cms_sites(:default), :category => {
|
21
|
+
:label => 'Test Label',
|
22
|
+
:categorized_type => 'Cms::Snippet'
|
23
|
+
}
|
24
|
+
assert_response :success
|
25
|
+
assert_template :create
|
26
|
+
assert assigns(:category)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_creation_failure
|
31
|
+
assert_no_difference 'Cms::Category.count' do
|
32
|
+
xhr :post, :create, :site_id => cms_sites(:default), :category => { }
|
33
|
+
assert_response :success
|
34
|
+
assert response.body.blank?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_update
|
39
|
+
category = cms_categories(:default)
|
40
|
+
xhr :put, :update, :site_id => cms_sites(:default), :id => category, :category => {
|
41
|
+
:label => 'Updated Label'
|
42
|
+
}
|
43
|
+
assert_response :success
|
44
|
+
assert_template :update
|
45
|
+
assert assigns(:category)
|
46
|
+
category.reload
|
47
|
+
assert_equal 'Updated Label', category.label
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_update_failure
|
51
|
+
category = cms_categories(:default)
|
52
|
+
xhr :put, :update, :site_id => cms_sites(:default), :id => category, :category => {
|
53
|
+
:label => ''
|
54
|
+
}
|
55
|
+
assert_response :success
|
56
|
+
assert response.body.blank?
|
57
|
+
category.reload
|
58
|
+
assert_not_equal '', category.label
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_destroy
|
62
|
+
assert_difference 'Cms::Category.count', -1 do
|
63
|
+
xhr :delete, :destroy, :site_id => cms_sites(:default), :id => cms_categories(:default)
|
64
|
+
assert assigns(:category)
|
65
|
+
assert_response :success
|
66
|
+
assert_template :destroy
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class CmsAdmin::FilesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index, :site_id => cms_sites(:default)
|
7
|
+
assert_response :success
|
8
|
+
assert assigns(:files)
|
9
|
+
assert_template :index
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_index_with_no_files
|
13
|
+
Cms::File.delete_all
|
14
|
+
get :index, :site_id => cms_sites(:default)
|
15
|
+
assert_response :redirect
|
16
|
+
assert_redirected_to :action => :new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_index_with_category
|
20
|
+
get :index, :site_id => cms_sites(:default), :category => cms_categories(:default).label
|
21
|
+
assert_response :success
|
22
|
+
assert assigns(:files)
|
23
|
+
assert_equal 1, assigns(:files).count
|
24
|
+
assert assigns(:files).first.categories.member? cms_categories(:default)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_index_with_category_invalid
|
28
|
+
get :index, :site_id => cms_sites(:default), :category => 'invalid'
|
29
|
+
assert_response :success
|
30
|
+
assert assigns(:files)
|
31
|
+
assert_equal 0, assigns(:files).count
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_new
|
35
|
+
site = cms_sites(:default)
|
36
|
+
get :new, :site_id => site
|
37
|
+
assert_response :success
|
38
|
+
assert assigns(:file)
|
39
|
+
assert_template :new
|
40
|
+
assert_select "form[action=/cms-admin/sites/#{site.id}/files]"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_get_edit
|
44
|
+
file = cms_files(:default)
|
45
|
+
get :edit, :site_id => file.site, :id => file
|
46
|
+
assert_response :success
|
47
|
+
assert assigns(:file)
|
48
|
+
assert_template :edit
|
49
|
+
assert_select "form[action=/cms-admin/sites/#{file.site.id}/files/#{file.id}]"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_get_edit_failure
|
53
|
+
get :edit, :site_id => cms_sites(:default), :id => 'not_found'
|
54
|
+
assert_response :redirect
|
55
|
+
assert_redirected_to :action => :index
|
56
|
+
assert_equal 'File not found', flash[:error]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_create
|
60
|
+
assert_difference 'Cms::File.count' do
|
61
|
+
post :create, :site_id => cms_sites(:default), :file => {
|
62
|
+
:label => 'Test File',
|
63
|
+
:description => 'Test Description',
|
64
|
+
:file => [fixture_file_upload('files/valid_image.jpg')]
|
65
|
+
}
|
66
|
+
assert_response :redirect
|
67
|
+
file = Cms::File.last
|
68
|
+
assert_equal cms_sites(:default), file.site
|
69
|
+
assert_equal 'Test File', file.label
|
70
|
+
assert_equal 'Test Description', file.description
|
71
|
+
assert_redirected_to :action => :edit, :id => file
|
72
|
+
assert_equal 'Files uploaded', flash[:notice]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_create_failure
|
77
|
+
assert_no_difference 'Cms::File.count' do
|
78
|
+
post :create, :site_id => cms_sites(:default), :file => { }
|
79
|
+
assert_response :success
|
80
|
+
assert_template :new
|
81
|
+
assert_equal 'Failed to upload files', flash[:error]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_create_multiple
|
86
|
+
Cms::File.delete_all
|
87
|
+
|
88
|
+
assert_difference 'Cms::File.count', 2 do
|
89
|
+
post :create, :site_id => cms_sites(:default), :file => {
|
90
|
+
:label => 'Test File',
|
91
|
+
:description => 'Test Description',
|
92
|
+
:file => [
|
93
|
+
fixture_file_upload('files/valid_image.jpg'),
|
94
|
+
fixture_file_upload('files/invalid_file.gif')
|
95
|
+
]
|
96
|
+
}
|
97
|
+
assert_response :redirect
|
98
|
+
file_a, file_b = Cms::File.all
|
99
|
+
assert_equal cms_sites(:default), file_a.site
|
100
|
+
|
101
|
+
assert_equal 'valid_image.jpg', file_a.file_file_name
|
102
|
+
assert_equal 'invalid_file.gif', file_b.file_file_name
|
103
|
+
assert_equal 'Test File 1', file_a.label
|
104
|
+
assert_equal 'Test File 2', file_b.label
|
105
|
+
assert_equal 'Test Description', file_a.description
|
106
|
+
assert_equal 'Test Description', file_b.description
|
107
|
+
|
108
|
+
assert_redirected_to :action => :edit, :id => file_b
|
109
|
+
assert_equal 'Files uploaded', flash[:notice]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_create_as_xhr
|
114
|
+
request.env['HTTP_X_FILE_NAME'] = 'test.pdf'
|
115
|
+
request.env['CONTENT_TYPE'] = 'application/pdf'
|
116
|
+
|
117
|
+
assert_difference 'Cms::File.count' do
|
118
|
+
xhr :post, :create, :site_id => cms_sites(:default)
|
119
|
+
assert_response :success
|
120
|
+
|
121
|
+
file = Cms::File.last
|
122
|
+
assert_equal 'test.pdf', file.file_file_name
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_update
|
127
|
+
file = cms_files(:default)
|
128
|
+
put :update, :site_id => file.site, :id => file, :file => {
|
129
|
+
:label => 'New File',
|
130
|
+
:description => 'New Description'
|
131
|
+
}
|
132
|
+
assert_response :redirect
|
133
|
+
assert_redirected_to :action => :edit, :site_id => file.site, :id => file
|
134
|
+
assert_equal 'File updated', flash[:notice]
|
135
|
+
file.reload
|
136
|
+
assert_equal 'New File', file.label
|
137
|
+
assert_equal 'New Description', file.description
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_update_failure
|
141
|
+
file = cms_files(:default)
|
142
|
+
put :update, :site_id => file.site, :id => file, :file => {
|
143
|
+
:file => nil
|
144
|
+
}
|
145
|
+
assert_response :success
|
146
|
+
assert_template :edit
|
147
|
+
file.reload
|
148
|
+
assert_not_equal nil, file.file
|
149
|
+
assert_equal 'Failed to update file', flash[:error]
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_destroy
|
153
|
+
assert_difference 'Cms::File.count', -1 do
|
154
|
+
delete :destroy, :site_id => cms_sites(:default), :id => cms_files(:default)
|
155
|
+
assert_response :redirect
|
156
|
+
assert_redirected_to :action => :index
|
157
|
+
assert_equal 'File deleted', flash[:notice]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_destroy_as_xhr
|
162
|
+
assert_difference 'Cms::File.count', -1 do
|
163
|
+
xhr :delete, :destroy, :site_id => cms_sites(:default), :id => cms_files(:default)
|
164
|
+
assert_response :success
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|