adding tests to check if proper form fields get rendered... still failing

Oleg committed Oct 04, 2010
commit 282d730db26e6c2f73da8cfcb49e38b0e076abfb
Showing 4 changed files with 79 additions and 18 deletions
app/models/cms_upload.rb +4 -12
@@ @@ -1,22 +1,18 @@
class CmsUpload < ActiveRecord::Base
# -- AR Extensions --------------------------------------------------------
-
has_attached_file :file,
:styles => { :thumb => '48x48>' }
before_post_process :image?
- # -- Validations ----------------------------------------------------------
+ # -- Relationships --------------------------------------------------------
+ belongs_to :cms_page
+ # -- Validations ----------------------------------------------------------
validates_attachment_presence :file
- # -- Relationships --------------------------------------------------------
-
- belongs_to :cms_page
-
# -- Instance Methods -----------------------------------------------------
-
def image?
!(file_content_type =~ /^image.*/).nil?
end
@@ @@ -33,11 +29,7 @@ class CmsUpload < ActiveRecord::Base
self.file.url(:thumb)
else
ext = self.file_file_name.split('.').last
- if FILE_ICONS.include?(ext)
- "cms/file_icons/#{ext}.png"
- else
- "cms/file_icons/_blank.png"
- end
+ FILE_ICONS.include?(ext) ? "cms/file_icons/#{ext}.png" : "cms/file_icons/_blank.png"
end
end
test/functional/cms_admin/pages_controller_test.rb +64 -2
@@ @@ -18,8 +18,70 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_template :new
assert_select 'form[action=/cms-admin/pages]'
- # assert_select "input[name='cms_page[cms_blocks_attributes][][label]']", 2
- # assert_select "input[name='cms_page[cms_blocks_attributes][][type]']", 2
+ end
+
+ def test_get_new_with_field_datetime
+ cms_layouts(:default).update_attribute(:content, '<cms:field:test_label:datetime>')
+ get :new
+ assert_select "input[type='datetime'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::FieldDateTime']"
+ end
+
+ def test_get_new_with_field_integer
+ cms_layouts(:default).update_attribute(:content, '<cms:field:test_label:integer>')
+ get :new
+ assert_select "input[type='number'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::FieldInteger']"
+ end
+
+ def test_get_new_with_field_string
+ cms_layouts(:default).update_attribute(:content, '<cms:field:test_label>')
+ get :new
+ assert_select "input[type='text'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::FieldString']"
+ end
+
+ def test_get_new_with_field_text
+ cms_layouts(:default).update_attribute(:content, '<cms:field:test_label:text>')
+ get :new
+ assert_select "textarea[name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::FieldText']"
+ end
+
+ def test_get_new_with_page_datetime
+ cms_layouts(:default).update_attribute(:content, '<cms:page:test_label:datetime>')
+ get :new
+ assert_select "input[type='datetime'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::PageDateTime']"
+ end
+
+ def test_get_new_with_page_integer
+ cms_layouts(:default).update_attribute(:content, '<cms:page:test_label:integer>')
+ get :new
+ assert_select "input[type='number'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::PageInteger']"
+ end
+
+ def test_get_new_with_page_string
+ cms_layouts(:default).update_attribute(:content, '<cms:page:test_label:string>')
+ get :new
+ assert_select "input[type='text'][name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::PageString']"
+ end
+
+ def test_get_new_with_page_text
+ cms_layouts(:default).update_attribute(:content, '<cms:page:test_label>')
+ get :new
+ assert_select "textarea[name='cms_page[cms_blocks_attributes][][content]']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][label]'][value='test_label']"
+ assert_select "input[type='hidden'][name='cms_page[cms_blocks_attributes][][type]'][value='CmsTag::PageText']"
end
def test_get_new_as_child_page
test/functional/cms_admin/snippets_controller_test.rb +1 -1
@@ @@ -49,7 +49,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
put :update, :id => snippet, :cms_snippet => {:label => ''}
assert_response :success
assert_template 'edit'
- assert_equal 'default_snippet', snippet.label
+ assert_equal 'default', snippet.label
end
def test_destroy
test/functional/cms_content_controller_test.rb +10 -3
@@ @@ -8,6 +8,10 @@ class CmsContentControllerTest < ActionController::TestCase
assert_response :success
end
+ def test_render_page_not_found
+ flunk 'TODO'
+ end
+
def test_render_css
get :render_css, :id => cms_layouts(:default)
assert_response :success
@@ @@ -15,6 +19,11 @@ class CmsContentControllerTest < ActionController::TestCase
assert_equal cms_layouts(:default).css, @response.body
end
+ def test_render_css_not_found
+ get :render_css, :id => 'bogus'
+ assert_response 404
+ end
+
def test_render_js
get :render_js, :id => cms_layouts(:default)
assert_response :success
@@ @@ -22,9 +31,7 @@ class CmsContentControllerTest < ActionController::TestCase
assert_equal cms_layouts(:default).js, @response.body
end
- def test_render_css_and_js_for_nonexistent_layout
- get :render_css, :id => 'bogus'
- assert_response 404
+ def test_render_js_not_found
get :render_js, :id => 'bogus'
assert_response 404
end