Sha256: 27ee0658c235381db8bdbd9b389cb9b543f971e51e9406b988f3abfe726bc548

Contents?: true

Size: 1.9 KB

Versions: 17

Compression:

Stored size: 1.9 KB

Contents

require 'spec/spec_helper'

describe ActiveYaml::Base do

  before do
    ActiveYaml::Base.set_root_path File.expand_path(File.dirname(__FILE__) + "/../fixtures")

    class ArrayRow < ActiveYaml::Base
    end

    class City < ActiveYaml::Base
    end

    class State < ActiveYaml::Base
    end
  end

  after do
    Object.send :remove_const, :ArrayRow
    Object.send :remove_const, :City
    Object.send :remove_const, :State
  end

  describe ".all" do

    context "before the file is loaded" do
      it "reads from the file" do
        State.all.should_not be_empty
        State.count.should > 0
      end
    end

  end

  describe ".delete_all" do
    context "when called before .all" do
      it "causes all to not load data" do
        State.delete_all
        State.all.should be_empty
      end
    end

    context "when called after .all" do
      it "clears out the data" do
        State.all.should_not be_empty
        State.delete_all
        State.all.should be_empty
      end
    end
  end

  describe ".raw_data" do

    it "returns the raw hash data loaded from yaml hash-formatted files" do
      City.raw_data.should be_kind_of(Hash)
      City.raw_data.keys.should include("albany", "portland")
    end

    it "returns the raw array data loaded from yaml array-formatted files" do
      ArrayRow.raw_data.should be_kind_of(Array)
    end

  end

  describe ".load_file" do

    describe "with array data" do
      it "returns an array of hashes" do
        ArrayRow.load_file.should be_kind_of(Array)
        ArrayRow.load_file.should include({"name" => "Row 1", "id" => 1})
      end
    end

    describe "with hash data" do
      it "returns an array of hashes" do
        City.load_file.should be_kind_of(Array)
        City.load_file.should include({"state" => :new_york, "name" => "Albany", "id" => 1})
        City.reload
        City.all.should include( City.new(:id => 1) )
      end
    end

  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
active_hash-0.8.7 spec/active_yaml/base_spec.rb
active_hash-0.8.6 spec/active_yaml/base_spec.rb
active_hash-0.8.5 spec/active_yaml/base_spec.rb
active_hash-0.8.4 spec/active_yaml/base_spec.rb
active_hash-0.8.3 spec/active_yaml/base_spec.rb
active_hash-0.8.2 spec/active_yaml/base_spec.rb
active_hash-0.8.1 spec/active_yaml/base_spec.rb
active_hash-0.8.0 spec/active_yaml/base_spec.rb
active_hash-0.7.9 spec/active_yaml/base_spec.rb
active_hash-0.7.8 spec/active_yaml/base_spec.rb
active_hash-0.7.7 spec/active_yaml/base_spec.rb
active_hash-0.7.6 spec/active_yaml/base_spec.rb
active_hash-0.7.5 spec/active_yaml/base_spec.rb
active_hash-0.7.4 spec/active_yaml/base_spec.rb
honkster-active_hash-0.7.3 spec/active_yaml/base_spec.rb
active_hash-0.7.3 spec/active_yaml/base_spec.rb
active_hash-0.7.2 spec/active_yaml/base_spec.rb