blowing away more stuff

Oleg committed Aug 27, 2010
commit 900226d6caa7c054dfafb0b539dde541ddfc4b20
Showing 17 changed files with 41 additions and 787 deletions
app/models/cms_layout.rb +8 -0
@@ @@ -1,5 +1,13 @@
class CmsLayout < ActiveRecord::Base
+ # -- Relationships --------------------------------------------------------
has_many :cms_pages, :dependent => :nullify
+ # -- Validations ----------------------------------------------------------
+ validates :label,
+ :presence => true,
+ :uniqueness => true
+ validates :content,
+ :presence => true
+
end
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb +3 -37
@@ @@ -1,39 +1,5 @@
- %w(
- cms_rails_extensions
- cms_acts_as_tree
- cms_tag
- cms_tags/block
- cms_tags/page_block
- cms_tags/snippet
- cms_tags/partial
- cms_tags/helper
- cms_form_builder
- engine
- ).each do |req|
- require File.join(File.dirname(__FILE__), 'comfortable_mexican_sofa', req)
- end
-
- ActiveSupport.on_load(:action_controller) do
- ActionController::Base.helper CmsHelper
- end
-
module ComfortableMexicanSofa
- class Config
- def self.cattr_accessor_with_default(name, value = nil)
- cattr_accessor name
- self.send("#{name}=", value) unless value === nil
- end
-
- cattr_accessor_with_default :http_auth_enabled, true
- cattr_accessor_with_default :http_auth_username, 'username'
- cattr_accessor_with_default :http_auth_password, 'password'
- cattr_accessor_with_default :cms_title
- cattr_accessor_with_default :additional_cms_tabs, { }
- cattr_accessor_with_default :extension_tabs, { }
- cattr_accessor_with_default :logo_path, '/images/cms/default-logo.png'
- end
-
- def self.config(&block)
- yield ComfortableMexicanSofa::Config
- end
+
+ # TODO
+
end
comfortable_mexican_sofa/cms_acts_as_tree.rb b/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb +0 -108
@@ @@ -1,108 +0,0 @@
- module ActiveRecord
- module Acts
- module Tree
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- # Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
- # association. This requires that you have a foreign key column, which by default is called +parent_id+.
- #
- # class Category < ActiveRecord::Base
- # acts_as_tree :order => "name"
- # end
- #
- # Example:
- # root
- # \_ child1
- # \_ subchild1
- # \_ subchild2
- #
- # root = Category.create("name" => "root")
- # child1 = root.children.create("name" => "child1")
- # subchild1 = child1.children.create("name" => "subchild1")
- #
- # root.parent # => nil
- # child1.parent # => root
- # root.children # => [child1]
- # root.children.first.children.first # => subchild1
- #
- # In addition to the parent and children associations, the following instance methods are added to the class
- # after calling <tt>acts_as_tree</tt>:
- # * <tt>siblings</tt> - Returns all the children of the parent, excluding the current node (<tt>[subchild2]</tt> when called on <tt>subchild1</tt>)
- # * <tt>self_and_siblings</tt> - Returns all the children of the parent, including the current node (<tt>[subchild1, subchild2]</tt> when called on <tt>subchild1</tt>)
- # * <tt>ancestors</tt> - Returns all the ancestors of the current node (<tt>[child1, root]</tt> when called on <tt>subchild2</tt>)
- # * <tt>root</tt> - Returns the root of the current node (<tt>root</tt> when called on <tt>subchild2</tt>)
- module ClassMethods
- # Configuration options are:
- #
- # * <tt>foreign_key</tt> - specifies the column name to use for tracking of the tree (default: +parent_id+)
- # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet.
- # * <tt>counter_cache</tt> - keeps a count in a +children_count+ column if set to +true+ (default: +false+).
- def acts_as_tree(options = {})
- configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil }
- configuration.update(options) if options.is_a?(Hash)
-
- belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
- has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy
-
- class_eval <<-EOV
- include ActiveRecord::Acts::Tree::InstanceMethods
-
- def self.roots
- find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
- end
-
- def self.root
- find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
- end
- EOV
- end
- end
-
- module InstanceMethods
- # Returns list of ancestors, starting from parent until root.
- #
- # subchild1.ancestors # => [child1, root]
- def ancestors
- node, nodes = self, []
- nodes << node = node.parent while node.parent
- nodes
- end
-
- # Returns all children and children of children
- def descendants
- nodes = []
- self.children.each do |c|
- nodes << c
- nodes << c.descendants
- end
- nodes.flatten
- end
-
- # Returns the root node of the tree.
- def root
- node = self
- node = node.parent while node.parent
- node
- end
-
- # Returns all siblings of the current node.
- #
- # subchild1.siblings # => [subchild2]
- def siblings
- self_and_siblings - [self]
- end
-
- # Returns all siblings and a reference to the current node.
- #
- # subchild1.self_and_siblings # => [subchild1, subchild2]
- def self_and_siblings
- parent ? parent.children : self.class.roots
- end
- end
- end
- end
- end
-
- ActiveRecord::Base.send :include, ActiveRecord::Acts::Tree
\ No newline at end of file
comfortable_mexican_sofa/cms_form_builder.rb b/lib/comfortable_mexican_sofa/cms_form_builder.rb +0 -165
@@ @@ -1,165 +0,0 @@
- class CmsFormBuilder < ActionView::Helpers::FormBuilder
-
- %w{ date_select text_field password_field text_area file_field}.each do |selector|
- src = <<-end_src
- def #{selector}(method, options = {})
- options.merge!(:size=> '') if #{%w{text_field password_field}.include?(selector)}
- standard_field('#{selector}', method, options) { super(method, options) }
- end
- end_src
- class_eval src, __FILE__, __LINE__
- end
-
- def standard_field(type, method, options={}, &block)
- description = options.delete(:desc)
- content = options.delete(:content)
- label = options[:label] || label_for(method, options)
- required = options.delete(:required)
-
- output = "<div class='form_element #{type}_element'>"
- if type != 'check_box'
- output << "<div class='label'>#{label}"
- output << "#{@template.content_tag(:span, '*', :class => 'required_ind') if required }"
- output << "</div>"
- end
- output << "<div class='value'>"
- output << "#{yield}#{content}"
- output << "#{error_messages_for(method)}"
- output << "#{description(description)}" if type != 'check_box'
- output << "</div>"
- output << "</div>"
-
- output.html_safe
- end
-
- def custom_element(label, content, options={})
- css_class = options[:css_class].blank? ? "text_field_element" : options[:css_class]
- errors = if options[:method_name]
- error_for(options.delete(:method_name))
- elsif options[:method_names]
- method_names = options.delete(:method_names)
- method_names.collect{|method_name| error_for(method_name)}.uniq.join(' ')
- end
- %{
- <div class='form_element #{css_class}'>
- <div class='label'>
- #{label}
- </div>
- <div class='value'>
- #{content}
- #{errors}
- #{description(options.delete(:desc))}
- </div>
- </div>
- }.html_safe
- end
-
- def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
- options[:content] = label_for(method, options)
- options[:label] = '&nbsp;'
- standard_field('check_box', method, options) { super(method, options, checked_value, unchecked_value) }
- end
-
- # Example Usage
- # form.radio_button :field_name, :foo_value
- # form.radio_button :gender, %w(Male Female)
- # form.radio_button :gender, [['Male','m'],['Female','f']]
- # form.radio_button :gender, {'Male' => 'm', 'Female' => 'f'}, :checked => 'f'
- def radio_button(method, tag_value, options = {})
- if tag_value.is_a? Hash
- tag_value_hash = tag_value
- tag_value = []
- tag_value_hash.each_pair do |label, value|
- tag_value << [label,value]
- end
- end
-
- if tag_value.is_a? Array
- checked_value = options.delete(:checked)
- radios = tag_value.collect do |choice|
- if choice.is_a? Array
- label, value = choice[0], choice[1]
- else
- label = value = choice
- end
-
- %(
- #{super(method,value,options.merge({:checked => (value == checked_value)}))}
- <label for='#{object_name}_#{method}_#{value.downcase}'>#{label}</label>
- ).html_safe
- end.join
-
- standard_field('radio_button', method, {:label => method.to_s.humanize}.merge(options)) { radios }
- else
- standard_field('radio_button', method, options) { super(method, tag_value, options = {}) }
- end
- end
-
- # Renders a jQuery UI datepicker on a text field
- def datepicker(method, options = {})
- text_field(method, ({'data-datepicker' => true}).merge(options))
- end
-
- def select(method, choices, options = {}, html_options = {})
- standard_field('select', method, options) { super(method, choices, options, html_options) }
- end
-
- def hidden_field(method, options = {}, html_options = {})
- super(method, options)
- end
-
- def submit(value, options={}, &block)
- cancel_link = @template.capture(&block) if block_given?
- cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : ''
- if options[:show_ajax_loader]
- options[:onclick] = "$(this).parent().next().css('display', 'block');$(this).parent().hide();"
- end
- out = @template.content_tag(:div, super(value, options) + cancel_link, :class => 'form_element submit_element')
- if options[:show_ajax_loader] === true
- options[:show_ajax_loader] = %{
- Sending.. <img src='/images/cms/spinner.gif' />
- }
- end
-
- if options[:show_ajax_loader]
- out << %{
- <div class="form_element submit_element" style="display:none">
- <div class="submit_ajax_loader">#{options[:show_ajax_loader]}</div>
- </div>
- }.html_safe
- end
- out.html_safe
- end
-
-
- def label_for(method, options)
- label = options.delete(:label) || method.to_s.titleize.capitalize
- "<label for=\"#{object_name}_#{method}\">#{label}</label>".html_safe
- end
-
- def description(description)
- "<div class='description'>#{description}</div>".html_safe unless description.nil?
- end
-
- def error_messages
- if @object && @object.errors.count > 0
- if @object.errors[:base].present?
- message = @object.errors[:base]
- else
- message = %(
- There were some problems submitting this form. <br/>
- Please correct all the highlighted fields and try again.
- ).html_safe
- end
- @template.content_tag(:div, message, :class => 'errorExplanation')
- end
- end
-
- def error_messages_for(method)
- if (!@object.nil? and @object.respond_to?(:errors) and errors = @object.errors[method] and errors.present?)
- "<div class='errors'>#{method.to_s.humanize} #{errors.is_a?(Array) ? errors.first : errors}</div>".html_safe
- else
- ''
- end
- end
- end
comfortable_mexican_sofa/cms_rails_extensions.rb b/lib/comfortable_mexican_sofa/cms_rails_extensions.rb +0 -12
@@ @@ -1,12 +0,0 @@
- class String
-
- # Converts string to something suitable to be used as an element id
- def idify
- self.strip.gsub(/\W/, '_').gsub(/\s|^_*|_*$/, '').squeeze('_')
- end
-
- # Converts a string to something usable as a url slug
- def slugify
- self.downcase.gsub(/\W|_/, ' ').strip.squeeze(' ').gsub(/\s/, '-')
- end
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag.rb b/lib/comfortable_mexican_sofa/cms_tag.rb +0 -108
@@ @@ -1,108 +0,0 @@
- module CmsTag
-
- class TagError < StandardError; end
-
- # Initializes all tags found in the provided content
- # Will ignore duplicate tags. Will use format definition of the first one.
- def self.parse_tags(*args)
- options = args.extract_options!
- content = args.first
-
- # bailing out if nothing was sent for parsing
- return [] if content.blank?
-
- tags = []
- CmsTag::Tag.subclasses.each do |tag|
- tags << tag.parse_tags(content).group_by{|s| s.split(':')[0...2].join(':')}.collect{|g, tag_signature| tag.new(tag_signature.first, options)}
- end
- tags.flatten
- end
-
- class Tag
- attr_accessor :tag_signature, :label, :view, :page
-
- # Returns tag type based on it's classname
- # CmsTag::MyAwesomeTag.tag_type => 'cms_my_awesome_tag'
- def self.tag_type
- 'cms_' + to_s.split('::').last.underscore
- end
-
- def tag_type
- self.class.tag_type
- end
-
- # regular expression that finds tag signature
- def self.regex
- 'tag regex not defined'
- end
-
- # regex needed for content substitution
- def regex
- 'tag regex not defined'
- end
-
- # Returns tag identifiers from passed content based on regex defined
- # for the particular tag
- def self.parse_tags(content)
- content.scan(regex).flatten
- end
-
- # order at which tags get replaced with their content during page rendering
- def self.render_priority
- 0
- end
-
- def self.has_form?
- false
- end
-
- def initialize(*args)
- options = args.extract_options!
- self.tag_signature = args.first
-
- # provides access to action view methods for rendering form elements
- if options[:view]
- unless options[:view].is_a?(ActionView::Base)
- raise TagError, "Expected ActionView::Base but got #{options[:view].class}"
- end
- self.view = options[:view]
- end
-
- # owner of the the tag
- if options[:page]
- unless options[:page].is_a?(CmsPage)
- raise TagError, "Expected CmsPage but got #{options[:page].class}"
- end
- self.page = options[:page]
- end
-
- tokens = self.tag_signature.split(':')
- self.label = tokens[1]
-
- assign_accessors
- end
-
- def assign_accessors
- # ... FIX: looks retarded
- end
-
- def form_label
- "Label Undefined!"
- end
-
- def form_input
- "Form Field Undefined!"
- end
-
- def content
- 'Undefined Tag'
- end
-
- # when cms_page renders its content this is what tag outputs on the page
- def render
- content
- end
-
- end
-
- end
comfortable_mexican_sofa/cms_tags/.partial.rb.swp b/lib/comfortable_mexican_sofa/cms_tags/.partial.rb.swp +0 -0
comfortable_mexican_sofa/cms_tags/block.rb b/lib/comfortable_mexican_sofa/cms_tags/block.rb +0 -117
@@ @@ -1,117 +0,0 @@
- class CmsTag::Block < CmsTag::Tag
-
- FORMAT = {
- :text => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20
- }
- },
- :string => {
- :db_column => :content_string,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_string]", tag.content
- }
- },
- :rich_text => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20,
- :class => 'richText'
- }
- },
- :code => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.content_tag :div, :class => 'codemirror' do
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20,
- :class => 'codeTextArea'
- end
- }
- },
- :integer => {
- :db_column => :content_integer,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_integer]", tag.content
- }
- },
- :boolean => {
- :db_column => :content_boolean,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.check_box_tag "cms_page[blocks][#{tag.label}][content_boolean]", tag.content
- }
- },
- :date => {
- :db_column => :content_datetime,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
- field.date_select :content_datetime, :default => tag.content
- end
- }
- },
- :time => {
- :db_column => :content_datetime,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
- field.datetime_select :content_datetime, :default => tag.content
- end
- }
- }
- }
-
- attr_accessor :format
-
- def self.regex
- /\{\{\s*?(cms_block:.*?)\s*?\}\}/
- end
-
- def regex
- /\{\{\s*?cms_block:#{Regexp.escape(label)}.*?\s*?\}\}/
- end
-
- def self.render_priority
- 1
- end
-
- def self.has_form?
- true
- end
-
- def assign_accessors
- tokens = self.tag_signature.split(':')
- self.label = tokens[1]
- self.format = tokens[2]
- end
-
- def form_label
- view.label_tag label.titleize
- end
-
- def form_input
- if FORMAT.has_key? self.format.to_sym
- FORMAT[self.format.to_sym][:form_output].call(self)
- else
- 'Unknown tag format'
- end
- end
-
- def content
- page && page.cms_block_content(self.label, FORMAT[self.format.to_sym][:db_column])
- end
-
- def render
- ''
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tags/helper.rb b/lib/comfortable_mexican_sofa/cms_tags/helper.rb +0 -3
@@ @@ -1,3 +0,0 @@
- class CmsTag::Helper < CmsTag::Tag
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tags/page_block.rb b/lib/comfortable_mexican_sofa/cms_tags/page_block.rb +0 -119
@@ @@ -1,119 +0,0 @@
- class CmsTag::PageBlock < CmsTag::Tag
-
- FORMAT = {
- :text => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20
- }
- },
- :rich_text => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20,
- :class => 'richText'
- }
- },
- :code => {
- :db_column => :content_text,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.content_tag :div, :class => 'codemirror' do
- tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
- :rows => 20,
- :class => 'codeTextArea'
- end
- }
- },
- :string => {
- :db_column => :content_string,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_string]", tag.content
- }
- },
- :integer => {
- :db_column => :content_integer,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_integer]", tag.content
- }
- },
- :boolean => {
- :db_column => :content_boolean,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.check_box_tag "cms_page[blocks][#{tag.label}][content_boolean]", tag.content
- }
- },
- :date => {
- :db_column => :content_datetime,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
- field.date_select :content_datetime, :default => tag.content
- end
- }
- },
- :time => {
- :db_column => :content_datetime,
- :description => '',
- :form_output => lambda { |tag|
- tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
- field.datetime_select :content_datetime, :default => tag.content
- end
- }
- }
- }
-
- attr_accessor :format
-
- def self.regex
- /\{\{\s*?(cms_page_block:.*?)\s*?\}\}/
- end
-
- def regex
- /\{\{\s*?cms_page_block:#{Regexp.escape(label)}.*?\s*?\}\}/
- end
-
- # this shold be the most important tag to render, but let's leave space
- # for some unforseen cases
- def self.render_priority
- 1
- end
-
- def self.has_form?
- true
- end
-
- def assign_accessors
- tokens = self.tag_signature.split(':')
- self.label = tokens[1]
- self.format = tokens[2]
- end
-
- def form_label
- view.label_tag label.titleize
- end
-
- def form_input
- if FORMAT.has_key? self.format.to_sym
- FORMAT[self.format.to_sym][:form_output].call(self)
- else
- 'Unknown tag format'
- end
- end
-
- def content
- page && page.cms_block_content(self.label, FORMAT[self.format.to_sym][:db_column])
- end
-
- def render
- content.to_s
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tags/partial.rb b/lib/comfortable_mexican_sofa/cms_tags/partial.rb +0 -19
@@ @@ -1,19 +0,0 @@
- class CmsTag::Partial < CmsTag::Tag
-
- def self.regex
- /\{\{\s*?(cms_partial:.*?)\s*?\}\}/
- end
-
- def self.render_priority
- 3
- end
-
- def regex
- /\{\{\s*?cms_partial:#{Regexp.escape(label)}\s*?\}\}/
- end
-
- def content
- "<%= render :partial => '#{self.label}' %>"
- end
-
- end
comfortable_mexican_sofa/cms_tags/snippet.rb b/lib/comfortable_mexican_sofa/cms_tags/snippet.rb +0 -19
@@ @@ -1,19 +0,0 @@
- class CmsTag::Snippet < CmsTag::Tag
-
- def self.regex
- /\{\{\s*?(cms_snippet:.*?)\s*?\}\}/
- end
-
- def self.render_priority
- 2
- end
-
- def regex
- /\{\{\s*?cms_snippet:#{Regexp.escape(label)}\s*?\}\}/
- end
-
- def render
- CmsSnippet.content_for(label)
- end
-
- end
comfortable_mexican_sofa/engine.rb b/lib/comfortable_mexican_sofa/engine.rb +0 -7
@@ @@ -1,7 +0,0 @@
- require 'comfortable_mexican_sofa'
- require 'rails'
-
- module ComfortableMexicanSofa
- class Engine < Rails::Engine
- end
- end
generators/cms_generator.rb b/lib/generators/cms_generator.rb +0 -65
@@ @@ -1,65 +0,0 @@
- require 'rails/generators'
- require 'rails/generators/migration'
-
- class CmsGenerator < Rails::Generators::Base
- include Rails::Generators::Migration
- include Thor::Actions
- source_root File.expand_path('../templates', __FILE__)
-
- def generate_migration
- empty_directory 'db/migrate'
- @cms_migration_number = 1
- %w(create_cms fix_children_count).each do |fix_migration|
- @cms_migration_number += 1
- begin
- migration_template "migrations/#{fix_migration}.rb", "db/migrate/#{fix_migration}.rb"
- rescue Rails::Generators::Error => e
- say_status :warning, "migration '#{fix_migration}' already exists - skipping", :red
- end
- end
- end
-
- def generate_stylesheets
- if defined?(Sass)
- sass_dir = Sass::Plugin.options[:template_location].gsub(Rails.root, '')
- directory "stylesheets", sass_dir.gsub(/^\//,'')
- else
- say_status :warning, "HAML/SASS not installed", :red
- end
- end
-
- def generate_javascript
- directory 'javascripts', 'public/javascripts/cms'
- end
-
- def generate_initializers
- directory 'initializers', 'config/initializers'
- end
-
- def generate_images
- directory 'images', 'public/images/cms'
- end
-
- def show_readme
- readme 'README'
- end
-
- # Implement the required interface for Rails::Generators::Migration.
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
- def self.next_migration_number(dirname)
- ret = nil
- if ActiveRecord::Base.timestamped_migrations
- ret = Time.now.utc.strftime("%Y%m%d%H%M%S")
- else
- ret = "%.3d" % (current_migration_number(dirname) + 1)
- end
-
- while (Dir.entries(dirname).detect {|f| f.match /^#{ret}_/})
- ret = (ret.to_i + 1).to_s
- end
-
- return ret
- end
-
- end
-
tasks/.gitkeep b/lib/tasks/.gitkeep +0 -0
test/test_helper.rb +20 -6
@@ @@ -1,16 +1,30 @@
- ENV["RAILS_ENV"] = "test"
+ ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
fixtures :all
+
+ # Example usage:
+ # assert_has_errors_on( @record, [:field_1, :field_2] )
+ # assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
+ def assert_has_errors_on(record, fields)
+ fields = [fields].flatten unless fields.is_a?(Hash)
+ fields.each do |field, message|
+ assert record.errors.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
+ if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
+ assert_not_nil record.errors[field].index(message)
+ elsif message
+ assert_equal message, record.errors[field]
+ end
+ end
+ end
+ end
- # Add more helper methods to be used by all tests here...
+ class ActionController::TestCase
+
def http_auth
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64('username:password')}"
end
+
end
test/unit/cms_layout_test.rb +10 -2
@@ @@ -2,8 +2,16 @@ require File.dirname(__FILE__) + '/../test_helper'
class CmsLayoutTest < ActiveSupport::TestCase
- def test_something
- flunk
+ def test_fixtures_validity
+ CmsLayout.all.each do |layout|
+ assert layout.valid?
+ end
+ end
+
+ def test_validations
+ layout = CmsLayout.create
+ assert layout.errors.present?
+ assert_has_errors_on layout, [:label, :content]
end
end