Block#identifier instead of #label
Oleg
committed Dec 04, 2011
commit 1a2283e0194be9eec8879eb8845ad7115e1f00cc
Showing 22
changed files with
147 additions
and 149 deletions
app/controllers/cms_admin/revisions_controller.rb
+2
-2
| @@ | @@ -10,8 +10,8 @@ class CmsAdmin::RevisionsController < CmsAdmin::BaseController |
| def show | |
| case @record | |
| when Cms::Page | |
| - | @current_content = @record.blocks.inject({}){|c, b| c[b.label] = b.content; c } |
| - | @versioned_content = @record.blocks.inject({}){|c, b| c[b.label] = @revision.data['blocks_attributes'].detect{|r| r[:label] == b.label}.try(:[], :content); c } |
| + | @current_content = @record.blocks.inject({}){|c, b| c[b.identifier] = b.content; c } |
| + | @versioned_content = @record.blocks.inject({}){|c, b| c[b.identifier] = @revision.data['blocks_attributes'].detect{|r| r[:identifier] == b.identifier}.try(:[], :content); c } |
| else | |
| @current_content = @record.revision_fields.inject({}){|c, f| c[f] = @record.send(f); c } | |
| @versioned_content = @record.revision_fields.inject({}){|c, f| c[f] = @revision.data[f]; c } | |
app/models/cms/block.rb
+2
-2
| @@ | @@ -14,14 +14,14 @@ class Cms::Block < ActiveRecord::Base |
| before_save :prepare_files | |
| # -- Validations ---------------------------------------------------------- | |
| - | validates :label, |
| + | validates :identifier, |
| :presence => true, | |
| :uniqueness => { :scope => :page_id } | |
| # -- Instance Methods ----------------------------------------------------- | |
| # Tag object that is using this block | |
| def tag | |
| - | @tag ||= page.tags(true).detect{|t| t.is_cms_block? && t.label == label} |
| + | @tag ||= page.tags(true).detect{|t| t.is_cms_block? && t.label == identifier} |
| end | |
| protected | |
app/models/cms/page.rb
+7
-5
| @@ | @@ -70,22 +70,24 @@ class Cms::Page < ActiveRecord::Base |
| def blocks_attributes(was = false) | |
| self.blocks.collect do |block| | |
| block_attr = {} | |
| - | block_attr[:label] = block.label |
| - | block_attr[:content] = was ? block.content_was : block.content |
| + | block_attr[:identifier] = block.identifier |
| + | block_attr[:content] = was ? block.content_was : block.content |
| block_attr | |
| end | |
| end | |
| # Array of block hashes in the following format: | |
| # [ | |
| - | # { :label => 'block_1', :content => 'block content' }, |
| - | # { :label => 'block_2', :content => 'block content' } |
| + | # { :identifier => 'block_1', :content => 'block content' }, |
| + | # { :identifier => 'block_2', :content => 'block content' } |
| # ] | |
| def blocks_attributes=(block_hashes = []) | |
| block_hashes = block_hashes.values if block_hashes.is_a?(Hash) | |
| block_hashes.each do |block_hash| | |
| block_hash.symbolize_keys! unless block_hash.is_a?(HashWithIndifferentAccess) | |
| - | block = self.blocks.detect{|b| b.label == block_hash[:label]} || self.blocks.build(:label => block_hash[:label]) |
| + | block = |
| + | self.blocks.detect{|b| b.identifier == block_hash[:identifier]} || |
| + | self.blocks.build(:identifier => block_hash[:identifier]) |
| block.content = block_hash[:content] | |
| self.blocks_attributes_changed = self.blocks_attributes_changed || block.content_changed? | |
| end | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+3
-3
| @@ | @@ -50,12 +50,12 @@ class CreateCms < ActiveRecord::Migration |
| # -- Page Blocks -------------------------------------------------------- | |
| create_table :cms_blocks do |t| | |
| - | t.integer :page_id |
| - | t.string :label |
| + | t.integer :page_id, :null => false |
| + | t.string :identifier, :null => false |
| t.text :content | |
| t.timestamps | |
| end | |
| - | add_index :cms_blocks, [:page_id, :label] |
| + | add_index :cms_blocks, [:page_id, :identifier] |
| # -- Snippets ----------------------------------------------------------- | |
| create_table :cms_snippets do |t| | |
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+4
-4
| @@ | @@ -107,10 +107,10 @@ module ComfortableMexicanSofa::Fixtures |
| blocks_attributes = [ ] | |
| Dir.glob("#{path}/*.html").each do |file_path| | |
| if page.new_record? || File.mtime(file_path) > page.updated_at | |
| - | label = file_path.split('/').last.split('.').first |
| + | identifier = file_path.split('/').last.split('.').first |
| blocks_attributes << { | |
| - | :label => label, |
| - | :content => File.open(file_path, 'rb').read |
| + | :identifier => identifier, |
| + | :content => File.open(file_path, 'rb').read |
| } | |
| end | |
| end | |
| @@ | @@ -229,7 +229,7 @@ module ComfortableMexicanSofa::Fixtures |
| }.to_yaml) | |
| end | |
| page.blocks_attributes.each do |block| | |
| - | open(File.join(page_path, "#{block[:label]}.html"), 'w') do |f| |
| + | open(File.join(page_path, "#{block[:identifier]}.html"), 'w') do |f| |
| f.write(block[:content]) | |
| end | |
| end | |
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb
+2
-2
| @@ | @@ -81,7 +81,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder |
| else | |
| content << @template.send(method, "page[blocks_attributes][#{index}][content]", tag.content, :id => nil, :class => input_class) | |
| end | |
| - | content << @template.hidden_field_tag("page[blocks_attributes][#{index}][label]", tag.label, :id => nil) |
| + | content << @template.hidden_field_tag("page[blocks_attributes][#{index}][identifier]", tag.label, :id => nil) |
| simple_field(label, content, :class => css_class) | |
| end | |
| @@ | @@ -141,7 +141,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder |
| @template.options_for_select(options, :selected => tag.content), | |
| :id => nil | |
| ) | |
| - | content << @template.hidden_field_tag("page[blocks_attributes][#{index}][label]", tag.label, :id => nil) |
| + | content << @template.hidden_field_tag("page[blocks_attributes][#{index}][identifier]", tag.label, :id => nil) |
| simple_field(tag.label.titleize, content, :class => tag.class.to_s.demodulize.underscore ) | |
| end | |
comfortable_mexican_sofa/render_methods.rb b/lib/comfortable_mexican_sofa/render_methods.rb
+2
-2
| @@ | @@ -61,13 +61,13 @@ module ComfortableMexicanSofa::RenderMethods |
| cms_app_layout = @cms_layout.try(:app_layout) | |
| cms_page = @cms_site.pages.build(:layout => @cms_layout) | |
| cms_blocks = options.delete(:cms_blocks) || { :content => render_to_string(:layout => false)} | |
| - | cms_blocks.each do |block_label, value| |
| + | cms_blocks.each do |identifier, value| |
| content = if value.is_a?(Hash) | |
| render_to_string(value.keys.first.to_sym => value[value.keys.first], :layout => false) | |
| else | |
| value.to_s | |
| end | |
| - | cms_page.blocks.build(:label => block_label.to_s, :content => content) |
| + | cms_page.blocks.build(:identifier => identifier.to_s, :content => content) |
| end | |
| options[:layout] ||= cms_app_layout.blank?? nil : cms_app_layout | |
| options[:inline] = cms_page.content(true) | |
comfortable_mexican_sofa/tag.rb b/lib/comfortable_mexican_sofa/tag.rb
+2
-1
| @@ | @@ -73,7 +73,8 @@ module ComfortableMexicanSofa::Tag |
| # Find or initialize Cms::Block object | |
| def block | |
| - | page.blocks.detect{|b| b.label == self.label.to_s} || page.blocks.build(:label => self.label.to_s) |
| + | page.blocks.detect{|b| b.identifier == self.label.to_s} || |
| + | page.blocks.build(:identifier => self.label.to_s) |
| end | |
| # Checks if this tag is using Cms::Block | |
comfortable_mexican_sofa/view_methods.rb b/lib/comfortable_mexican_sofa/view_methods.rb
+2
-2
| @@ | @@ -32,9 +32,9 @@ module ComfortableMexicanSofa::ViewMethods |
| # Example: | |
| # cms_page_content(:left_column, CmsPage.first) | |
| # cms_page_content(:left_column) # if @cms_page is present | |
| - | def cms_page_content(block_label, page = nil) |
| + | def cms_page_content(identifier, page = nil) |
| return '' unless page ||= @cms_page | |
| - | return '' unless block = page.blocks.find_by_label(block_label) |
| + | return '' unless block = page.blocks.find_by_identifier(identifier) |
| render :inline => ComfortableMexicanSofa::Tag.process_content(page, block.content) | |
| end | |
| end | |
test/fixtures/cms/blocks.yml
+2
-2
| @@ | @@ -1,11 +1,11 @@ |
| default_field_text: | |
| page: default | |
| - | label: default_field_text |
| + | identifier: default_field_text |
| content: default_field_text_content | |
| default_page_text: | |
| page: default | |
| - | label: default_page_text |
| + | identifier: default_page_text |
| content: |- | |
| default_page_text_content_a | |
| {{cms:snippet:default}} | |
test/fixtures/cms/revisions.yml
+4
-4
| @@ | @@ -9,10 +9,10 @@ page: |
| record: default (Cms::Page) | |
| data: <%= { | |
| 'blocks_attributes' => [ | |
| - | { 'label' => 'default_page_text', |
| - | 'content' => 'revision page content' }, |
| - | { 'label' => 'default_field_text', |
| - | 'content' => 'revision field content'} |
| + | { 'identifier' => 'default_page_text', |
| + | 'content' => 'revision page content' }, |
| + | { 'identifier' => 'default_field_text', |
| + | 'content' => 'revision field content'} |
| ]}.to_yaml.inspect %> | |
| snippet: | |
test/functional/cms_admin/pages_controller_test.rb
+33
-34
| @@ | @@ -51,7 +51,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='text'][name='page[blocks_attributes][0][content]'][class='datetime']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_field_integer | |
| @@ | @@ -59,7 +59,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='number'][name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_field_string | |
| @@ | @@ -67,7 +67,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='text'][name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_field_text | |
| @@ | @@ -75,7 +75,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "textarea[name='page[blocks_attributes][0][content]'][class='code']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_datetime | |
| @@ | @@ -83,7 +83,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='text'][name='page[blocks_attributes][0][content]'][class='datetime']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_integer | |
| @@ | @@ -91,7 +91,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='number'][name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_string | |
| @@ | @@ -99,7 +99,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='text'][name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_text | |
| @@ | @@ -107,7 +107,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "textarea[name='page[blocks_attributes][0][content]'][class='code']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_file | |
| @@ | @@ -115,7 +115,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='file'][name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_page_files | |
| @@ | @@ -123,7 +123,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "input[type='file'][name='page[blocks_attributes][0][content][]'][multiple=multiple]" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_collection | |
| @@ | @@ -135,7 +135,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| assert_select "option[value='']", :html => '---- Select Cms/Snippet ----' | |
| assert_select "option[value='#{snippet.id}']", :html => snippet.label | |
| end | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='snippet']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='snippet']" |
| end | |
| def test_get_new_with_rich_page_text | |
| @@ | @@ -143,7 +143,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "textarea[name='page[blocks_attributes][0][content]'][class='rich_text']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| end | |
| def test_get_new_with_several_tag_fields | |
| @@ | @@ -151,9 +151,9 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "textarea[name='page[blocks_attributes][0][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='label_a']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='label_a']" |
| assert_select "textarea[name='page[blocks_attributes][1][content]']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][1][label]'][value='label_b']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][1][identifier]'][value='label_b']" |
| end | |
| def test_get_new_with_crashy_tag | |
| @@ | @@ -167,9 +167,9 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| get :new, :site_id => cms_sites(:default) | |
| assert_response :success | |
| assert_select "textarea[name='page[blocks_attributes][0][content]'][class='code']" | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][0][label]'][value='test_label']" |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][0][identifier]'][value='test_label']" |
| assert_select "textarea[name='page[blocks_attributes][1][content]'][class='code']", 0 | |
| - | assert_select "input[type='hidden'][name='page[blocks_attributes][1][label]'][value='test_label']", 0 |
| + | assert_select "input[type='hidden'][name='page[blocks_attributes][1][identifier]'][value='test_label']", 0 |
| end | |
| def test_get_new_as_child_page | |
| @@ | @@ -215,10 +215,10 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :layout_id => cms_layouts(:default).id, | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'content content' }, |
| - | { :label => 'default_field_text', |
| - | :content => 'title content' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'content content' }, |
| + | { :identifier => 'default_field_text', |
| + | :content => 'title content' } |
| ] | |
| }, :commit => 'Create Page' | |
| assert_response :redirect | |
| @@ | @@ -235,10 +235,10 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| post :create, :site_id => cms_sites(:default), :page => { | |
| :layout_id => cms_layouts(:default).id, | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'content content' }, |
| - | { :label => 'default_field_text', |
| - | :content => 'title content' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'content content' }, |
| + | { :identifier => 'default_field_text', |
| + | :content => 'title content' } |
| ] | |
| } | |
| assert_response :success | |
| @@ | @@ -271,10 +271,10 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| :label => 'Updated Label', | |
| :layout_id => cms_layouts(:nested).id, | |
| :blocks_attributes => [ | |
| - | { :label => 'content', |
| - | :content => 'new_page_text_content' }, |
| - | { :label => 'header', |
| - | :content => 'new_page_string_content' } |
| + | { :identifier => 'content', |
| + | :content => 'new_page_text_content' }, |
| + | { :identifier => 'header', |
| + | :content => 'new_page_string_content' } |
| ] | |
| } | |
| page.reload | |
| @@ | @@ -282,7 +282,7 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| assert_redirected_to :action => :edit, :id => page | |
| assert_equal 'Page updated', flash[:notice] | |
| assert_equal 'Updated Label', page.label | |
| - | assert_equal ['content', 'default_field_text', 'default_page_text', 'header'], page.blocks.collect{|b| b.label} |
| + | assert_equal ['content', 'default_field_text', 'default_page_text', 'header'], page.blocks.collect{|b| b.identifier} |
| end | |
| end | |
| @@ | @@ -341,8 +341,8 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :layout_id => layout.id, | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'preview content' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'preview content' } |
| ] | |
| } | |
| assert_response :success | |
| @@ | @@ -361,9 +361,8 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| put :update, :site_id => page.site, :preview => 'Preview', :id => page, :page => { | |
| :label => 'Updated Label', | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'preview content', |
| - | :id => cms_blocks(:default_page_text).id} |
| + | { :identifier => 'default_page_text', |
| + | :content => 'preview content' } |
| ] | |
| } | |
| assert_response :success | |
test/functional/cms_admin/revisions_controller_test.rb
+2
-2
| @@ | @@ -115,8 +115,8 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| page.reload | |
| assert_equal [ | |
| - | { :label => 'default_field_text', :content => 'revision field content' }, |
| - | { :label => 'default_page_text', :content => 'revision page content' } |
| + | { :identifier => 'default_field_text', :content => 'revision field content' }, |
| + | { :identifier => 'default_page_text', :content => 'revision page content' } |
| ], page.blocks_attributes | |
| end | |
| end | |
test/functional/cms_content_controller_test.rb
+6
-7
| @@ | @@ -51,9 +51,8 @@ class CmsContentControllerTest < ActionController::TestCase |
| :layout_id => cms_layouts(:default).id, | |
| :is_published => '1', | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :type => 'CmsTag::PageText', |
| - | :content => 'custom 404 page content' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'custom 404 page content' } |
| ] | |
| ) | |
| assert_equal '/404', page.full_path | |
| @@ | @@ -105,8 +104,8 @@ class CmsContentControllerTest < ActionController::TestCase |
| :layout_id => cms_layouts(:default).id, | |
| :is_published => '1', | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'text <%= 2 + 2 %> text' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'text <%= 2 + 2 %> text' } |
| ] | |
| ) | |
| get :render_html, :cms_path => 'irb' | |
| @@ | @@ -124,8 +123,8 @@ class CmsContentControllerTest < ActionController::TestCase |
| :layout_id => cms_layouts(:default).id, | |
| :is_published => '1', | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'text <%= 2 + 2 %> text' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'text <%= 2 + 2 %> text' } |
| ] | |
| ) | |
| get :render_html, :cms_path => 'irb' | |
test/integration/render_cms_test.rb
+2
-2
| @@ | @@ -10,7 +10,7 @@ class RenderCmsTest < ActionDispatch::IntegrationTest |
| end | |
| cms_layouts(:default).update_attribute(:content, '{{cms:page:content}}') | |
| cms_pages(:child).update_attribute(:blocks_attributes, [ | |
| - | { :label => 'content', :content => 'TestBlockContent' } |
| + | { :identifier => 'content', :content => 'TestBlockContent' } |
| ]) | |
| super | |
| end | |
| @@ | @@ -29,7 +29,7 @@ class RenderCmsTest < ActionDispatch::IntegrationTest |
| page = site.pages.create!( | |
| :label => 'default', | |
| :layout => layout, | |
| - | :blocks_attributes => [{ :label => 'content', :content => 'SiteBContent' }]) |
| + | :blocks_attributes => [{ :identifier => 'content', :content => 'SiteBContent' }]) |
| end | |
| class ::RenderTestController < ApplicationController | |
test/unit/models/block_test.rb
+27
-27
| @@ | @@ -24,14 +24,14 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => [ | |
| { | |
| - | :label => 'default_page_text', |
| - | :content => 'test_content' |
| + | :identifier => 'default_page_text', |
| + | :content => 'test_content' |
| } | |
| ] | |
| ) | |
| assert_equal 1, page.blocks.count | |
| block = page.blocks.first | |
| - | assert_equal 'default_page_text', block.label |
| + | assert_equal 'default_page_text', block.identifier |
| assert_equal 'test_content', block.content | |
| end | |
| end | |
| @@ | @@ -46,14 +46,14 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => { | |
| '0' => { | |
| - | :label => 'default_page_text', |
| - | :content => 'test_content' |
| + | :identifier => 'default_page_text', |
| + | :content => 'test_content' |
| } | |
| } | |
| ) | |
| assert_equal 1, page.blocks.count | |
| block = page.blocks.first | |
| - | assert_equal 'default_page_text', block.label |
| + | assert_equal 'default_page_text', block.identifier |
| assert_equal 'test_content', block.content | |
| end | |
| end | |
| @@ | @@ -68,18 +68,18 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => { | |
| '0' => { | |
| - | :label => 'default_page_text', |
| - | :content => 'test_content' |
| + | :identifier => 'default_page_text', |
| + | :content => 'test_content' |
| }, | |
| '1' => { | |
| - | :label => 'default_page_text', |
| - | :content => 'test_content' |
| + | :identifier => 'default_page_text', |
| + | :content => 'test_content' |
| } | |
| } | |
| ) | |
| assert_equal 1, page.blocks.count | |
| block = page.blocks.first | |
| - | assert_equal 'default_page_text', block.label |
| + | assert_equal 'default_page_text', block.identifier |
| assert_equal 'test_content', block.content | |
| end | |
| end | |
| @@ | @@ -97,13 +97,13 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :slug => 'test_page', | |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => [ | |
| - | { :label => 'file', |
| - | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/document.pdf')] } |
| + | { :identifier => 'file', |
| + | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/document.pdf')] } |
| ] | |
| ) | |
| assert_equal 1, page.blocks.count | |
| block = page.blocks.first | |
| - | assert_equal 'file', block.label |
| + | assert_equal 'file', block.identifier |
| assert_equal nil, block.content | |
| assert_equal 1, block.files.count | |
| assert_equal 'image.jpg', block.files.first.file_file_name | |
| @@ | @@ -115,8 +115,8 @@ class CmsBlockTest < ActiveSupport::TestCase |
| assert_no_difference ['Cms::Block.count', 'Cms::File.count'] do | |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'file', |
| - | :content => fixture_file_upload('files/document.pdf') } |
| + | { :identifier => 'file', |
| + | :content => fixture_file_upload('files/document.pdf') } |
| ] | |
| ) | |
| page.reload | |
| @@ | @@ -141,13 +141,13 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :slug => 'test_page', | |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => [ | |
| - | { :label => 'files', |
| - | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/image.gif')] } |
| + | { :identifier => 'files', |
| + | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/image.gif')] } |
| ] | |
| ) | |
| assert_equal 1, page.blocks.count | |
| block = page.blocks.first | |
| - | assert_equal 'files', block.label |
| + | assert_equal 'files', block.identifier |
| assert_equal nil, block.content | |
| assert_equal 2, block.files.count | |
| assert_equal ['image.jpg', 'image.gif'], block.files.collect(&:file_file_name) | |
| @@ | @@ -158,8 +158,8 @@ class CmsBlockTest < ActiveSupport::TestCase |
| assert_difference 'Cms::File.count', 2 do | |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'files', |
| - | :content => [fixture_file_upload('files/document.pdf'), fixture_file_upload('files/image.gif')] } |
| + | { :identifier => 'files', |
| + | :content => [fixture_file_upload('files/document.pdf'), fixture_file_upload('files/image.gif')] } |
| ] | |
| ) | |
| page.reload | |
| @@ | @@ -185,16 +185,16 @@ class CmsBlockTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :blocks_attributes => { | |
| '0' => { | |
| - | :label => 'header', |
| - | :content => 'header content' |
| + | :identifier => 'header', |
| + | :content => 'header content' |
| }, | |
| '1' => { | |
| - | :label => 'file', |
| - | :content => fixture_file_upload('files/document.pdf') |
| + | :identifier => 'file', |
| + | :content => fixture_file_upload('files/document.pdf') |
| }, | |
| '2' => { | |
| - | :label => 'footer', |
| - | :content => 'footer content' |
| + | :identifier => 'footer', |
| + | :content => 'footer content' |
| } | |
| } | |
| ) | |
test/unit/models/layout_test.rb
+10
-10
| @@ | @@ -90,10 +90,10 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| :layout_id => layout_1.id, | |
| :is_published => '1', | |
| :blocks_attributes => [ | |
| - | { :label => 'header', |
| - | :content => 'header_content' }, |
| - | { :label => 'content', |
| - | :content => 'content_content' } |
| + | { :identifier => 'header', |
| + | :content => 'header_content' }, |
| + | { :identifier => 'content', |
| + | :content => 'content_content' } |
| ] | |
| ) | |
| page_2 = cms_sites(:default).pages.create!( | |
| @@ | @@ -103,12 +103,12 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| :layout_id => layout_2.id, | |
| :is_published => '1', | |
| :blocks_attributes => [ | |
| - | { :label => 'header', |
| - | :content => 'header_content' }, |
| - | { :label => 'left_column', |
| - | :content => 'left_column_content' }, |
| - | { :label => 'right_column', |
| - | :content => 'left_column_content' } |
| + | { :identifier => 'header', |
| + | :content => 'header_content' }, |
| + | { :identifier => 'left_column', |
| + | :content => 'left_column_content' }, |
| + | { :identifier => 'right_column', |
| + | :content => 'left_column_content' } |
| ] | |
| ) | |
| assert_equal "header_content\ncontent_content", page_1.content | |
test/unit/models/page_test.rb
+3
-3
| @@ | @@ -62,8 +62,8 @@ class CmsPageTest < ActiveSupport::TestCase |
| :parent => cms_pages(:default), | |
| :layout => cms_layouts(:default), | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'test' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'test' } |
| ] | |
| ) | |
| assert page.is_published? | |
| @@ | @@ -165,7 +165,7 @@ class CmsPageTest < ActiveSupport::TestCase |
| def test_cms_blocks_attributes_accessor | |
| page = cms_pages(:default) | |
| assert_equal page.blocks.count, page.blocks_attributes.size | |
| - | assert_equal 'default_field_text', page.blocks_attributes.first[:label] |
| + | assert_equal 'default_field_text', page.blocks_attributes.first[:identifier] |
| assert_equal 'default_field_text_content', page.blocks_attributes.first[:content] | |
| end | |
test/unit/revisions_test.rb
+10
-10
| @@ | @@ -9,8 +9,8 @@ class RevisionsTest < ActiveSupport::TestCase |
| 'js' => 'revision js' }), cms_revisions(:layout).data | |
| assert_equal ({'blocks_attributes' => [ | |
| - | { 'label' => 'default_page_text', 'content' => 'revision page content' }, |
| - | { 'label' => 'default_field_text', 'content' => 'revision field content' } |
| + | { 'identifier' => 'default_page_text', 'content' => 'revision page content' }, |
| + | { 'identifier' => 'default_field_text', 'content' => 'revision field content' } |
| ]}), cms_revisions(:page).data | |
| assert_equal ({ | |
| @@ | @@ -59,8 +59,8 @@ class RevisionsTest < ActiveSupport::TestCase |
| assert_difference 'page.revisions.count' do | |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'default_page_text', |
| - | :content => 'new content' } |
| + | { :identifier => 'default_page_text', |
| + | :content => 'new content' } |
| ] | |
| ) | |
| page.reload | |
| @@ | @@ -68,10 +68,10 @@ class RevisionsTest < ActiveSupport::TestCase |
| revision = page.revisions.first | |
| assert_equal ({ | |
| 'blocks_attributes' => [ | |
| - | { :label => 'default_field_text', |
| - | :content => 'default_field_text_content' }, |
| - | { :label => 'default_page_text', |
| - | :content => "default_page_text_content_a\n{{cms:snippet:default}}\ndefault_page_text_content_b" }] |
| + | { :identifier => 'default_field_text', |
| + | :content => 'default_field_text_content' }, |
| + | { :identifier => 'default_page_text', |
| + | :content => "default_page_text_content_a\n{{cms:snippet:default}}\ndefault_page_text_content_b" }] |
| }), revision.data | |
| end | |
| end | |
| @@ | @@ -137,8 +137,8 @@ class RevisionsTest < ActiveSupport::TestCase |
| page.restore_from_revision(revision) | |
| page.reload | |
| assert_equal [ | |
| - | { :label => 'default_field_text', :content => 'revision field content' }, |
| - | { :label => 'default_page_text', :content => 'revision page content' } |
| + | { :identifier => 'default_field_text', :content => 'revision field content' }, |
| + | { :identifier => 'default_page_text', :content => 'revision page content' } |
| ], page.blocks_attributes | |
| end | |
| end | |
test/unit/tag_test.rb
+14
-17
| @@ | @@ -121,19 +121,16 @@ class TagTest < ActiveSupport::TestCase |
| assert page.tags.blank? | |
| page.blocks_attributes = [ | |
| { | |
| - | :label => 'default_field_text', |
| - | :content => 'new_default_field_content', |
| - | :type => 'CmsTag::FieldText' |
| + | :identifier => 'default_field_text', |
| + | :content => 'new_default_field_content' |
| }, | |
| { | |
| - | :label => 'default_page_text', |
| - | :content => "new_default_page_text_content\n{{cms:snippet:default}}", |
| - | :type => 'CmsTag::PageText' |
| + | :identifier => 'default_page_text', |
| + | :content => "new_default_page_text_content\n{{cms:snippet:default}}" |
| }, | |
| { | |
| - | :label => 'bogus_field_that_never_will_get_rendered', |
| - | :content => 'some_content_that_doesnot_matter', |
| - | :type => 'CmsTag::PageText' |
| + | :identifier => 'bogus_field_that_never_will_get_rendered', |
| + | :content => 'some_content_that_doesnot_matter' |
| } | |
| ] | |
| assert_equal 3, page.blocks.size | |
| @@ | @@ -237,10 +234,10 @@ class TagTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :layout_id => layout.id, | |
| :blocks_attributes => [ | |
| - | { :label => 'content', |
| - | :content => 'text {{ cms:snippet:no-irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }, |
| - | { :label => 'snippet', |
| - | :content => snippet.id } |
| + | { :identifier => 'content', |
| + | :content => 'text {{ cms:snippet:no-irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }, |
| + | { :identifier => 'snippet', |
| + | :content => snippet.id } |
| ] | |
| ) | |
| assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'partials/cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> <%= 1 + 1 %>", page.content | |
| @@ | @@ -263,10 +260,10 @@ class TagTest < ActiveSupport::TestCase |
| :parent_id => cms_pages(:default).id, | |
| :layout_id => layout.id, | |
| :blocks_attributes => [ | |
| - | { :label => 'content', |
| - | :content => 'text {{ cms:snippet:irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }, |
| - | { :label => 'snippet', |
| - | :content => snippet.id } |
| + | { :identifier => 'content', |
| + | :content => 'text {{ cms:snippet:irb-snippet }} {{ cms:partial:path/to }} {{ cms:helper:method }} text' }, |
| + | { :identifier => 'snippet', |
| + | :content => snippet.id } |
| ] | |
| ) | |
| assert_equal "<% 1 + 1 %> text <% 2 + 2 %> snippet <%= 2 + 2 %> <%= render :partial => 'path/to' %> <%= method() %> text <%= render :partial => 'partials/cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %> <%= 1 + 1 %>", page.content | |
test/unit/tags/page_file_test.rb
+4
-4
| @@ | @@ -47,8 +47,8 @@ class PageFileTagTest < ActiveSupport::TestCase |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'file', |
| - | :content => fixture_file_upload('files/image.jpg') } |
| + | { :identifier => 'file', |
| + | :content => fixture_file_upload('files/image.jpg') } |
| ] | |
| ) | |
| file = tag.block.files.first | |
| @@ | @@ -96,8 +96,8 @@ class PageFileTagTest < ActiveSupport::TestCase |
| assert_difference 'Cms::File.count' do | |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'file', |
| - | :content => fixture_file_upload('files/image.jpg') } |
| + | { :identifier => 'file', |
| + | :content => fixture_file_upload('files/image.jpg') } |
| ] | |
| ) | |
| file = Cms::File.last | |
test/unit/tags/page_files_test.rb
+4
-4
| @@ | @@ -47,8 +47,8 @@ class PageFilesTagTest < ActiveSupport::TestCase |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'files', |
| - | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/image.gif')] } |
| + | { :identifier => 'files', |
| + | :content => [fixture_file_upload('files/image.jpg'), fixture_file_upload('files/image.gif')] } |
| ] | |
| ) | |
| files = tag.block.files | |
| @@ | @@ -89,8 +89,8 @@ class PageFilesTagTest < ActiveSupport::TestCase |
| assert_difference 'Cms::File.count' do | |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| - | { :label => 'file', |
| - | :content => fixture_file_upload('files/image.jpg') } |
| + | { :identifier => 'file', |
| + | :content => fixture_file_upload('files/image.jpg') } |
| ] | |
| ) | |
| file = Cms::File.last | |