change load behaviour in a better engine way and add more tests

This commit is contained in:
2012-12-14 18:19:04 +01:00
parent 0d6aeea49a
commit 90fd490909
13 changed files with 146 additions and 61 deletions
+26 -1
View File
@@ -14,7 +14,32 @@ require 'bourbon'
module Cmtool
class Engine < ::Rails::Engine
isolate_namespace Cmtool
initializer "cmtool" do
initializer "cmtool.build_menu" do
Cmtool::Menu.register do
group label: :site do
title t('cmtool.menu.site.title')
resource_link Page, scope: Cmtool
resource_link Cmtool::Keyword
end
group label: :publications do
title t('cmtool.menu.publications.title')
resource_link Cmtool::News
resource_link Cmtool::Faq
resource_link Cmtool::Quote
end
group label: :forms do
title t('cmtool.menu.forms.title')
resource_link Cmtool::ContactForm
resource_link Cmtool::NewsletterSubscription
end
group label: :files do
title t('cmtool.menu.files.title')
resource_link Cmtool::Image
resource_link Cmtool::Directory
end
resource_link User, label: :users, scope: Cmtool
end
end
ActiveSupport.on_load(:action_view) do
require File.expand_path('../../../app/helpers/cmtool/application_helper', __FILE__)
+7
View File
@@ -22,6 +22,7 @@ module Cmtool
klass.validates :name, presence: true
klass.validates :locale, presence: true
klass.validate :parent_locale_match
# RELATIONS
klass.has_and_belongs_to_many :keywords, storing_keys: true, class_name: 'Cmtool::Keyword'
@@ -36,6 +37,12 @@ module Cmtool
def generate_name
name = self.class.generate_name(title)
end
private
def parent_locale_match
if parent.present?
errors.add(:locale, 'must be the same as the parent') unless parent.locale == locale
end
end
end
module ClassMethods
+1 -1
View File
@@ -1,3 +1,3 @@
module Cmtool
VERSION = "0.4.0"
VERSION = "0.5.0"
end