Sha256: 06198e2a915a336ba8cce93fc79c9ce78da28865277f41566f89fcda15aac1a9

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')

class CategoryTest < ModelTestCase
  
  include DataCatalog

  before do
    @required = {
      :name => "Science & Technology"
    }
  end

  context "Category#new" do
    context "correct params" do
      before do
        @category = Category.new(@required)
      end
      
      test "should be valid" do
        assert_equal true, @category.valid?
      end
    end
    
    [:name].each do |missing|
      context "missing #{missing}" do
        before do
          @category = Category.new(@required.delete_if { |k, v| k == missing })
        end
        
        missing_key(:category, missing)
      end
    end
  end
  
  context "Category with 0 categorizations" do
    before do
      @category = Category.create(@required)
    end
    
    test "#sources should be empty" do
      assert_equal [], @category.sources
    end
  end
  
  context "Category with 3 categorizations" do
    before do
      @category = Category.create(@required)
      @sources = 3.times.map do |i|
        create_source(
          :title => "Source #{i}"
        )
      end
      @categorizations = 3.times.map do |i|
        create_categorization(
          :category_id => @category.id,
          :source_id   => @sources[i].id
        )
      end
    end
  
    test "#sources should have 3 categorizations" do
      categorizations = @category.categorizations
      assert_equal 3, categorizations.length
      categorizations.each do |categorization|
        assert_include categorization, @categorizations
      end
    end

    test "#sources should have 3 sources" do
      sources = @category.sources
      assert_equal 3, sources.length
      sources.each do |source|
        assert_include source, @sources
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinatra_resource-0.4.21 examples/datacatalog/test/models/category_test.rb