Sha256: 4986280414d6e9ce87da59b5a9ca95ec42f440b17468b7386d648193f63ff3b5

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe Snippet do
  dataset :snippets
  test_helper :validations
  
  before :each do
    @original_filter = Radiant::Config['defaults.snippet.filter']
    @snippet = @model = Snippet.new(snippet_params)
  end

  after :each do
    Radiant::Config['defaults.snippet.filter'] = @original_filter
  end

  it "should take the filter from the default filter" do
    Radiant::Config['defaults.snippet.filter'] = "Textile"
    snippet = Snippet.new :name => 'new-snippet'
    snippet.filter_id.should == "Textile"
  end

  it "shouldn't override existing snippets filters with the default filter" do
    snippet = Snippet.find(:first, :conditions => {:filter_id => nil})
    Radiant::Config['defaults.snippet.filter'] = "Textile"
    snippet.reload
    snippet.filter_id.should_not == "Textile"
  end
  
  it 'should validate length of' do
    {
      :name => 100,
      :filter_id => 25
    }.each do |field, max|
      assert_invalid field, ('this must not be longer than %d characters' % max), 'x' * (max + 1)
      assert_valid field, 'x' * max
    end
  end
  
  it 'should validate presence of' do
    [:name].each do |field|
      assert_invalid field, 'this must not be blank', '', ' ', nil
    end
  end
  
  it 'should validate uniqueness of' do
    assert_invalid :name, 'this name is already in use', 'first', 'another', 'markdown'
    assert_valid :name, 'just-a-test'
  end
  
  it 'should validate format of name' do
    assert_valid :name, 'abc', 'abcd-efg', 'abcd_efg', 'abc.html', '/', '123'
    assert_invalid :name, 'cannot contain spaces or tabs'
  end
  
  it 'should allow the filter to be specified' do
    @snippet = snippets(:markdown)
    @snippet.filter.should be_kind_of(MarkdownFilter)
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
radiant-1.0.1 spec/models/snippet_spec.rb
radiant-snippets-extension-1.0.0 spec/models/snippet_spec.rb
radiant-1.0.0 spec/models/snippet_spec.rb
radiant-1.0.0.rc5 spec/models/snippet_spec.rb
radiant-1.0.0.rc4 spec/models/snippet_spec.rb
radiant-1.0.0.rc3 spec/models/snippet_spec.rb
radiant-1.0.0.rc2 spec/models/snippet_spec.rb
radiant-1.0.0.rc1 spec/models/snippet_spec.rb