Sha256: 66b51afc6d9a463c586cfea0cf5f5ec23d5cabd783c9997efd541be354d0b231

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require 'test_helper'

class ActiveYamlTest < Test::Unit::TestCase
  
  ActiveYAML::RAILS_ROOT = 'test'
  require 'app/models/city.rb'
  require 'app/models/state.rb'
  
  context "class" do
    should "create find_all" do
      assert_respond_to City, :find_all
    end
    
    should "create first and last" do
      assert_respond_to City, :first
      assert_respond_to City, :last
    end
    
    should "create find_by methods for each attribute" do
      assert_respond_to City, :find_by_id
      assert_respond_to City, :find_by_display_name
      assert_respond_to City, :find_by_population
    end
    
    should "create find_all_by methods for each attribute" do
      assert_respond_to City, :find_all_by_id
      assert_respond_to City, :find_all_by_display_name
      assert_respond_to City, :find_all_by_population
    end
    
    should "support each" do
      assert_respond_to City, :each
    end
    
    should "be Enumerable" do
      assert_respond_to City, :any?
    end
    
    should "print out fields in to_s" do
      assert_equal "City(id, population, display_name)", City.to_s
    end
  end
  
  context "instance" do
    setup do 
      @i = City.first
    end
    
    should "create attribute accessors" do
      assert_respond_to @i, :id
      assert_respond_to @i, :display_name
      assert_respond_to @i, :population
    end
  end

  context "data" do
    should "load all records" do
      assert_equal 3, City.find_all.size
    end
    should "load fields" do
      nyc = City.find('NYC')
      assert_equal "New York", nyc.display_name
      assert_equal 8274527, nyc.population
    end
    should "not confuse records from different models" do
      assert_equal 3, City.find_all.size
      assert_equal 2, State.find_all.size
      assert_equal 3, City.find_all.size
    end
    should "support enumerable" do
      assert_equal 14951385, City.inject(0) { |a, c| a + c.population }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ascheink-active_yaml-0.0.4 test/active_yaml_test.rb
ascheink-active_yaml-0.0.5 test/active_yaml_test.rb
ascheink-active_yaml-0.0.6 test/active_yaml_test.rb