page_file testing is done
Oleg
committed Sep 28, 2011
commit fd433d2e9b70743aee7d11b2a201d8e07723dbb6
Showing 11
changed files with
146 additions
and 40 deletions
.travis.yml
+2
-2
| @@ | @@ -6,8 +6,8 @@ rvm: |
| - ree | |
| # - jruby | |
| gemfile: | |
| - | - gemfiles/Gemfile.rails-3.0.x |
| - | - gemfiles/Gemfile.rails-3.1.x |
| + | - test/gemfiles/Gemfile.rails-3.0.x |
| + | - test/gemfiles/Gemfile.rails-3.1.x |
| notifications: | |
| recipients: | |
| - oleg@twg.ca | |
Gemfile
+3
-7
| @@ | @@ -1,14 +1,10 @@ |
| source 'http://rubygems.org' | |
| gem 'rails', '>=3.0.0' | |
| - | gem 'active_link_to', '>=1.0.0' |
| - | gem 'paperclip', '>=2.3.14' |
| - | |
| - | group :development do |
| - | # gem 'sqlite3' |
| - | end |
| + | gem 'active_link_to', '~>1.0.0' |
| + | gem 'paperclip', '~>2.4.2' |
| group :test do | |
| gem 'sqlite3' | |
| - | gem 'jeweler', '>=1.4.0' |
| + | gem 'jeweler' |
| end | |
app/models/cms/block.rb
+2
-1
| @@ | @@ -30,9 +30,10 @@ protected |
| temp_files = [self.content].flatten.select do |f| | |
| %w(ActionDispatch::Http::UploadedFile Rack::Test::UploadedFile).member?(f.class.name) | |
| end | |
| + | |
| # only accepting one file if it's PageFile. PageFiles will take all | |
| single_file = self.tag.is_a?(ComfortableMexicanSofa::Tag::PageFile) | |
| - | temp_files = [temp_files.first] if single_file |
| + | temp_files = [temp_files.first].compact if single_file |
| temp_files.each do |file| | |
| self.files.collect{|f| f.mark_for_destruction } if single_file | |
gemfiles/Gemfile.rails-3.0.x
+0
-14
| @@ | @@ -1,14 +0,0 @@ |
| - | source 'http://rubygems.org' |
| - | |
| - | gem 'rails', '3.0.10' |
| - | gem 'active_link_to', '>=1.0.0' |
| - | gem 'paperclip', '>=2.3.14' |
| - | |
| - | group :development do |
| - | # gem 'sqlite3' |
| - | end |
| - | |
| - | group :test do |
| - | gem 'sqlite3' |
| - | gem 'jeweler', '>=1.4.0' |
| - | end |
gemfiles/Gemfile.rails-3.1.x
+0
-14
| @@ | @@ -1,14 +0,0 @@ |
| - | source 'http://rubygems.org' |
| - | |
| - | gem 'rails', '3.1.0' |
| - | gem 'active_link_to', '>=1.0.0' |
| - | gem 'paperclip', '>=2.3.14' |
| - | |
| - | group :development do |
| - | # gem 'sqlite3' |
| - | end |
| - | |
| - | group :test do |
| - | gem 'sqlite3' |
| - | gem 'jeweler', '>=1.4.0' |
| - | end |
comfortable_mexican_sofa/tags/page_file.rb b/lib/comfortable_mexican_sofa/tags/page_file.rb
+23
-1
| @@ | @@ -16,7 +16,29 @@ class ComfortableMexicanSofa::Tag::PageFile |
| end | |
| def content | |
| - | # ... |
| + | block.files.first |
| + | end |
| + | |
| + | def render |
| + | if file = block.files.first |
| + | case self.type |
| + | when 'url' |
| + | file.file.url |
| + | when 'link' |
| + | text = params[1] || label |
| + | "<a href='#{file.file.url}' target='_blank'>#{text}</a>" |
| + | when 'image' |
| + | text = params[1] || label |
| + | "<img src='#{file.file.url}' alt='#{text}' />" |
| + | when 'partial' |
| + | path = params[1] || 'partials/page_file' |
| + | ps = (self.params[2..-1] || []).collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ') |
| + | ps = ps.present?? ", #{ps}" : '' |
| + | "<%= render :partial => '#{path}', :locals => {:identifier => #{file.id}#{ps}} %>" |
| + | end |
| + | else |
| + | '' |
| + | end |
| end | |
| end | |
| \ No newline at end of file | |
test/gemfiles/Gemfile.rails-3.0.x
+10
-0
| @@ | @@ -0,0 +1,10 @@ |
| + | source 'http://rubygems.org' |
| + | |
| + | gem 'rails', '~>3.0.10' |
| + | gem 'active_link_to', '~>1.0.0' |
| + | gem 'paperclip', '~>2.4.2' |
| + | |
| + | group :test do |
| + | gem 'sqlite3' |
| + | gem 'jeweler' |
| + | end |
test/gemfiles/Gemfile.rails-3.1.x
+10
-0
| @@ | @@ -0,0 +1,10 @@ |
| + | source 'http://rubygems.org' |
| + | |
| + | gem 'rails', '~>3.1.0' |
| + | gem 'active_link_to', '~>1.0.0' |
| + | gem 'paperclip', '~>2.4.2' |
| + | |
| + | group :test do |
| + | gem 'sqlite3' |
| + | gem 'jeweler' |
| + | end |
test/unit/models/block_test.rb
+1
-1
| @@ | @@ -99,7 +99,7 @@ class CmsBlockTest < ActiveSupport::TestCase |
| def test_creation_and_update_via_nested_attributes_with_files | |
| layout = cms_layouts(:default) | |
| - | layout.update_attribute(:content, '{{cms:page_file:files}}') |
| + | layout.update_attribute(:content, '{{cms:page_files:files}}') |
| page = nil | |
| assert_difference ['Cms::Page.count', 'Cms::Block.count'] do | |
test/unit/tags/page_file_test.rb
+78
-0
| @@ | @@ -0,0 +1,78 @@ |
| + | require File.expand_path('../../test_helper', File.dirname(__FILE__)) |
| + | |
| + | class PageFileTagTest < ActiveSupport::TestCase |
| + | |
| + | def test_initialize_tag |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag( |
| + | cms_pages(:default), '{{ cms:page_file:label }}' |
| + | ) |
| + | assert 'url', tag.type |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag( |
| + | cms_pages(:default), '{{ cms:page_file:label:partial }}' |
| + | ) |
| + | assert 'partial', tag.type |
| + | end |
| + | |
| + | def test_initialize_tag_failure |
| + | [ |
| + | '{{cms:page_file}}', |
| + | '{{cms:not_page_file:label}}', |
| + | '{not_a_tag}' |
| + | ].each do |tag_signature| |
| + | assert_nil ComfortableMexicanSofa::Tag::PageFile.initialize_tag( |
| + | cms_pages(:default), tag_signature |
| + | ) |
| + | end |
| + | end |
| + | |
| + | def test_content_and_render |
| + | page = cms_pages(:default) |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag( |
| + | page, '{{ cms:page_file:file }}' |
| + | ) |
| + | assert_equal nil, tag.content |
| + | assert_equal '', tag.render |
| + | |
| + | page.update_attributes!( |
| + | :blocks_attributes => [ |
| + | { :label => 'file', |
| + | :content => fixture_file_upload('files/valid_image.jpg') } |
| + | ] |
| + | ) |
| + | file = tag.block.files.first |
| + | timestamp = file.updated_at.to_f.to_i |
| + | |
| + | assert_equal file, tag.content |
| + | assert_equal "/system/files/#{file.id}/original/valid_image.jpg?#{timestamp}", tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:link }}') |
| + | assert_equal "<a href='/system/files/593363171/original/valid_image.jpg?#{timestamp}' target='_blank'>file</a>", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:link:link label }}') |
| + | assert_equal "<a href='/system/files/593363171/original/valid_image.jpg?#{timestamp}' target='_blank'>link label</a>", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:image }}') |
| + | assert_equal "<img src='/system/files/593363171/original/valid_image.jpg?#{timestamp}' alt='file' />", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:image:image alt }}') |
| + | assert_equal "<img src='/system/files/593363171/original/valid_image.jpg?#{timestamp}' alt='image alt' />", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial }}') |
| + | assert_equal "<%= render :partial => 'partials/page_file', :locals => {:identifier => #{file.id}} %>", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial:path/to/partial }}') |
| + | assert_equal "<%= render :partial => 'path/to/partial', :locals => {:identifier => #{file.id}} %>", |
| + | tag.render |
| + | |
| + | assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial:path/to/partial:a:b }}') |
| + | assert_equal "<%= render :partial => 'path/to/partial', :locals => {:identifier => #{file.id}, :param_1 => 'a', :param_2 => 'b'} %>", |
| + | tag.render |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
test/unit/tags/page_files_test.rb
+17
-0
| @@ | @@ -0,0 +1,17 @@ |
| + | require File.expand_path('../../test_helper', File.dirname(__FILE__)) |
| + | |
| + | class PageFilesTagTest < ActiveSupport::TestCase |
| + | |
| + | def test_initialize_tag |
| + | flunk |
| + | end |
| + | |
| + | def test_initialize_tag_failure |
| + | flunk |
| + | end |
| + | |
| + | def test_content_and_render |
| + | flunk |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |