most of tests are ok
Oleg
committed Aug 18, 2011
commit 35b40f3d36ce207c374e28554cb31570faf5f0ea
Showing 8
changed files with
207 additions
and 26 deletions
app/assets/stylesheets/comfortable_mexican_sofa/content.css
+17
-16
| @@ | @@ -129,43 +129,44 @@ |
| text-decoration: blink; | |
| } | |
| /* -- Page Specific stuff ------------------------------------------------ */ | |
| - | .c_cms_admin_sites.a_index ul.list li .item .label, |
| - | .c_cms_admin_layouts.a_index ul.list li .item .label, |
| - | .c_cms_admin_snippets.a_index ul.list li .item .label { |
| + | #cms_body.c_cms_admin_sites.a_index ul.list li .item .label, |
| + | #cms_body.c_cms_admin_layouts.a_index ul.list li .item .label, |
| + | #cms_body.c_cms_admin_snippets.a_index ul.list li .item .label, |
| + | #cms_body.c_cms_admin_files.a_index ul.list li .item .label { |
| margin-left: 32px; | |
| } | |
| - | .c_cms_admin_layouts.a_index ul.list li .item .icon { |
| + | #cms_body.c_cms_admin_layouts.a_index ul.list li .item .icon { |
| background-image: url(/assets/comfortable_mexican_sofa/icon_layout.gif); | |
| } | |
| - | .c_cms_admin_snippets.a_index ul.list li .item .icon { |
| + | #cms_body.c_cms_admin_snippets.a_index ul.list li .item .icon { |
| background-image: url(/assets/comfortable_mexican_sofa/icon_snippet.gif); | |
| } | |
| /* -- Revisions ---------------------------------------------------------- */ | |
| - | .c_cms_admin_revisions.a_show .form_element.submit_element .value { |
| + | #cms_body.c_cms_admin_revisions.a_show .form_element.submit_element .value { |
| margin-left: 0px; | |
| } | |
| - | .c_cms_admin_revisions.a_show .current { |
| + | #cms_body.c_cms_admin_revisions.a_show .current { |
| width: 50%; | |
| float: left; | |
| } | |
| - | .c_cms_admin_revisions.a_show .versioned { |
| + | #cms_body.c_cms_admin_revisions.a_show .versioned { |
| width: 50%; | |
| float: right; | |
| } | |
| - | .c_cms_admin_revisions.a_show .title, |
| - | .c_cms_admin_revisions.a_show .content { |
| + | #cms_body.c_cms_admin_revisions.a_show .title, |
| + | #cms_body.c_cms_admin_revisions.a_show .content { |
| padding: 2px 5px; | |
| margin: 0px 3px; | |
| } | |
| - | .c_cms_admin_revisions.a_show .title { |
| + | #cms_body.c_cms_admin_revisions.a_show .title { |
| background: #f1f1f1; | |
| border-bottom: 2px solid #bbb; | |
| } | |
| - | .c_cms_admin_revisions.a_show .content { |
| + | #cms_body.c_cms_admin_revisions.a_show .content { |
| min-height: 16px; | |
| border: 1px dashed #f1f1f1; | |
| } | |
| - | .c_cms_admin_revisions.a_show .revisions a { |
| + | #cms_body.c_cms_admin_revisions.a_show .revisions a { |
| display: block; | |
| background-color: #252525; | |
| border-radius: 2px; | |
| @@ | @@ -174,10 +175,10 @@ |
| margin-bottom: 2px; | |
| color: #fff; | |
| } | |
| - | .c_cms_admin_revisions.a_show .revisions a:hover, |
| - | .c_cms_admin_revisions.a_show .revisions a.active { |
| + | #cms_body.c_cms_admin_revisions.a_show .revisions a:hover, |
| + | #cms_body.c_cms_admin_revisions.a_show .revisions a.active { |
| opacity: 1; | |
| } | |
| - | .c_cms_admin_revisions.a_show .revisions a:last-child { |
| + | #cms_body.c_cms_admin_revisions.a_show .revisions a:last-child { |
| margin-bottom: 0px; | |
| } | |
| \ No newline at end of file | |
app/controllers/cms_admin/files_controller.rb
+24
-5
| @@ | @@ -5,7 +5,8 @@ class CmsAdmin::FilesController < CmsAdmin::BaseController |
| before_filter :load_file, :only => [:edit, :update, :destroy] | |
| def index | |
| - | @files = @site.files |
| + | return redirect_to :action => :new if @site.files.count == 0 |
| + | @files = @site.files.all(:order => 'label') |
| end | |
| def new | |
| @@ | @@ -13,17 +14,34 @@ class CmsAdmin::FilesController < CmsAdmin::BaseController |
| end | |
| def create | |
| - | params[:file][:file].each do |file| |
| - | @site.files.create!(:file => file) |
| + | @file = @site.files.new |
| + | file_array = params[:file][:file] || [nil] |
| + | label = params[:file][:label] |
| + | |
| + | file_array.each_with_index do |file, i| |
| + | file_params = params[:file].merge(:file => file) |
| + | if file_array.size > 1 && file_params[:label].present? |
| + | label = file_params[:label] + " #{i + 1}" |
| + | end |
| + | @file = @site.files.create!(file_params.merge(:label => label)) |
| end | |
| flash[:notice] = I18n.t('cms.files.created') | |
| - | redirect_to :action => :index |
| + | redirect_to :action => :edit, :id => @file |
| rescue ActiveRecord::RecordInvalid | |
| flash.now[:error] = I18n.t('cms.files.creation_failure') | |
| render :action => :new | |
| end | |
| + | def update |
| + | @file.update_attributes!(params[:file]) |
| + | flash[:notice] = I18n.t('cms.files.updated') |
| + | redirect_to :action => :edit, :id => @file |
| + | rescue ActiveRecord::RecordInvalid |
| + | flash.now[:error] = I18n.t('cms.files.update_failure') |
| + | render :action => :edit |
| + | end |
| + | |
| def destroy | |
| @file.destroy | |
| flash[:notice] = I18n.t('cms.files.deleted') | |
| @@ | @@ -35,6 +53,7 @@ protected |
| def load_file | |
| @file = @site.files.find(params[:id]) | |
| rescue ActiveRecord::RecordNotFound | |
| - | render :nothing => true |
| + | flash[:error] = I18n.t('cms.files.not_found') |
| + | redirect_to :action => :index |
| end | |
| end | |
app/models/cms/file.rb
+12
-0
| @@ | @@ -12,4 +12,16 @@ class Cms::File < ActiveRecord::Base |
| validates :site_id, :presence => true | |
| validates_attachment_presence :file | |
| + | validates_uniqueness_of :file_file_name, |
| + | :scope => :site_id |
| + | |
| + | # -- Callbacks ------------------------------------------------------------ |
| + | before_save :assign_label |
| + | |
| + | protected |
| + | |
| + | def assign_label |
| + | self.label ||= self.file_file_name.gsub(/\.[^\.]*?$/, '').titleize |
| + | end |
| + | |
| end | |
app/views/cms_admin/files/_form.html.erb
+9
-1
| @@ | @@ -1,4 +1,12 @@ |
| - | <%= form.file_field :file, :multiple => true %> |
| + | <%= form.text_field :label %> |
| + | <% if @file.new_record? %> |
| + | <%= form.file_field :file, :multiple => true %> |
| + | <% else %> |
| + | <%= form.simple_field 'File', nil do %> |
| + | <%= link_to @file.file.url, @file.file.url, :target => '_blank' %> |
| + | <% end %> |
| + | <% end %> |
| + | <%= form.text_area :description %> |
| <%= form.simple_field nil, nil, :class => 'submit_element' do %> | |
| <%= form.submit t(@file.new_record?? '.create' : '.update'), :disable_builder => true %> | |
app/views/cms_admin/files/index.html.erb
+2
-2
| @@ | @@ -11,9 +11,9 @@ |
| <%= link_to t('.delete'), cms_admin_site_file_path(@site, file), :method => :delete, :confirm => t('.are_you_sure') %> | |
| </div> | |
| <div class='label'> | |
| - | <%= link_to file.file_file_name, edit_cms_admin_site_file_path(@site, file) %> |
| + | <%= link_to file.label, edit_cms_admin_site_file_path(@site, file) %> |
| <div class='sublabel'> | |
| - | <%= link_to file.file_file_name, edit_cms_admin_site_file_path(@site, file) %> |
| + | <%= link_to file.file_file_name, file.file.url, :target => '_blank' %> |
| </div> | |
| </div> | |
| </div> | |
config/locales/en.yml
+1
-1
| @@ | @@ -76,7 +76,7 @@ en: |
| not_found: Revision Not Found | |
| files: | |
| - | created: Files Uploaded |
| + | created: Files uploaded |
| creation_failure: Failed to upload files | |
| updated: File updated | |
| update_failure: Failed to update file | |
test/functional/cms_admin/files_controller_test.rb
+140
-0
| @@ | @@ -2,6 +2,146 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__)) |
| class CmsAdmin::FilesControllerTest < ActionController::TestCase | |
| + | def test_get_index |
| + | get :index, :site_id => cms_sites(:default) |
| + | assert_response :success |
| + | assert assigns(:files) |
| + | assert_template :index |
| + | end |
| + | |
| + | def test_get_index_with_no_files |
| + | Cms::File.delete_all |
| + | get :index, :site_id => cms_sites(:default) |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :new |
| + | end |
| + | |
| + | def test_get_new |
| + | site = cms_sites(:default) |
| + | get :new, :site_id => site |
| + | assert_response :success |
| + | assert assigns(:file) |
| + | assert_template :new |
| + | assert_select "form[action=/cms-admin/sites/#{site.id}/files]" |
| + | end |
| + | |
| + | def test_get_edit |
| + | file = cms_files(:default) |
| + | get :edit, :site_id => file.site, :id => file |
| + | assert_response :success |
| + | assert assigns(:file) |
| + | assert_template :edit |
| + | assert_select "form[action=/cms-admin/sites/#{file.site.id}/files/#{file.id}]" |
| + | end |
| + | |
| + | def test_get_edit_failure |
| + | get :edit, :site_id => cms_sites(:default), :id => 'not_found' |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'File not found', flash[:error] |
| + | end |
| + | |
| + | def test_create |
| + | assert_difference 'Cms::File.count' do |
| + | post :create, :site_id => cms_sites(:default), :file => { |
| + | :label => 'Test File', |
| + | :description => 'Test Description', |
| + | :file => [fixture_file_upload('files/valid_image.jpg')] |
| + | } |
| + | assert_response :redirect |
| + | file = Cms::File.last |
| + | assert_equal cms_sites(:default), file.site |
| + | assert_equal 'Test File', file.label |
| + | assert_equal 'Test Description', file.description |
| + | assert_redirected_to :action => :edit, :id => file |
| + | assert_equal 'Files uploaded', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_create_failure |
| + | assert_no_difference 'Cms::File.count' do |
| + | post :create, :site_id => cms_sites(:default), :file => { } |
| + | assert_response :success |
| + | assert_template :new |
| + | assert_equal 'Failed to upload files', flash[:error] |
| + | end |
| + | end |
| + | |
| + | def test_create_multiple |
| + | Cms::File.delete_all |
| + | |
| + | assert_difference 'Cms::File.count', 2 do |
| + | post :create, :site_id => cms_sites(:default), :file => { |
| + | :label => 'Test File', |
| + | :description => 'Test Description', |
| + | :file => [ |
| + | fixture_file_upload('files/valid_image.jpg'), |
| + | fixture_file_upload('files/invalid_file.gif') |
| + | ] |
| + | } |
| + | assert_response :redirect |
| + | file_a, file_b = Cms::File.all |
| + | assert_equal cms_sites(:default), file_a.site |
| + | |
| + | assert_equal 'valid_image.jpg', file_a.file_file_name |
| + | assert_equal 'invalid_file.gif', file_b.file_file_name |
| + | assert_equal 'Test File 1', file_a.label |
| + | assert_equal 'Test File 2', file_b.label |
| + | assert_equal 'Test Description', file_a.description |
| + | assert_equal 'Test Description', file_b.description |
| + | |
| + | assert_redirected_to :action => :edit, :id => file_b |
| + | assert_equal 'Files uploaded', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_create_as_xhr |
| + | flunk |
| + | end |
| + | |
| + | def test_create_failure_as_xhr |
| + | flunk |
| + | end |
| + | |
| + | def test_update |
| + | file = cms_files(:default) |
| + | put :update, :site_id => file.site, :id => file, :file => { |
| + | :label => 'New File', |
| + | :description => 'New Description' |
| + | } |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :edit, :site_id => file.site, :id => file |
| + | assert_equal 'File updated', flash[:notice] |
| + | file.reload |
| + | assert_equal 'New File', file.label |
| + | assert_equal 'New Description', file.description |
| + | end |
| + | |
| + | def test_update_failure |
| + | file = cms_files(:default) |
| + | put :update, :site_id => file.site, :id => file, :file => { |
| + | :file => nil |
| + | } |
| + | assert_response :success |
| + | assert_template :edit |
| + | file.reload |
| + | assert_not_equal nil, file.file |
| + | assert_equal 'Failed to update file', flash[:error] |
| + | end |
| + | |
| + | def test_destroy |
| + | assert_difference 'Cms::File.count', -1 do |
| + | delete :destroy, :site_id => cms_sites(:default), :id => cms_files(:default) |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'File deleted', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_destroy_as_xhr |
| + | flunk |
| + | end |
| + | |
| # def test_create | |
| # assert_difference 'Cms::File.count', 1 do | |
| # xhr :post, :create, :site_id => cms_sites(:default), :file => fixture_file_upload('files/valid_image.jpg') | |
test/unit/models/file_test.rb
+2
-1
| @@ | @@ -18,9 +18,10 @@ class CmsFileTest < ActiveSupport::TestCase |
| def test_create | |
| assert_difference 'Cms::File.count' do | |
| - | cms_sites(:default).files.create( |
| + | file = cms_sites(:default).files.create( |
| :file => fixture_file_upload('files/valid_image.jpg') | |
| ) | |
| + | assert_equal 'Valid Image', file.label |
| end | |
| end | |