Added snippets + unit tests.
Hesham E
committed Aug 18, 2010
commit 0ae9df418e8a804baa343a0326e5ea5e9d5eaa7a
Showing 6
changed files with
47 additions
and 10 deletions
Gemfile
+3
-3
| @@ | @@ -25,6 +25,6 @@ gem 'sqlite3-ruby', :require => 'sqlite3' |
| # Bundle gems for the local environment. Make sure to | |
| # put test-only gems in this group so their generators | |
| # and rake tasks are available in development mode: | |
| - | # group :development, :test do |
| - | # gem 'webrat' |
| - | # end |
| + | group :test do |
| + | gem 'shoulda' |
| + | end |
app/models/cms_snippet.rb
+14
-0
| @@ | @@ -1,2 +1,16 @@ |
| class CmsSnippet < ActiveRecord::Base | |
| + | |
| + | # -- Validations ---------------------------------------------------------- |
| + | |
| + | validates :label, |
| + | :presence => true, |
| + | :uniqueness => true, |
| + | :format => { :with => /^\w[a-z0-9_-]*$/i } |
| + | |
| + | # -- Class Methods -------------------------------------------------------- |
| + | |
| + | def self.content_for(label) |
| + | (s = find_by_label(label)) ? s.content : '' |
| + | end |
| + | |
| end | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+12
-0
| @@ | @@ -1,20 +1,32 @@ |
| class CreateCms < ActiveRecord::Migration | |
| def self.up | |
| + | # -- Layouts ------------------------------------------------------------ |
| create_table :cms_layouts do |t| | |
| t.timestamps | |
| end | |
| + | # -- Pages -------------------------------------------------------------- |
| + | |
| create_table :cms_pages do |t| | |
| t.timestamps | |
| end | |
| + | # -- Blocks ------------------------------------------------------------- |
| + | |
| create_table :cms_blocks do |t| | |
| t.timestamps | |
| end | |
| + | # -- Snippets ----------------------------------------------------------- |
| + | |
| create_table :cms_snippets do |t| | |
| + | t.string :label |
| + | t.text :content |
| t.timestamps | |
| end | |
| + | add_index :cms_snippets, :label, :unique => true |
| + | |
| + | # -- Assets ------------------------------------------------------------- |
| create_table :cms_assets do |t| | |
| t.timestamps | |
test/fixtures/cms_snippets.yml
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | default: |
| + | label: default_snippet |
| + | content: snippet content |
| \ No newline at end of file | |
test/unit/cms_snippet_test.rb
+15
-3
| @@ | @@ -1,8 +1,20 @@ |
| require 'test_helper' | |
| class CmsSnippetTest < ActiveSupport::TestCase | |
| - | # Replace this with your real tests. |
| - | test "the truth" do |
| - | assert true |
| + | |
| + | # -- Validations ---------------------------------------------------------- |
| + | |
| + | should validate_presence_of(:label) |
| + | should validate_uniqueness_of(:label) |
| + | should_not allow_value("bogus label").for(:label) |
| + | should_not allow_value("bogus^").for(:label) |
| + | should allow_value("snippet-label").for(:label) |
| + | |
| + | # -- Class Methods -------------------------------------------------------- |
| + | |
| + | test "get snippet content" do |
| + | assert_equal cms_snippets(:default).content, CmsSnippet.content_for('default_snippet') |
| + | assert_equal '', CmsSnippet.content_for('nonexistent_snippet') |
| end | |
| + | |
| end | |
test/unit/helpers/cms_content_helper_test.rb
+0
-4
| @@ | @@ -1,4 +0,0 @@ |
| - | require 'test_helper' |
| - | |
| - | class CmsContentHelperTest < ActionView::TestCase |
| - | end |