comfortable_mexican_sofa 1.4.13 → 1.4.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.13
1
+ 1.4.14
@@ -36,7 +36,9 @@ class CmsAdmin::FilesController < CmsAdmin::BaseController
36
36
  io.class.class_eval { attr_accessor :original_filename, :content_type }
37
37
  io.original_filename = request.env['HTTP_X_FILE_NAME']
38
38
  io.content_type = request.env['CONTENT_TYPE']
39
- @file = @site.files.create!(:file => io)
39
+ @file = @site.files.create!(
40
+ (params[:file] || { }).merge(:file => io)
41
+ )
40
42
  end
41
43
  end
42
44
  rescue ActiveRecord::RecordInvalid
@@ -6,6 +6,10 @@ class Cms::File < ActiveRecord::Base
6
6
 
7
7
  cms_is_categorized
8
8
 
9
+ attr_accessor :layout_id,
10
+ :page_id,
11
+ :snippet_id
12
+
9
13
  # -- AR Extensions --------------------------------------------------------
10
14
  has_attached_file :file, ComfortableMexicanSofa.config.upload_file_options
11
15
 
@@ -20,7 +24,8 @@ class Cms::File < ActiveRecord::Base
20
24
  :scope => :site_id
21
25
 
22
26
  # -- Callbacks ------------------------------------------------------------
23
- before_save :assign_label
27
+ before_save :assign_label,
28
+ :categorize_file
24
29
 
25
30
  protected
26
31
 
@@ -28,4 +33,15 @@ protected
28
33
  self.label = self.label.blank?? self.file_file_name.gsub(/\.[^\.]*?$/, '').titleize : self.label
29
34
  end
30
35
 
36
+ def categorize_file
37
+ category = if layout_id && layout = site.layouts.find_by_id(layout_id)
38
+ Cms::Category.find_or_create_by_label_and_categorized_type("[layout] #{layout.slug}", 'Cms::File')
39
+ elsif page_id && page = site.pages.find_by_id(page_id)
40
+ Cms::Category.find_or_create_by_label_and_categorized_type("[page] #{page.full_path}", 'Cms::File')
41
+ elsif snippet_id && snippet = site.snippets.find_by_id(snippet_id)
42
+ Cms::Category.find_or_create_by_label_and_categorized_type("[snippet] #{snippet.slug}", 'Cms::File')
43
+ end
44
+ self.category_ids = { category.id => 1 } if category
45
+ end
46
+
31
47
  end
@@ -1,6 +1,17 @@
1
1
  <div id='file_uploads' class='box'>
2
2
 
3
- <%= form_for :file, :url => cms_admin_site_files_path(@site), :html => {:multipart => true} do |form| %>
3
+ <%
4
+ key, id = if @layout && !@layout.new_record?
5
+ [:layout_id, @layout.id]
6
+ elsif @page && !@page.new_record?
7
+ [:page_id, @page.id]
8
+ elsif @snippet && !@snippet.new_record?
9
+ [:snippet_id, @snippet.id]
10
+ end
11
+ url_param = key.present?? "?file[#{key}]=#{id}" : ''
12
+ %>
13
+
14
+ <%= form_for :file, :url => cms_admin_site_files_path(@site) + url_param, :html => {:multipart => true} do |form| %>
4
15
  <a id='uploader_button' href='#' class='big button'><%= t('.button') %></a>
5
16
  <%= form.file_field :file, :multiple => true %>
6
17
  <% end %>
@@ -10,4 +21,4 @@
10
21
  <%= render :partial => 'cms_admin/files/file', :object => file %>
11
22
  <% end %>
12
23
  </div>
13
- </div>
24
+ </div>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.4.13"
8
+ s.version = "1.4.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc"]
12
- s.date = %q{2011-09-19}
12
+ s.date = %q{2011-09-20}
13
13
  s.description = %q{}
14
14
  s.email = %q{oleg@theworkinggroup.ca}
15
15
  s.extra_rdoc_files = [
@@ -123,6 +123,24 @@ class CmsAdmin::FilesControllerTest < ActionController::TestCase
123
123
  end
124
124
  end
125
125
 
126
+ def test_create_as_xhr_with_page_id
127
+ request.env['HTTP_X_FILE_NAME'] = 'test.pdf'
128
+ request.env['CONTENT_TYPE'] = 'application/pdf'
129
+
130
+ assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
131
+ xhr :post, :create, :site_id => cms_sites(:default), :file => {
132
+ :page_id => cms_pages(:default).id
133
+ }
134
+ assert_response :success
135
+
136
+ file = Cms::File.last
137
+ assert_equal 'test.pdf', file.file_file_name
138
+ assert_equal 1, file.categories.count
139
+ assert_equal '[page] /', file.categories.first.label
140
+ assert_equal 'Cms::File', file.categories.first.categorized_type
141
+ end
142
+ end
143
+
126
144
  def test_update
127
145
  file = cms_files(:default)
128
146
  put :update, :site_id => file.site, :id => file, :file => {
@@ -24,6 +24,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
24
24
  assert_equal '{{ cms:page:content:text }}', assigns(:layout).content
25
25
  assert_template :new
26
26
  assert_select "form[action=/cms-admin/sites/#{site.id}/layouts]"
27
+ assert_select "form[action='/cms-admin/sites/#{site.id}/files']"
27
28
  end
28
29
 
29
30
  def test_get_edit
@@ -33,6 +34,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
33
34
  assert assigns(:layout)
34
35
  assert_template :edit
35
36
  assert_select "form[action=/cms-admin/sites/#{layout.site.id}/layouts/#{layout.id}]"
37
+ assert_select "form[action='/cms-admin/sites/#{layout.site.id}/files?file[layout_id]=#{layout.id}']"
36
38
  end
37
39
 
38
40
  def test_get_edit_failure
@@ -43,6 +43,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
43
43
  assert_template :new
44
44
  assert_select "form[action=/cms-admin/sites/#{site.id}/pages]"
45
45
  assert_select "select[data-url=/cms-admin/sites/#{site.id}/pages/0/form_blocks]"
46
+ assert_select "form[action='/cms-admin/sites/#{site.id}/files']"
46
47
  end
47
48
 
48
49
  def test_get_new_with_field_datetime
@@ -124,6 +125,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
124
125
  assert_template :edit
125
126
  assert_select "form[action=/cms-admin/sites/#{page.site.id}/pages/#{page.id}]"
126
127
  assert_select "select[data-url=/cms-admin/sites/#{page.site.id}/pages/#{page.id}/form_blocks]"
128
+ assert_select "form[action='/cms-admin/sites/#{page.site.id}/files?file[page_id]=#{page.id}']"
127
129
  end
128
130
 
129
131
  def test_get_edit_failure
@@ -41,6 +41,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
41
41
  assert assigns(:snippet)
42
42
  assert_template :new
43
43
  assert_select "form[action=/cms-admin/sites/#{site.id}/snippets]"
44
+ assert_select "form[action='/cms-admin/sites/#{site.id}/files']"
44
45
  end
45
46
 
46
47
  def test_get_edit
@@ -50,6 +51,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
50
51
  assert assigns(:snippet)
51
52
  assert_template :edit
52
53
  assert_select "form[action=/cms-admin/sites/#{snippet.site.id}/snippets/#{snippet.id}]"
54
+ assert_select "form[action='/cms-admin/sites/#{snippet.site.id}/files?file[snippet_id]=#{snippet.id}']"
53
55
  end
54
56
 
55
57
  def test_get_edit_failure
@@ -25,6 +25,42 @@ class CmsFileTest < ActiveSupport::TestCase
25
25
  end
26
26
  end
27
27
 
28
+ def test_creation_with_layout_link
29
+ assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
30
+ file = cms_sites(:default).files.create(
31
+ :file => fixture_file_upload('files/valid_image.jpg'),
32
+ :layout_id => cms_layouts(:default)
33
+ )
34
+ assert_equal 1, file.categories.count
35
+ assert_equal '[layout] default', file.categories.first.label
36
+ assert_equal 'Cms::File', file.categories.first.categorized_type
37
+ end
38
+ end
39
+
40
+ def test_creation_with_page_link
41
+ assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
42
+ file = cms_sites(:default).files.create(
43
+ :file => fixture_file_upload('files/valid_image.jpg'),
44
+ :page_id => cms_pages(:default)
45
+ )
46
+ assert_equal 1, file.categories.count
47
+ assert_equal '[page] /', file.categories.first.label
48
+ assert_equal 'Cms::File', file.categories.first.categorized_type
49
+ end
50
+ end
51
+
52
+ def test_creation_with_snippet_link
53
+ assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
54
+ file = cms_sites(:default).files.create(
55
+ :file => fixture_file_upload('files/valid_image.jpg'),
56
+ :snippet_id => cms_snippets(:default)
57
+ )
58
+ assert_equal 1, file.categories.count
59
+ assert_equal '[snippet] default', file.categories.first.label
60
+ assert_equal 'Cms::File', file.categories.first.categorized_type
61
+ end
62
+ end
63
+
28
64
  def test_create_failure
29
65
  assert_no_difference 'Cms::File.count' do
30
66
  cms_sites(:default).files.create(:file => '')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.13
4
+ version: 1.4.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-19 00:00:00.000000000 -04:00
13
+ date: 2011-09-20 00:00:00.000000000 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70312533718100 !ruby/object:Gem::Requirement
18
+ requirement: &70246633386860 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 3.0.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70312533718100
26
+ version_requirements: *70246633386860
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: active_link_to
29
- requirement: &70312533717260 !ruby/object:Gem::Requirement
29
+ requirement: &70246633385460 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70312533717260
37
+ version_requirements: *70246633385460
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: paperclip
40
- requirement: &70312533716220 !ruby/object:Gem::Requirement
40
+ requirement: &70246633384540 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: 2.3.14
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70312533716220
48
+ version_requirements: *70246633384540
49
49
  description: ''
50
50
  email: oleg@theworkinggroup.ca
51
51
  executables: []
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
349
349
  version: '0'
350
350
  segments:
351
351
  - 0
352
- hash: -3297284522108590513
352
+ hash: 3075297949995048561
353
353
  required_rubygems_version: !ruby/object:Gem::Requirement
354
354
  none: false
355
355
  requirements: